Question
Using C++, write a program to calculate the area and perimeter of four simple plane figures: a rectangle, a circle, a square and a triangle.
Using C++, write a program to calculate the area and perimeter of four simple plane figures: a rectangle, a circle, a square and a triangle.
The program should begin by explaining itself to the user. It must then prompt the user for appropriate input (i.e: ask the user to select a rectangle, circle, square or triangle and then ask for necessary information based on the users selection). Next, the program must calculate and output the perimeter and area of the appropriate figure and then ask the user if he or she would like to find the perimeter and area of another figure.
We will assume all plane figures are measured in centimeters.
The program MUST take advantage of the concepts of Inheritance and Polymorphism.
A base class must be defined (you can call it whatever you like, but better has a meaningful name, such as PlaneFigure might be a good choice). Other classes (for example, Rectangle, Circle, Square and Triangle) must be derived from the PlaneFigure base class.
Also, two methods must be defined for the PlaneFigure class: perimeter and area. These methods are to be overridden for each derived class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started