CS 127: Data Structures
Assignment 3: Shape Inheritance
Assigned on Friday, 9/28/01
Due on Wednesday, 10/3/01 at 5 PM.
Overview
This project will give you a chance to practice creating classes using
inheritance. Check out this program: shapesbad.cpp
. This program asks a user to select a shape of interest, namely a circle,
rectangle or square. It gets the dimensions from the user, then computes
the area and perimeter and displays it to the screen. The code for the
individual classes can be found at the links below:
Look now at the program shapesgood.cpp. Look
how much cleaner it is when inheritance is used! Your mission is to create
a single class called Shape, and derive the Circle, Rectangle, and Square
classes from it using inheritance. You should do so in such a way so that
without modification of shapesgood.cpp, your code can be
compiled as follows:
g++ Shape.cpp shapesgood.cpp -o shapesgood
You should submit only the files Shape.h and Shape.cpp. The Shape.h
and Shape.cpp files should contain the code for the class Shape as well
as for the derived classes Circle, Rectangle, and Square.
Good luck!