Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Primarily using DEV C + + for doing coding. This is my code with correct output and the question is below the coding and the

Primarily using DEV C++ for doing coding.
This is my code with correct output and the question is below the coding and the sample output needed is given below.
#include
#include
using namespace std;
class Shapes
{
private:
int parameter1, parameter2;
public:
// Member function to accept inputs
void getParameters()
{
cout << "Enter the first parameter(length of a rectangle, or base of a triangle): ";
cin >> parameter1;
cout << "Enter the second parameter(height of a rectangle/triangle): ";
cin >> parameter2;
}
// Member function to calculate area of rectangle
void rectangleArea()
{
float area = parameter1* parameter2;
cout << "Area of rectangle: "<< area <<"."<< endl;
}
// Member function to calculate area of triangle
void triangleArea()
{
float area =0.5* parameter1* parameter2;
cout << "Area of triangle: "<< area <<"."<< endl;
}
};
int main()
{
// Create an object of the Shapes class
Shapes shapeObj;
// Call member function to accept inputs
shapeObj.getParameters();
// Use do-while loop
do
{
string choice;
// Read the shape choice from the user
cout << "Select shape ('R' for rectangle, and 'T' for triangle): ";
cin >> choice;
// If choice is 'R', then call rectangleArea() method
if (choice =="R")
{
shapeObj.rectangleArea();
}
// If choice is 'T', then call triangleArea() method
else if (choice =="T")
{
shapeObj.triangleArea();
}
// Else print Invalid message
else
{
cout << "Invalid choice." << endl;
}
} while (true); // Infinite loop, user can exit as per their choice
return 0;
}
QUESTION.
Implement a new derived class called ShapesExtend.[10marks]
- This class should inherit from the base class Shapes that you have designed before.
- In this class, implement additional methods to check for the input values. If the values are equal, and the choice for shape is a rectangle, then modify the output to Area of square is...
Sample Output:
Enter the first parameter (length of a rectangle, or base of a triangle): 8
Enter the second parameter (height of a rectangle/triangle): 8
Select shape (R for rectangle, and T for triangle): C Invalid choice.
Select shape (R for rectangle, and T for triangle): R
Area of the square is 64.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions