上机试题与答案

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Next
Fori = 1 To 3
For j = i To 4
If sin ger(i).score < sin ger(j).score Then
p=sin ger(i): sin ger(i) = sin ger(j): sin ger( j) = p
End If
Next
Next
For i = 1 To 4
Dim p As geshou
For i = 1 To 4
Forj = 1 To 5
For k = j To 6
If sin ger(i).fe nshu(j) > sin ger(i).fe nshu(k) Then
t = sin ger(i).fe nshu(j)
sin ger(i).fe nshu(j) = sin ger(i).fe nshu(k)
sin ger(i).fe nshu(k) = t
End If
Next
Next
Next
For i = 1 To 4
Forj = 2 To 5
sin ger(i).score = sin ger(i).score+sin ger(i).fe nshu(j)
Nextsin ger(i).p ingjun = sin ger(i).score/4
Print singer(i).xuhao&"得分:"&singer(i).pingjun
Next
End Sub
Private Sub Form_Load()
End Sub
10个评委给10个选手打分
Private Sub Form_Load()
Show
n = UBou nd(b)
For i = 1 To 10
上机操作练习题2011-5
1.某数组有20个元素,其值为随机产生的两位整数。现要求将前10个 元素与后10个元素对换。即第1个元素与第20个元素互换,第2个数与第19个元素互换,…,第10个元素与第11个元素互换。在窗体上输出数组原来各元 素的值与对换后各元素的值。
Opti on explicit
Dim a(1 to 20) as in teger, I as in teger, j as in teger, t as in teger
a(k) = a(k-1)
Next k
a(k) = m
For i = 1 To n
Print a(i);
Next i
Print
End Sub
4.6个评委为4位歌手打分,分数介于1-100之间。去掉一个最高分,一 个最低分,求出每位选手的最后得分。将4位歌手得分从高到低排列输出,同
时输出该选手的编号
如:
Print a(i);
Next i
End If
End Sub
3.数组a中存放着升序排列的数据,使用array赋值,将inputbox输入的新数插入到数组中,插入后数组仍有序。
注意:要求利用动态数组,能够实现多次插入
Private Sub Form_Load()
Show
n = 8: ReDim a(n)
Print a(i);
m = m+1
Next i
Print
n = InputBox("查找的数是:")
i = 0: flag = False
Do
If a(i) = n The n
j = i: flag = True
For k = j To UBound(a) - 1
a(k) = a(k+1)
Next k
For i = 1 To 10
j = 21-i
t = a(i): a(i) = a(j): a(j) = t
Next i
For i= 1To 20
Print a(i);
If i Mod 10 = 0 Then Print
Next i
End Sub
2.从数组中删除一个数。先定义一个一维数组,大小、数组的值自定。 从键盘上输入一个数,若这个数在数组当中,就把它删除;若这个数不在数组 中,提示该数不在数组中”
ReDim Preserve a(UBou nd(a)-1)
i = i-1
End If
i = i+1
Loop While (i <= UBou nd(a))
If flag = False Then
MsgBox n & "不在该数组中"
Else
Print "删除"& n & "后的数组是:"
For i = 0 To UBou nd(a)
Private Sub Comma nd1_Click()
For i = 1 To 4
Forj = 1 To 6
singer(i).fenshu(j) = Int(Rnd * 100)
singer(i).xuhao ="歌手"&i
Next
Next
Call paixu
End Sub
Private Sub paixu()
Private Sub Form_Load()
Show
Print "原始数组是wenku.baidu.com"
Ran domize
For i = 1 To 20
a(i) = Int(Rnd * 90)+10
Print a(i);
If i Mod 10 = 0 Then Print
Next i
Print
Print "现在数组是:"
a = Array(5, 15, 23, 52, 68, 88, 90, 99)
n = n+1: ReDim Preserve a( n)
m = InputBox("请输入要插入的数据:")
For i = 1 To n - 1
If m < a(i) The n Exit For
Next i
For k = n To i+1 Step -1
歌手3 95分歌手1 87分歌手4 80分歌手2 70分
Option Base1
Private Type geshou
xuhao As String
fen shu(6) As In teger
score As In teger
pingjun As In teger
End Type
Dim si nger(1 To 4) As geshou
、、亠 注意:
1)如果数组中存在多个与该数相同的元素,每一个都能删除;
2)能实现多次删除
Private Sub Form_Load()
Show
ReDim a(9) As In teger
m = 1
Print "原来数组为:"
For i = 0 To 9
a(i) = InputBox("请输入第"&m&"个数:")
相关文档
最新文档