现在设计一个VB程序,计算三个年级每一个批次进入食堂排队打菜完需要的相对等待时间平均值(输出到标签Label1,单位:分钟),以及抽样调查:在文本框Text3中输入某年级第n位进入食堂的同学,排队打到饭菜需要的时间(单位分钟,取整)并输出到标签Label2中。程序运行界面如第16题图所示。
Const n= 1500:Const nj = "
Dim d(1 To 3 * 5) As Integer, cw(1 To 100) As Integer, w(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t(1 To 3) As Integer
Dim k As Integer, sum As Long, aver As Integer
t(1) = TtoM(Text1.Text):k = Val(Text2.Text)
For i = 1 To 3
If i > 1 Then t(i) = '三个年级的午餐时间
For j = 1 To 5
d((i -1) * 5 + j) = t(i) + j -1 '记录三个年级每个批次进入食堂的时间点
Next j
Next i
List1.Clear
For i = 1 To 15
'输出三个年级每个批次进入食堂的时间点,代码略
Next i
For j = 1 To n
If j Mod 15 = 1 Then
i = (j -1) \15 + 1
cw(i) = (i -1) * 10 '每个打菜窗口的等待时间(单位:秒)
End If
w(j) = cw(i) -() * 60 '每位同学打菜等待时间
sum = sum + w(j)
Next j
aver = sum \n \60
Label1.Caption = "平均排队打菜时间:" + Str(aver) + "分钟"
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, k As Integer, s As String
s = Text3.Text
i = 1
Do While i <= 3
If Then j = (i -1) * 500 + Val(Mid(s, 4)): Exit Do
i = i + 1
Loop
Label2.Caption = s+"进入食堂的同学大约" +Str(w(j)\60)+ "分钟左右打到饭菜。"
End Sub
Function TtoM(t As String) As Integer
'将时间转换为绝对数值,例如t="12:01"→TtoM=721,代码略
End Function
Function MtoT(m As Integer) As String
'将时间绝对数值转换为时间格式,代码略
End Function