《C语言程序设计》模拟试卷_第1页
《C语言程序设计》模拟试卷_第2页
《C语言程序设计》模拟试卷_第3页
《C语言程序设计》模拟试卷_第4页
《C语言程序设计》模拟试卷_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、C+语言程序设计模拟试卷一、单选题(21分,每空1.5分)1.在C+中,函数原型不能标识( ) A.函数的返回类型 B.函数参数的个数 C.函数参数类型 D.函数的功能2.可以用p.a的形式访问派生类对象p的基类成员a,其中a是( ) A.私有继承的公有成员 B.公有继承的私有成员 C.公有继承的保护成员 D.公有继承的公有成员 3. 以下关于switch语句和break描述中 , 是正确的。 A. switch语句中必须用break语句 B. break语句只能用于switch语句 C. 在switch语句中,可以根据需要使用或不使用break语句D. break语句是switch语句必须的

2、一部分 4. 若以下语句,则正确描述是 char c1=boy; char c2=b,o,y; A. c1,c2数组等价 B. c1,c2数粗元素个数相同 C. c1数组元素个数大于c2数组元素个数D. c1数组元素个数小于c2数组元素个数 5.派生类的对象对它的基类成员中 是可以访问的。公有继承的public成员。公有继承的private成员。公有继承的protected成员。D. 私有继承的public成员。 6.若有语句: int x=1,2,3,4,5; int *ptr; ptr=x;则 是对数组元素x1的正确引用。ptr+1 B.*ptr+1 C.*(ptr+1) D.*ptr+7

3、.对于任意一个类,析构函数的个数最多为( ) A.0 B.1 C.2 D.38. 如执行以下语句,,循环结束后cout语句输出值是 for (i=1;i=100;i+) sum=sum+i; coutsetn(34); D、setn(34);13. 在调用函数时,如果实参是简单变量,它与对应形参之间的数据传递方式是 A) 地址传递 B) 单向值传递C) 由实参传给形参,再由形参传回实参 D) 传递方式由用户指定14.下列常量中,哪个的类型为float类型? A 2.F B .2L C 0.2E100 D 0.0二、填空题(10分,每空1分)1、在堆中动态分配、释放内存,可以使用 和delete

4、运算符。也可使用malloc( )和 函数。2、表达式coutend1还可表示为_。3、 类的三大特点是:1)_ 2)_ 3)_。4、创建类对象时,系统自动调用_函数,在类对象生命期结束时,自动调用_函数。5.C+中语句const char * const p=hello;所定义的指针p和它所指的内容都不能被_。6.定义类的动态对象数组时,系统只能够自动调用该类的_构造函数对其进行初始化。三、改错题(本大题共4小题,每小题3分,共12分)1.指出下面程序段中的错误,并说明出错原因。class Aprivate: int a,b;public: A(int aa,int bb) a=aa;b=b

5、b;void main()A x(2,3),y(4);2.指出下面程序段中的错误,并说明出错原因。#include class A public: void fun( )couta.funendl; ;class B public: void fun( )coutb.funendl; void gun( )coutb.gunendl;class C:public A,public B private:int b; public:void gun( )coutc.gunendl; void hun( )fun( ); 3.要求下面循环体中的语句x+=3执行30次,请改正程序。for(j=0; j

6、90; j+) if(j/3=0) x+=3;4.请指出程序片段的语法错误。 int * age_ptr; int m = 3; *age_ptr = &m;四、判断题(10分)1、_MyInt 是一个合法的变量名。( )2、使用关键字class地定义的类缺省的访问权限是private。( )3、函数的原型说明和函数定义的作用不一样,可以进行多次的函数原型说明。( )4、构造函数和析构函数都不可以重载。 ( )递归调用是指一个函数在执行时直接或间接的又调用该函数自身的调用过程。( )各种类型的指针表示的是内存的地址,所以指针加1,总是内存的地址加1。( )对于int a10; ,a5与*(a+

7、5)是同一个元素。( )友元的作用是实现数据的隐藏性。( )函数可能有左值(出现在=的左边),数组名不能够有左值。( )10、虚函数一定是类的成员函数。( )五、简答题(7分,每小题4分)C+语言提供了那些分支语句?break、continue的作用是什么?单一继承和多重继承的区别?列表显示基类的成员访问权限在公有继承,私有继承后的访问权限? 访问权限继承方式 publicprotectedprivate公有继承私有继承六、读程序写出运行结果(16分)(每小题4分)1#include using namespace std;void main()char a=abcdabcabfgacd;in

8、t i1=0,i2=0,i=0;while (ai!=0) if (ai=a) i1+;if (ai=b) i2+;i+;cout i1 i2endl;2、include class A public: A( ) virtual void func( )coutDestructor Aendl; A( ) func(); ; class B:public A public: B( ) void func()coutDestructor Bendl; B( ) func(); ; void main( ) B b; A &a=b; 输出为: 3、include void main( ) int

