You are on page 1of 2

Object Oriented Programming

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

A parameterized constructor to assign values to both data members


Four functions i.e. addition(), subtraction(), multiplication(), and division() to perform their
respective functions on data members and return result in double

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

 A single data member as an array named stack of size 50 to store certain


elements
 A constructor to initialize stack with value 0 or 0.0 at all its indexes
 Three member functions i.e. push(type) to add elements in the Stack, pop() to
remove elements from the stack, and currentStatus() to check whether the array
is filled or not. (A filled array is an array that has non-zero value at all of its
indexes).

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.

You might also like