青岛理工大学C++考试真题

合集下载

青岛理工大学考试题库

青岛理工大学考试题库

简述12位的AD 单极性转化中要求量化误差为1/2LSB ±,(电压范围为0~5V )零位调整和满量程调整的步骤。

(8分)答:先输入电压为1/2LSB ,电压范围为0~5V 时为0.66mV ,调节调整电阻使得数字输出为000000000000B 到00000000001B 的跳变点。

即为零位调整(4分),输入电压为 , 调节调整电阻使得数字输出为111111111110B 到111111111111B 的跳变点。

即为满量程调整(4分)简述加权平均值滤波原理。

答:在算术平均滤波程序中,n 次采样值在最后的结果中所占的比重是相等的,这样虽然消除了随机干扰,但有用信号的灵敏度也随之降低。

为了提高滤波效果,将各个采样值取不同的比重,然后再相加求平均值,这种方法称为加权平均滤波。

一个n 项加权平均式为:n 11i n 1i 00Y(k)C X 1n i i C ---====∑∑式中:Ci 为各次采样值的系数项,它体现了各次样值在平均值中所占的比例。

压力测量仪表的量程为300~1500pa ,采用8位的A/D 转换器,设某采样周期计算机中经采样和滤波的数字量为10H ,求此时压力的真实值为多少pa ?(x x m 00mN A (A A )A N =-+) 答:由题意,0A =300 pa ,m A =1500 pa ,, x N =16D ,m N =255D ;(5分) x x m 00m N 16A (A A )A (1500300)300375pa N 255=-+=-⨯+=(5分)5V-3/2LSB 5V-3/2LSB说明以下计算机开关量输出的工作原理。

答:P1.0输出高电平,经反向器7406变为低电平,使得发光二极管发光,从而使光敏三极管导通,9013基极为高电平,故9013导通,使继电器J的线圈带电,使触电闭合,使得交流220V电源接通。

反之当P1.0输出低电平,使得交流220V电源断开。

青岛理工大学试题及答案

青岛理工大学试题及答案

青岛理工大学试题及答案一、单项选择题(每题2分,共20分)1. 青岛理工大学位于我国的哪个省份?A. 山东B. 江苏C. 浙江D. 广东答案:A2. 青岛理工大学的校训是什么?A. 求实创新B. 厚德博学C. 笃学力行D. 明德新民答案:A3. 青岛理工大学的校徽中包含哪种元素?A. 书卷B. 齿轮C. 火炬D. 帆船答案:B4. 青岛理工大学的校园占地面积大约是多少?A. 1000亩B. 2000亩C. 3000亩D. 4000亩答案:C5. 青岛理工大学的图书馆藏书量超过多少册?A. 50万册B. 100万册C. 150万册D. 200万册答案:B二、填空题(每空2分,共20分)1. 青岛理工大学的前身是成立于______年的青岛建筑工程学校。

答案:19532. 青岛理工大学的校庆日是每年的______月______日。

答案:10月18日3. 青岛理工大学的校园内有一个著名的______湖,是校园内的一大景观。

答案:镜湖4. 青岛理工大学的校歌名称为《______》。

答案:《青岛理工大学之歌》5. 青岛理工大学的校训“求实创新”中的“求实”指的是______,而“创新”则强调______。

答案:实事求是;不断追求新知三、简答题(每题10分,共30分)1. 简述青岛理工大学的发展历程。

答案:青岛理工大学始建于1953年,最初名为青岛建筑工程学校。

经过多年的发展,学校不断壮大,于1985年升格为青岛建筑工程学院。

2004年,学校更名为青岛理工大学,标志着学校进入了一个新的发展阶段。

2. 青岛理工大学有哪些特色专业?答案:青岛理工大学的特色专业包括土木工程、建筑学、机械工程、环境工程等。

这些专业在国内外享有较高的声誉,为社会培养了大量的优秀工程技术人才。

3. 青岛理工大学的校园文化建设有哪些特点?答案:青岛理工大学的校园文化建设注重培养学生的综合素质,通过举办各类文化、科技、体育活动,丰富学生的校园生活,促进学生全面发展。

青岛理工大学C模拟练习B篇

青岛理工大学C模拟练习B篇

一.填空题(每空2分,共30分)1.一个C语言程序总是从__开始执行。

2.变量名由字母、数字和下划线组成,并且必须是__打头。

3. C 语言对数组下标的引用一般从__开始。

4.在C语言中,单目运算符的结合方向(运算方向)是__;唯一的一个三目运算符是__。

5.C语言程序的三种基本结构是顺序结构、__和__结构。

6.在C语言中,char类数据在内存中是以___形式存储的。

7.在C 语言中,表示逻辑“真”值用__。

