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 .
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();
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.