中央广播电视大学2001-2002学年度第二学期“开放本科”期末考试(开)
2002年7月
得分 | 评卷人 |
---|---|
一、是非题(每小题2分,共20分)
题号 | . | 三 | 四 | 总分 | |
分数 |
说明:判断各小题说法的正确性扌在下列表格中对应的题号下填入是菲选择,若正确,则打
■
钩否则『打叉(X),
题号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
是/否 | L |
L在程序中,变量定义语句可以出现在该变量使用前的任何位置口
£说明函数原型时,必须指明每个参数的类型和名字’以及返回值类型。
在内存中,一个字符常量或变量是以ASCII码值存储的,它可直接作为整数值参加运
4-头文件中只允存放着变量和常量,以及类的定义亡
If
5・指针变量可以在定义时初始化十但初始化的值只能是该指针类型所指对象的地址值或
NULL。
问,
&若类B某成员函数定义为另一个类A的友元,则该成员函数可以直接访问类A的所
有成员。
(1008号)面向对象程序设计试题第1页(共12页)
得分评卷人-
二、填空题(共20分)
说明:按各小题的要求,在下列表格中对应的空项号右边填入相应的内容。
(1)下面程序的每行前面加有行号,它求一个数组元素之最小值。主程序中定义并初始化
了一个数组,然后,调用函数min()取得其最小值,最后,输出结果。填入程序中不完整部分的
应有的内容。(每项空项2分,共10分)
空项号 | 应有的内容 |
A | |
B | |
C | |
D | |
E |
L A
e
I
15- return iMin;
16. }
(2)下面程序的每行前面加有行号,共15行。将程序中变量value、sum、j、对象cout和函
数print-funcO的作用域范围的起止行号分别填入下表中& (每项空项1分,共10分)
变量、对象或函数名称 | 作用域起始行号 | 作用域终止行号 |
value | ||
sum | ||
.
J |
||
cout | .1 | |
print^func |
1- # include<iostream. h>
2. int value ;
- void print_func();
- void main()
- {
- int num[5]H{2,5,7,10,15};
- int sum = 0;
- for(int j = 0;jV5;j + + ) sum + = numEjJ;
- value—sum
- print_func();
- }
- void print一func()
- (
- coutVV”The summation~ ^«value<<endll ;
- }
评卷人
三、简单编程题(共20分)
说明:根据各个小题程序功能要求,写岀函数的完整定义。
1.(本小题10分)写一个函数,找出给定字符串中大写字符(即’A,一N,)的个数(如字符 串wCapital_Letter_in_Stringw中大写字符的个数为3个)。函数的原型为:
int CalcCapitalCchar * str);
函数参数:str为所要处理的字符串;
函数返回值:所给字符串中大写字符的个数
int CalcCapitalCchar * str)
( 〃在下面写上程序的实现
double power (double x,int n);
该函数完成xn的运算,并返回运算结果,其中|x|<l. 0,n> = 0.
double power (double xUnt n)
( //在下面写上程序的实现
hi
评卷人
四、问答题(本题共40分)
U1
说明:读懂各个小题程序,为了便于提问,程序的每行前面加有行号,请对所提的问题作出
准确的相应解答。
(1)(本小题10分)读懂如下程序:
L 甘 includeViostream. h> 2・ int CircleAreaO ;
4-
double * pd=new double;
if(! pd)
6.
cout<<aError memory allocation!”VVendl; return 1;
7.
9.
10.
double& rd= * pd;
11-
coutVV”the radius is:”;
12.
cin»rd;
13.
14.
delete &rd;
15.
return 0;
16.
17.
void mainO
18.
19.
if (Circle Area ())
coutVV”the area of circle is”VVrd * rd * 3.14VVendl;
cout«KThe program failed!”VVendl;
20・
else
cout«aThe program successed!”VVendl;
22.
23.
请写出下列问题答案:
答:
< ..
答:
答:
■
答:
答:
(2)(本小题15分)读懂如下程序:
4
f
1. # include Viostream. h>
2- class Paternity
- {
- private:
- static object-count;
- 〃…其他成员
- public:
- Paternity () {object-count+ + ;}
- 〜 Paternity () (objct-count ;}
- static int GetobjectCount() {return object-count;}
IL void func() {cout<<afunction in Paternity without parameter! \n”;}
12- virtual void func(char % str) {coutVV“class Paternity : “VVstrVVendl;}
c
I.
13. };
private:
17. 〃…其他成员
J
18- public:
- void funcO (cout<<afunction in Children withount parameter! \n”;}
- void func(int data){coutVV”class Children:”VVdataVVendl;}
- void func(char * str) {coutV〈”class Children: ^«str«endl ;}
- };
- int Paternity:: object-count=0 ;
- void main(int argc?char * argv口)
- {
■
26- Children son;
27. Paternity pPal —&son;
2& Paternity * pPa2 = new Paternity [^5 ]; ・
D
请写出此程序执行所显示的结果。
(3)(本小题15分)读懂如下程序:
3- (
4・ | private: |
5- | int *_mem;
• |
6. | int 一length; |
7. | const int _max-length; |
8. | public: |
9- | List (int Max-length = 10) :一max_length (Max一length)
♦ ■■ |
10. | { |
11-
12. |
_mem = new int[一max_length];
_length=0; • |
13. | } . |
14. | 〜List() {delete □一 mem; } |
15. | bool Insert(int index? int data); |
16. | int Delete(int i); |
17- | void PrintListO ; |
18. | void PrintList(char *);
1 |
19. | bool IsEmptyO (return 一length==0;} |
20. | bool IsFulK) (return _length= = _mex_length;} |
21. | int GetLengthO (return -length;} |
22. | int GetMaxLengthO (return _mex_length;} 、 |
23. | int operator]] (int i) (return 一mem[i];} |
24- | };
■3 |
25. | / ******************* 文件 list, cpp **************** / |
26. | # include Viostream. h> |
27- | # include alist. h” |
28. | a
bool List: :Insert(int index, int data) |
29. | { |
30. | if (^-length—= ^max_length)return false; |
31- | if (index> length )index = – length; |
32. | 〃将从index开始的元素向后挪 |
33. | for(int i=_length; i>index; i ) _mem[i] = _mem[i — l]; |
34. | _length + + ; |
35. | 一 mem [index] = data ; |
36. | return true; |
37. | } |
38. | int List: : Delete (int index) |
39. | { |
40. | if (index〉=—length) |
41- | { |
42. | coutVV’No, Can’t be deleted I <endl; |
43. | return 0; |
44. | } |
45. | int retData = _ mem [index]; |
46. | 〃将从index+1开始的元素向前挪 |
47. | for(int i=index+l; iV-length; i+ + )一mem[i —= |
48. | 1
-length——; |
49. | return retData ; |
50. | } |
51- | void List:: PrintListO |
52. | { |
53- for(int i=O;i<_length; i + + )coutVV一mem[i]VV”“;
56< void List:: PrintList(char * str)
59* cout«i£ — — w<<str«w-,length — w<<_length<<endl ;
6L / ************************ 文件 main, cpp ***************** /
.
68- if (A. IsEmpty ( ) &&-B. IsEmptyO)
• •
mt i;
- for(i = 0; i<A. GetMaxLengthO ; i+ + )A・ Insert(i92 * i + 1);
- for(i = 0; i<B. GetMaxLengthO ; i + + )B. Insert(i,2 * i);
- if (A. IsFull()&&B. IsFull())cout «aLists are full J w«endl ;
- else cout VV“A or B List is not full!”VVendl;
- for(i = 0; i<(B. GetMaxLength())/2; i + + )B. Delete(0);
- B. PrintList(^List_Bw) ;
- for(i = 0; iV(B・ GetMaxLength())/2;i+ + )B. Insert(0,AEi]);
- B. PrintListO ;
- }-
请写出此程序执行所显示的结果。
中央广播电视大学2001-2002学年度第二学期“开放本科”期末考试
tn
2002年7月
一、是非题标准答案(每题2分,共20分)
n
. |
题号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9’ | 10 | ■■ |
是/否 | V | X | X | X
J |
X | P – | X |
评分标准说明:每答对一小题得.2分,共20分。
1-标准答案
空项号 | 应有的内容 , |
A “ | # include Viostream. h> ,
i |
B | int iMin^of Array ; |
C | i < den 、 |
D | i + + “ |
E | if (iMin<arrayGJ)iMin=arrayEiZI; 、 |
评分标准说明:每填对一空项得2分,共10分。
L
评分标准说明:每填对一空项得1分,共10分。
变量、对象或函数名称 | 作用域起始行号 | 作用域终止行号 |
value | 2 | 15 |
sum | 7 | 11
1 |
j | 8 | 11(8也对) |
cout
1 |
1 | 15
• |
print 一 func | 3 | 15 |
2.标准答案.
-T
〃判断字符指针是否为空
if (str= —NULDreturn 0;
〃记录字符个数的变量
int num-of-capital = 0 ;
//依次检査各个字符,如果是大写字符,则计数加1
for(int i = 0; str[i];i+ + )
if (str[i]=str[i]V= 2) num-of_capital+ + ;.
〃返回大写字符个数
return num_of-capital ;
评分标准说明:本小题共1。分,具体评分要点如下
strlen(str),也可以通过判断str[:订是否为0x0来判断是否到了字符串的结尾。
double power (double x9int n)
〃检查参数是否合理,若不合理,给出错提示信息,并立即退出,返回一1.
if <(x> = l. 0| |x< = -1.0| |n<0)
cout V〈”Error!” Wendl ;
return —1 ;
〃递归算法求藉函数
if (n= =0)
return 1 ;
else
return x power (x?n—1);
•评分标准说明:本小题共10分,具体评分要点如下
- 参数合理性检査与处理,占2分。
- 判断递归结束条件的语句占4分,如果没有写或者根本不正确,扣4分,如果写了,但有 错误,则视情节轻重扣分:如果、==0,写成¥=0,或等,扣2分,但写成^<1?是正 确的。如果没有写return语句或者返回值不是1,扣2分。
- 递归调用语句占4分,如果递归语句逻辑不正确,扣3分,如果有语法错误,则适当扣 分°如果没有return语句,扣1分。, 四、问答题(共40分)
(1)标准答案
■j
⑤答:执行结果输出内容为:
the radius is:2. 0
the area of ciricle is 12. 56
The program successedj
评分标准说明:本小题共10分,①一⑤各占2分。
(2)标准答案
3
执行结果输出内容为:
0
There are 6 objects*
class Children: Hi!
■ ■
r-
■ ■
class Paternity: Good!
■I
p
function in Paternity without parameter!
There are 1 objects.
评分标准说明:本小题共15分,输出每行信息占3分;
+
执行结果输出内容为:
L • I
Lists are empty when initialized!
Lists are full!
13 5 | 7 | 9 11 13 | 15 | 17 | 1 –
19 List_A-length=10 |
16 18 | 20 | 22 24 26 | 28 | 30- | List_B_length = 8 |
15 13 | 11 | 9 7 5 3 | 1 | 16 | 18 20 22 24 26 28. 30 |
I
评分标准说明:本小题共15分,输岀每行信息占3分。
评论0