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

Given the following Shape base class with a virtual function undefined Create a

ID: 3575528 • Letter: G

Question

Given the following Shape base class with a virtual function undefined Create a derived class called, Square, with the necessary attributes/Properties and virtual function from the base class Create a constructor with all the attributes and implement the virtual function Create an object and initialize the pointer variable, called myShape, Print the area using the shape object Change the property to your choice and print the area again #include using namespace std; class Shape {public: void printArea(); virtual double getArea()=0;}; void Shape::printArea(){cout

Explanation / Answer

#include <iostream>
#include <conio.h>

using namespace std;

// Base class
class Shape {
public:
       void printArea();
       virtual double getArea()=0;
   void setWidth(int w) {
width = w;
}
  
void setHeight(int h) {
height = h;
}

protected:
int width;
int height;
};

void Shape::printArea(){
   cout<<"Area"<<getArea();
}

// Derived class
class Square: public Shape {
public:
double getArea() {
return (width * height);
}
};

int main(void) {
Square sqr;
cout<<"CS|| lab final exam"<<endl;
sqr.setWidth(5);
sqr.setHeight(7);

// Print the area of the object.
cout << "Total area: " << sqr.getArea() << endl;
   getch();
return 0;
}

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