Question
C++ Develop a menu driven program to input the sides and calculate the perimeter and area of a triangle, square, rectangle, pentagon, and polygon. The
C++
Develop a menu driven program to input the sides and calculate the perimeter and area of a triangle, square, rectangle, pentagon, and polygon. The application should close on selecting the Exit option.
1. Define a C++ abstract class named shape. The class will have attributes for the sides of the shape. The class will also need the accessor method getSide that returns the sides of the shape. The class also needs one mutator method called setSides which will set the sides of the shape. The setSides method should return a Boolean value indicating if the set was successful or not and update the sides accordingly. (You cannot have a 0 or negative side.)
You will need to do the class declaration in a header(.h) file and the class implementation in the .cpp file.
Also add two more methods in the class namely getArea andgetPerimeter to calculate the area and perimeter of the shape. Define a method Display() for this class to print the sides of the shape on the screen.
2. Make this class generic so that the sides of the shape may be integer or float.
3. Use the abstract class shape to define TwoD shape and add all the functionalities to the methods.
Define the instances triangle, square and rectangle in the driver class to test the functionality of the TwoD class you have extended from the shapeclass.
4. Define a new class ThreeD extended from ThreeD class. The constructor of ThreeD class should call constructor of TwoD class, and also the print method should call the Display() of the super class. Override the functions getArea and getPerimeter to work with the new formula. The ThreeD class will represent instances of ThreeD class as a cube and a box.
Extend the driver program to display a menu to take user input for the figure user is selecting and display all details about that figure.
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