8.设x,y, z 均为整型变量,则描述“ x 或y中有一个小于z”的表达式是__。

9.表达式98&&8&&31&1的值为__。

10.使用字符串函数时,必须将头文件包含在主程序中11.若有char a[10]="abcd",则sizeof(a)、strlen(a)的值分别是、。

12.表达式sizeof("shanda")的值为__。

二、单项选择(1-10每小题1分,11-30,每小题2分,共50分)1.以下叙述正确的是(单击此处选择)A) 在C程序中,main函数必须位于程序的最前面B) C语言的每一行中只能写一条语句C) C语言本身没有输入输出语句D) 在对一个C语言进行编译的过程中,可发现注释中的拼写错误2.以下选项中关于C语言常量的叙述错误的是(单击此处选择)。

A)所谓常量,是指在程序运行过程中,其值不能被改变的量B)常量分为整型常量、实型常量、字符常量和字符串常量C)常量可分为数值型常量和非数值型常量D)经常被使用的变量可以定义成常量3.以下选项中不能用作C程序合法常量的是(单击此处选择)。

A)1,234 B) '\123' C)123 D)"\x7G"4.以下选项中可用作C程序合法实数的是(单击此处选择)。

A).1e0 B)3.0e0.2 C)E9 D)9.12E5.以下选项中,能用作用户标识符的是(单击此处选择)。

2015-2016青岛理工C语言试题

2015-2016青岛理工C语言试题

一.单项选择题(每题1分,共30分)(1)按照C语言规定的用户标识符命名规则,不能出现在标识符中的是()。

A)字母B)数字C)下划线D)连接符(2)计算机能直接执行的程序是()。

A)源程序B)目标程序C)可执行程序D)汇编程序(3)有以下定义语句,编译时会出现编译错误的是()。

A)char a='a'; B)char a='\n'; C)char a='aa'; D)char a='\t';(4)以下选项中正确的定义语句是()。

A)double a; b; B)double a=b=7; C)double a=7, b=7; D)double, a, b;(5)以下不能正确表示代数式2ab除cd的C语言表达式是()。

A)2*a*b/c/d B)a*b/c/d*2 C)a/c/d*b*2 D)2*a*b/c*d (6)若变量均已正确定义并赋值,以下合法的C语言赋值语句是()。

A)x=y==5; B)x=n%2.5; C)x+n=1; D)x=5=4+1;(7)设有定义:int k=0;,以下选项的四个表达式中与其他三个表达式的值不相同的是()。

A)k++ B)k+=1 C)++k D)k+1(8)以下选项中,当x=3时,值为0的表达式是()。

A)x%2==1 B)x/2 C)x%2!=0 D)x%2==0(9)下列关于C语言文件的叙述中正确的是()。

A)文件是由一组相关数据组成,只能构成二进制文件B)文件是由一组相关结构组成,可以构成二进制文件或文本文件C)文件是由一组相关数据组成,可以构成二进制文件或文本文件D)文件是由一组相关数据组成,只能构成文本文件(10)以下叙述中错误的是()。

A)C语言是一种结构化程序设计语言B)结构化程序有顺序、分支、循环三种基本结构组成C)使用三种基本结构构成的程序只能解决简单问题D)结构化程序设计提倡模块化的设计方法(11)有以下程序#include <stdio.h>void main(){ char c1,c2;c1=’A’+’8’-‘4’;c2=’A’+’8’-‘5’;printf(“%c,%d\n”,c1,c2);}已知字母A的ASCII码为65,程序运行后的输出结果是()A)E,68 B)D,69 C)E,D D)输出无定值(12)已知字符‘A’的ASCⅡ代码值是65,字符变量c1的值是‘A’,c2的值是’D’。

青岛理工大学C语言考试题

青岛理工大学C语言考试题

学号:姓名:班级:。

密。

封。

线。

计算、网络、软件专业2014 年级全院班2014~2015学年第1 学期《C程序设计基础》课试卷试卷类型:测试卷试题要求: 1.试题后标注本题得分;2.试卷应附有评卷用标准答案,并有每题每步得分标准;3.试卷必须提前一周送考试中心;4.考试前到指定地点领取试卷;5.考生不得拆散试卷,否则试卷无效。

学号:姓名:班级:。

密。

封。

线。

计算、网络、软件专业2014 年级全院班2014~2015学年第1 学期《C程序设计基础》课试卷试卷类型:测试卷青岛理工大学试卷纸共 4 页第1 页试题要求: 1.试题后标注本题得分;2.试卷应附有评卷用标准答案,并有每题每步得分标准;3.试卷必须提前一周送考试中心;4.考试前到指定地点领取试卷;5.考生不得拆散试卷,否则试卷无效。

学号:姓名:班级:。

密。

封。

线。

