欢迎来到天天文库
浏览记录
ID:10951547
大小:40.50 KB
页数:10页
时间:2018-07-09
《c++面向对象程序设计模拟试题2》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++面向对象程序设计模拟试题二一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。1.说明内联函数的关键字是()。A)inlineB)virtualC)defineD)static2.假定CAb为一个类,则执行CAboX;语句时将自动调用该类的()A)有参构造函数B)无参构造函数C)拷贝构造函数D)赋值重载函数3.cin是某个类的标准对象的引用,该类是()。A)ostreamB)istreamC)stdoutD)stdin4.下面的哪个保留字不能作为函数的返回类型?()A
2、)voidB)intC)templateD)long5.派生类的成员函数不能访问基类的()。A)保护成员B)公有成员C)私有成员D)前面各选项都正确6.在语句“cout<3、和“父类”二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。错填或不填均无分。1.设函数max是由函数模板实现的,并且max(3.5,5)和max(3,5)都是正确的函数调用,则此函数模板具有()个类型参数。2.在C++中,函数重载与虚函数帮助实现了类的()性。3.由static修饰的数据成员为该类的所有对象()。4.重载函数一般在参数类型或参数个数上不同,但()相同。5.使用new建立的动态对象在不用时应该用()释放所占用的空间。三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。1.阅读下面程序,写出输出结4、果。#includeusingnamespacestd;classPoint{public:Point(inta=0,intb=0):x(a),y(b){}intGetX()const{returnx;}intGetY()const{returny;}voidSetX(inta){x=a;}voidSetY(inta){y=a;}private:intx;inty;};intmain(){Pointu;constPointv(6,8);cout<5、out<usingnamespacestd;templateclassTest{public:Test(Typea[],intiSize):elem(a){size=iSize;}voidPrint()const{for(inti=0;i6、e;};intmain(){inta[]={1,0,8};doubleb[]={1.6,1.8};Testar1(a,3);ar1.Print();Testar2(b,sizeof(b)/sizeof(double));ar2.Print();cout<usingnamespacestd;classGoods{public:Goods(intw):weight(w){totalWeight=totalWeight+w;}Goods(cons7、tGoods&g){weight=g.weight;totalWeight=totalWeight+weight;}~Goods(){totalWeight=totalWeight-weight;}voidPrint()const;staticintGetTotalWeight(){returntotalWeight;}private:intweight;staticinttotalWeight;};intGoods::totalWeight=0;void
3、和“父类”二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。错填或不填均无分。1.设函数max是由函数模板实现的,并且max(3.5,5)和max(3,5)都是正确的函数调用,则此函数模板具有()个类型参数。2.在C++中,函数重载与虚函数帮助实现了类的()性。3.由static修饰的数据成员为该类的所有对象()。4.重载函数一般在参数类型或参数个数上不同,但()相同。5.使用new建立的动态对象在不用时应该用()释放所占用的空间。三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。1.阅读下面程序,写出输出结
4、果。#includeusingnamespacestd;classPoint{public:Point(inta=0,intb=0):x(a),y(b){}intGetX()const{returnx;}intGetY()const{returny;}voidSetX(inta){x=a;}voidSetY(inta){y=a;}private:intx;inty;};intmain(){Pointu;constPointv(6,8);cout<5、out<usingnamespacestd;templateclassTest{public:Test(Typea[],intiSize):elem(a){size=iSize;}voidPrint()const{for(inti=0;i6、e;};intmain(){inta[]={1,0,8};doubleb[]={1.6,1.8};Testar1(a,3);ar1.Print();Testar2(b,sizeof(b)/sizeof(double));ar2.Print();cout<usingnamespacestd;classGoods{public:Goods(intw):weight(w){totalWeight=totalWeight+w;}Goods(cons7、tGoods&g){weight=g.weight;totalWeight=totalWeight+weight;}~Goods(){totalWeight=totalWeight-weight;}voidPrint()const;staticintGetTotalWeight(){returntotalWeight;}private:intweight;staticinttotalWeight;};intGoods::totalWeight=0;void
5、out<usingnamespacestd;templateclassTest{public:Test(Typea[],intiSize):elem(a){size=iSize;}voidPrint()const{for(inti=0;i6、e;};intmain(){inta[]={1,0,8};doubleb[]={1.6,1.8};Testar1(a,3);ar1.Print();Testar2(b,sizeof(b)/sizeof(double));ar2.Print();cout<usingnamespacestd;classGoods{public:Goods(intw):weight(w){totalWeight=totalWeight+w;}Goods(cons7、tGoods&g){weight=g.weight;totalWeight=totalWeight+weight;}~Goods(){totalWeight=totalWeight-weight;}voidPrint()const;staticintGetTotalWeight(){returntotalWeight;}private:intweight;staticinttotalWeight;};intGoods::totalWeight=0;void
6、e;};intmain(){inta[]={1,0,8};doubleb[]={1.6,1.8};Testar1(a,3);ar1.Print();Testar2(b,sizeof(b)/sizeof(double));ar2.Print();cout<usingnamespacestd;classGoods{public:Goods(intw):weight(w){totalWeight=totalWeight+w;}Goods(cons
7、tGoods&g){weight=g.weight;totalWeight=totalWeight+weight;}~Goods(){totalWeight=totalWeight-weight;}voidPrint()const;staticintGetTotalWeight(){returntotalWeight;}private:intweight;staticinttotalWeight;};intGoods::totalWeight=0;void
此文档下载收益归作者所有