Listed below are definitions of two classes that use inheritance, code fortheir implementation, and a main function. Put the code into appropriatefiles with the necessary include statements and...

Listed below are definitions of two classes that use inheritance, code fortheir implementation, and a main function. Put the code into appropriatefiles with the necessary include statements and preprocessor statements sothat the program compiles and runs. It should output “Circle has radius 2and area XXXXXXXXXX”.class Shape{ public:Shape();Shape(string name);string getName(); void setName(string newName); virtual doubleprivate:string name;};Shape::Shape(){name="";} Shape::Shape(string name){this->name = name;} string Shape::getName(){return this->name;}void Shape::setName(string newName){this->name = newName;} class Circle :public Shape{ public:Circle();Circle(int theRadius);void setRadius(int newRadius);double getRadius();virtual double getArea();private:int radius;};Circle::Circle() : Shape("Circle"), radius(0){ }Circle::Circle(int theRadius) : Shape("Circle"),radius(theRadius){ }void Circle::setRadius(int newRadius){this->radius = newRadius;} double Circle::getRadius(){ return radius;} double Circle::getArea(){ return XXXXXXXXXX *radius *radius;} int main(){Circle c(2);cout c.getRadius() c.getArea() return 0;}Add another class, Rectangle, that is also derived from the Shape class.Modify the Rectangle class appropriately so it has private width and heightvariables, a constructor that allows the user to set the width and height,functions to retrieve the width and height, and an appropriately definedgetArea function that calculates the area of the rectangle.The following code added to main should output “Rectangle has width 3has height 4 and area 12.0”.Rectangle r(3,4);cout r.getWidth() r.getHeight() r.getArea()



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here