青岛理工大学试卷纸共 4 页第 4 页答案:一、单选题1~5AACDD 6~10 ABDAD 11~15 BDDAB 16~20 BDDAC二. 填空1、函数。

2、编译链接3、 14、 05、字母、下划线、数字。

6、非07、a=1,b=3,c=28 、”a”是字符串常量,而‟a‟是字符常量9 、 3.141593,3.1416,3.14210、条件运算符11、112、a%3==0&&a%5!=013、; }14、f=++p;15、1 4三、程序结果填空题1、答案:Sum of the digits in 26587 is 282 、8 10 123、j=814、x=8,y=45、326、i=123,j=457、m=110, n=48、c1=a c2=A c3=A c4=Ac1=97 c2=65 c3=65 c4=65sum=95四编程题1、答案:#include<stdio.h>void main(){int a=3,b=4;char c;scanf("%c",c);switch(c){ case …+‟ : printf("\n %d",a+b); break;case …-‟: printf("\n %d",a-b); break;case …*‟: printf("\n %d",a*b); break;case …/‟:printf("\n %d",a/b); break;}}2、答案:main(){ int i,g,s,b;for(i=100;i<=999;i++){ b=i/100;s=(i%100)/10;g=i%10;if(i==(b*b*b+s*s*s+g*g*g))printf(“%d ”,i);} }3、答案:#include<stdio.h>main(){ int i,j;for (i=1;i<=5;i++){for (j=1;j<=i;j++)printf("*");printf("\n");}}。

青岛理工大学c语言试题

青岛理工大学c语言试题

第一套一.选择题(共70分,每题1~50每题1分,51~60每题2分) 1.以下说法中正确的是( )。

A.c 语言程序总是从第一个定义的函数开始执行B.在c 语言程序中,要调用的函数必须在main()函数中定义C.c 语言程序总是从main()函数开始执行D.c 语言程序中的main()函数必须放在程序的开始部分 2.下列标识符中正确的有( )。

A.5fileB._fileC.?fileD.FILE3. 若已定义x 和y 为double 型数据,则表达式(x=1,y=x+3/2)的值是( )。

A. 1B. 3C. 2.0D. 2.5 4. 设x 、y 、z 、t 均为int 型变量,则执行以下语句后,t 的值为( )。

x=y=z=0; t=x++||++y&&++z; A. 不定值 B. 2 C. 1 D. 0 5. 执行语句for(i=1;i<4;i++);后,变量i 的值是( )。

A.3 B. 4 C. 5 D.不定 6. 以下程序段( )。

x=-1; do {x=x*x;} while(!x); A. 是死循环 B.循环执行二次 C.循环执行一次 D.语法错误 7. 以下能对数组a 进行正确初始化的语句是( )。

A. int a[10]=(0,1,2,3,4,5); B. int a[0]=( ); C. int a[]={‘0’}; D.int a[10]={10*2}; 8. 下列关于自增运算符++和自减运算符--的叙述中正确的是( )A .它们的运算对象可以是任何类形的变量和常量B .它们的运算对象可以是char 型变量和int 型变量,但不能是float 型变量C .它们的运算对象可以是int 型变量,但不能是double 型变量和float 型变量D .它们的运算对象可以是char 型变量,int 型变量和float 型变量 9. 以下选项中,( )是不正确的字符常量。

青岛理工大学2011-2012微型计算机技术试题

学号;姓名:班级:。

密。

封。

线。

专业年级班2011 ~2012学年第 1 学期微型计算机系统课试卷试卷类型:A 卷
试卷类型:(A)卷考核方式:(闭)卷共 5 页第 1 页
试题要求: 1.试题后标注本题得分;2.试卷应附有评卷用标准答案,并有每题每步得分标准;3.试卷必须提前一周送考试中心;4.考试前到指定地点领取试卷;5.考生不得拆散试卷,否则试卷无效。

学号;姓名:班级:。

密。

封。

线。

5.什么叫做波特率?MCS-51系统有几个串口,串口有几个工作方式?哪些工作方式的波特率与
学号;姓名:班级:
试卷类型:(A)卷考核方式:(闭)卷共 5 页第 4 页。

python期末考试题及答案青岛理工大学

