Starting from:

$20

C++ Programming Homework 5

● Define a class hierarchy with the following structure. You get to pick the problem domain, and I suggest you try to pick something you might have found useful in a project you may have worked on or would like to work on in the future. Here are the details:
○ (20 points) Define an abstract base class (e.g., Shape) with one pure virtual
function (e.g., area). This class should describe an abstract category (example
a Shape). Be sure this class has a constructor and at least one data member.
○ (40 points) Derive three classes directly from your abstract base class and
make them concrete by providing implementations for the virtual function you
introduced in your abstract base class. The methods for each of these three
classes must actually behave differently from one another (example: Circle area
vs. Square area vs. Triangle area).
○ (20 points) Write one interesting polymorphic function that operates on any type
derived from your abstract base class. It should take a list (or array) of
instances of your abstract base class (e.g., Shape *) and call the virtual function
on each to do something interesting. Also, have each of these virtual functions
print something so you can see which is being called.
○ (20 points) Write a main program that builds a list (or array) of several
instances of each of your concrete classes, then pass this off to your
polymorphic function.

More products