t = "abcd123456" : x = Int(Sqr(Len(t))) : y=1
If x > 3 Then
y =2
ElseIf x > 2 Then
y=3
ElseIf x > 1 Then
y=4
End If
执行该程序段后,变量y的值为( )
x = 4095 : s1 = "ABCDEFGHIJ" : s2 = "abcdefghij"
ret=""
Do While x > 0
r = x Mod 10
If r Mod 2 = 1 Then
ret = Mid(s1, r + 1, 1) & ret
Else
ret = ret & Mid(s2, r + 1, 1)
End If
x = x \ 10
Loop
Text1.Text = ret
执行该程序段后,文本框Text1中显示的内容为( )
Dim i As Integer, imax As Integer
①
For i = 3 To 10
If Abs(a(i) - a(i - 1)) >= ② Then imax = i
Next i
Text1.Text = "GDP变化最大的年份区间是" + Str(imax + 2008) + "-" + Str(imax + 2009)
划线处①、②应填入的代码为( )
For i = 1 To 6
a(i) = Int(Rnd * 20) + 1: b(i) = i
Next i
For i = 1 To 5
For j = i+1 To 6
If a(b(i))>a(b(j)) Then
t = b(j): b(j) = b(i): b(i) = t
End If
Next j
Next i
i = 1 : j = 6: s="" : Key = Val(Text1.Text)
Do While i <= j
m = (i + j) \ 2
If Key = a(b(m)) Then Exit Do
If Key < a(b(m)) Then j = m - 1 Else i = m + 1
s = s + Str(m)
Loop
Text2.Text = s
在文本框Text1中输入10,运行以上程序段后,文本框Text2中显示的内容为 3 5 4,则 a 数组中 a(1)到 a(6)各元素的值可能的是( )
Const m = 6
Const n = 8
Dim a(1 To m * n) As String '存储学号
Dim b(1 To m * n) As Integer '存储身高
Dim num As Integer '班级总人数
Private Sub Command1_Click( )
'从数据库中读取该班的学号和身高数据存入数组a和数组b,班级人数存入变量num,代码略
'以下代码为在列表框List1中输出数据
s = "" : List1.AddItem " ( 讲 台 )"
For i = 1 To num
s = s & Str(b(i)) & "[" & a(i) & "] "
If Then
List1.AddItem s : s = ""
End If
Next i
If s <> "" Then List1.AddItem s
End Sub
Private Sub Command2_Click( )
Dim i As Integer, j As Integer, imin As Integer
Dim t1 As String, t2 As Integer, s As String
List2.AddItem " ( 讲 台 ) "
For i = 1 To
s = ""
For j = (i - 1) * n + 1 To (i - 1) * n + n
If j <= num Then
If imin <> j Then
t1 = a(imin): a(imin) = a(j): a(j) = t1
t2 = b(imin): b(imin) = b(j): b(j) = t2
End If
s = s & Str(b(j)) & "[" & a(j) & "] "
End If
Next j
List2.AddItem s
Next i
End Sub
Function fPos(p As Integer) As Integer
Dim i As Integer, j As Integer, k As Integer
k = p
For i =
If b(i) < b(k) Then k = i
Next i
fPos = k
End Function
①根据考生的考试总分从高到低依次对考生的填报志愿进行投档;
②每位考生可填三个志愿学校,轮到该考生投档时依次对其三个志愿进行投档,若第一志愿学校还有剩余招生名额,就被第一志愿学校录取,结束该考生的投档,否则需对其后续志愿学校进行同样的投档操作,若该考生所填的所有志愿学校都没有剩余招生名额,则该考生无法被任何学校录取,该考生的投档结束。
③当所有学校都已完成计划招生数时,停止投档,录取结束。
编写 VB 程序,实现上述“平行志愿”投档录取的功能,单击“读取考生数据”按钮 Command1, 则从数据库中获取所有考生的成绩、志愿信息以及每个学校的计划招生数,单击“投档录取”按钮 Command2,开始进行投档录取, 并在列表框 List1 中输出每个学校的计划招生数、实际招生数、录取分数线和最低录取名次信息,程序运行界面如图所示。请回答下列问题:
Const schCnt = 5 '学校数量
Const stuMaxCnt = 10000 '最多考生人数
Dim zsCnt(1 To schCnt) As Integer '存储每个学校的计划招生人数
Dim zsCnt2(1 To schCnt) As Integer '存储每个学校的实际招生人数
Dim a(1 To stuMaxCnt) As Single '存储考生总分成绩
Dim b(1 To stuMaxCnt * 3) As Integer '存储考试志愿,每个考生有3个志愿,每个志愿为学校编号
Dim stuCnt As Integer '实际考生总人数
Private Sub Command1_Click()
'从数据库中读取所有考生的总分和志愿信息存储到数组a和数组b中(第1个考生总分存储到a(1),第1个考生的3个志愿分别存储到b(1)、b(2)、b(3)中, …),然后按总分对数组a和数组b进行降序排序,总分相同时,需根据各科成绩决定排序先后,但名次相同,考生总人数存储到stuCnt变量中;
'读取每个学校的计划招生数,存储到数组zsCnt中;
'以上功能代码略
End Sub
Private Sub Command2_Click()
Dim sch As Integer '学校代码,用1~5中的一个数字表示某学校代码
Dim i As Integer, j As Integer, finished As Integer, prevScore As Single
Dim stuMc(1 To stuMaxCnt) As Integer
Dim MinScore(1 To schCnt) As Single
Dim MinMc(1 To schCnt) As Integer
finished = 0: i = 1
prevScore = -1
Do While
If a(i) = prevScore Then
stuMc(i) = stuMc(i - 1)
Else
End If
prevScore = a(i)
For j = 1 To 3
If zsCnt2(sch) < zsCnt(sch) Then
zsCnt2(sch) = zsCnt2(sch) + 1
MinScore(sch) = a(i)
MinMc(sch) = stuMc(i)
Exit For
End If
Next j
finished = 0
For j = 1 To schCnt
If zsCnt2(j) = zsCnt(j) Then
finished = finished + 1
End If
Next j
i = i + 1
Loop
'在List1中输出每所学校的代码、计划招生数、实际招生数、录取分数线、最低录取名次,代码略
End Sub