随机产生20个学生的成绩6
① [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
② 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
③ java题,用类方法随机生成20名学生成绩成绩并计算平均分和总分,按总分排序
④ 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
⑤ 编一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
⑥ 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
⑦ 随机产生20个学生的成绩(整数),统计各分数段人数。即0~59、60~69、70~79、80~89、90~100,
Dim sj(19), i As Integer
Private Sub command1_Click()
Dim sj(19), i As Integer
For i = 0 To 19
sj(i) = Int(Rnd * 101)
Picture1.Print sj(i);
If (i + 1) Mod 4 = 0 Then Picture1.Print
Next i
End Sub
Private Sub Command2_Click()
Dim a, b, c, d, e As Integer, s(9), sj(19), i As Integer
For i = 0 To 19
sj(i) = Int(Rnd * 101)
Picture1.Print "";
If (i + 1) Mod 4 = 0 Then Print ""
Next i
a = 0
b = 0
c = 0
d = 0
e = 0
For i = 0 To 19
If sj(i) <= 59 Then a = a + 1
Next i
For i = 0 To 19
If sj(i) >= 60 And sj(i) <= 69 Then b = b + 1
Next i
For i = 0 To 19
If sj(i) >= 70 And sj(i) <= 79 Then c = c + 1
Next i
For i = 0 To 19
If sj(i) >= 80 And sj(i) <= 89 Then d = d + 1
Next i
For i = 0 To 19
If sj(i) >= 90 And sj(i) <= 100 Then e = e + 1
Next i
Picture2.Print "s(5)"; a; Chr(13);
Picture2.Print "s(6); b; ; Chr(13);
Picture2.Print "s(7); c; "??"; Chr(13); "s(8)"; d; ; Chr(13); "s(9)"; e;
End Sub
⑧ 编程 随机生成20个学生的成绩(60分—100分)(用数组存放数据) 输出最高分和最低分,平均分 利用数组
#include<stdio.h>
main()
{ double a[20],s=0.0;
int i ,j ,t;
for(i=0;i<20;i++)
{ scanf(a[i]);
s=s+a[i];
}
priintf(''平均分是%f '',s/20);
for(i=0;i<19;i++)
for(j=i+1;j<20;j++)
{ if(a[i]>a[j])
{ t=a[i];
a[i]=a[j];
a[j]=t;
}
}
printf("最大值为专%f,最小属值为%f",a[19],a[0]);
}
⑨ java编程实现随机生成20个百分制成绩并输出,统计出平均分并输出前五名同学的成绩
1、可以使用lambda来实现
int[] ints = new Random().ints(1, 100).distinct().limit(20).sorted().toArray();
//--统计信息
LongSummaryStatistics stats = Arrays.stream(ints)
.mapToLong((x) -> x)
.summaryStatistics();
System.out.println(stats);
//--输出
IntStream.range(0, 5)
.forEach(i -> System.out.println(ints[i]));//前五版权
IntStream.range(0, ints.length)
.forEach(i -> System.out.println(ints[i]));//所有