當前位置:首頁 » 考試成績 » vb隨即產生20個學生成績

vb隨即產生20個學生成績

發布時間: 2020-12-25 19:32:22

1. 利用數組方法輸入20個學生的成績,求VB大神解答這道題!

PrivateSubCommand1_Click()
Dimarr(1To20),brr(1To5),i
Fori=LBound(arr)ToUBound(arr)
Randomize
arr(i)=InputBox("分數:",i,Int(Rnd*101))
SelectCaseVal(arr(i))
Case90To100:brr(1)=brr(1)+1
Case80To89:brr(2)=brr(2)+1
Case70To79:brr(3)=brr(3)+1
Case60To69:brr(4)=brr(4)+1
Case0To59:brr(5)=brr(5)+1
EndSelect
Next
Print"所有人的分數:";Join(arr,",")
Print"90分到100分,80到89分,70到79分,60到69分,0到59分人數分別為:";Join(brr,",")
EndSub

2. [vb]隨機產生20個學生的成績,統計各分數段人數。

Option Explicit
Dim d(1 To 20) As Integer
Private Sub Command1_Click()
Dim i As Integer
Picture1.Cls
For i = 1 To 20
d(i) = Int(Rnd() * 100) + 1
Picture1.Print Format(d(i), " 0");
If i Mod 4 = 0 Then Picture1.Print
Next i

End Sub

Private Sub Command2_Click()
Dim b(5) As Integer
Dim i As Integer
Picture2.Cls
For i = 1 To 20
Select Case d(i)
Case 0 To 59
b(1) = b(1) + 1
Case 60 To 69
b(2) = b(2) + 1
Case 70 To 79
b(3) = b(3) + 1
Case 80 To 89
b(4) = b(4) + 1
Case 90 To 100
b(5) = b(5) + 1
End Select
Next
Picture2.Print "0~:"; b(1); "個"
Picture2.Print "60~79:"; b(2); "個"
Picture2.Print "70~89:"; b(3); "個"
Picture2.Print "80~99:"; b(4); "個"
Picture2.Print "90~100:"; b(5); "個"

End Sub

Private Sub Form_Load()
Command1.Caption = "產生並顯示數據"
Command2.Caption = "統計分數段人數"
End Sub

3. 編一VB應用程序。要求如下: ⑴ 隨機產生20個學生的VB程序設計課程的成績,存入一維數組中,並顯示結果;

這道題的完整答案:所需控制項:一個text1,一個command1按鈕
其屬性設置:text1的multiline屬性設為true(即可以接受多行)
command1是數組控制項(共四個,見上)。
Option Base 1

Dim x() As Integer
Dim i, j, k, p, t, y, z, s As Integer
Dim a, b, c, d, e As Double
Private Sub Command1_Click(Index As Integer)

ReDim Preserve x(21) '重新定義一個有21個元素的一維數組x
k = UBound(x) - 1 '把一維數組x的下標上界減1剩下就是20個元素(學生)了
Randomize '隨機數的初始化
Select Case Index

Case 0
Text1 = "隨機產生" & Trim(Str(Val(k))) & "個學生的成績:"
Text1 = Text1 & vbNewLine
For i = 1 To k
x(i) = Int(Rnd * 100)
Text1.Text = Text1.Text & x(i) & " "
Next i
Text1 = Text1 & vbNewLine
Text1 = Text1 & vbNewLine
Case 1
Text1 = Text1 & "20個學生中最高分的是:"
y = x(1) '假設第一學生的成績最高
For i = 1 To k
If y < x(i) Then '把第一個學生的成績與其餘的19學生兩兩對比找出比第一個學生的成績要高的學生
y = x(i) '如果找到要高的就互換
End If
Next i
Text1 = Text1 & Str(Val(y)) & "分"
Text1 = Text1 & vbNewLine

Text1 = Text1 & "20個學生中最低分的是:"
y = x(1) '同樣的思維,假設第一個學生的成績最低
For i = 1 To k
If y > x(i) Then '把第一個學生的成績與其餘的19學生兩兩對比找出比第一個學生的成績要低的學生
y = x(i) '如果找到要低的就互換
End If
Next i
Text1 = Text1 & Str(Val(y)) & "分"
Text1 = Text1 & vbNewLine

Text1 = Text1 & "20個學生中的平均分數是:"
j = 0
For i = 1 To k
j = j + x(i) '先求20個學生的總分
Next i
s = j / (k) '總分數除於人數得平均數
Text1 = Text1 & Str(Val(s)) & "分"
Text1 = Text1 & vbNewLine
Text1 = Text1 & vbNewLine
Case 2

