Sei sulla pagina 1di 3

Operator Overloading

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

with same key.


4. Fill an array with even numbers and set with odd numbers.Use the merge() algorithm to merge
these containers into vectors.Display the vector contents.
5. Sort an array of integers into descending order using sort function and greater<>() function
object.
6. Using for_each algorithm output an array of celsius values to farenheit values.
7. Create a vector of integer values.Using push_back() enter the following values into the vector
{2,6,8,12,13,15,17}Using insert() member function add the value 19 to 3rd position..Using
erase() member function erase the value from 6th position.Sort and display the resulting vector.
8. Create a map with keys student ID and values will be marks scored in exam .Create
a map with students names - { Mary,John,Amit,Isha,Anwar,Fathima} and marks {80,90,75,85,70,80} Write the program to output the corresponding mark of student when the
user types the name of student.
9. Copy elements from one array to another using reverse_copy algorithm.
10. Initialize a vector with values 1 3 7 8 9 .Using the binary_search algorithm search whether value
3,5 is present in the vector.
11. Initialize an array with 10 elements [1..10] Using accumulate function show that the 5+0+1+..10
=60 and 10*1*2*3*4=240
12. A table gives a list of car models and the number of units sold in each type in a specified
period.Write a program to store this table in a suitable container,and to display interactively the total
value of a particular model sold,given the unit cost of the model.
13. Write a program that accepts a shopping list of five items from the keyboard and stores them in a
vector.Extend the program to accomplish the following.
a. To delete a specified item in the list.
b. To add an item at a specified location
c. To add an item at the end
d. To print the contents of vector.
14.Write a program using find() algorithm to locate the position of a specified value in a sequence
container

Potrebbero piacerti anche