ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:19.47KB ,
资源ID:9710312      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9710312.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c++模拟试题一.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

c++模拟试题一.docx

1、c+模拟试题一模拟试题一一、单项选择题(本大题共 10 小题,每小题 2 分,共 20 分) 1.面向对象程序设计中的数据隐藏指的是( ) A.输入数据必须输入保密口令 B.数据经过加密处理 C.对象内部数据和代码合并在一起D.对象内部数据结构的不可访问性 2.在 C+中,编写一个内联函数 Fun,使用 int 类型的参数,求其平方并返回,返回值也为 int 类型,下列定 义正确的是 ( ) A.int Fun(int x)return x*x; B.inline int Fun(int x)return x*x;C.int inline Fun(int x)return x*x; D.int

2、 Fun(int x)inline return x*x; 3.下面关于重载函数的叙述中正确的是 ( ) A.重载函数必须具有不同的返回值类型 B.重载函数的形参个数必须不同C.重载函数必须有不同的形参列表 D.重载函数的函数名可以不同 4.若有定义int x=17; ,则语句coutoctx;的输出结果是( ) A.11 B.0x11 C.21 D.021 5.下列关于析构函数的描述中正确的是( ) A.析构函数可以重载 B.析构函数可以是虚函数 C.析构函数名与类名相同 D.析构函数的返回类型为 void 6.下列关于纯虚函数的描述中,正确的是 ( ) A.纯虚函数是一种特殊的虚函数,它是

3、个空函数 B.具有纯虚函数的类称为虚基类 C.一个基类中说明有纯虚函数,其派生类一定要实现该纯虚函数 D.具有纯虚函数的类不能创建类对象 7.下列关于运算符重载的描述中,正确的是 ( ) A.可以改变运算符的目数 B.可以改变运算符的优先级 C.可以改变运算符的结合性 D.可以改变运算符的功能 8.要将类A说明是类B的虚基类,正确的描述是 ( ) A.class virtual B:public A B.class B:virtual public A C.virtual class B:public A D.class B:public A virtual 9.下面关于静态成员的描述中,正确

4、的是 ( ) A.静态数据成员是类的所有对象共享的数据 B.类的每个对象都有自己的静态数据成员 C.类的不同对象有不同的静态数据成员值 D.静态数据成员不能通过类的对象访问 10.假设 Sample 是个类,则语句Sample a2,*p3;调用构造函数的次数为( ) A.0 B.2 C.3 D.5 二,填空题(本大题共 10 小题,每小题 2 分,共 20 分) 11.在面向对象的程序设计中,将一组对象的共同特性抽象出来形成_类_. 12.在 C+中要创建一个文件输入流对象 fin,同时该对象打开文件Test.txt用于输入,则正确的声明语句 是._ 答案:ifstream fin(“tes

5、t.txt”,ios:in);13.如果要把类 B 的成员函数 void fun( )说明为类 A 的友元函数,则应在类A中加入语句_. 答案:friend void B:fun();14. 是一个类,已有语句 A A* p;p=new A 10 . ;要释放由 p 指向的动态空间, 正确的语句应该是_. 答案:delete p;15.如果一个引用不是用作函数参数或返回值,则在说明该引用时必须对它进行_. 答案:赋初值16.如果要把 PI 声明为值为 3.14159 类型为双精度实数的符号常量,该声明语句是_. 答案:const double PI=3.14159;17.在 C+中函数原型不但

6、要标识一个函数的返回类型,同时还要标识该函数的_. 答案:形参的类型18.类 A 的后置自增运算符+以成员函数的形式进行重载,其在类内的函数声明是_. 答案:A operator+(A);19.动态联编是通过基类类型的指针或引用调用_函数来完成. 答案:虚20.基类的保护成员通过私有派生其在派生类中的访问权限是_. private或者私有的三,改错题(本大题共 5 小题,每小题 2 分,共 10 分) 21.下面的类定义中有一处错误,请用下横线标出错误所在行并给出修改意见.class Sample private: int data; Sample( )data=10; public: Sam

7、ple(int d)data=d; int operator int( )return data; /int operator +()return data; 22.下面的类定义中有一处错误,请用下横线标出错误所在行并给出修改意见. #include class Point int X,Y; public: Point( )X=0;Y=0; Point(int x=0,int y=0)X=x;Y=y; void display( )coutx,Yendl; /x改为大写的X; 23.下面的程序有一处错误,请用下横线标出错误所在行并说明错误原因. #include templatevoid Sw

8、ap(T&a, T& b) T t; t=a,a=b,b=t; void main( ) int a=3,b=4; char str15=abcd,str25=hijk; Swap(a,b); Swap(str1,str2); /需要特定模板couta=a,b=bendl; coutstr1=str1,str2=str2endl; 24.下面的程序有一处错误,请用下横线标出错误所在行并说明错误原因. #include class Base public: virtual void fun( )coutBase functionendl; ; class Derived:public Base

9、public:void fun( )coutDerived functionfun( ); 25.下面的程序有一处错误,请用下横线标出错误所在行并说明错误原因. #include class A int x; protected: int y; public: A(int xx,int yy)x=xx; y=yy; ; class B:public A public: B(int a,int b):A(a,b) void display( )coutx,yendl; /x是不可访问的; void main( ) B b(5,10); b.display( ); 四,完成程序题(本大题共 5 小

