You are on page 1of 2

C++ Programming Problems

1.

Shape

Circle Rectangle

float area( ) float area( )

Sphere Cone Cube

float volume( ) float volume( ) float volume( )

Observe the figure above. This inheritance hierarchy contains six different
classes with defined functions. Assume appropriate functions to input the
values. Apply run-time polymorphism to call area( ) and volume( ) function
from different classes to calculate area and volume of particular shape.
Prototype of area( ) and volume( ) must be same wherever it is defined.
Formulae:
Area: Circle: ∏ * radius2 Rectangle: length * width
3
Volume: Sphere: (4/3) * ∏ * r , Cone: (1/3) * ∏ * radius2 * height,
Cube: side3

2.

KKWP1 KKWP2 KKWWP


private: private: private:
int intake int intake int intake
char name[10] char name[10] char name[10]
public: public: public:
void print( ) void print( ) void print( )

Above three classes are defined with given variables and functions. Define
appropriate constructors to initialize the values. Create an independent function
which has objects of all three classes as arguments. This function will call the

-1-
print( ) function of particular object which has highest value of intake. The
print( ) function prints name and intake.

3.

Computer
private:
int array[10]

The class ‘Computer’ is defined with an integer array of 10 integers.


Assume suitable function to initialize this array. Give a new meaning for the
operator > to check which object has higher value of addition of array
elements. For example, ‘A’ and ‘B’ are two objects of ‘Computer’ the statement
A > B will find the addition of array elements for each object and display whose
value is larger.

-2-

You might also like