- 6
- 0
- 约2.2千字
- 约 9页
- 2021-01-11 发布于广东
- 举报
C++程序设计实践上机指导书;2;3;}
void show(){
coutID: IDendl; coutname: nameendl;;Course::show();
coutScore: scoreendl;
}
private:
float score;
};
void main(){
Student s1(0001,林维,S,21); s1.show();
coutendl;
Course c1(1001,高级语言程序设计,64); c1.show();
coutendl;
SelCourse sc1(9901,张帅,M,22,1002,面向对象程序设计C++,56,89); sc1.show();
}
;Point(int xx=0, int yy=0){ x=xx;
y=yy;
}
int getX() { return x; } int getY() { return y; }
void show() {cout(x,y)endl;} protected:
int x,y;
};
class Circle:virtual public Point{ public:
Circle(int xx=0,int yy=0,float r=1):Point(xx,yy){ radius=r;
}
int getR() {return radius;} void show(){
cout圆心坐标:; Point::show();
cout圆半径:radiusendl;
}
protected:
float radius;
};
class cylinder:public Circle{ public:
cylinder(int xx=0,int yy=0,float r=1,float h=2):Point(xx,yy),Circle(r){ height=h;
}
int getH() {return height;} void show(){
Circle::show();
cout圆柱体高度:heightendl;
}
private:
float height;
};
int main(){
Point p1(1,2);
p1.show();;coutendl;
Circle c1(2,2,3);
c1.show(); coutendl;
cylinder cy1; cy1.show();
system(pause); return 0;
}
不使用虚基类。如果circle类继承point,cylinder继承circle,并且在cylinder类中 Point(xx,yy),Circle(r)这样在构造函数中赋值就会报错“错误 1 error C2614: “cylinder”: 非法的成员初始化:“Point”不是基或成员”。修改办法一,将point 设置为虚基类,修改办法二,在cylinder构造函数中通过Circle(xx,yy,r)传值给point。 #include iostream
#include string using namespace std;
class Point { public:
Point(int xx=0, int yy=0){
x=xx;
y=yy;
}
int getX() { return x; }
int getY() { return y; }
void show() {cout(x,y)endl;} protected:
int x,y;
};
class Circle:public Point{ public: ;protected:
float radius;
};
class cylinder:public Circle{ public:
cylinder(int xx=0,int yy=0,float r=1,float h=2):Circle(xx,yy,r){
height=h;
}
int getH() {return height;}
void show(){
Circle::show();
cout圆柱体高度:heightendl;
}
private:
float height;
};
int main(){
Point p1(1,2);
p1.show();
coutendl;
Circle c1(2,2,3);
c1.show();
coutendl;
您可能关注的文档
最近下载
- 专业月嫂服务合同范本及注意细节.docx VIP
- 《煤化学》全套教学课件.pdf
- 铁路工程沉降变形观测作业指导书.docx VIP
- tsg zf001-2006 《安全阀安全技术监察规程》新.pdf VIP
- 2024年山东省淄博市高青县中考一模英语试题.docx VIP
- 2015款一汽大众高尔夫_汽车使用手册用户操作图示图解详解驾驶指南车主车辆说明书电子版.pdf
- 铁路工程沉降变形观测与评估技术2015年稿.pdf VIP
- JBL JBL专业 无线麦克风系统 VM200 用户手册.pdf
- 相贯体的投影与相贯线一相贯体及相贯线的概念相贯体两相交的立体相贯线相交立体表面的交线立体相贯三种情.ppt VIP
- 妊娠期心肺复苏中国急诊专家共识测试卷及答案.docx
原创力文档

文档评论(0)