欢迎来到天天文库
浏览记录
ID:48510130
大小:84.50 KB
页数:23页
时间:2020-02-06
《程序的设计与问题求解.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、......桂林电子科技大学试卷2010-2011学年第2学期A卷课号课程名称程序设计与问题求解2适用班级(专业)考试时间120分钟座位号学号姓名题号一二三四五六七八成绩满分502030得分评卷人一、阅读程序,写出程序运行结果(每题10分,5题共50分)1.结构体#include#includeusingnamespacestd;structWorker{charname[15];//姓名intage;//年龄floatpay;//工资};voidmain(){WorkerW
2、orker1,Worker2;专业.专注.......char*t="liouting";intd=38;floatf=493;strcpy(Worker1.name,t);Worker1.age=d;Worker1.pay=f;cout<3、ting 38 493liouting 38 4932.构造函数与析构函数#includeusingnamespacestd;classTAdd{private:intx,y;专业.专注.......public:TAdd(inta,intb):x(a),y(b){cout<<"调用构造函数1."<4、rnx+y;}};voidmain(){TAddp1(2,3);TAddp2=p1;cout<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing";}};classB:publicA{public:voidf(){cout<<"B::f()execu5、ting";}};voidmain()专业.专注.......{Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;专业.专注.......templateclassmyclass{private:Type1i;6、Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<ob1(1,3);myclassob2(10,0.23);myclassob3('A',"Thisisatest");ob1.show();专业.专注.......ob2.show();ob3.show();}输出结果是:13100.23AThisisat7、est5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<8、ic:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}};intmain()专业.专注.......{Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBdes!Bdes!Ades!二、程序填空(每题10
3、ting 38 493liouting 38 4932.构造函数与析构函数#includeusingnamespacestd;classTAdd{private:intx,y;专业.专注.......public:TAdd(inta,intb):x(a),y(b){cout<<"调用构造函数1."<4、rnx+y;}};voidmain(){TAddp1(2,3);TAddp2=p1;cout<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing";}};classB:publicA{public:voidf(){cout<<"B::f()execu5、ting";}};voidmain()专业.专注.......{Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;专业.专注.......templateclassmyclass{private:Type1i;6、Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<ob1(1,3);myclassob2(10,0.23);myclassob3('A',"Thisisatest");ob1.show();专业.专注.......ob2.show();ob3.show();}输出结果是:13100.23AThisisat7、est5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<8、ic:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}};intmain()专业.专注.......{Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBdes!Bdes!Ades!二、程序填空(每题10
4、rnx+y;}};voidmain(){TAddp1(2,3);TAddp2=p1;cout<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing";}};classB:publicA{public:voidf(){cout<<"B::f()execu
5、ting";}};voidmain()专业.专注.......{Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;专业.专注.......templateclassmyclass{private:Type1i;
6、Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<ob1(1,3);myclassob2(10,0.23);myclassob3('A',"Thisisatest");ob1.show();专业.专注.......ob2.show();ob3.show();}输出结果是:13100.23AThisisat
7、est5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<8、ic:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}};intmain()专业.专注.......{Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBdes!Bdes!Ades!二、程序填空(每题10
8、ic:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}};intmain()专业.专注.......{Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBdes!Bdes!Ades!二、程序填空(每题10
此文档下载收益归作者所有