0% found this document useful (0 votes)
36 views

C++ Programming Problems: Kkwp1 Kkwp2 KKWWP

This document contains three C++ programming problems involving object-oriented concepts like inheritance, polymorphism, constructors, and operator overloading. The first problem involves defining classes for different shapes like circle, rectangle, sphere, etc. in an inheritance hierarchy with area() and volume() functions. It asks to calculate these values for different shapes using polymorphism. The second problem defines three classes with intake and name variables and a print() function. It asks to create constructors to initialize values and a function to call print() on the object with the highest intake. The third problem defines a Computer class with an integer array and asks to initialize the array with a suitable function. It asks to give new meaning to

Uploaded by

api-3728136
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

C++ Programming Problems: Kkwp1 Kkwp2 KKWWP

This document contains three C++ programming problems involving object-oriented concepts like inheritance, polymorphism, constructors, and operator overloading. The first problem involves defining classes for different shapes like circle, rectangle, sphere, etc. in an inheritance hierarchy with area() and volume() functions. It asks to calculate these values for different shapes using polymorphism. The second problem defines three classes with intake and name variables and a print() function. It asks to create constructors to initialize values and a function to call print() on the object with the highest intake. The third problem defines a Computer class with an integer array and asks to initialize the array with a suitable function. It asks to give new meaning to

Uploaded by

api-3728136
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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