exam7.cpp

来自「C++语言程序设计题典」· C++ 代码 · 共 36 行

CPP
36
字号
#include <iostream.h>
#include <string.h>
class circle
{
	double radius;
public:
	circle(double r) { radius=r; }
	double getarea() { return radius*radius*3.14; }
};
class table
{
	double height;
public:
	table(double h) { height=h; }
	double getheight() { return height; }
};
class roundtable : public table,public circle
{
	char *color;
public:
	roundtable(double h,double r,char c[]):circle(r),table(h)
	{
		color=new char[strlen(c)+1];
		strcpy(color,c);
	}
	char *getcolor() { return color; }
};
void main()
{
	roundtable rt(0.8,1.2,"黑色");
    cout << "圆桌属性数据:" << endl;
	cout << "  高度:" << rt.getheight() << "米" << endl;
	cout << "  面积:" << rt.getarea() << "平方米" << endl;
	cout << "  颜色:" << rt.getcolor() << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?