试题

试题 试卷

logo

题型:综合题 题类:模拟题 难易度:困难

浙江省教育绿色评价联盟2020届高三信息技术6月适应性考试试卷

某次技术考试后进行成绩处理,学生信息包括姓名、班级、成绩,要按班级从小到大,同一班级按成绩从高到低进行排序。按上述要求,编写一个VB程序,功能如下:在列表框List1中显示排序前的数据,单击“排序”按钮Command1,在列表框List2中显示排序后结果,程序运行界面如图所示。

(1)、  将数组元素temp1(1)到temp1(500)分为10段,每段刚好存储一个班的学生成绩,10个班的学生数如下表所示。从数组temp1第1个元素开始依次存储这10个班的学生成绩,如1班学生成绩存储在temp1的第1个元素到第50个元素,则3班学生成绩存储在temp1的第个到第个元素(填数字)。

班级

1班

2班

3班

4班

5班

6班

7班

8班

9班

10班

人数

50

45

50

51

49

55

50

48

52

50

(2)、请在划线处填入合适的代码。

Const n = 500     '总学生数

Const m = 10     '总班级数Dim score(1 To n) As Integer

Dim stu_name(1 To n) As Integer Dim class(1 To n) As Integer Dim temp1(1 To n) As Integer Dim temp2(1 To n) As Integer Dim temp3(1 To n) As Integer Function adj(s As String)

'本函数在字符串s 前添加若干空格,实现右对齐,代码略

End Function

Private Sub Form_Load()

'本过程读取学生姓名、班级和成绩数据分别存储在数组stu_name,class 和score 中,

'并在 List1 中显示,代码略

End Sub

Private Sub Command1_Click()

    Dim i As Integer, j As Integer, k As Integer, t1 As Integer, t2 As String

    Dim c(0 To m + 1) As Integer

    For i = 0 To m

        c(i) = 0

    Next i

    For i = 1 To n

       

        c(k) = c(k) + 1

    Next i

    For i = 1 To m

        c(i) = c(i) + c(i - 1)

    Next i

    For i = n To 1 Step -1

        k = class(i)

        temp1(c(k)) = score(i)

        temp2(c(k)) = stu_name(i)

        temp3(c(k)) = class(i)

       

    Next i        '处理完毕 c(i+1)表示第 i 个班级的最后一个学生的存储位置

    c(m + 1) = n

    For k = 1 To m        '对每一个班级学生成绩进行排序For i = c(k) + 1 To c(k + 1) - 1

        For j = c(k + 1) To i + 1 Step -1

            If Then

                t1 = temp1(j): temp1(j) = temp1(j - 1): temp1(j - 1) = t1

                t2 = temp2(j): temp2(j) = temp2(j - 1): temp2(j - 1) = t2

                t1 = temp3(j): temp3(j) = temp3(j - 1): temp3(j - 1) = t1

            End If

        Next j

    Next i

Next k

For i = 1 To n

    score(i) = temp1(i): stu_name(i) = temp2(i): class(i) = temp3(i)

    List2.AddItem adj(Str(stu_name(i))) & adj(Str(class(i))) & adj(Str(score(i)))

    Next i

End Sub

举一反三
【加试题】字符串排序。编写VB程序,实现如下功能:程序运行时,单击命令按钮Command1 产生100个随机字符串(每个字符串长度不超过10),并显示在列表框List1中,单击命令按钮Command2对产生的100个随机字符串按权值进行降序排序,将排序结果显示在列表框List2中。每个字符串的权值定义为该字符串中ASCII码值最大的字母的ASCII码值,例如字符串“Hello”中ASCII码值最大的字母是“o”(ASCII码值为111),则字符串“Hello”的权值为111。程序运行效果如图所示。实现上述功能的VB代码如下,但加框处代码有错,请改正。

Dim a(1 To 100) As String '依次存放100 个随机字符串

Dim b(1 To 100) As Integer '依次存放每个字符串的权值

Private Sub Command1_Click() '产生100 个随机字符串

Dim i As Integer, k As Integer, t As Integer, x As Integer

Randomize

For i = 1 To 100

k = Int(Rnd * 10 + 1) : t = 0  'k 表示第i 个字符串的长度

Do While t < k '通过循环依次产生第i 个字符串a(i)的k 个字符

If Int(Rnd * 2 + 1) = 1 Then '产生一个小写字母的ASCII 码值

x = Asc("a") + Int(Rnd * 26)

Else

x = Asc("A") + Int(Rnd * 26) '产生一个大写字母的ASCII 码值

End If

                '①

If b(i) < x Then b(i) = x

t = t + 1

Loop

List1.AddItem a(i)

Next i

End Sub

Private Sub Command2_Click() '对100 个字符串按字符串权值降序排序

Dim i As Integer, j As Integer, y As Integer

Dim s As String

For i = 1 To 99

k = i

For j = i + 1 To 100

    '②

Next j

If k <> i Then

s = a(k): a(k) = a(i): a(i) = s

y = b(k): b(k) = b(i): b(i) = y

End If

Next i

For i = 1 To 100

List2.AddItem a(i)

Next i

End Sub

①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#} 

返回首页

试题篮