欢迎来到天天文库
浏览记录
ID:37914859
大小:63.50 KB
页数:9页
时间:2019-06-02
《C++程序设计程序分析题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、三程序分析题阅读以下程序,写出其运行结果。1.#includeinta[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.#includevoidf();classT{public:T(){cou
2、t<<"constructor"<classBclass{pu
3、blic: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、<fun()<classBASE{public:virtualvoidgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<5、){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeclassBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<"调用基类BASE2的构造函数:"<classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c7、=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*obj.c;returntempobj;}voidmain(){Tobj1(1,2,3),obj2(5,5,5),obj3;inta,b,c;obj3=obj1*obj2;obj3.get(a,
4、<fun()<classBASE{public:virtualvoidgetxy(inti,intj=0){x=i;y=j;}virtualvoidfun()=0;protected:intx,y;};classA:publicBASE{public:voidfun(){cout<<"x="<5、){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeclassBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<"调用基类BASE2的构造函数:"<classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c7、=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*obj.c;returntempobj;}voidmain(){Tobj1(1,2,3),obj2(5,5,5),obj3;inta,b,c;obj3=obj1*obj2;obj3.get(a,
5、){cout<<"x="<getxy(10);pb->fun();pb=&obj2;pb->getxy(100,20);pb->fun();}5.#includeclassBASE1{public:BASE1(inti){cout<<"调用基类BASE1的构造函数:"<6、<"调用基类BASE2的构造函数:"<classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c7、=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*obj.c;returntempobj;}voidmain(){Tobj1(1,2,3),obj2(5,5,5),obj3;inta,b,c;obj3=obj1*obj2;obj3.get(a,
6、<"调用基类BASE2的构造函数:"<classT{public:T(){a=0;b=0;c=0;}T(inti,intj,intk){a=i;b=j;c
7、=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*obj.c;returntempobj;}voidmain(){Tobj1(1,2,3),obj2(5,5,5),obj3;inta,b,c;obj3=obj1*obj2;obj3.get(a,
此文档下载收益归作者所有