欢迎来到天天文库
浏览记录
ID:55514224
大小:37.00 KB
页数:10页
时间:2020-05-15
《实验11 继承与派生.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验十一继承与派生1实验目的:(1)理解继承的含义,掌握派生类的定义方法和实现;(2)理解公有继承下基类成员对派生类成员和派生类对象的可见性,能正确地访问继承层次中的各种类成员;(3)理解保护成员在继承中的作用,能够在适当的时候选择使用保护成员以便派生类成员可以访问基类的部分非公开的成员;实验内容:【一、读程序,写出结果,运用断点测试】1、指出并改正下面程序中的错误。#includeclassPoint{intx,y;public:Point(inta=0,intb=0){x=a;y=b;}voidmove(intxoffset,intyoffset){x
2、+=xoffset;y+=yoffset;}intgetx(){returnx;}intgety(){returny;}};classRectangle:protectedPoint{intlength,width;public:Rectangle(intx,inty,intl,intw):Point(x,y){length=l;width=w;}intgetlength(){returnlength;}intgetwidth(){returnwidth;}};voidmain(){Rectangler(0,0,8,4);r.move(23,56);cout<3、<","<classBase{inti;public:Base(intn){cout<<"Constuctingbaseclass"<4、ic:Derived(intn,intm,intp):Base(m),aa(p){cout<<"Constructingderivedclass"<classA{public:A(inti,intj){a=5、i;b=j;}voidMove(intx,inty){a+=x;b+=y;}voidShow(){cout<<"("<6、d.fun();d.Show();d.f1();}4、程序运行结果#includeclassobject{private:intWeight;public:object(){cout<<"构造object对象"<7、t<<"构造box对象"<classBaseClass{p
3、<","<classBase{inti;public:Base(intn){cout<<"Constuctingbaseclass"<4、ic:Derived(intn,intm,intp):Base(m),aa(p){cout<<"Constructingderivedclass"<classA{public:A(inti,intj){a=5、i;b=j;}voidMove(intx,inty){a+=x;b+=y;}voidShow(){cout<<"("<6、d.fun();d.Show();d.f1();}4、程序运行结果#includeclassobject{private:intWeight;public:object(){cout<<"构造object对象"<7、t<<"构造box对象"<classBaseClass{p
4、ic:Derived(intn,intm,intp):Base(m),aa(p){cout<<"Constructingderivedclass"<classA{public:A(inti,intj){a=
5、i;b=j;}voidMove(intx,inty){a+=x;b+=y;}voidShow(){cout<<"("<6、d.fun();d.Show();d.f1();}4、程序运行结果#includeclassobject{private:intWeight;public:object(){cout<<"构造object对象"<7、t<<"构造box对象"<classBaseClass{p
6、d.fun();d.Show();d.f1();}4、程序运行结果#includeclassobject{private:intWeight;public:object(){cout<<"构造object对象"<7、t<<"构造box对象"<classBaseClass{p
7、t<<"构造box对象"<classBaseClass{p
此文档下载收益归作者所有