C++语言程序设计实验报告
Table(float r1,float gao){this->r1=r1,this->gao=gao;};
float GetR1(){return r1;}
float GetG(){return gao;}
private:
float r1;
float gao;
};
class Yuanzhuo:public Yuan,public Table
{
public:
Yuanzhuo(float r,float q,float g,char *y):Yuan(r),Table(q,g){strcpy(yanse,y);}
show(){cout<<yanse<<endl;}
private:
char y;
char yanse[30];
};
void main()
{
Yuanzhuo yz(1,1,1,"绿");
cout<<"圆桌的半径为: "<<yz.GetR()<<endl;
cout<<"圆桌的高度为: "<<yz.GetG()<<endl;
cout<<"圆桌的面积为: "<<yz.GetArea()<<endl;
cout<<"圆桌的颜色为: ";
yz.show();
}
结果:
选做题
实验任务:
设计一个基类,包括编号、姓名、住址及相关的成员函数,由它派生出学生类和教师类,并用一些数据进行测试。
分析:
本题中的xinxi类的类体重的指针及数组参考了前面作业中的结构,该题利用字符数组处理十分方便,最后在main函数中调用display函数,必须直接调用,而不能用cout,否则会在