永发信息网

急!!!!求C++高手帮个忙

答案:1  悬赏:30  手机版
解决时间 2021-05-23 02:26
  • 提问者网友:雾里闻花香
  • 2021-05-22 21:05
采用面向对象的程序编写一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度,面积和颜色等数据
最佳答案
  • 五星知识达人网友:执傲
  • 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();
}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