python期末考试题及答案青岛理工大学一、选择题(每题2分,共20分)1. Python中用于定义函数的关键字是?A. classB. defC. returnD. function答案:B2. 下列哪个选项是Python中的注释?A. // 这是注释B. /* 这是注释 */C. # 这是注释D. <!-- 这是注释 -->答案:C3. 在Python中,以下哪个数据类型是不可变的?A. 列表B. 字典C. 元组D. 集合答案:C4. Python中,如何实现循环遍历列表中的每个元素?A. for element in listB. for i in listC. for i in range(len(list))D. for element in range(len(list))5. Python中,以下哪个是正确的列表推导式?A. [x for x in range(10)]B. (x for x in range(10))C. {x for x in range(10)}D. [x if x % 2 == 0 for x in range(10)]答案:D6. Python中,以下哪个函数用于将字符串转换为浮点数?A. int()B. float()C. str()D. list()答案:B7. 在Python中,以下哪个操作符用于检查成员资格?A. +B. -C. inD. %答案:C8. Python中,以下哪个模块提供了日期和时间的功能?A. datetimeB. timeC. calendarD. date答案:A9. Python中,以下哪个关键字用于捕获异常?B. exceptC. finallyD. raise答案:B10. Python中,以下哪个函数用于将字符串连接成一个新的字符串?A. str()B. join()C. concat()D. append()答案:B二、填空题(每题2分,共20分)1. Python中,使用____关键字可以定义一个类。

程序设计基础(C语言)(山东联盟)智慧树知到课后章节答案2023年下青岛理工大学

程序设计基础(C语言)(山东联盟)智慧树知到课后章节答案2023年下青岛理工大学青岛理工大学第一章测试1.以下叙述中正确的是()。

答案:用C程序实现的算法可以没有输入但必须要有输出2.以下不能定义为用户标识符的是()。

答案:printf3.按照C语言规定的用户标识符命名规则,不能出现在标识符中的是()。

答案:连接符4.以下C语言用户标识符中,不合法的是()。

答案:a--b5.结构化程序由三种基本结构组成,三种基本结构组成的算法()。

答案:可以完成任何复杂的任务6.以下叙述中正确的是()。

答案:C语言规定必须用main作为主函数名,程序将从此开始执行,在此结束7.C语言源程序名的后缀是()。

.c8.以下叙述中错误的是()。

答案:C程序在书写时,有严格的缩进要求,否则不能编译通过9.下列关于C语言用户标识符的叙述中正确的是()。

答案:用户标识符中不可以出现中划线,但可以出现下划线10.下列4个选项中,()是合法的用户自定义标识符。

答案:_isw第二章测试1.下列选项中,()可以将x、y定义成double类型变量,并赋同一初值3.14。

double x=3.14, y=3.14;2.若变量已正确定义并赋值,表达式()不符合C语言语法。

答案:3.14%23.下列表达式中值为0的是()。

答案:3/54.以下选项中,()是不正确的字符常量。

答案:"a"5.以下选项中不正确的整型常量是()。

答案:1,9006.以下正确的字符串常量是()。

答案:"5111"7.假设在程序中a,b,c均被定义成整型,并且已赋大于1的值,则下列能正确表示代数式的表达式是()。

答案:1.0/a/b/c8.以下能正确定义且赋初值的语句是()。

答案:char ch='A';9.设x、y、z和k都是int型变量,则执行表达式:x=(y=4,z=16,32+z)后,x的值为()。

答案:4810.C语言中,运算对象必须是整型数的运算符是()。

2022年青岛理工大学公共课《C语言》科目期末试卷B(有答案)

