急!!!!求C++高手帮个忙
- 提问者网友:雾里闻花香
- 2021-05-22 21:05
- 五星知识达人网友:执傲
- 2021-05-22 21:26
#include<iostream>
#include<string>
using namespace std;
class Circle
{
public:
double radius;
Circle(double dr=0);
void setRadius(double);
double area();
};
Circle::Circle(double dr)
{
radius=dr;
}
void Circle::setRadius(double dr)
{
radius=dr;
}
double Circle::area()
{
return(3.1415926*radius*radius);
}
//--------------------------------------------------
class Table
{
public:
double height;
string colour;
double tarea;
public:
Table(double dh=0,string sc="black",double da=0);
void setHeight(double);
void setColour(string);
void setArea(double);
void showTable();
};
Table::Table(double dh,string sc,double da)
{
height=dh;
colour=sc;
tarea=da;
}
void Table::setHeight(double dh)
{
height=dh;
}
void Table::setColour(string sc)
{
colour=sc;
}
void Table::setArea(double da)
{
tarea=da;
}
void Table::showTable()
{
cout<<"the height of the table is:"<<height<<endl;
cout<<"the colour of the table is:"<<colour<<endl;
cout<<"the area of the table is:"<<tarea<<endl;
}
//--------------------------------------------------
class Roundtable:public Circle,public Table
{
public:
Roundtable(double dr=0,double dh=0,string sc="string");
void showTable();
};
Roundtable::Roundtable(double dr, double dh, string sc)
{
radius=dr;
height=dh;
colour=sc;
}
void Roundtable::showTable()
{
cout<<"the height of the roundtable is:"<<height<<endl;
cout<<"the colour of the roundtable is:"<<colour<<endl;
cout<<"the radius of the roundtable is:"<<radius<<endl;
cout<<"the area of the roundtable is:"<<area()<<endl;
}
//--------------------------------------------------
void main()
{
double height;
string colour;
Roundtable tab;
cout<<"please input the radius of the roundtable:";
cin>>tab.radius;
cout<<"please input the height of the roundtable:";
cin>>height;
tab.setHeight(height);
cout<<"please input the colour of the roundtable:";
cin>>colour;
tab.setColour(colour);
cout<<"-----------------------------------"<<endl;
tab.showTable();
}