Create a program with classes


Discuss thebelow:

Q: Write a C++ program with 4 classes called A,B,C and D. D should inherit C, C should inherit B and B should inherit A. All classes should have 1 data member of type int, 1 constructor and 1 function called print. The constructor should initialize the data member to a rand() value. The print function should display the data member on the screen.

In the main function, try to access the print functions using only an object of class D.

 

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Create a program with classes
Reference No:- TGS01937046

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)