Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!