欢迎来到天天文库
浏览记录
ID:58476439
大小:2.21 MB
页数:11页
时间:2020-05-15
《实验6 继与派生1.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、学号1207010103天津城建大学高级程序设计语言C++实验报告(实验名称)继承与派生学生姓名余祥班级成绩指导教师(签字)计算机与信息工程学院年月日实验六继承与派生(1)一、实验目的和要求1.学习定义和使用类的继承关系,定义派生类;2.掌握类派生,类的成员访问权限,派生类中构造和析构的次序;3.熟悉不同继承方式下对基类成员的访问控制;4.掌握初始化基类成员的方法;5.掌握多重继承和派生类的方法;二、实验内容和结果1.看程序给结果#includeusingnamespacestd;classA{public:voidset_XY(){cout<<"
2、Entertwonumbersofx,y:";cin>>x>>y;}voidget_XY(){cout<<"x="<>h;}intget_V(){returnv;}voidmake_V(
3、){make_S();v=get_S()*h;//使用基类数据成员x,y}protected:inth,v;};intmain(){Aa;Bb;Cc;cout<<"Itisobject_A:"<4、ndl;return0;}实验结果:2、程序改错题#includeusingnamespacestd;classA{protected:voidset_XY(){cout<<"Entertwonumbersofx,y:";cin>>x>>y;}voidget_XY(){cout<<"x="<5、tmain(){Bb;cout<<"Itisobject_B:"<usingnamespacestd;classA{public:voidset_XY(){cout<<"Entertwonumbersofx,y:";cin>>x>>y;}voidget_XY(){cout<<"x="<6、c:intget_S(){returns;}voidmake_S(){set_XY();s=x*y;//使用基类数据成员x,y}private:ints;};intmain(){Bb;cout<<"Itisobject_B:"<7、te:stringname;charsex;};源程序:公有继承:#include#includeusingnamespacestd;classPerson{public:voidintput(){cout<<"请输入姓名:"<>name;cout<<"性别:"<>sex;}voiddisplay();private:stringname;charsex;};classAdult:publicPerson{public:voidget();voiddisplay_1();pr
4、ndl;return0;}实验结果:2、程序改错题#includeusingnamespacestd;classA{protected:voidset_XY(){cout<<"Entertwonumbersofx,y:";cin>>x>>y;}voidget_XY(){cout<<"x="<5、tmain(){Bb;cout<<"Itisobject_B:"<usingnamespacestd;classA{public:voidset_XY(){cout<<"Entertwonumbersofx,y:";cin>>x>>y;}voidget_XY(){cout<<"x="<6、c:intget_S(){returns;}voidmake_S(){set_XY();s=x*y;//使用基类数据成员x,y}private:ints;};intmain(){Bb;cout<<"Itisobject_B:"<7、te:stringname;charsex;};源程序:公有继承:#include#includeusingnamespacestd;classPerson{public:voidintput(){cout<<"请输入姓名:"<>name;cout<<"性别:"<>sex;}voiddisplay();private:stringname;charsex;};classAdult:publicPerson{public:voidget();voiddisplay_1();pr
5、tmain(){Bb;cout<<"Itisobject_B:"<usingnamespacestd;classA{public:voidset_XY(){cout<<"Entertwonumbersofx,y:";cin>>x>>y;}voidget_XY(){cout<<"x="<6、c:intget_S(){returns;}voidmake_S(){set_XY();s=x*y;//使用基类数据成员x,y}private:ints;};intmain(){Bb;cout<<"Itisobject_B:"<7、te:stringname;charsex;};源程序:公有继承:#include#includeusingnamespacestd;classPerson{public:voidintput(){cout<<"请输入姓名:"<>name;cout<<"性别:"<>sex;}voiddisplay();private:stringname;charsex;};classAdult:publicPerson{public:voidget();voiddisplay_1();pr
6、c:intget_S(){returns;}voidmake_S(){set_XY();s=x*y;//使用基类数据成员x,y}private:ints;};intmain(){Bb;cout<<"Itisobject_B:"<7、te:stringname;charsex;};源程序:公有继承:#include#includeusingnamespacestd;classPerson{public:voidintput(){cout<<"请输入姓名:"<>name;cout<<"性别:"<>sex;}voiddisplay();private:stringname;charsex;};classAdult:publicPerson{public:voidget();voiddisplay_1();pr
7、te:stringname;charsex;};源程序:公有继承:#include#includeusingnamespacestd;classPerson{public:voidintput(){cout<<"请输入姓名:"<>name;cout<<"性别:"<>sex;}voiddisplay();private:stringname;charsex;};classAdult:publicPerson{public:voidget();voiddisplay_1();pr
此文档下载收益归作者所有