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

the questions has to be answered using IDE Visual Studio laNguage C++ OBJECT ORI

ID: 3834217 • Letter: T

Question

the questions has to be answered using IDE Visual Studio
laNguage C++ OBJECT ORIENTED PROGRAMMING
ALSO it would be appreciated if each step was explained in detail

follow the instructions as is please .


Create a class hierarchy as follows: The base is called shape and has the following data memberi 1. A private data member -name litringi tohold the name of the shape. 2. Aprivate data member-color (stringl to hold the color of the shape. 3. A public member function display that does not return anything but displays the characteristics of the shape Icolor, name, area, and other information as applicable based on the shape). 4. Apublic member function CatArea that returns double It calculates the area of the shape. For the class shape, this member function should dsplay an error message stating that the shape Create the following derived classes using public inheritance as follows 1. Aciree (derived from the inepe clask0 a Aprivate data member called radius (double) to hold the radius of the circle. b. A public member function called coorcumference which returns double and calculates the area of the drcke. rectangle Iderived from the shape class0 a Two private data members A public member function called Colperimeter which calculates the perimater of the create all necessary get" and "set functions to access the private data members. Also, redefine the member function display to produce appropriate messages based on the object type. The functon should display name,color, width, height area and perimeter for the dais ectangle and name, color adius, area, and circumference for the clakk circle. For the class shape, the function displays name and color. Also, redefine CoIAreo to calculate the area properly for each object type

Explanation / Answer

class Shape{
private:
string name;
string color;
public:
  
string getColor(){
return color;
}
  
void setColor(string c){
color = c;
}
  
void setName(string n){
name =n;
}
  
string getName(){
return name;
}
  
void display(){
cout<<" Name of the shape is: "<<name;
cout<<" color of the shape is: "<<color;
}
double calArea(){
cout<<"Shape is unknown "<<endl;
return 0;
}
};

class circle: public Shape{
private:
double radius;
public :
double calCircumference(){
return 2*3.14*radius;
}
  
double calArea(){
return 3.14*radius*radius;
}
      
       void display(){
cout<<" Name of the shape is: "<<getName();
cout<<" color of the shape is: "<<getColor();
           cout<<" Radius of the circle is: "<<getRadius();
           cout<<" Area of the circle is: "<<calArea();
           cout<<" Circumfrence of the circle is: "<<calCircumference();
}
      
       double getRadius(){
           return radius;
       }
      
       void setRadius(double r){
           radius = r;
       }
  
};


class rectangle: public Shape{
private:
int width;
int height;
public:
double calPerimeter(){
return 2*(getHeight() + getWidth());
}
  
void setWidth(int w){
width = w;
}
int getWidth(){
return width;
}
  
void setHeight(int h){
height = h;
}
  
int getHeight(){
return height;
}
  
double calArea(){
return (getWidth() * getHeight());
}
  
void display(){
cout<<" Name of the shape is: "<<getName();
cout<<" color of the shape is: "<<getColor();
           cout<<" Height of the rectangle is: "<<getHeight();
           cout<<" Width of the rectangle is: "<<getWidth();
           cout<<" Area of the rectangle is: "<<calArea();
           cout<<" Perimeter of the rectangle is: "<<calPerimeter();
}
  
};