高级语言程序设计
上海市(2000.4)

答 案

一、填空题(每空1分,共14分)
1、设c=‘E’,表达式chr(ord(c)+2)的值是__________________,而表达式chr(ord(c)-2)的值是__________________。

3、表达式(round(-63.4)<trunc(-74.3))and (7.6>4.2)的值是___________________。
4、为了避免if语句嵌套使用中的岐义性,PASCAL规定一个else应与_________________相匹配。
5、设
type rec=record
c,d:char
end;
var x::rec;
执行语句序列:
read (x.c,x.d);
if ord (x.c)>ord (x.d) then writeln (x.c)
else writeln (x.d);
输入GM时,输出结果是__________。
6、执行语句序列:
read(x);
if x>0 then write (‘1’) else if x<0
then write (‘-1’) else write (‘0’);
输入-3 时,输出结果是___________________________。
7、设var
x:array [1..4] of char; i:integer;
执行语句序列:
for i:=1 to 4 do
begin read(x[i]); write chr(ord (x[i])+1) end;
输入cemr时,输出结果是_______________。
8、函数的结果类型只允许是____________________和________________。
9、用过程语句p(-5)调用过程:
procedure p(x:integer);
begin if x>0 then write (x)
else writeln (abs(x))
end:
输出结果是_______________。
10、由于分程序的嵌表,按不同层分程序可将标识符区分为______________和________。

二、单项选择题(在下列每小题四个备选答案中选出一个正确答案,并将其字母标号填入题干的括号内。每小题2分,共16分)
1、表达式中的运算符与相应运算成分的( )有关。
A、值
B、语法位置
C、作用域
D、类型
2、函数odd(x)当x为( )时,其结果为逻辑值true。
A、偶数
B、整数
C、奇数
D、逻辑数
3、说明过程或函数时,关于过程首部与函数首部下述说明正确的是( )
A、过程首部与函数首部必须有形式参数表
B、过程首部与函数首部可以没有形式参数表
C、过程首部可以没有形式参数表, 但函数首部一定有形式参数表
D、过程首部应有形式参数表, 但函数首部可以没有形式参数表
4、由过程说明运行得到的结果数据值,是通过( )返给调用者的。
A、值参数
B、变量参数
C、局部量
D、过程说明中的返回语句
5、程序的风格和( )有关。
A、程序的易读性
B、程序的结构(例如使用不使用过程与函数)
C、程序的算法
D、程序的难易程度
6、标识符的作用域是该标识符的定义点区域除去嵌套在内的一些区域。除去的区域是指( )
A、嵌套在内的所有分程序
B、另一些标识符的定义点区域
C、与该标识符拼写相同的标识符的定义点区域
D、没有使用该标识符的区域
7、缓冲区变量的类型是( )
A、整型
B、批针类型
C、文件类型
D、文件的成分类型
8、直接访问文件指可对文件中( )直接访问。
A、指定成分
B、任一成分
C、当前成分
D、下一成分

三、改错题(指出下列程序(段)中的错误及出错理由。每小题2分,共8分)
1、program
er1 (input,output);
type a=’A’..’Z’;
var c:a;
begin
read(c)
if c=a then write(a) else write(c)
end.
(1)____________________________
(2)____________________________
2、program er2 (input,output);
var s,i,j:integer;
begin
read (I,j); s:=0;
while i mod2 do
begin s:=s+j mod 10; j:=j div 10 end;
writeln (s:4)
end.
(1)_______________________________
(2)_______________________________
3、program er3 (input,output);
var a:integer; b:real; c:boolean;
function f(a :real;b:intger) : boolean;
begin
if a<b then c:=true else c:=false
end;
begin
read (a,b);
c:=f(a,b); write(c:6)
end.
(1)__________________________________________
(2)__________________________________________________________________________.
4、program er4 (input,output);
type ta =arrary [‘A’..’Z’] of char;
var a:ta; ch: char;
begin
for ch:=’a’to ‘z’ do a [ch]:=ch;
write(a)
end.
(1)___________________________________________________________________________________________________.
(2)___________________________________________________________________

四、阅读程序题:阅读下列程序,说明其功能(7分)(不需给出运行结果)
program matrix (output);
const n=20;
var a:array[1..n,1..n] of integer; i,j: integer;
begin
for i: =1 to n do
begin
for j:=1 to n do
begin
if i=j then a[i,j]:=1
else if i+j=n+1 then a [i,j]:=1 else a[i,j]:=0;
write(a[I,j]:2)
end ;
writeln
end
end.

五、计算题(每小题10分,共30分)
阅读如下程序,将程序运行时的输出填写在相应答题栏内。
1、计算程序1如下:
program calc1(input,output); 答题栏:
var x,y:integer:
procedure prosub(x:integer;var y:integer);
begin
x:=succ(x+2)div 2;
y:=pred(y-3)mod 2;
writeln (‘x=’,x,’y=’,y)
end;
begin
read(x,y);prosub(x,y);
writeln(‘x=’,x,’y=’,y)
end.
当程序运行输入10 14时,其输出为:
2、计算程序2如下:
program calc 2(input,output); 答题栏:
type cset=set of char;
var cs:cset; ch:char; i:1..10;
begin
cs:=[ ];
for i:=1 to 10 do
begin
read(ch);
if ch in [‘a’..’z’,’A’..’Z’] then cs:=cs+[ch];
end;
writeln;
for ch :=’a’to ‘z’do
if ch in cs then write (ch:2);
writeln;
for ch :=’A’ to’Z’ do
if ch in cs then write(ch:2);
writeln
end.
当程序运行输入 Abffce675E时,其输出为:
3、计算程序3如下:
program calc3; 答题栏:
type cha =’a’..’z’;ptc=?cha;
var c1,c2:ptc;
procedure sub(ch1,ch2:ptc);
var t:char;
begin t:=ch1?;ch1?:=ch2?:=t
end;
begin
new(c1); new(c2);
read(c1?);read(c2?);
if cl?>=’b’ then
c1?:=pred(c1?);
if c2?<=’y’ then
c2?:=succ(c2?);
sub(c1,c2);
writeln(‘cl?=’,cl?,’c2?=’,c2?);
dispose(c1);dispose(c2)
end.
当程序运行输入dm时,其输出为:

六、编程题(第1题12分,第2题13分,共25分)
阅读如下问题说明和程序,将应填入
处的语句、表达式或其它成分,填写在相应答题栏内。
1、方阵逆时针旋转90
该程序读入n×n矩阵的值,然后以矩阵中心点为轴心,逆时针地旋转90,例如n=5时,读入矩阵为





























































旋转成:

0 1 2 3 4 4 9 19 24
5 6 7 8 9 3 8 18 23
10 11 12 13 14 2 7 17 22
15 16 17 18 19 1 6 16 21
20 21 22 23 24 0 5 15 20

 

6 7 8 8 13 18
旋转算法是将矩阵分层处理,如上例矩阵第2层为11 13将这8个数交换成7 17
16 17 18 6 11 16
[程序]
program k1;
const m=20;
type tarr=array[1..m,1..m]of integer;
var a:tarr; i,j,n:integer;
procedure rotation( A ;n:integer );

vqr i,j,c:integer;
begin
for i:= 1 to n div 2 do
for j:= B do
begin c:=a[i,j];
a[i,j]:= C ;
D := E
F :=a[n-j+1,i];
a[n-j+1]:=c
end
end;(* end of p7roc7 &*)
procedure pntm(var a:tarr; n:integer);
var i,j:integer;
begin writeln;
for i:=1 to n do
begin
for j:=1 to n do write (a[i,j]:38);
writeln end
end;(* end of pntm *)
begin
read(n);
for i:=1 to7 n do
for j:=1 to n do
a[i,j]:=(i-1)*n+j-1;
pntm(a,n);
potation(a,n);
pntm(a,n)
end.
2、生成链
该程序读入一级非零整数,并按其奇偶分别生成奇数链和偶数链。两链的链接关系分别按整数由小到大顺序链接。当读入一个整数,若是奇(偶)数,则在奇(偶)数链上插入一个新结点最后输出两条链。例如,读入1 2 3 5 6 7 0 生成的链为

program prg2;
type link=?node;
node=record c:integer; next:link end;
var pod,pev:link;n:integer;
procedure inst ( A ; n:integr);
var p1,p2,q:link;
begin new(q);q?.next:=nil end
else if B
then begin C ; p:=q end
else begin p2:=p;
repeat p1:=p2;p2:=p2?.nrxt;
if p2=nil
then begin D ;
q?.next:=nil end
else if E
the begin p1?.next:=q;
F ned
until (p2=nil)or(n<=p2?.c)end
end:
procedure pnt(p:link);
begin writeln;write(‘Link:’);
while p<>nil do
begin write(p?.c:3);p:=p?.next
end end;
begin
pod:=nil;pev:=nil;read(n);
while n<>0 do
begin if odd (n)
then inst(pod,n)
else inst(pev,n);read(n)end;
pnt(pod);pnt(pev)
end.
六、答题栏:
1、方阵逆时针旋转90
A ___________________________________
B ___________________________________
C ___________________________________
D ___________________________________
E ___________________________________
F ___________________________________
2、生成链
A ___________________________________
B ___________________________________
C ___________________________________
D ___________________________________
E ___________________________________
F ___________________________________