欢迎来到天天文库
浏览记录
ID:60779079
大小:58.50 KB
页数:10页
时间:2020-12-18
《c++程序分析题资料.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、精品好文档,推荐学习交流三程序分析题阅读以下程序,写出其运行结果。1.#includeusingnamespacestd;inta[10]={1,2,3,4,5,6,7,8,9,10};intfun(inti);voidmain(){inti,s=0;for(i=0;i<=10;i++){try{s=s+fun(i);}catch(int){cout<<"数组下标越界!"<=10)throwi;returna[i];}2.#inc
2、ludeusingnamespacestd;voidf();classT{public:T(){cout<<"constructor"<3、;}cout<<"mainfunction"<usingnamespacestd;classBclass{public:Bclass(inti,intj){x=i;y=j;}virtualintfun(){return0;}protected:intx,y;};classIclass:publicBclass{public:Iclass(inti,intj,intk):Bclass(i,j){z=4、k;}intfun(){return(x+y+z)/3;}private:intz;};voidmain(){Iclassobj(2,4,10);Bclassp1=obj;cout<fun()<usingnamespacestd;classBASE{public:virtualvoi5、dgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<6、dl;}};voidmain(){BASE*pb;Aobj1;Bobj2;pb=&obj1;pb->getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<7、;}};classA:publicBASE1,publicBASE2{public:A(inta,intb,intc,intd):BASE2(b),BASE1(c),b2(a),b1(d){cout<<"调用派生类A的构造函数:"<usingnamespacestd;classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i8、;b=j;c=k;}voidget(int&i,int&j,int&k)仅供学习与交流,如有侵权请联系网站删除谢谢10精品好文档,推荐学习交流{i=a;j=b;k=
3、;}cout<<"mainfunction"<usingnamespacestd;classBclass{public:Bclass(inti,intj){x=i;y=j;}virtualintfun(){return0;}protected:intx,y;};classIclass:publicBclass{public:Iclass(inti,intj,intk):Bclass(i,j){z=
4、k;}intfun(){return(x+y+z)/3;}private:intz;};voidmain(){Iclassobj(2,4,10);Bclassp1=obj;cout<fun()<usingnamespacestd;classBASE{public:virtualvoi
5、dgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<6、dl;}};voidmain(){BASE*pb;Aobj1;Bobj2;pb=&obj1;pb->getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<7、;}};classA:publicBASE1,publicBASE2{public:A(inta,intb,intc,intd):BASE2(b),BASE1(c),b2(a),b1(d){cout<<"调用派生类A的构造函数:"<usingnamespacestd;classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i8、;b=j;c=k;}voidget(int&i,int&j,int&k)仅供学习与交流,如有侵权请联系网站删除谢谢10精品好文档,推荐学习交流{i=a;j=b;k=
6、dl;}};voidmain(){BASE*pb;Aobj1;Bobj2;pb=&obj1;pb->getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<7、;}};classA:publicBASE1,publicBASE2{public:A(inta,intb,intc,intd):BASE2(b),BASE1(c),b2(a),b1(d){cout<<"调用派生类A的构造函数:"<usingnamespacestd;classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i8、;b=j;c=k;}voidget(int&i,int&j,int&k)仅供学习与交流,如有侵权请联系网站删除谢谢10精品好文档,推荐学习交流{i=a;j=b;k=
7、;}};classA:publicBASE1,publicBASE2{public:A(inta,intb,intc,intd):BASE2(b),BASE1(c),b2(a),b1(d){cout<<"调用派生类A的构造函数:"<usingnamespacestd;classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i
8、;b=j;c=k;}voidget(int&i,int&j,int&k)仅供学习与交流,如有侵权请联系网站删除谢谢10精品好文档,推荐学习交流{i=a;j=b;k=
此文档下载收益归作者所有