欢迎来到天天文库
浏览记录
ID:53255391
大小:101.50 KB
页数:12页
时间:2020-04-02
《程序设计与问题求解.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、桂林电子科技大学试卷2010-2011学年第2学期A卷课号课程名称程序设计与问题求解2适用班级(专业)考试时间120分钟座位号学号姓名题号一二三四五六七八成绩满分502030得分评卷人一、阅读程序,写出程序运行结果(每题10分,5题共50分)1.结构体#include#includeusingnamespacestd;structWorker{charname[15];//姓名intage;//年龄floatpay;//工资};voidmain(){WorkerWorker1,Worker2;
2、char*t="liouting";intd=38;floatf=493;strcpy(Worker1.name,t);Worker1.age=d;Worker1.pay=f;cout<3、数#includeusingnamespacestd;classTAdd{12private:intx,y;public:TAdd(inta,intb):x(a),y(b){cout<<"调用构造函数1."<4、)<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing";}};classB:publicA{public:voidf(){cout<<"B::f()executing";}12};voidmain(){Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结5、果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;templateclassmyclass{private:Type1i;Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<6、>ob1(1,3);myclassob2(10,0.23);12myclassob3('A',"Thisisatest");ob1.show();ob2.show();ob3.show();}输出结果是:13100.23AThisisatest5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<7、){cout<<"Ades!";}};classB{inti;public:B(intii){i=ii;cout<<"Bcon!";}~B(){cout<<"Bdes!";}};classC:publicA,publicB{public:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}12};intmain(){Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBde8、s!Bdes!Ades!二、程序填空(每题10分,2题共20分)1.词频统计:输入一系列英文单词,单词之间用空格隔开,用“xyz”表示结束输入,统计输入过哪些单词以及各单词出现的次数,统计时区分大小写字母,最后按单词的字典顺序输出单词
3、数#includeusingnamespacestd;classTAdd{12private:intx,y;public:TAdd(inta,intb):x(a),y(b){cout<<"调用构造函数1."<4、)<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing";}};classB:publicA{public:voidf(){cout<<"B::f()executing";}12};voidmain(){Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结5、果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;templateclassmyclass{private:Type1i;Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<6、>ob1(1,3);myclassob2(10,0.23);12myclassob3('A',"Thisisatest");ob1.show();ob2.show();ob3.show();}输出结果是:13100.23AThisisatest5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<7、){cout<<"Ades!";}};classB{inti;public:B(intii){i=ii;cout<<"Bcon!";}~B(){cout<<"Bdes!";}};classC:publicA,publicB{public:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}12};intmain(){Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBde8、s!Bdes!Ades!二、程序填空(每题10分,2题共20分)1.词频统计:输入一系列英文单词,单词之间用空格隔开,用“xyz”表示结束输入,统计输入过哪些单词以及各单词出现的次数,统计时区分大小写字母,最后按单词的字典顺序输出单词
4、)<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing";}};classB:publicA{public:voidf(){cout<<"B::f()executing";}12};voidmain(){Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结
5、果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;templateclassmyclass{private:Type1i;Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<6、>ob1(1,3);myclassob2(10,0.23);12myclassob3('A',"Thisisatest");ob1.show();ob2.show();ob3.show();}输出结果是:13100.23AThisisatest5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<7、){cout<<"Ades!";}};classB{inti;public:B(intii){i=ii;cout<<"Bcon!";}~B(){cout<<"Bdes!";}};classC:publicA,publicB{public:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}12};intmain(){Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBde8、s!Bdes!Ades!二、程序填空(每题10分,2题共20分)1.词频统计:输入一系列英文单词,单词之间用空格隔开,用“xyz”表示结束输入,统计输入过哪些单词以及各单词出现的次数,统计时区分大小写字母,最后按单词的字典顺序输出单词
6、>ob1(1,3);myclassob2(10,0.23);12myclassob3('A',"Thisisatest");ob1.show();ob2.show();ob3.show();}输出结果是:13100.23AThisisatest5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<7、){cout<<"Ades!";}};classB{inti;public:B(intii){i=ii;cout<<"Bcon!";}~B(){cout<<"Bdes!";}};classC:publicA,publicB{public:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}12};intmain(){Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBde8、s!Bdes!Ades!二、程序填空(每题10分,2题共20分)1.词频统计:输入一系列英文单词,单词之间用空格隔开,用“xyz”表示结束输入,统计输入过哪些单词以及各单词出现的次数,统计时区分大小写字母,最后按单词的字典顺序输出单词
7、){cout<<"Ades!";}};classB{inti;public:B(intii){i=ii;cout<<"Bcon!";}~B(){cout<<"Bdes!";}};classC:publicA,publicB{public:C(intcx,intcy,intbi):A(cx,cy),B(bi){cout<<"AwithBcon!";}~C(){cout<<"AwithBdes!";}12};intmain(){Ccm(3,4,5);}输出结果是:A:34Bcon!AwithBcon!AwithBde
8、s!Bdes!Ades!二、程序填空(每题10分,2题共20分)1.词频统计:输入一系列英文单词,单词之间用空格隔开,用“xyz”表示结束输入,统计输入过哪些单词以及各单词出现的次数,统计时区分大小写字母,最后按单词的字典顺序输出单词
此文档下载收益归作者所有