Great Deal! Get Instant $25 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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...

1 answer below »
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()
Answered Same DayNov 20, 2021

Solution

Arun Shankar answered on Nov 21 2021
54 Votes
Shape.cpp
#include "Shape.h"
#include #include Default constructor
Shape::Shape() { name =""; }
Value constructor
Shape::Shape(string a) {name = a;}
string Shape::getName() {return name;}
void Shape::setName(string newName){name = newName;}
Default constructor for the circle class
Circle::Circle(): Shape("Circle"), radius(0){}
Value constructor for the circle class
Circle::Circle(int theRadius) : Shape("Circle"),radius(theRadius){}
Setter for the circle class
void Circle::setRadius(int newRadius)
{radius = newRadius;}
Getter for the circle class
double Circle::getRadius(){return radius;}
Compute area for the circle class
double Circle::getArea(){ return 3.14159 *radius *radius;}
Default constructor for the rectangle...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here