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: 3834218 • 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 .

Update the class hierarchycreated in assignment n as follows: For the shape class: Add a static data member caled count that kaeps track of the umber of shapes created. This data member should be updated when dass objects are estrayed. Also, add a static member function that returns the number of the dass shape. Make the shape class an abstract dass. For the drde class Add a constructor that can be used to initialize the name, color, and radius of an object of the dass ance. ngle claki. constructor that can be used initialie the name, color, height, and object of the class rectan Make display0 and calAreall functions virtual functiorris and use them to show polymorphism. for-oop or a while loop to alow a user to enter data for 10 program that uses a objects of class circle or dais rectangle. Uue an amav of pointers to the shape dais to store the data for these objects. once the user done entering the data, use a or a while-loop to display the contents of each object in the array.

Explanation / Answer

#include <iostream>

using namespace std;

// Base class
class Shape {

public:
// pure virtual function providing interface framework.
virtual int getArea() = 0;
  
   void setName(string n){
       name = n;
   }
   Shape(string n,string c){
       name =n;
       color=c;
   }
   string getName(){
       return name;
   }

   void setColor(string c){
       color = c;
   }
   string getColor(){
       return color;
   }
protected :
   string name;
   string color;
  
};

// Derived classes
class Rectangle: public Shape {

public:
   Rectangle(string n,string c,int h,int w)
   :Shape(n,c)
   {
       width = w;
       height = h;
   }

int getArea() {
return (width * height);
}
void setWidth(int w) {
width = w;
}
  
void setHeight(int h) {
height = h;
}
  
private:
int width;
int height;
};

// Derived classes
class Circle: public Shape {

public:
   Circle(string n,string c,int r)
   :Shape(n,c)
   {
       radius= r;
   }

int getArea() {
return (22/7)*radius*radius;
}
void setRadius(int r) {
radius= r;
}
  
  
private:
int radius;
};



int main(void) {
Rectangle* Rects[2];
Circle* circles[3];
   for(int i=0; i<2; i++){
       cout << "Enter height:";
       int h;
       cin >>h;
       cout << "Enter width:";
       int w;
       cin >> w;
       Rects[i] = new Rectangle("Rect","Red",h,w);
   }

for(int i=0; i<3; i++){
       cout << "Enter radius:";
       int r;
       cin >>r;
      
       circles[i] = new Circle("Rect","Red",r);
   }

   for(int i=0; i<2; i++){
       cout << "Area :"<<Rects[i]->getArea()<<endl;
      
   }
   for(int i=0; i<3; i++){
       cout << "Area :"<<circles[i]->getArea()<<endl;
   }
return 0;
}