22、【
单选题
】 下面是求最大公约数的函数的首部
function gcd(byval x as integer, byval y as integer) as integer
若要输出8、12、16这3个数的最大公约数,下面正确的语句是
[2分]
、
print gcd(8,12),gcd(12,16),gcd(16,8)
、
print gcd(8,12,16)
、
print gcd(8),gcd(12),gcd(16)
、
print gcd(8,gcd(12,16))
答案:
23、【
单选题
】 有下面的程序段,其功能是按图1所示的规律输出数据
dim a(3,5) as integer
for i=1 to 3
for j=1 to 5
a(i,j)=i+j
print a(i,j);
next
print
next
若要按图2所示的规律继续输出数据,则接在上述程序段后面的程序段应该是
[2分]
、
for i=1 to 5
for j=1 to 3
print a(j,i);
next
print
next
、
for i=1 to 3
for j=1 to 5
print a(j,i);
next
print
next
、
for j=1 to 5
for i=1 to 3
print a(j,i);
next
print
next
、
for i=1 to 5
for j=1 to 3
print a(i,j);
next
print
next
答案:
24、【
单选题
】 窗体上有一个text1文本框,一个command1命令按钮,并有以下程序
private sub commandl_click()
dim n
if text1.text<>"23456" then
n=n+1
print "口令输入错误" & n & "次"
end if
end sub
、
private sub p1_mousemove(button as integer,shift as integer,x as single, y as single)
print x,y
end sub
、
private sub p1_mousedown(button as integer,shift as integer,x as single, y as single)
picture.print x,y
end sub
、
private sub p1_mousemove(button as integer,shift as integer,x as single, y as single)
p1.print x,y
end sub
、
private sub form_mousemove(button as integer,shift as integer,x as single, y as single)
p1.print x,y
end sub
答案:
26、【
单选题
】 计算二的近似值的一个公式是
。
某人编写下面的程序用此公式计算并输出π的近似值:
private sub comand1_click()
pi=1
sign=1
n=20000
for k=3 to n
sign=-sign/k
pi=pi+sign/k
next k
print pi*4
end sub
运行后发现结果为3.22751,显然,程序需要修改。下面修改方案中正确的是
[2分]
、
把for k=3 to n 改为 for k=1 to n
、
把n=20000改为n=20000000
、
把for k=3 to n改为for k=3 to n step 2
、
把pi=1改为pi=0
答案:
27、【
单选题
】 下面程序计算并输出的是
private sub comand1_click()
a=10
s=0
do
s=s+a*a*a
a=a-1
loop until a<=0
print s
end sub
[2分]
、
1
3+2
3+3
3+…+10
3的值
、
10!+…+3!+2!+1!的值
、
(1+2+3+…+10)
3的值
、
10个10
3的和
答案:
28、【
单选题
】 若在窗体模块的声明部分声明了如下自定义类型和数组
private type rec
code as integer
caption as string
end type
dim arr(5) as rec
则下面的输出语句中正确的是
[2分]
、
print arr.code(2),arr.caption(2)
、
print arr.code,arr.caption
、
print arr(2).code,arr(2).caption
、
print code(2),caption(2)
答案:
29、【
单选题
】 设窗体上有一个通用对话框控件cd1,希望在执行下面程序时,打开如图所示的文件对话框
private sub comand1_click()
cd1.dialogtitle="打开文件"
cd1.initdir="c:\"
cd1.filter="所有文件|*.*|word文档|*.doc|文本文件|*.txt"
cd1.filename=""
cd1.action=1
if cd1.filename=""then
print"未打开文件"
else
print"要打开文件"& cd1.filename
end if
end sub
但实际显示的对话框中列出了c:\下的所有文件和文件夹,“文件类型”一栏中显示的是“所有文件”。下面的修改方案中正确的是
[2分]
、
把cd1.action=1改为cd1.action=2
、
把“cd1.filter=”后面字符串中的“所有文件”改为“文本文件”
、
在语句cd1.action=1的前面添加:cd1.filterindex=3
、
把cd1.filename=""改为cd1.filename="文本文件"
答案:
30、【
单选题
】 下面程序运行时,若输入395,则输出结果是
private sub comand1_click()
dim x%
x=inputbox("请输入一个3位整数")
print x mod 10,x\100,(x mod 100)\10
end sub
[2分]
private sub comand1_click()
for k=list1.listcount-1 to 0 step -1
if list1.selected(k) then
list2.additem list1.list(k)
list1.removeitem k
end if
next k
end sub
程序运行时,按照图示在list1中选中2个列表项,然后单击commandl命令按钮,则产生的结果是
[2分]
、
在list2中插入了“外语”、“物理”两项
、
在list1中删除了“外语”、“物理”两项
、
同时产生A.和B.的结果
、
把list1中最后1个列表项删除并插入到list2中
答案:
32、【
单选题
】 设工程中有2个窗体: form1、form2,form1为启动窗体。form2中有菜单。其结构如表。要求在程序运行时,在form1的文本框text1中输入口令并按回车键(回车键的ascii码为13)后,隐藏form1,显示form2。若口令为“teacher”,所有菜单项都可见;否则看不到“成绩录入”菜单项。为此,某人在form1窗体文件中编写如下程序:
private sub text1_keypress(keyascii as integer)
if keyascii=13 then
if text1.text="teacher" then
form2.input.visible=true
else
form2.input.visible=false
end if
end if
form1.hide
form2.show
end sub
程序运行时发现刚输入口令时就隐藏了form1,显示了form2,程序需要修改。下面修改方案中正确的是
[2分]
、
把form1中text1文本框及相关程序放到form2窗体中
、
把form1.hide、form2.show两行移到2个end if之间
、
把if keyascii=13 then改为 if keyascii="teaeher" then
、
把2个form2.input.visible中的“form2”删去
答案:
33、【
单选题
】 某人编写了下面的程序,希望能把text1文本框中的内容写到out.txt文件中
private sub comand1_click()
open "out.txt" for output as #2
print "text1"
close #2
end sub
调试时发现没有达到目的,为实现上述目的,应做的修改是
[2分]
、
把print "text1"改为print #2,text1
、
把print "text1"改为print text1
、
把print "text1"改为write "text1"
、
把所有#2改为#1
答案:
34、【
单选题
】 窗体上有一个名为command1的命令按钮,并有下面的程序:
private sub comand1_click()
dim arr(5) as integer
for k=1 to 5
arr(k)=k
next k
prog arr()
for k=1 to 5
print arr(k)
next k
end sub
sub prog(a() as integer)
n=ubound(a)
for i=n to 2 step -1
for j=1 to n-1
if a(j)
t=a(j):a(j)=a(j+1):a(j+1)=t
end if
next j
next i
end sub
程序运行时,单击命令按钮后显示的是
[2分]
、
12345
、
54321
、
01234
、
43210
答案:
35、【
单选题
】 下面程序运行时,若输入“visual basic programming”,则在窗体上输出的是
private sub comand1_click()
dim count(25) as integer, ch as string
ch=ucase(inputbox("请输入字母字符串"))
for k=1 to len(ch)
n=asc(mid(ch,k,1))-asc("a")
if n>=0 then
count(n)=count(n)+ 1
end if
next k
m=count(0)
for k=1 to 25
if m
m=count(k)
end if
next k
print m
end sub
[2分]