根据上述要求编写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