For i = 1 To k
y = x(i) '將所有同學們的分數逐一賦給變數y

Select Case y '在所有分數中查找符合條件的分數並進行計算人數
Case 0 To 59
e = e + 1
Case 60 To 69
d = d + 1
Case 70 To 79
c = c + 1
Case 80 To 89
b = b + 1
Case 90 To 100
a = a + 1
End Select
Next i
Text1 = Text1 & "0~59分的人有:"
Text1 = Text1 & Str(Val(e)) & "個人"
Text1 = Text1 & vbNewLine

Text1 = Text1 & "60~69分的人有:"
Text1 = Text1 & Str(Val(d)) & "個人"
Text1 = Text1 & vbNewLine

Text1 = Text1 & "70~79分的人有:"
Text1 = Text1 & Str(Val(c)) & "個人"
Text1 = Text1 & vbNewLine

Text1 = Text1 & "80~89分的人有:"
Text1 = Text1 & Str(Val(b)) & "個人"
Text1 = Text1 & vbNewLine

Text1 = Text1 & "90~100分的人有:"
Text1 = Text1 & Str(Val(a)) & "個人"
Text1 = Text1 & vbNewLine
Text1 = Text1 & vbNewLine
Case 3
For i = 1 To 19
For j = i + 1 To 20
If x(i) < x(j) Then
t = x(i)
x(i) = x(j)
x(j) = t
End If
Next j
Next i
Text1 = Text1 & "成績由高到低;"
Text1 = Text1 & vbNewLine
For i = 1 To 20
Text1 = Text1 & x(i) & " "
Next i
Text1 = Text1 & vbNewLine
Text1 = Text1 & vbNewLine
End Select
End Sub

4. VB程序,隨機產生20個學生的成績,並顯示.統計各分數段人數,即0~59,60~69,70~79,80~89,90~100,並顯示結果

'添加窗體Form1,按鈕Command1,然後添加如下代碼:
PrivateSubCommand1_Click()
Dims(19),a(4),i,tempAsInteger
Me.AutoRedraw=True
Cls
Fori=0To19
Randomize
s(i)=Int(Rnd*101)
temp=Int(s(i)/10)
Iftemp=10Then
a(4)=a(4)+1
ElseIftemp<5Then
a(0)=a(0)+1
Else
a(temp-5)=a(temp-5)+1
EndIf
Prints(i)
Next
Print
Print"各分數段人數分別是:"&Join(a,"")
EndSub

5. VB設計:隨機產生20個學生的成績,並顯示.統計各分數段人數,即50~59 60~69 70~79 80-89,90-100。

Randomize
Dim a(20)
Dim s1, s2, s3, s4, s5, s6
s1 = 0: s2 = 0: s3 = 0: s4 = 0: s5 = 0: s6 = 0
For i = 0 To 19
a(i) = Round(100 * Rnd(1))
Print a(i);
Next
Print
For i = 0 To 19
If a(i) >= 50 And a(i) <= 59 Then s1 = s1 + 1
If a(i) >= 60 And a(i) <= 69 Then s2 = s2 + 1
If a(i) >= 70 And a(i) <= 79 Then s3 = s3 + 1
If a(i) >= 80 And a(i) <= 89 Then s4 = s4 + 1
If a(i) >= 90 And a(i) <= 100 Then s5 = s5 + 1
If a(i) < 50 Then s6 = s6 + 1
Next

Print "50-59的有:" & s1 & "人"
Print "60-69的有:" & s2 & "人"
Print "70-79的有:" & s3 & "人"
Print "80-89的有:" & s4 & "人"
Print "90-100的有:" & s5 & "人"
Print "小於50的有:" & s6 & "人"

6. VB設計:隨機產生20個學生的成績,並顯示.統計各分數段人數,即50~59, 60~69, 70~79,80-89,90-100。

Option Explicit

Private Sub showScore()
Dim score(1 To 20) As Integer
Dim an(1 To 5) As Integer
Dim i As Integer
Randomize

For i = 1 To UBound(score)
score(i) = CInt(Rnd * 100)
Select Case score(i)
Case 0 To 59
an(1) = an(1) + 1
Case 60 To 69
an(2) = an(2) + 1
Case 70 To 79
an(3) = an(3) + 1
Case 80 To 89
an(4) = an(4) + 1
Case 90 To 100
an(5) = an(5) + 1
End Select
Next