9、*a; int *&p=a; int b=10; p=&b; cout*a; 输出为:4、main()int i,j;for(i=0;i=i;j-) printf(“0” ); for(j=0;j2*i-1;j+) printf(“#”); printf(“n”); 输出为:5#include # include void fun(char *w,int m) char s,*p1,*p2; p1=w; p2=w+m-1; while(p1p2) s=*p1;*p1=*p2;*p2=s; p1+; p2-; int main()char a10=”GFEDCBA”;fun(a,strlen(a

10、); couta;return 0;6#includeclass AAAprivate:int A,B;public:AAA()A=100;B=200; coutdefault constructingn;AAA(int i,int j)A=i,B=j; coutconstructingn;AAA()coutdestructingn;void print( )coutA,Bprint(); a2-print();delete a1;delete a2;return 0;七、程序设计(24分) 1 输出以下图形:(5分)*2、写一个程序计算1!-2! +3! 4!+5!.-10! (5分)封装一

11、个被称为日期Tdate类。用这个类存储年、月、日。(6分)要求:Show()成员函数显示某日期对象的信息,格式为日、月、年。add()成员函数可实现在日期上加一天的操作。(不考虑年底月底情况)4给出复数(Complex)类 class Complex public : void print(); private: double real; double image; ;要求print ()成员函数实现显示复数的信息,增加适当的构造函数以及重载加法,实现对复数(Complex)类对象加法。 (8分)要求实现以下运算:Complex a(2,5),b(7,8),C(0,0)C=a+b;C=4.1+

12、a;C=b+5.6;注:复数有实部、虚部组成Complex a(2,5)既代表 2+5i第9章第4题,#includeusing namespace std;class student private: int num;int socre;public:student(int n,int s)num=n;socre=s;void display() coutnumscoreendl;int main()student a5=student(0,70),student(1,50),student(2,30),student(3,40),student(4,50)student *p=a;for(

13、p=&a0;pdisplay();不能将num,score声明为private,而只有将它们声明public时指针p才能访问第1题 重载+为非成员函数、非友元函数的普通函数。 #include using namespace std;class Complex public: Complex()real=0;imag=0; Complex(double r,double i)real=r;imag=i; double get_real(); double get_imag(); void display(); private: double real; double imag; ; doubl

14、e Complex:get_real()return real;double Complex:get_imag()return imag;void Complex:display()cout(real,imagi)endl;Complex operator + (Complex &c1,Complex &c2) return Complex(c1.get_real()+c2.get_real(),c1.get_imag()+c2.get_imag();int main()Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; coutc3=; c3.display();

15、 return 0;第3题#include using namespace std; class Complex public: Complex()real=0;imag=0; Complex(double r,double i)real=r;imag=i; Complex operator+(Complex &c2); Complex operator+(int &i); friend Complex operator+(int&,Complex &); void display(); private: double real; double imag; ; Complex Complex:

16、operator+(Complex &c)return Complex(this-real+c.real,this-imag+c.imag); Complex Complex:operator+(int &i)return Complex(this-real+i,imag);void Complex:display()cout(real,imagi)endl;Complex operator+(int &i,Complex &c)return Complex(i+c.real,c.imag);int main()Complex c1(3,4),c2(5,-10),c3; int i=5; c3

17、=c1+c2; coutc1+c2=; c3.display(); c3=i+c1; couti+c1=; c3.display(); c3=c1+i; coutc1+i=; c3.display(); return 0; 试卷A答案一、单选题(21分,每空1.5分)1D 2D 3C 4C 5A 6C 7B 8C 9A 10A 11B 12C 13B 14A二、 填空题(10分,每空1分)1. new free() 2. coutn3. 封装性,继承性,多态性 4. 构造函数,析构函数5. 赋值 6.默认三、改错题(本大题共4小题,每小题3分,共12分)1.指出下面程序段中的错误,并说明出错原

18、因。A x(2,3),y(4);语句出错,因为没有单参数的构造函数(或者y(4)少写了一个参数)。2. void hun()fun();出错,C:fun()有二义性。3. if(j%3= =0) x+=3;4. *age_ptr = &m; 改为age_ptr = &m;四、 判断题(10分)正确:1、2、3、5、7、9、10错误:4、6、8五、 简答题(15分,每小题5分)1、if语句 ifelse语句 switch语句break :结束分支continue:结束本次循环2、单一继承:派生类只有一个直接的基类。 多重继承:派生类有两个以上的直接基类。 访问权限继承方式 publicprote

19、ctedprivate公有继承 publicprotected不可访问权限私有继承privateprivate不可访问权限六、 读程序写出运行结果(20分)(小题5分)4 3(5分)2. Destructor B Destructor A3、104、 输出为: . 0 0*0 0*0 0*0七、 程序设计(24分)1输出以下图形:(5分)#includevoid main()int i,j;for(i=1;i=5;i+) for(j=1;ji;j+) cout ; for(j=1;j=11-2*i;j+) cout*; coutn; 2、写一个程序计算1!-2! +3! 4!+5!.-10!

20、(5分)#includevoid main() int f=1,n,s=0,t=1;n=10; for(int i=1;i=n;i+) t= -t;f=f*i*t;s=s+f; couts;4(6分)#include class Tdate private: int year;int month;int day; public: void Show(); void add(); Tdate(int y,int m,int d);void Tdate:Show()coutyear/month/dayendl;void Tdate:add()day+;Tdate: Tdate(int y,int m,int d) year=y;month=m;day=d; void main() Tdate a(2005,3,23);a.Show();a.add();a.Show();5(8分)#include class complexpublic: complex() real=imag=0; complex(double r, double i) real = r, imag = i; complex ope

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论