10、题,每小题 4 分,共 20 分) 26.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:2,1 4,3 #include class A int a; public: A(int i=0)a=i; int Geta( )return a; ; class B A a; int b;public: B(int i=0,int j=0): a(j)b=i; void display( )couta.Geta(),bendl; ; void main( ) B b2=B(1,2),B(3,4); for(int i=0;i2;i+) bi.display() ; 27.下面程序中

11、 A 是抽象类.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为: B1 called B2 called #include class A public: virtual void display()=0 ; ; class B1:public A public: void display( )coutB1 calledendl; ; class B2:public A public: void display( )coutB2 calleddisplay( ); void main( ) B1 b1; B2 b2; A* p2=& b1,& b2; for(int i=0;

12、i2;i+) show(pi); 28.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为: Name:王小明Grade:90 #include #include class Person char name20; public: Person(char* s)strcpy(name,s); void display( )coutName:nameendl; ; class Student:public Person int grade; public: Student(char* s, int g): Person(s) grade=g; void display( ) dis

13、play() ; coutGrade:gradeendl; ; void main( ) Student s(王小明,90); s.display( ); 29.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为 5. #include class Integer int x; public: Integer(int a=0)x=a; void display( )coutxb.get() return a; return b; void main( ) Integer a(3),b(5),c; c=Max(a,b); c.display( ); 30.请在下面的横线处填上适当内

14、容,以使类的定义完整. class Array int* ptr; int size; public: Array( )size=0; ptr=0; Array(int n)size=n;ptr=new intsize; Array(Array & a ) /复制初始化构造函数 size=a.size; ptr=new intsize; for(int i=0;isize;i+) ptri=a.ptri ; /将源对象的动态数组内容复制到目标对象 ; 五,程序分析题(本大题共 6 小题,每小题 5 分,共 30 分) 阅读下面的程序,写出程序运行的结果. 31.#include class T

15、est private: int num; public: Test(int n=0)num=n;num+; Test( )coutDestructor is active,number=numendl; ; void main( ) Test x2; coutExiting mainendl; Exiting mainDestructor is active,number=1Destructor is active,number=132.#include class A public: virtual void fun (int data)coutclass A:dataendl; void

16、 fun(char *str) coutclass A:strendl; ; class B: public A public: void fun( ) coutclass Bendl; void fun(int data) coutclass B:dataendl; void fun(char *str) coutclass B:strfun(1); pA-fun(Hello); class B:1class A:Hello33.#include void main( ) cout.fill(*); cout.width(10); cout123.45endl; cout.width(8);

17、 cout123.45endl; cout.width(4); cout123.45endl; *123.45*123.45123.4534.#include class Num int X,Y; public: Num(int x,int y=0)X=x;Y=y; void value(int x,int y=0)X=x;Y=y; void value( ) coutX; if(Y!=0) cout0?+:-)0?Y:-Y)i; coutendl; ; void main( ) Num n(1); n.value( ); n.value(2,3); n.value( ); Num m(3,-

18、4); m.value( ); 12+3i3-4i35.#include class Sample private: int i; static int count; public: Sample( ); void display( ); ; Sample:Sample( ) i=0; count+; void Sample:display( ) couti=i+,count=countendl; int Sample:count=0; void main( ) Sample a,b; a.display( ); b.display( ); i=0,cout=2i=0,cout=236.#in

19、clude class A int a; public: A(int aa=0)a=aa;couta=aendl; ; class B int b;public: B(int bb=0)b=bb;coutb=bendl; ; class C:public B A a; public: C( )coutC default constructorendl; C(int i,int j):a(i),B(j)coutC constructorendl; ; void main( ) C c1,c2(5,6); b=0a=0C default constructorb=6a=5C constructor

20、参考答案(一)一,单项选择题(本大题共 lO 小题,每小题 2 分:共 20 分) 1.D 2.B 3.C 4.C 5.B 6.D 7.D 8.B 9.A 10.B 二,填空题(本大题共 10 小题,每小题 2 分,共 20 分) 11. 类 12. ifstream fin (Test.txt); 13. friend void B:fun(); 14. delete p; 15. 赋初值 16. const double PI = 3.14159; 17. 形参的类型 18. A operator + (A); 19. 虚 20. 私有的 三,改错题(本大题共 5 小题:每小题 2 分,共

21、 lO 分)说明:各小题中,指出错误得 l 分,说明出错原因或 改正正确得 l 分. 21. 错误:int operator int( )return data; 修改:int operator +( )return data; 22. 错误:void display( )coutx,Yendl; 修改:void display( )coutX,Yendl; 23. 错误:Swap(str1,str2); 原因:需要特定模板 24. 错误:Derived* p=&b; 原因:不能把基类指针赋给派生类指针 25. 错误:void display( )coutx,yb.get() 30.

22、. Array &a . ptri=a.ptri五,程序分析题(本大题共 6 小题,每小题 5 分,共 30 分) 31. Exiting main Destructor is active,number=1 Destructor is active,number=1 32. class B:1 class A:Hello 33. *123.45 *123.45 123.45 34. 1 2+3i 3-4i 35. i=0,count=2 i=0,count=2 36. b=0 a=0 C default constructor b=6 a=5 C constructor C constructor

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1