c++程序(不是很难,由于时间紧迫,请高人帮忙!)
来源:百度知道 编辑:UC知道 时间:2024/05/20 06:01:20
用c++编写一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度,面积和颜色等数据
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
class Circle
{
double rad;
public:
Circle(double r)
{
rad = r;
}
};
class Table
{
char color[20];
double height;
public:
Table(double h, char* c)
{
strcpy(color, c);
height = h;
}
};
class RoundTable : public Circle, public Table
{
double rtRad, rtHeight;
char rtColor[20];
public:
RoundTable(double rad, double height, char* color)
: Circle(rad), Table(height, color)
{
rtRad = rad;
rtHeight = height;
strcpy(rtColor, color);
}
void Info()
{
printf("面积: %.2lf 高度: %.2lf 颜色: %s\n", rtRad * rtRad * 3.14, rtHeight, rtColor);
}
};
int main()
{
RoundTable roundTable(10, 20, "White"