Assignment 8: Polymorphic Data Types (20 points)

This short assignment covers inheritance and subtype polymorphism. For this project, you will create a series of classes to represent some simple geometric shapes and a small program to test your classes.

Files We Give You

None. You will write all of the files for this assignment including a suitable makefile.

Files You Must Write

For this assignment, you will need to write the following files:

This probably seems like a lot, but all four of the classes are quite small and highly similar to each other.

class Shape

Shape is an abstract base class.

Data Members

A Shape has the following private data member:

Member Functions

The Shape class must have the following public member functions:

class Circle

Circle is derived from Shape using public inheritance.

Data Members

A Circle has the following private data member:

Member Functions

The Circle class must have the following member functions:

class Rectangle

Rectangle is derived from Shape using public inheritance.

Data Members

A Rectangle has the following private data members:

Member Functions

The Rectangle class must have the following member functions:

class Triangle

Triangle is derived from Shape using public inheritance.

Data Members

A Triangle has the following private data members:

Member Functions

The Triangle class must have the following member functions:

Main Program

Write a main() function that does the following:

Output from your program must look like this:

Printing all shapes...

green [area 314.159], circle, radius 10
red [area 48], rectangle, height 8, width 6
yellow [area 16], triangle, height 8, base 4
black [area 20], triangle, height 4, base 10
orange [area 78.5398], circle, radius 5
blue [area 21], rectangle, height 3, width 7

Printing only circles...

green [area 314.159], circle, radius 10
orange [area 78.5398], circle, radius 5

Note that when grading your output, we will not require perfect whitespace match. We will use a diff command with the following parameters to check your output:

diff -w -a youroutput.txt answerkey.txt

Other Points