Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. Write a C++ program to create a class called COMPLEX and implement the
complex numbers by overloading +
addition of two
2. Write a C++ program to create a class STRING and implement the following operations.
Display the results after every operation by overloading the operator ==(To compare two strings),+(to
concatenate two strings
i) STRING s1=C-DAC
ii) STRING s2=Electronics City
(iii) STRING s3=s1+s2
3. Overload + operator to add two Box objects. Create a class Box with member functions
getVolume,setlength,setbreadth,setheight ,Add l,b,h of two box objects and find the volume of
resulting box object.
4. Write a C++ program to create a class called DATE. Accept two valid dates in the from of
dd/mm/yyyy. Implement the following operation by overloading the operator + & -.
i) no_of_days=d1- d2, where d1 and d2 are DATE objects, d1>=d2, no_of_days is an integer.
ii) d2=d1+no_of_days, where d1 is DATE object and no_of_days is an integer.
5. Write a C++ program to create a class MATRIX using two dimensional array of integers.
Implement the following operations by overloading the operator = = which checks the
compatibility of two matrices to be added and subtracted. Perform the addition and subtraction
by overloading the operators + and respectively.
Templates
1. Create a template class to store two numbers and inside the template class define a template function
to find maximum of stored numbers.Write a main() program that stores two integer and display the
maximum of two,store two double values and display their maximum.
2. Create a function called amax() that returns the value of the largest element in an array. The
arguments to the function should be the address of the array and its size. Make this function into a
template so it will work with an array of any numerical type. Write a main() program that applies this
function to arrays of various types.
3. Create a template class with arithmetic operations add,subtract,multiply.Use this template class to
add,subtract,multiply any data types
4. Write a class template to represent a generic vector. Include member functions to
perform the following tasks:
1) To create the vector.
2) To modify the value of a given element.
3) To multiply the vector by a scalar value.
4) To display the vector in the form (10, 20, 30,.....)
5. Create a function called swap that interchanges the values of two arguments sent to it.Make the
function into a template so it can be used with all numerical data types(char,int,float).Write a
main() program to exercise the function into several types.
6. Write a program to implement Stack class as template and store numbers of type float and int.
STL
1.Using count() algorithm to find how many elements in a container have a specified value and return
the number.{20,30,20,50,60,70}
2. Write a program using sort() algorithm to vector container containing array of words entered by the
user and display the contents of vector.Use push_back() to insert the words
3. Create a Student class with member data name,Student ID and create a multiset to hold pointers
to Student objects.Define the multiset with compare Students function object,so it will be sorted
automatically by name of students.define 10 students and put them in multiset and display
contents.Include two students with same name to verify that multiset stores multiple objects