①number=0 ′团购券数量用变量number表示。
②Do While number<=29
③读入用餐顾客的情况
④If 使用团购券顾客 then
变量number增加1
允许使用团购券进行消费
End If
⑤Loop
对于上述算法,下列说法错误的是( )
小敏编写了一个VB程序,用来求一个偶数(6到100之间)可能存在多少这样是素数岁(注:A+B与B+A认为是相同素数对,不重复统计),并把这些结果输出到一个列表框中,通过逻辑推理,小敏发现这些素数对都是奇数,所以她只需要验证奇数的素数对即可,运行界面如图所示,程序代码如下。但加框处代码有错误,请改正。
Dim IsPrime(100)As B00lean ‘用来存储是否素数,True为素数,False为非素数
privatw Suh Command1_Click()
Dim x As Integer,y As Integer,i As Integer,num As Integer
Call Init ‘调用Init函数
x=Val(Text1.Text)
y=x\2
num==0
For i==3 To y Step 2
If Then ‘①
num=num+1
List1.AddItem Str(x)+“=”+Str(i)+“+”+Str(x-i)
End If
Next i
Label2.Caption=“偶数”+Str(x)+“共有”+Str(num)+“个素数对。”
End Sub
Sub Init() ‘初始化IsPrime数组的值
Dim i As Integer.j As Integer,X As Integer
For i=3 To 100 Step 2
X=Int(Sqr(i))
For Step 2 ‘②
If i Mod j=0 Then Exit For
Next j
If i>x Then IsPrime(i)-True Else IsPrime(i)=False
Next i
End Sub
①处加框代码应该为。
②处加框代码应该为。
a=5
b=3
If a>b Then
a=b
End lf
Dim f1 as long, f2 as long, f as long
n=val(Text1.Text)
f1=1
f2=1
For k=3 to n
Next k
Label1.Caption=“斐波那契数列第”+str(n)+“项的值为”+str(f)
方框中的代码由以下三部分组成:
①f2=f ②f1=f2 ③f=f1+f2
代码顺序正确的选项是( )
1a=3
b=input()
c=a+b
print("c")
a=3
b=2
c=a
b=c
print(“a=”,a)
print(“b=”,b)
该程序的功能是交换变量a、b的值,该程序段划线处应填入的代码为:
If I Mod 2= 0 Then
a(i) = Mid(s, i, 1)
Else
a(Len(s) - i + 1) = Mid(s, i, 1)
End If
Next i
B . For i = 1 To Len(s)If i Mod 2= 0 Then
a(Len(s) - i+1) = Mid(s, i, 1)
Else
a(i) = Mid(s, Len(s) - i+1, 1)
End If
Next i
C . For i = 1 To Len(s)If i Mod 2 = 1 Then
a(i) = Mid(s, i, 1)
Else
a(Len(s) - i+1) = Mid(s, i, 1)
End If
Next i
D . For i= 1 To Len(s)If i Mod 2 = 1 Then
a(i) = Mid(s, i, 1)
Else
a(Len(s) - i+1) =Mid(s, Len(s) - i+1, 1)
End If
Next i
x=1
For i=1 to 20 step 2
x=x+i\5
Next i
PRIVATE SUB FORM_CLICK( )
S=0
FOR A= 1 TO 5
S=S+10^A-1
NEXT A
PRINT S
END SUB
根据上述要求编写VB程序,功能如下:读取某天上午办理业务的num个客户信息(已按到达时间顺序排列),显示在列表框List1中。程序运行时,在文本框Text1中输入可同时办理业务的窗口数量m,单击“输出”按钮Command1,在列表框List2中输出客户平均等待时间、等待时间最长的客户编号及其等待时间。程序运行界面如第16题图所示。
请回答下列问题:
Const n = 300
Dim no(1 To n) As String, st(1 To n) As String, ti(1 To n) As Integer
Dim num As Integer 'num为待办理业务总人数
Private Sub Form_ load ()
'从数据库中读取所有客户编号、到达时间和办理业务所需要时间等信息,分别保存在
'数组no、st和ti中,统计总人数num,并在列表框List1中显示客户信息,代码略。
End Sub
Function t2d(x As String) As Integer
'将时间转化成从0点开始的时长(单位:分钟)来表示,例如8:18用498来表示;
'代码略
End Function
Private Sub Command1_ Click ()
Dim max_ no As String,max_ wait As Integer
Dim wait_ sum As Integer, wait_ time As Integer, wait_ num As Integer
Dim m As Integer, k As Integer, t As Integer
Dim w(1 To 10) As Integer '数组w存储窗口办理业务结束的时间(从0点开始的时长)
Dim i As Integer, p As Integer, q As Integer
m = Val (Text1. Text)
wait_ sum = 0
wait_ num = 0
max_ wait = 0
max_ no =""
k=0
For i=1 To m
w(i) = 0
Next i
For i=1 To num
If Then '当前办理业务不需要等待
t = t2d(st(i)) + ti(i)
Else
wait_ num = wait_ num + 1
wait_ time = w(1) - t2d(st (i))
wait_ sum = wait_ sum + wait_ time
If wait_ time > max_ wait Then
max_ wait = wait_ time
max_ no = no(i)
End If
End If
p =1
Do While w(p)<t And p<=k
p=p+1
Loop
If k<m Then '当前办理业务不需要等待
q=k
Do While q > = p
w(q+1)=w(q)
q=q-1
Loop
w(p) = t
k=k+1
Else
q=1
Do While q< p -1
q=q+1
Loop
w(q) = t
End If
Next i
List2. AddItem "平均等待时间:"+Str (Int (wait_ _sum/wait_ _num*10+0. 5)/10)+*分钟"
List2. AddItem "等待时间最长的是:"+max_ no+"号, 等待了"+Str (max_ wait)+^ 分钟"
End Sub