2022年青岛理工大学公共课《C语言》科目期末试卷B(有答案)一、填空题1、设有一输入函数scanf("%d”,k);它不能使float类型变量k得到正确数值的原因是_______未指明变量k的地址和_______格式控制符与变量类型不匹配。

2、C语言的源程序必须通过【】和【】后,才能被计算机执行。

3、结构化程序由________、________ 、________ 3种基本结构组成。

4、表达式pow(2.8,sqrt(double(x))值的数据类型为_______。

5、在C语言中,用关键字_______定义单精度实型变量,用关键字_______定义双精度实型变量,用关键字_______定义字符型变量。

6、设x的二进制数是11001101,若想通过x&y运算使x中的低4位不变,高4位清零,则y的二进制数是_______。

7、鸡兔共有30只,脚共有90只,下面程序段是计算鸡兔各有多少只。

请填空。

for(x=0;x<=30;x++){y=30一x;if(_______)printf("%d,%d\n",x,y);}8、若有定义:inta[3][4]={{1,2},{0},{4,6,8,10}};,则初始化后,a[1][2]得到的初值是_______,a[2][1]得到的初值是_______。

9、设有如下定义:#define SWAP(T,X,Y){T=X;X=Y;Y=T;}以下程序段将通过调用宏实现变量x和y内容的交换,请填空。

Double x=2.5,y=6.4,z;SWAP(_______);10、若有以下定义和语句:int*p[3],a[6],i;for(i=0;i<3;i++)p[i]=8&a[2*i];则*p[0]引用的是a数组元素_______,*(p[1]+1)引用的是a数组元素_______。

二、选择题11、以下正确的叙述是( )。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

I.Judgment. (The right answer is “T”, the wrong one is “F” .Each judgment is 2 points, total 201. Both constructor and destructor of base class can be inherited by derived class.2. Static data member is shared by all objects of this class.3. Constructors can be declared as virtual function.4. When overloading an operator, at least one argument of the resulting overloaded operator must be of a class type.5. Constructors have no return type.6. A friend function is not a member of the class, but it can access the private members of that class.7. We can only list types of formal parameters in function declarations.8. There are loop statements can be wrote in the inline function.9. The assignment operator can only be overloaded into a member function.10.In C++, STL is a standard function template library.II.Fill in the blank . (Each blank is 1 point, total:10 points)1. The default access labelfor class is ___________.2. The constructor and the destructor must have the same as the class,.3. The member functions of derived classes can get access to __ _ members and __ members ofa base class, do not get access to private members of a base class.4. In C++, a class with a pure virtual function is called an _______.5. Suppose we have a class named as Dc, when such code like “Dc a[5], b(2),*p;” is implemented, the system will auto-call the constructor of class Dc for _______ times.6. Statement ___________ can catch all kinds of exceptions.7. In C++, in addition to “.”, “*”, “sizeof”, the operator ________ and _______ are also can’t be overload.8. Class istream is used to support input operation, and class _______ is used to support output operation.III.Single Choice (Each choice is 2 point, total:10 points)1. ( )Usually copy constructor’s parameter isA) the name of some object B) the reference of some objectC) member name of some object D) the pointer of some object2. ( )Which is wrong about constructor?A) The compiler may supply default constructor.B) Constructors can have parameters, and returned value.C) Constructors can be overloaded.D) Constructors can have default parameter value.3. ( )Which is wrong about friend?A) The keyword friend is used to declare the friend.B) The member function of one class can be the friend of another class.C) The friend functions can access any specified access label member.D) The friend functions access the member of some object by this pointer. 4. ( )The purpose of virtual base class is.A) to eliminate(消除)ambiguity B) to make a program simpleC) to increase the run efficiency D) to reduce the object codes5. ( )Which is right about the static data member?A) The static data member can not be called by the object name.B) The static data member can be initialized in the constructors.C) The static data member belongs to a certain class.D) The static data member must not be initialized in the file scope.Ⅳ.Point out the error the following programming and explain the reason(write out error linenumber, total:10points)1. const size=10; //L1int a[size]; //L22. class Point{ public:Point() { c=0; x=-1 ;} //L3Point(Point pobj); //L4Point(Point& p) ; //L5 private:int x ; //L6const int c ; //L7} ;3. #include <iostream>using namespace std;class Example{public:Example (int i){m=i;} //L8void Example() { m=0; } //L9void show(){cout<<m;} //L10 private:int m; //L11};int main( ){ Example ex1; //L12Example ex2(5); //L13ex2.m+=10; //L14Example.show(); //L15return 0;}4. int x=9 , *x_ptr=&x; //L16int y=78; //L17 4. int x=9 , *x_ptr=&x;int y=78;*x_ptr = &y ;*x_ptr = &y ; //L18 5. #include<iostream>using namespace std;class BC{ public:void set_x(int a) {x=a;} //L19 protected:int get_x() const { return x; } //L20 private:int x;};class DC : public BC{ public:void add2( ) //L21{ int c=get_x( ); set_x(c+2);} //L22 void add3( ) { x+=3; } //L23 };int main( ){ DC d;d.set_x(3); //L24cout<<d.get_x( )<<endl; //L25d.x=77; //L26d.add2(); //L27return 0;}Ⅴ.Write out the results of the following programs. (Each subject is 5 points; total:30 points) 1. #include <iostream>using namespace std;char str[20]="Hello C++ world.";char &rep(int k){return str[k];}int main( ){rep(15)='!';cout<<"The string is:"<<str<<endl;return 0;}2.#include <iostream>#include <iomanip>using namespace std;int main(){ double values[]={1.23,35.36,657.6,778.2};char* names[]={"Zoot","Jimmy","A1","Stan"};for(int i=0;i<4;i++)cout<<left<<setw(6)<<names[i]<<right<<setw(6) <<fixed<<setprecision(1)<<values[i]<<endl;return 0;}3. #include <iostream>const double PI=3.14;using namespace std;class Figure{ public:Figure(){};virtual double area() const {return 0.0;}};class Circle : public Figure{ public:Circle(double myr){R=myr;}double area() const {return PI*R*R;}protected:double R;};class Rectangle : public Figure{ public:Rectangle (double myl,double myw){L=myl;W=myw;}double area() const {return L*W;}private:double L,W;};void func(Figure &p){ cout<<p.area()<<endl;}int main(){ Figure fig;cout<<"Area of Figure is "; func(fig);Circle c(3.0);cout<<“Area of circle is ”; func(c);Rectangle rec(4.0,5.0);cout<<"Area of rectangle is "; func(rec);return 0;}4. #include <fstream>#include <iostream>using namespace std;int main(){cout<<“Opening data.txt for appending.”<<endl;ofstream fout;fout.open(“data.txt”,ios::app);if ( fout.fail( ) ){cout<<“Input file opening failed.”<<endl;exit(1);}fout<<“Hello C++ world!”<<endl<<“This is an appending program.”<<endl;fout.close();cout<<“End of appending to file.”<<endl;return 0;}Suppose that there is the content: “This is a test program!” in the d ata.txt.when the program executes, what content will exist in the data.txt? 5. #include <iostream>using namespace std;class Base1{ public:Base1(int i){ a=i; cout<<"constructing Base1 a=" <<a<<endl; } private:int a;};class Base2{ public:Base2(int i){b=i; cout<<"constructing Base2 b=" <<b<<endl;} private:int b;};class Base3{ public:Base3(int i){c=i;cout<<"constructing Base3 c=" <<c<<endl; } private:int c;};class Derivedclass:public Base1{ public:Derivedclass(int i,int j,int k,int m);private:int d;Base2 f;Base3 g;};Derivedclass::Derivedclass(int i,int j,int k,int m):Base1(i),g(j),f(k){ d=m;cout<<"constructing Derivedclass d="<<d<<endl; } int main(){ Derivedclass x(5,7,6,8);return 0;}6. #include<iostream >using namespace std;template<class T>class A{T m;static T n;public :A(T a) : m(a) { n+=m; }void disp( ){ cout<<"m="<<m<<",n="<<n<<endl; }};template<class T>T A<T> ::n=0;int main(){A<int> a(2) , b(3);a.disp();b.disp();A<double> c(1.6),d(5.4);c.disp();d.disp();return0;}Ⅵ.Programming Design. (total 20 points)1. (10 points) To define a Point class to satisfy the given test function main:int main(){Point p1(1,2), p2;cout<<"请输入点p2的坐标:"<<endl; p2.input( );p1.show( ) ; //输出(1,2)p2.show( ) ;cout<<"The distance of point p1 and point p2 is "<<p1.dist(p2)<<endl;return 0;}2. (10 points) To design a RMB class to satisfy the given test function main:int main(){ RMB m1(100,2,8), m2(200,9), m;if( m1==m2) cout<<”两者的钱数相等!”<<endl;else cout<<”两者的钱数不相等!”<<endl;m=m1+m2;m=m+50;m.show( ); //按元角分输出return 0;}2011~ 2012学年第一学期C++面向对象程序设计课程试卷标准答案及评分标准A(√)/B( ) 卷_专业软件103-5I.Judgment. (The right answer is “T”, the wrong one is “F” .Each judgment is 2 points, total 20 points.)IIIII .Single Choice (Each choice is 1 point, total:10 points) 1.B 2.B 3.D 4.A 5.CⅤ.Write out the results of the following programs. (Each subject is 5 points; total:30 points) 1. The string is Hello C++ world! 2. Zoot 1.2 Jimmy 35.4 A1 657.6 Stan 778.24. This is a test program!Hello C++ world!This is an appending program.5.constructing Base1 a=5constructing Base2 b=6 constructing Base3 c=7constructing Derivedclass d=8Ⅵ. Programming Design. (total 20 points) 1.#include <iostream>#include <cmath> //1 point using namespace std; class Point {public: Point(int xx,int yy) { x=xx; y=yy; } // 2 points Point(){x=y=0;} //2 points void input() //2 points { cin>>x>>y; } void show(){ cout<<'('<<x<<','<<y<<')'<<endl; } // 1 point3. Area of Figure is 0 Area of circle is 28.26 Area of rectangle is 20 6. m=2,n=5m=3,n=5m=1.6,n=7m=5.4,n=7double dist(Point p); //2 pointsprivate:int x;int y;};double Point::dist(Point p){ return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y)); }int main(){Point p1(1,2), p2;cout<<"请输入点p2的坐标:"<<endl; p2.input( );p1.show( ) ; //输出(1,2)p2.show( ) ;cout<<"The distance of point p1 and point p2 is "<<p1.dist(p2)<<endl;return 0;}2. #include<iostream>using namespace std;class RMB{public:RMB (int y,int j,int f){yuan=y;jiao=j;fen=f;} //1 pointRMB (int y,int j) { yuan=y; jiao=j; fen=0; } //1 pointRMB (int y) { yuan=y; jiao=0; fen=0; } //2 pointsRMB (){yuan=0;jiao=0;fen=0;}; //1 pointvoid show(){cout<<yuan<<"元"<<jiao<<"角"<<fen<<"分"<<endl;} //1 point RMB operator+(RMB m); //2 pointsfriend bool operator==(RMB my,RMB your) //1 point{if(my.yuan ==your.yuan && my.jiao ==your.jiao &&my.fen &&your.fen ) return true;else return false;}private:int yuan,jiao,fen; //1 point};RMB RMB::operator+(RMB m){RMB mon;mon.yuan =yuan+m.yuan ;mon.jiao =jiao+m.jiao ;mon.fen =fen+m.fen ;if (mon.fen >=10){ mon.fen -=10;mon.jiao ++;}if(mon.jiao >=10){ mon.jiao -=10;mon.yuan ++;}return mon;}int main(){ RMB m1(100,2,8), m2(200,9), m;if( m1==m2) cout<<”两者的钱数相等!”<<endl;else cout<<”两者的钱数不相等!”<<endl;m=m+50;m.show( ); //按元角分输出return 0;}Judgment.(The right answer is “T”,the wrong one is “F”.)The keyword friend is used in a function definition,not in a function declaration.(F)Values stored in the elements of a vector may be accessed the same way as values stored in the elements array.()A class can only have one subclass.(F)It is not possible to access the attributes of a class with no member fuctions(methods).(F)The meaning of all the C++ operators(such as *,+etc.)is fixed and cannot be changed.(T)If you do not declare a constructor in a class, the compiler will furnish a default constructor for you automatically.(T)An object of a class A can be a private member of a class B.(T)Because we cannot instantiate objects of abstract base classes, we cannot declare pointers and references to abstract base classes.(F)In dynamic binding an object’s type must be known at compile time for a virtual function call to be compiled.()The assignment operator can only be overloaed into a nonmember function.(F)Fill in the blank.There are four stream object defined in <iostream.h>,the object_____cerr________is the standarderror output stream.In C++,Encapsulation is achieved by making______class(类)_______.In a class,maximum number of destructors are_______1______.Assume that A is a class,the constructor of class A had be called____4_____times when the statement “A a[3],b(6),*p;”was executed.Assume that the name of type parameter is defined as T,when defining the function template,you should add prefix statement____template<class T>____.If the name of a is Myclass,then the name of its destructor is________it has _______return values.If class B is derived from class A,class C is derived from class B,an object of class C is created,then the called order of constructor is_________In the C++,in addition to “,”,”* ”,”sizeof ”,the operator_______and_______are also can’t be overload.选择1、()Which are isn’t the member funcition of a class?A)Constructor B)Destructor C)Friend Function D)Copy Constructor2、()Opening the file”d:\file.dat”and write data to it,which statement should we use?A)ifstream infile(“d:\file.dat”,ios::in); B)ifstream infile(“d:\\file.dat”,ios::in);C)ofstream infile(“d:\file.dat”,ios::out); D)fstream infile(“d:\\file.dat”,ios::in/ios::out);3、()Which is wrong about class?A)Class is one kind of type, it encapsulates data and operates.B)Object is a instance of a class.C)One object can only belong to a class.D)There are only one object in a class.4、()Usually the parameter of a copy constructor is_________.A) a object B)the member of a objectC)the reference of a object D)the pointer of a object5、( ) If there are a pure virtual function in a class,then we call this class as_____________A)abstract class B)virtual basic class C)derived class D)none of above Point out the error the following programming and explain the reason(write out the error line member,total:15 points)1、class Move{private:double x;double y;public:Move(double a = 0, double b=0); //set x,y to a,bshowmove()const; //shows current x,y values;Move add(const Move & m)const; //this function adds x of m to x of invoking object to get//new x, adds y of m to y of invoking//object to get new y,create a new//move object initialized to new x,y values, and returns it reset(double a=0,double b=0); //reset x,y to a,b};Int main(){ Move Point1(3,4),Point2,Point3;cout<<”x and y values of Point1 are:”;Point1.showmove();Point2.reset(5,6);Point3=Point1.add(Point2);cout<<”x and y values of Point3 are:”;Point3.showmove();return 0; }Create member function definitions to satisfy the test function main.2、(9 points)Deine a Complex class,it has two private member real and image.1)Please write a constroctor which can accept 0-2 parameters,a copy constructor, a Print function which can display the value of data member;2) Write Set function:setReal and setImage,which can change the value of private data member;3)Overload operator “+”and”-”;which can finish addition and subtraction of two complex.The main() function listed as following:void main(){Complex c1(1.5,7.9);Complex c2(c1);c2.setReal(2.7);c2.setImage(0);c1.Print();c2.Print();(c1+c2).Print();(c1-c2).Print();};一、Judgement(Please judge the following 10 sentence, and full the blank of the list withyour result. The right answer is “√”, the wrong one is “×”.20 point.)1. We can assign a value to a constant when it is declared. ×2. int sort (int arr[ ]) and float sort (float arr[ ]) are overloaded functions.√3.A function that the compiler generates using a function template is called an instance of the function template or a template function. ×4.A constant pointer to a constant cannot be changed to point to another constant of the same type. √5.Just like the structure members, the default access specifier for class members is private. (×)6.If we defined a constructor in a class, we must define a destructor to destroy it. (×)7.When passing an object to a function, its copy is created in memory. But it does not,invoke (调用)a class constructor. (×)8. When instantiating an object of a derived class, constructors of all of its parent class are executed prior to the derived-class constructors. Destructor functions are always executed inthe same order. ×9. Virtual functions are used with inheritance to resolve conflicts when both base and derived class declare member functions with the same signature. ×10. The member defined in base-class as protected or private can only be accessed by the member functions in derived-class. ×二、Fill in the blank (each blank has 1 point,total:24 score)1.A pointer type specifies the type of __object_________ to which the pointer points 2.Passing a reference to a function is like passing the ___ the address of the variable_used as the argument in the function call.3.A program that uses _______dynamically ___________allocates exactly the amount of memory needed during its execution.4.The default access specifier(指示符,区分符,说明符) for data members and member function are _____private_______5.If member function of class don’t proviet to initialize a class object ,___default constructor_____________is automatically called.6.When member function is called, _____________of the member function point function called.7.While the friend function is not a member of class,it has access to the class______all menber___________ .8.When declared static data member outside the class, _______class name______________must precede the static data member name.9.Constant member functions must be used when working with____constant data member ______________.10. A binary operator can be overloaded by using a ________friend function_______________ rather thana member function.11. ______control_______________access specifier is used only when implementing inheritance.12. To pass arguments from a derived-class to a base-class, a ________derived-class constructor ______________must be created.NUM12345678910RESULT三、Write out result of the following programs(each subject is 6 point;total:36 point) 1.# include <iostream.h>class A {int a;public:A(int aa=0) { a=aa; }~A() { cout <<"Destructor A!"<<a<<endl; }};class B:public A {int b;public:B(int aa=0,int bb=0):A(aa) { b=bb; }~B() { cout <<"Destructor B!"<<b<<endl; }};void main() {B x(5),y(6,7);}2.#include<iostream.h>class Counter{public:Counter(){val=0;cout<<”Default Constructor of Counter”<<endl;} Counter(int x){val=x;cout<<”Coustructor of Counter:”<<val<<endl;} ~Counter(){cout<<”Destructor of counter:”<<val<<endl;} private:int val;};class Example{public:Example(){ val=0;cout<<”Default Constructor of Example”<<endl;} Example(int x):c2(x){val=x,cout<<”Constructor of Example:”<<val<<endl;}~Example(){cout<<”Destructor of Example:”<<val<<endl;}void Print(){cout<<”value=”<<val<<endl;}private:Counter c1,c2;int val;};void main(){Example e1,e2(4);e2.Print()}3. #include<iostream.h>class Test;void fun1(Test t);Test fun2();class Testpublic:Test(int n=1){val=n;cout<<"Con."<<endl;}Test(const Test&t){val=t.val;cout<<"Copy con."<<endl;} Test&operator=(Test&t){val=t.val;cout<<"Assignment."<<endl;return *this;}private:int val;};void main(){Test t1(1);Test t2=t1;Test t3;t3=t1;fun1(t2);t3=fun2();}void fun1(Test t){}Test fun2(){Test t;return t;}4.#include<iostream.h>class Person{public:Person(){cout<<"Constructor of Person."<<endl;}~Person(){cout<<"Destructor of Person."<<endl;} };class Student:public Person{public:Student(){cout<<"Constructor of Student."<<endl;}~Student(){cout<<"Destructor of Student."<<endl;} };class Teacher:public Person{public:Teacher(){cout<<"Coustructor of Teacher."<<endl;}~ Teacher(){cout<<"Destructor of Teacher."<<endl;} };void main(){Student s;Teacher t;}5. #include <iostream.h>#include< iomanip.h>void main ( ){int a[9]={2,4,6,8,10,12,14,16,18};for ( int i=0 ; i<9 ;i++){ cout<<setw(5)<< *(a+i) ;if ((i+1)%3==0) cout<<endl;};}结果: 2 4 68 10 1214 16 186. #include<iomanip.h>void LE(int *a ,int *b){ int x=*a;*a = *b; *b=x ;cout<<*a<<' '<<*b<<endl ;}void main( ){ int x=10, y=25;LE(&x,&y); cout<<x<<' '<<y<<endl ;}四、Programming Design (Each subject is 10 point)1.一个圆型游泳池如图所示。

相关文档
最新文档