欢迎来到天天文库
浏览记录
ID:56932630
大小:34.00 KB
页数:9页
时间:2020-07-26
《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.#includeusingnamespacestd;void
2、f();classT{public:T(){cout<<"constructor"<3、m>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=k;}intfun(){return(x+y+z)/3;}private:intz;};voidmain(){Iclassobj(2,4,10);Bclassp1=obj;cout<4、j;cout<fun()<usingnamespacestd;classBASE{public:virtualvoidgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<5、}};classB:publicBASE{public:voidfun(){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<usingnamespacestd;clas7、sT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c=k;}voidget(int&i,int&j,int&k){i=a;j=b;k=c;}Toperator*(Tobj);private:inta,b,c;};TT::operator*(Tobj){Ttempobj;tempobj.a=a*obj.a;tempobj.b=b*obj.b;tempobj.c=c*o
3、m>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=k;}intfun(){return(x+y+z)/3;}private:intz;};voidmain(){Iclassobj(2,4,10);Bclassp1=obj;cout<4、j;cout<fun()<usingnamespacestd;classBASE{public:virtualvoidgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<5、}};classB:publicBASE{public:voidfun(){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<usingnamespacestd;clas7、sT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c=k;}voidget(int&i,int&j,int&k){i=a;j=b;k=c;}Toperator*(Tobj);private:inta,b,c;};TT::operator*(Tobj){Ttempobj;tempobj.a=a*obj.a;tempobj.b=b*obj.b;tempobj.c=c*o
4、j;cout<fun()<usingnamespacestd;classBASE{public:virtualvoidgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<5、}};classB:publicBASE{public:voidfun(){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<usingnamespacestd;clas7、sT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c=k;}voidget(int&i,int&j,int&k){i=a;j=b;k=c;}Toperator*(Tobj);private:inta,b,c;};TT::operator*(Tobj){Ttempobj;tempobj.a=a*obj.a;tempobj.b=b*obj.b;tempobj.c=c*o
5、}};classB:publicBASE{public:voidfun(){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeusingnamespacestd;classBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<usingnamespacestd;clas7、sT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c=k;}voidget(int&i,int&j,int&k){i=a;j=b;k=c;}Toperator*(Tobj);private:inta,b,c;};TT::operator*(Tobj){Ttempobj;tempobj.a=a*obj.a;tempobj.b=b*obj.b;tempobj.c=c*o
6、<usingnamespacestd;clas
7、sT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c=k;}voidget(int&i,int&j,int&k){i=a;j=b;k=c;}Toperator*(Tobj);private:inta,b,c;};TT::operator*(Tobj){Ttempobj;tempobj.a=a*obj.a;tempobj.b=b*obj.b;tempobj.c=c*o
此文档下载收益归作者所有