Assignment No.7 (Templates)
Assignment No.7 (Templates)
Assignment No.7 (Templates)
Assignment #7(13-01-2023)
Due Date: Before Coming Class (20-01-2023, 9:30 am)
Instructor: Dr. Javid ()
Note: The deadline is hard, late submission and copied solutions will
credit zero marks. It is an extra assignment. So solve it if you have missed
any of the earlier assignments. (Comment your program properly, write
down your Name, Registration No. at the top of .cpp file in comments. Take
care of indentation when writing program.). Demos will be held in last class.
No mark will be assigned without demos.
Task-1
Consider a class named Calculator that contains
Two data members i.e. num1 and num2
Make the class Calculator into a template and in this way, a user would be able to instantiate it
using different data types for the data members. In the main function, instantiate two objects of
Calculator class with data members of type integer and float, respectively and invoke all
functions of class Calculator.
Task-2
Create a class template for a class named GeneralStack that holds
In the main() function, create three objects with different data types of class GeneralStack and
test the functionality of member functions for various values of data members for these objects.
Task-3
Write a generic function minimum() that returns the value of the minimum
element in an array. The function arguments 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 data type i.e.
int, long, double.
Task-4
Write two generic functions (overloaded) named area(). Create function template
for the first area() function that it is able to receive the radius of a circle as its parameter
and returns area of circle as of same data type. Similarly, create function template for the
second area() function that it is able to receive two parameters as length and width of a
rectangle and returns the area of rectangle as of same data type.