中央广播电视大学2001 —2002学年度第一学期“开放本科”期末考试(开)
2002年1月
得分 | 评卷人 |
---|---|
r是非题(每小题2分,共20分)
题号 | 一 | 二 | . | 四 | 总分 |
分数 |
说明:判断各小题说法的正确性,在下列表格中对应的题号下填入是非选择,若正确测打
钩(/);否则。打叉(乂儿
题号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
是/否 |
1变量必须在程序开头定义或说明,以便给它分配空间七
数中,
3在内存中,含N个字符的一个字符串常璽以一串相应的ASCII码值存储,占用N个字
节。
指针变量在使用前,应先定义和初始化,而且,必须在定义的同时进行初始化。
=1 —i
5头文件中不仅存放着变量的声明和常量的定义尸也可以有类的定义和函数的原型声
明口
6引用是个别名,建立引用时,用另一个同莖变量或对象的名字初始化它n
10+类模板或函数模板都只是模板的定义,并非一个实实在在的类或函数,定义中用到通
用类型參数口
评卷人
二、填空题(共20分)
说明:按各小题的要求,在下列表格中对应的空项号右边填入相应的内容。
(1)下面程序的每行前面加有行号,它是求一个数组元素之最大值。主程序中定义并初 始化了一个数组,然后,调用函数max()取得其最大值,最后,输出结果。填入程序中不完整部
分的应有的内容。(每填空项2分,共10分)
空项号 应有的内容
A
B
C
D
一E — | — —
- A ;
- mt max (mt 口 ,mt);
- void main()
- {
- int ia[10] = {17, -2, -13,6,4,7,23, -10,51,9};
- B ;
- iMax.of Array = max(ia,10);
- cout < V “Max of array: ” < < iMax of Array < < endl;
- I 10 int max( int array] ] ,mt len)
- {
- mt iMax = 0;
- for ( mt i = 0 ; C ; D )
- E ;
- return iMax;
(2)下面程序的每行前面加有行号,共20行。将程序中变量len、k、chk、对象cout和函数 pnnt„func()的作用域范围的起止行号分别填入下表中。(每项空项1分,共10分)
变量、对象或函数名称 | 作用域起始行号 | 作用域终止行号 |
len | ||
k | ||
chk | ||
cout | ||
pnnt func |
L #mclude < lostream h >
2. mt len ;
3・ void pnnt func ();
4. void mam()
5 1 | |
6 | static char name[ ] = “Zhang”, |
7. | mt k =0; |
8 | while (name[ k] ) { |
9. | char chk; |
10. | chk = name[ k]; |
11. | cout < < chk ; |
12. | k+ + ; |
13. | ! |
14 | len = k ; |
15. | pnnt _ func (); |
16. | } |
17. | void print _ fiinc () |
18. | { |
19 | cout < < “The stnng length = n < < len < < endl; |
20. }
评卷人
三、简单编程题(共20分)
说明:根据各个小题程序功能要求,写出函数的完整定义。
L (本小题10分)写一个函数,找出给定字符串中小写字符(即如,-財)的个数(如字
符串”LowercaseString”中小写字符的个数为15个)o函数的原型为:
mt CalcLowercase( char * str);
函数参数:str为所要处理的字符串;
函数返回值:所给字符串中小写字符的个数
int CalcLowercase( char * str)
( //在下面写上程序的实现。
2 (本小题10分)用递归函数完成四分之一圆周率(PI)的近似值计算,公式如下:
U!
丝5)二」丄+丄-丄+・・・+-(m)“”
4 七丿 3 5 7 2n-l
函数的原型如下:
double quarter^PI(int n);
该函数实现对四分之一圆周率(PI)的运算,并返回运算结果,其中n〉0。
U!
提示:可使用递归表示,即,若n= =1,取值为1 ; h > 1时,取如下递归表达式:
PI,、 PL ( -I)71‘1
quarter = quarter ^PI(n — 1) + —J—
2n — 1
double quarter^ PI (mt n)
{〃在下面写上程序的实现Q
评卷人
四、问答题(共40分)
U!
说明:读懂各个小题程序,为了便于提问,程序的每行前面加有行号,请对所提的问题作出 准确的相应解答。
L #mclude < mstream. h > 2・ mt Rectangle Area ();
- cm > > sd;
- cout < < “the area of rectangle is” < < sd sd < < endl;
- delete &sd ;
- return 0 ;
- !
- void main()
- {
- if( Rectangle Area ())
- cout < < ^ The program failed!” V V endl;
- else
- cout V < “The program successed!” < V endl;
- }
请写出下列问题答案:(每个问题2分)
答:
答:
答:
答:
答:
9. ~ Paternity ( ) { otgect^ count 」
10 static int GetobjectCount( ) {return object.count;}
IL virtual void func( mt data) { cout V V ” class Paternity:” V < data < < endl;}
- void fiinc(char * str) { cout < < “class Paternity: ” < <str< < endl;}
- };
- class Children: public Paternity
- {
16 pnvate:
- 〃…其他成员
- public:
- void func( ) j cout < < u function m Children without parameter J \n” ;}
- void fiinc(int data) { cout < < wclass Children:< < data < < endl;}
- void fiznc(char * str) { cout < < aclass Children:” < < str < < endl;}
- }
- mt Paternity:: object, count = 0 ;
- void mam( mt argc,char * argv[])
- {
- Paternity * pPa ;
- cout <〈”There are ” < <pPa – > GetobjectCount( ) < < u objectsn < < endl;
- Children son ;
- pPa = &son ;
- cout < < “There are” < <Paternity::GetobjectCount( ) < < “objects” < < endl;
- pPa – >func(10);
- pPa – >func( “Hi”);
- son. func( ” OK”);
34.
请写出此程序执行所显示的结果O
const mt . max length ;
7
104
public:
List( mt Max .length = 10):. max length( Max length)
mem = new mt[ max. length];
.length =0;
~ List() bool Insert ( mt index, mt data); mt Delete( mt i);
bool IsEmpty()
bool IsFull()
mt GetLength ()
mt GetMaxLength ()
{return length = =0;}
I return length = = max length ; \
j return – length ;}
{return max . length; |
int operator [ ] ( mt i)
{ return mem[ i] ;}
/ *甲*牙木****************屮 文件 list, cpp **才**4«扌甲很**申**出***木* /
#mclude < lostream h > #mcludew list, h” bool List: :Insert(int index, mt data)
{
if( .length = = max,length)return false;
if (index > length) index = . length;
〃将从index开始的元素向后挪
for(mt i = .length; i > index;i ) = _mem[i – 1];
length + + ;
mem [index] = data;
return true;
mt List:: Delete(int index)
if( index > = length)
cout < V ” No, Can *t be deleted!” V V endl ;
return 0,
mt retData = mem[ index];
〃将从index +1开始的元素向前挪
fbr( int i = index + 1 ; i < length; i + + ) mem[ i – 1] = mem[ i];
length
return retData ;
/ *不**木*彳甲***才******:!■耳 **** 戈1件 main cpp 才**甲**才**#**4«屮4«** / #mclude < lostream. h > #mclude” list h” void mam()
{
List A;
List B(5);
if( ! A. IsEmpty()11! B. IsEmpty())
!
cout < < u Lists are not empty when initialized! \n”; return ;
mt i;
for(i =0; i < ( A. GetMaxLength( ) )/2; i+ + )A. Insert(i,2 * i);
fbr(i =0: i <B. GetMaxLength() ;i + + )B. Insert。,2 才 i +1);
- if (A. IsFulI( ) ) cout < < ‘”List A is full! \n”;
- else cout < < “List A is not foil! \nM ;
- if (B. IsFull( ) ) cout < < <(List B is full! \n”;
- else cout < < “List B is not full! \n”;
- cout <(<List B is Deleted< < B. Delete(2) < < endl;
- for(i =0; i <B. GetLength( ) ; i + + )A. Insert(2 * i +1 ,B[i]);
- cout V v ” List A is Deleted:”;
- A Delete(lO);
- for(i =0; i < A GetLength ( ) ; i + +) cout <‘< A[i] < ‘
- cout < < endl ;
- }
请写出此程序执行所显示的结果O
Is
中央广播电视大学2001-2002学年度第一学期“开放本科”期末考试(开)
计算机专业面向对象程序设计
(供参考)
2002年1月
题号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
是/否 | X | X | X | y | X | X | y |
评分标准说明:每答对一小题得2分,共20分。
1.标准答案
空项号 | 应有的内容 |
A | #include < xostream h > “ |
B | mt iMax of. Array ; |
C | i < len |
D | i + + |
E | if( iMax < array[ i] ) iMax = array[ i]; |
评分标准说明:每填对一空项得2分,共10分。
2.标准答案
变量、对象或函数名称 | 作用域起始行号 | 作用域终止行号 |
len | 2 | 20 |
k | 7 | 16 |
chk | 9 | 13 |
cout | 1 | 20 |
pnnt fiinc | 3 | 20 |
评分标准说明:每填对一空项得1分,共10分。
(1)标准答案
mt CalcLowercase ( char * str)
)
〃判断字符指针是否为空
if (str = = NULL)return 0;
〃记录小写字符个数的变量
mt num – of_ Lowercase = 0 ;
〃依次检查各个字符,如果是小写字符,则计数加1
fbr(int 1 =0; str[i] ;i + + )
if( str[ = 5 a5 && str[i] < = W ) numof Lowercase + + ;
//返回小写字符个数
return num of. Lowercase ;
评分标准说明:本小题共10分,具体评分要点如下。
- 判断若字符指针为空,则返回0,占2分。
- 定义小写字符计数变量并初始化为0,占2分。
- 正确的循环条件和循环增量,占2分。循环的条件可以有多种。可以用循环变量从0 到strlen(str),也可用str[i]为0x0来判断到了串的结尾。
- 循环体占3分。其中,正确的判断条件表达式占2分,小写字符计数占1分。
- 返回小写字符计数,占1分。
(2)标准答案
double quarter^ PI( mt n)
〃检查参数是否合理,若不合理,给出错提示信息,并立即退出,返回- L
if (n <0)
cout V V ” Error!” V V endl ;
return 1 ;
〃递归算法计算四分之一圆周率
U!
if(n = = 1)
return = 1 ;
else
if( n%2 = = 1)
return quarter PI ( n — 1) + 1/( 2n – 1),
else
return quarter PI(n — 1) – l/(2n – 1);
评分标准说明:本小题共10分,具体评分要点如下
正确的。如果没有写retum语句或者返回值不是1,扣2分。
四、问答题(共40分)
(1)标准答案
⑤答:执行结果输出内容为:
the side is : 1.2 the area of rectangle is 1 . 44
The program successed!
评分标准说明:本小题共10分⑤各占2分。
⑵标准答案
执行结果输出内容为:
There are 0 objects.
There are 1 objects
class Children: 10 class Paternity:Hi class Children: OK
评分标准说明:本小题共15分,输出每行信息占3分。
(3)标准答案
执行结果输出内容为:
List A is not full!
List B is full!
List B is Deleted:5
List A is Deleted : No, Cant be deleted!
012347698
评分标准说明:本小题共15分,输出每行信息占3分。
评论0