Explore BrainMass
Share

A C++ example of classes and inheritance

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

Write a C++ program that uses 7 classes following a tree inheritance structure.

The base class must also have a virtual print() function that displays the class name.

Randomly assign print functions in three other classes that display the class name.

Create 7 pointers of the base class and have them point to all the classes.

Use the pointers to call print functions of all classes.

© BrainMass Inc. brainmass.com March 21, 2019, 7:49 pm ad1c9bdddf
https://brainmass.com/engineering/electrical-engineering/cplusplus-example-classes-inheritance-309594

Solution Preview

We will start by creating an inheritance structure where each class has two subclasses. The diagram looks like following:

A
/
B C
/ /
D E F G

The virtual ...

Solution Summary

This solution provides a simple example of class inheritance in C++. It also illustrates the difference between virtual and non-virtual overridden methods.

$2.19