Consider a graphics system that has classes for various figures - rectangles, circles, squares, triangles, and so on. For example, a rectangle might have data members for height, width; a circle might have a radius, while a square and triangle might have only an edge length or three sides of the triangle, respectively. In a well-designed system, these would derive from a common class, GeometricObject.
You are to implement such a system. Square is a rectangle. You will create a derived class (Square) from the Rectangle class.
Figure: see image.
1. (The GeometricObject class) - Save two files individually: GeometricObject's specification file (header file) (GeometricObject.h) and implementation file (GeometricObject.cpp).
The based class has pure virtual functions for member functions getArea() and getPerimeter(). You will create all members and functions based on the above figure.
2. (The Rectangle class: is-a GeometricObject) - Based on the above figure to modify and create the Rectangle class.Save two files individually: Rectangle's specification file (header file) (Rectangle.h) and implementation file (Rectangle.cpp)
3. (The Circle class: is-a GeometricObject) - Based on the above figure to modify and create the Circle class. Save two files individually: Circle's specification file (header file) (Circle.h) and implementation file (Circle.cpp)
4. (The Triangle class: is-a GeometricObject) Design a class named Triangle that is derived from the GeometricObject. Save two files individually: Triangle's specification file (header file) (Triangle.h) and implementation file (Triangle.cpp)
The class is based on the following figure: see image.
5. (The Square class: is-a Rectangle) Design a class named Square that is derived from the Rectangle.
Save two files individually: Square's specification file (header file) (Square.h) and implementation file (Square.cpp)
The class contains the following:
After you have created these classes, create a driver program that demonstrates by asking the user to enter the information for a Circle object, a Square object, a Triangle object and a Rectangle object. Demonstrate that each object properly calculates and reports its area and perimeter.
The program that prompts the user to enter the choice from the menu. If the user chooses 1 for the Circle, then the program will also prompt for radius, color, and enter 1 or 0 to indicate whether the color is filled or not. The program should display the result with radius, diameter, area, and perimeter, color, true or false to indicate whether filled or not. All information will display with two decimal places. The program will be continuing to asking the user to quit or not. The program will continue run as long as until the user enters "5" for quitting. If not, it will be displayed the menu for the choice.
The program should include "Input Validation: Decide how the program should handle any illegal inputs". Display an error message if the user enters a number outside the range of 1 through 5 when selecting an item from the menu.
Exception handling for negative values of the circle's radius, the rectangle's width or height, the triangle's side, or any shape of geometric object.
The program should divide the program onto the different functions.
For example,
showMenu() will display the menu for the user to choose.
//Display the menu
void showMenu(); //see the below figure
1. Circle
2. Rectangle
3. Square
4. Triangle
5. Quit the program
Enter your choice: 1
A function for displaying a geometric object for polymorph:
void displayGeometricObject(const GeometricObject& g)
This function will perform polymorph for creating individual object and pass reference variable. This function is responsible for displaying all the information about the chosen GeometricObject on the console. It does polymorphically.
Hint: For the definition of the function:
GeometricObject* p = &g;
Circle* p1 = dynamic_cast< Circle* >(p);
cout << "The radius is << p1->getRadius() << endl;
The program's result is similar to the following figure: see image.