For i = 1 To 5
Select Case i
Case 1
Print "0 - 59 :",
Case 2
Print "60 - 69:",
Case 3
Print "70 - 79:",
Case 4
Print "80 - 89:",
Case 5
Print "90 - 100:",
End Select
Print CStr(an(i))
Next
End Sub

Private Sub Form_Click()
Cls
showScore
End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
showScore
End Sub

7. vb編程:隨機產生20個學生課程分數並顯示,統計各分數段人數,顯示統計結果

Private Sub Command1_Click()
Dim a(0 To 4) As Integer, i As Integer, iScore As Integer
Randomize
For i = 1 To 20
iScore = Rnd * 100
If i Mod 4 = 0 Then Print '每4個一行
Print "學生 " & i & " 成績: " & iScore,

If iScore >= 90 Then
a(4) = a(4) + 1
ElseIf iScore >= 80 Then
a(3) = a(3) + 1
ElseIf iScore >= 70 Then
a(2) = a(2) + 1
ElseIf iScore >= 60 Then
a(1) = a(1) + 1
Else
a(0) = a(0) + 1
End If
Next i

Print '換行
Print "0-59共有: " & a(0) & " 人"
Print "60-69共有: " & a(1) & " 人"
Print "70-79共有: " & a(2) & " 人"
Print "80-89共有: " & a(3) & " 人"
Print "90-100共有: " & a(4) & " 人"
End Sub

8. VB編程 隨機產生20個學生的成績,統計各分數段人數

辦法是有,不過很難實現,也不實際。
如果可以的話,先將值放到label或者textbox裡面,然後再生成圖片

9. VB程序,隨機產生20個學生的成績,並顯示.統計各分數段人數,即0~59,60~69,70~79,8

Private Sub Command1_Click()

Dim a(20) As Integer

Cls

c1 = 0: c2 = 0: c3 = 0: c4 = 0: c5 = 0: c6 = 0

Randomize

Print "20個成績:"

For i = 1 To 20

a(i) = Int(Rnd * 101)

Print a(i);

If i Mod 10 = 0 Then Print

Next i

For i = 1 To 20

If a(i) = 100 Then

c1 = c1 + 1

Else

If a(i) > 89 Then

c2 = c2 + 1

Else

If a(i) > 79 Then

c3 = c3 + 1

Else

If a(i) > 69 Then

c4 = c4 + 1

Else

If a(i) > 59 Then

c5 = c5 + 1

Else

c6 = c6 + 1

End If

End If

End If

End If

End If

Next i

Print: Print "統計結果:"

Print " 100分:"; c1

Print "90~99分:"; c2

Print "80~89分:"; c3

Print "70~79分:"; c4

Print "60~69分:"; c5

Print " 0~59分:"; c6

End Sub


或者換一種寫法(運行效果完全一樣):

Private Sub Command1_Click()

Dim a(20) As Integer

Dim cj(5 To 10) As Integer

Cls

Randomize

Print "20個成績:"

For i = 1 To 20

a(i) = Int(Rnd * 101)

Print a(i);

t = a(i) 10

If t < 5 Then t = 5

cj(t) = cj(t) + 1

If i Mod 10 = 0 Then Print

Next i

Print: Print "統計結果:"

Print " 100分:"; cj(10)

Print "90~99分:"; cj(9)

Print "80~89分:"; cj(8)

Print "70~79分:"; cj(7)

Print "60~69分:"; cj(6)

Print " 0~59分:"; cj(5)

End Sub

熱點內容
武漢大學學生會輔導員寄語 發布:2021-03-16 21:44:16 瀏覽:612
七年級學生作文輔導學案 發布:2021-03-16 21:42:09 瀏覽:1
不屑弟高考成績 發布:2021-03-16 21:40:59 瀏覽:754
大學畢業證會有成績單 發布:2021-03-16 21:40:07 瀏覽:756
2017信陽學院輔導員招聘名單 發布:2021-03-16 21:40:02 瀏覽:800
查詢重慶2018中考成績查詢 發布:2021-03-16 21:39:58 瀏覽:21
結業考試成績怎麼查詢 發布:2021-03-16 21:28:40 瀏覽:679
14中醫醫師資格筆試考試成績查分 發布:2021-03-16 21:28:39 瀏覽:655
名著賞析課程標准 發布:2021-03-16 21:27:57 瀏覽:881
北京大學商業領袖高端培訓課程 發布:2021-03-16 21:27:41 瀏覽:919