Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need an abstract class called Shape with the protected member String shapeName

ID: 3693934 • Letter: I

Question

I need an abstract class called Shape with the protected member String shapeName. It should have two public abstract methods getArea and getVolume. Finally, it should contain a public String method called getName which returns the shapeName. You should create a Circle class, Square class, Rectangle class, Triangle class which extend the Shape class.

Each class should contain the necessary private variables. For example, a square has a side. The area and the volume can all be derived from the side value so the only private variable necessary for the square class is the side. The circle requires a radius. The triangle requires a base, length and a height. Finally, the rectangle requires length, height and width. The classes should also contain constructors and appropriate implementations of the two abstract methods getArea and the getVolume.

**Shape Calculator** Enter 1 for a Circle Enter 2 for a Square Enter 3 for a Rectangle Enter 4 for a Triangle Enter 5 to Exit

You should use a menu with a case/switch statement that allows the user to choose which shape they want. After the user enters their choice, ask them to enter the necessary information, perform the calculations and display the area and volume for the shape the user chose. The program should continue to allow the user to choose shapes and display the results until the user enters 5 to exit.

Triangle volume: length * base * height/3
Triangle area: base * height/2
Circle area: Math.PI * radius * radius
Circle volume: 4/3 * Math.PI * radius * radius * radius Square area: side * side

Square volume: side * side * side Rectangle area: length * width
Rectangle volume: length * width * height

Be sure to verify the user enters positive numbers and limit the display to 2 decimals. Any thoughts would be helpful . Getting errors on my output .

Explanation / Answer

Program:

#include "iostream"
#include "conio.h"
using namespace std;
class measure
{
   public:
       void shape(int r);
       void shape(int l,int b,int h);
       void shape(float t,int d,int e);
       void shape(long a);
       void shape(float c, long int g);
       void shape(double j,rs,s);
       void shape(float f);
};
void measure::shape(int r)
{
   cout<<"area of the circle is "<<3.14*r*r;
}
void measure::shape(int l,int b,int h)
{
   cout<<"area of the rectangle is"<<l*b*h;
}
void measure::shape(float t,int d,int e)
{
   cout<<"area of the triangle volume is"<<t*d*e*(1/3);
}
void measure::shape(float c, long int g)
{
   cout<<"Volume of the triangle area is "<<c*g*(1/2);
}
void measure::shape(double j)
{
   cout<<"Volume of the circle volume is "<<(4/3)*3.14*j*j*j;
}
void measure::shape( double rs double s )
{
   cout<<"Volume of the square volume is "<<s*s*rs
}
int main()
{
   int r,d,e,l,b;
   float t,c,h;
   int ch;
   double j,f;
   long int g;
   measure obj;
   cout<<" CALCULATION OF AREA AND VOLUME";
   cout<<" 1. area of circle";
   cout<<" 2. area of rectangle";
   cout<<" 3. area of triangle volume";
   cout<<" 4. Volume of the triangle";
cout<<" 5. Volume of the circle";
cout<<" 6. Volume of the square";
   cout<<" Enter a quit ";
   cin>>ch;
   switch(ch)
   {
       case 1:
           cout<<"enter the value of radius of the circle ";
           cin>>r;
           obj.shape(r);
           break;
       case 2:
           cout<<"enter the sides of rectangle ";
           cin>>l>>b>>h;
           obj.shape(l,b,h);
           break;
       case 3:
           cout<<"enter the sides of triangle ";
           cin>>t>>d>>e;
           obj.shape(0.5,t,d,e);
           break;
       case 4:
           cout<<" Enter the radius of the cone";
           cin>>c;
           cout<<" Enter the height of the cone";
           cin>>g;
           obj.shape(c,g);
           break;
       case 5:
           cout<<" Enter the circle volume";
           cin>>j;
           obj.shape(j);
           break;
       case 7:
           cout<<" Enter the volume of square";
           cin>>s,rs;
           obj.shape(s,rs);
           break;
       default:
           cout<<" The choice entered is a exit choice";
   }
   getch();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote