软件水平考试1997程序员下午试卷
试题一
阅读下列basic程序,将应填入__(n)__处的字句,写在答卷的对应栏内。
[程序1.1]
a=1
b=-1
if a>b and b=abs(b) then goto p
a=2
if a=b or not(a+b)<(a-b)then goto p
a=3
if(a=2 or b-1=-a)or(a=b+4 and not (a<>3) then goto p
a=4
p:print a+abs(b)
end
程序执行后,输出结果为__(1)__.
[程序1.2]
declare function p$(x,y)
common shared a,b,c$
input “a=”,a
input “b=”,b
c$=“test-result”
print p$(a,b)
end
function p$(x,y)
if x>=y then
z$=mid$(c$,6,6)+“1=”+str$((sqr(x)+abs(y))/2)
else
z$=mid$(c$,6,6)+“2=”+str$(int(x+y)*100)
end if
p$=z$
end function
若对变量a、b分别输入16和-3,则输出结果为__(2)__。
若对变量a、b分别输入23.3和39.5,则输出结果为__(3)__。
[程序1.3]
c$=“0123456789abcdef”
i=16
dim x$(i)
l: input“s=”,s
input“d=”,d
if (s<2’ors>16 or d < 0 or d>32767 then
print “error”
goto l
end ir
do while d<> 0
a=d
d=int(a/s)
b=a-d*s
x$(i)=mid$(c$,b+1,1)
i=i-1
loop
for j=i+1 to 16
print x$(j);
next j
end
若对变量s、d分别输入16和175,则输出结果为__(4)__。
[程序1.4]
option base 1
dim b(6)
k=1
while k<=6
read b(k)
k=k+1
wend
for k1=1 to 5
l=b(k1+1)
for k2=k1 to 1 step –1
if l>b(k2)then
goto s
end if
b(k2+1)=b(k2)
next k2
s: b(k2+1)=l
next k1
i=1
do until i>6
print b(i);” ”;
i=i+1
loop
data 9,-1,4,18,-5,7
end
程序执行后,输出结果为__(5)__。
试题二
阅读以下与c语言有关的叙述,将应填入__(n)__处的字句,写在答卷的对应栏内。
已知int x=1,y=2,z=3;
则z + = x > y ? + + x : + + y的值是__(1)__。
已知int a[ ] ={10,9,8,7,6},*p=a;
则*(p+1)*(p+2)[2]的值是__(2)__。
已知char ch ;
则判别 ch 是英文字符的逻辑表达式是__(3)__。
已知int p( ),(*q)( );
则p是__(4)__,而q是__(5)__.
试题三
阅读以下foxbase程序,将应填入__(n)__ 处的字句,写在答卷的对应栏内。
[程序3.1]
set talk off
p=ctod(‘07/01/97’)
q=‘东方之珠:香港’
r=‘庆祝回归’
m=substr(q,10,4)+substr(r,5,4)+’日’
? dtoc(p)+’是+substr(r,1,4)+m
set talk on
return
程序执行后,输出结果为__(1)__。
[程序3.2]
* p1.prg
set talk off
a=100
b=1
do p2 with b
? b*4+sqrt(a)
set talk on
return
* p2.prg
parameters u
u=u+2
if u<20
retry
endif
return
程序执行后,输出结果为__(2)__。
[程序3.3]
* g1.prg
set talk off
clear
dimension x (2)
public a
a=’绿化’
b=146.77
x(1)=’bc’
x(2)=’ef’
c=’祖国’
do g2
? a+c
?x(1)+x(2),b+100.1
set talk on
return
* g2.prg
private b
a=’保卫’
b=476.22
store’aa’ to x
return
程序执行后,输出结果为__(3)__和__(4)__。
[程序]
*.prg
set talk off
clear
input’a=’ to a
input’b=’ to b
input’c=’ to c
g=100*cal(a,b,c)
?’程序输出:‘+str(g,5,1)
set talk on
return
*自定义函数cal.prg
parameters x,y,z
s=(x+y+z)/2
return sqrt(s*(s-x)*(s-y)*(s-z)
当a、b、c分别键盘输入3,4,5经程序执行后,输出结果为__(5)__。
试题四
阅读以下程序说明和basic程序,将应填入__(n)__处的字句。写在答卷的对应栏内。
[程序说明]
本程序按得分从大至小打印出十佳运动员的编号、得分和名次。运动员编号、得分由data语句提供,分别存入在数组n和数组m中。每个运动员得分最高为120分。得分从大到小排序方法采用冒泡法,为提高排序速度,算法中啬了下列措施:若在某一次冒泡过程中发现没有发生过数据交换,则表示数据已排序完毕,此时可提前结束排序。
具有相同得分的运动员,其名次相同。例如前4位运动员排序后的名次情况如下:
编号 得分 名次
4 119 1
7 119 1
2 116 3
5 110 4
[程序]
dim n(10),m(10),l (10)
for i=i to 10
read n(i),m(i)
next i’
i=10
s1: flag=0
for__(1)__
if m(j) < m(j-1) then __(2)__
swap n(j), n(j-1)
swap m(j),m(j-1)
flag=1
s2: next j
i=i-1
if__(3)__ then goto s1
print“编号”,“得分”,“名次”
l(1)=1
for i=2 to 10
print n(i-1),m(i-1),l(i-1)
if m(i-1)=m(i) then __(4)__else __(5)__
next i
print n(10),m(10),l(10)
data 1,102,2,118,3,99,4,107,5,117
data 6,115,7,111,8,117,9,102,10,104
end
试题五
阅读以下程序说明和c语言,将应填入__(n)__处的字名,写在答卷的对应栏内。