Shape Hierarchy
In this assignment you will implement a simple class-hierarchy for
simple geometric shapes. This will help you hone your skills with
defining classes and using pure virtual functions. It will also help
you gain a hands-on understanding of some of the concepts of Object
Oriented Programming.
The Spec
Note: All class interfaces should be in their own .h files, all
implementations must be in their own .cc files, you need a program
called "main.cc", and a Makefile for the project.
You will be defining a parent class Shape which will have at
least the following methods (you are welcome to define more, if they
are useful you may receive extra credit.)
- double area()
- double perimeter()
- void printInstanceClassName()
- string instanceClassName()
printInstanceClassName should be the following method:
void Shape::printInstanceClassName()
{
std::cout <<
"The object on which this function was called is a" <<
"Shape instantiated as a " << instanceClassName() << "\r";
}
instanceClassName should return a string representing what the class
was declared as.
Deriving from Shape you should have two additional classes,
Round and Quadrilateral. At least one of these should
add additional methods to those provided by Shape (for example,
Quadrilateral could have bool isEquilateral()).
Deriving from Round should be Circle and Ellipse.
Deriving from Quadrilateral should be Rectangle and
Rhombus.
You need to implement (.cc files) Circle, Ellipse,
Rectangle and Rhombus.
Create a main program that instantiates several shapes (Circle
and Rhombus and so on) and tests them in functions written to
use class Shape. Does everything work as intended?
Hints
- The perimeter of an ellipse can be approximated with 2 * pi *
sqrt((a*a + b*b)/2.0)
- The area of an ellipse is pi * a * b
- You will want to have a handy reference for the syntax on virtual
and inheritance and such.
- All together you need to turn in the following files: Makefile,
shape.h, round.h, quadrilateral.h, ellipse.h, circle.h, rectangle.h,
rhombus.h, ellipse.cc, circle.cc, rectangle.cc, rhombus.cc, main.cc.