c语言程序设计模拟试卷1-6,C语言程序设计模拟试卷.doc-资源下载在线文库www.lddoc.cn...

《C语言程序设计》模拟试卷.doc

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语句必须的一部分 4. 若以下语句,则正确描述是 char c1boyb,o,y int *ptr; ptrx;则 是对数组元素x1的正确引用。A. ptr1 B.*ptr1 C.*ptr1 D.*ptr7.对于任意一个类,析构函数的个数最多为 A.0 B.1 C.2 D.38. 如执行以下语句,,循环结束后cout语句输出值是 for i1;i100;i sumsumi; couti; A. 100 B. 99 C. 101 D. 1029. 若有定义int a8,b5,C;,执行语句Ca/b0.4;后,c的值为 A 1.4 B 1 C 2.0 D 210. 是析构函数的特征A. 一个类中只能定义一个析构函数B. 析构函数与类名相同C. 析构函数的定义只能在类体中D. 析构函数可以有一个或多个参数11通常拷贝构造函数的参数是 A. 对象 B.对象的引用C对象的成员 D. 对象的指针12.一段程序的定义如下,在函数f 中将对象的成员n的值改为34的语句应该为 class A Private int n;publicsetnint nl nnl;Aint x n x; ;int f A * ptr new A45;. A、 A34; B、 ptr.setn34; C、 ptr-setn34; D、setn34;13. 在调用函数时,如果实参是简单变量,它与对应形参之间的数据传递方式是 A 地址传递 B 单向值传递C 由实参传给形参,再由形参传回实参 D 传递方式由用户指定14.下列常量中,哪个的类型为float类型 A 2.F B .2L C 0.2E100 D 0.0二、填空题(10分,每空1分)1、在堆中动态分配、释放内存,可以使用 和delete运算符。也可使用malloc 和 函数。2、表达式coutend1还可表示为_。3、 类的三大特点是1) 2) 3)_。4、创建类对象时,系统自动调用函数,在类对象生命期结束时,自动调用函数。5.C中语句const char * const phello;所定义的指针p和它所指的内容都不能被_。6.定义类的动态对象数组时,系统只能够自动调用该类的_构造函数对其进行初始化。三、改错题本大题共4小题,每小题3分,共12分1.指出下面程序段中的错误,并说明出错原因。class Aprivate int a,b;public Aint aa,int bb aaa;bbbvoid mainA x2,3,y4;2.指出下面程序段中的错误,并说明出错原因。include iostream.hclass A public void fun couta.funendl; ;class B public void fun coutb.funendl; void gun coutb.gunendlclass Cpublic A,public B privateint b; publicvoid gun coutc.gunendl; void hun fun 3.要求下面循环体中的语句x3执行30次,请改正程序。forj0; j90; j ifj/30 x3;4.请指出程序片段的语法错误。 int * age_ptr; int m 3; *age_ptr m;四、判断题(10分)1、_MyInt 是一个合法的变量名。 2、使用关键字class地定义的类缺省的访问权限是private。 3、函数的原型说明和函数定义的作用不一样,可以进行多次的函数原型说明。 4、构造函数和析构函数都不可以重载。 5、 递归调用是指一个函数在执行时直接或间接的又调用该函数自身的调用过程。 6、 各种类型的指针表示的是内存的地址,所以指针加1,总是内存的地址加1。 7、 对于int a10; ,a5与*a5是同一个元素。 8、 友元的作用是实现数据的隐藏性。 9、 函数可能有左值(出现在的左边),数组名不能够有左值。 10、虚函数一定是类的成员函数。 五、简答题(7分,每小题4分)1、 C语言提供了那些分支语句break、continue的作用是什么2、 单一继承和多重继承的区别列表显示基类的成员访问权限在公有继承,私有继承后的访问权限 访问权限继承方式 publicprotectedprivate公有继承私有继承六、读程序写出运行结果(16分)(每小题4分)1include iostreamusing namespace std;void mainchar aabcdabcabfgacdwhile ai0 if aia i1;if aib i2;i;cout i1 i2endl;2、include iostream.h class A public A virtual void func coutDestructor Aendl; A func; ; class Bpublic A public B void funccoutDestructor Bendl; B func; ; void main B b; A ab; 输出为 3、include iostream.h void main int *a; int *pa; int b10; pb; cout*a; 输出为4、mainint i,j;fori0;i6;i forj6;ji;j printf“0” ; forj0;j2*i-1;j printf“”; printf“n”; 输出为5include iostream.h include string.hvoid funchar *w,int m char s,*p1,*p2; p1w; p2wm-1; whilep1p2 s*p1;*p1*p2;*p2s; p1; p2; int mainchar a10”GFEDCBA”;funa,strlena; couta;return 0;6includeiostream.hclass AAAprivateint A,B;publicAAAA100;B200; coutdefault constructingn coutconstructingndestructingnA,Bnint mainAAA *a1,*a2;a1new AAA;a2new AAA5,6;a1-print; a2-print;delete a1;delete a2;return 0;七、程序设计(24分) 1 输出以下图形(5分)*2、写一个程序计算1-2 3 45-10 5分3、 封装一个被称为日期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)Cab;C4.1a;Cb5.6;注复数有实部、虚部组成Complex a(2,5)既代表 25i第9章第4题,includeiostreamusing namespace std;class student private int num;int socre;publicstudentint n,int snumn;socres;void display coutnumscoreendlint mainstudent a5student0,70,student1,50,student2,30,student3,40,student4,50student *pa;forpa0;pa5;p2p-display;不能将num,score声明为private,而只有将它们声明public时指针p才能访问第1题 重载为非成员函数、非友元函数的普通函数。 include iostreamusing namespace std;class Complex public Complexreal0;imag0; Complexdouble r,double irealr;imagi; double get_real; double get_imag; void display; private double real; double imag; ; double Complexget_realreturn real;double Complexget_imagreturn imag;void Complexdisplaycoutreal,imagiendl;Complex operator Complex c1,Complex c2 return Complexc1.get_realc2.get_real,c1.get_imagc2.get_imag;int mainComplex c13,4,c25,-10,c3; c3c1c2; coutc3 return 0;第3题include iostream using namespace std; class Complex public Complexreal0;imag0; Complexdouble r,double irealr;imagi; Complex operatorComplex c2; Complex operatorint i; friend Complex operatorint,Complex ; void display; private double real; double imag; ; Complex ComplexoperatorComplex creturn Complexthis-realc.real,this-imagc.imag; Complex Complexoperatorint ireturn Complexthis-reali,imag;void Complexdisplaycoutreal,imagiendl;Complex operatorint i,Complex creturn Complexic.real,c.imag;int mainComplex c13,4,c25,-10,c3; int i5; c3c1c2; coutc1c2 c3ic1; coutic1 c3c1i; coutc1i 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.指出下面程序段中的错误,并说明出错原因。A x2,3,y4;语句出错,因为没有单参数的构造函数或者y4少写了一个参数。2. void hunfun;出错,Cfun有二义性。3. ifj3 0 x3;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、单一继承派生类只有一个直接的基类。 多重继承派生类有两个以上的直接基类。 访问权限继承方式 publicprotectedprivate公有继承 publicprotected不可访问权限私有继承privateprivate不可访问权限六、 读程序写出运行结果(20分)(小题5分)1 4 35分2. Destructor B Destructor A3、104、 输出为 . 0 0*0 0*0 0*0七、 程序设计(24分)1输出以下图形(5分)includeiostream.hvoid mainint i,j;fori1;i5;i forj1;ji;j cout j11-2*i;j cout*niostream.hvoid main int f1,n,s0,t1;n10; forint i1;in;i t -t;ff*i*t;ssf; couts;46分include iostream.hclass Tdate private int year;int month;int day; public void Show; void add; Tdateint y,int m,int dvoid TdateShowcoutyear/month/dayendl;void Tdateaddday;Tdate Tdateint y,int m,int d yeary;monthm;dayd; void main Tdate a2005,3,23;a.Show;a.add;a.Show;5(8分)include iostream.hclass complexpublic complex realimag0; complexdouble r, double i real r, imag i; complex operator const complex c;complex operator double c; void print;private double real, imaginline complex complexoperator const complex c return complexreal c.real, imag c.imag;inline complex complexoperator double c return complexreal c, imag;void complexprint ifimag0 coutrealimagirealimagiendl;void main complex a2.0, 3.0, b4.0, -2.0,c;cab;c.print;ca4.2; c.print;2005年编程题(40分)输出以下图形(必须用循环语句编写,不能用cout直接显示,否则不给分)* * * * * * * * * *编写程序,输入10个double型数据,并对这10个数从小到大排序,最后显示排序结果。编写程序,实现两个字符串比较的自定义版;函数原形为int strcmpchar * str1,char *str2当str1str2时,返回正数当str1 str2时,返回0当str1str2时,返回负数4封装一个CStudent类,用来描述学生的属性和行为。具体要求如下1)学生有姓名、籍贯、学号、年龄、成绩五个成员数据,编写构造函数,拷贝构造函数,同时编写Display成员函数显示学生的信息;(6分) 2)编写“”运算符重载函数,使类CStudent的两个对象相加返回两个对象总成绩相加的和;(4分)3)编写主函数,定义两个CStudent类对象(初始化值任定),分别调用成员函数Display显示两个对象的学生信息,同时显示两个对象相加的结果。(2分)5.声明一个Shape抽象类,在此基础上派生出正方形和圆类,两者都由GetArea函数计算对象面积,由GetPerim函数计算对象的周长。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值