二级上机测试中VB程序设计及程序调试样题 联系客服

发布时间 : 星期日 文章二级上机测试中VB程序设计及程序调试样题更新完毕开始阅读63662a868762caaedd33d4ea

Case Else

Form1.Print \太小了,继续猜!\ End Select times = times + 1 '****** 错误3 ****** Loop While times > 5 If times > 5 Then

Form1.Print \猜数失败,游戏结束!\ '****** 错误4 ******

Form1.Print \正确答案为\ End If End Sub

5.已有一模块文件Modify.Bas。该模块中的ArmstrongNumber过程是用于求出1--999之间所有的Armstrong数,并打印出来,但不完整,请在横线上填入必要的内容,使其完整。所谓Armstrong数是指一个数等于它每位上数字的立方和。例如:371=3^3+7^3+1^3,那么371就是一个Armstrong数。

程序如下:

Public Sub ArmstrongNumber() Dim armstrong As Integer Dim i As Integer

Dim hundred As Integer '百位上的数字 Dim ten As Integer '十位上的数字 Dim one As Integer '个位上的数字 For i = 1 To 999 hundred = ----1---- ten = ----2---- one = ----3---- If ----4---- Then

Form1.Print i; \ End If Next i End Sub

6.已有一模块文件Modify.Bas。该模块中的 CountTo60 过程是用于从一堆一分、二分、五分的硬币中取出20枚,使其总值为60分,要求输出取法的数量及每一种取法的一分、二分、五分的个数。

程序如下: Public Sub CountTo60()

'从一堆一分、二分、五分的硬币中取出20枚,使其总值为60分 '输出取法的数量及每一种取法的一分、二分、五分的个数 Dim one As Integer '一分硬币个数 Dim two As Integer '二分硬币个数 Dim five As Integer '五分硬币个数

Const n = 20 '总数20枚 Dim k As Integer '取法数量 k = 0

For one = 1 To n

'******* 错误1 ******** For two = one + 1 To n five = n - one - two '******* 错误2 ********* If one + two + five = 60 Then k = k + 1

Form1.Print \ End If

'******* 错误3 ******** Next one

'****** 错误4 ****** Next two

Form1.Print \End Sub

7.已有一模块文件Modify.Bas。该模块中的TJ过程是将一批数据中小于零的数及它们的积打印出来,但不完整,请在横线上填入必要的内容,使其完整。Modify.Bas模块中的SCSJ过程是产生数据,数据的取值范围为-10 ~ 10 之间的随机数。 程序如下: Private Const n = 10 Private a(1 To n) As Integer

'TJ过程是将一批数据中小于零的数及它们的积打印出来

'数据由SCSJ过程产生,数据的取值范围为-10 ~ 10 之间的随机整数

Public Sub TJ() Dim i As Integer Dim t As Single -------- 1 -------- For i = 1 To 10

If -------- 2 -------- Then t = t * a(i) End If Next i

Form1.Print \End Sub

Public Sub SCSJ() Randomize

Form1.Print \原始数据\ Dim i As Integer

Dim j As Integer For i = 1 To n

'随机产生0或1,为0时取负,为1时取正 j = Int(Rnd * 2)

If ------ 3 ----- Then J = -1 a(i) = j * Int(Rnd * (n + 1)) Form1.Print a(i); Next i Form1.Print End Sub

8.已有一模块文件Modify.Bas。该模块中的Money过程是用于统计一个有7个工作人员的餐厅发工资所需的100元、50元、10元、5元和1元的票面数,但不完整,请在横线上填入必要的内容,使其完整。

Modify.Bas模块中的SalaryData过程是给出7个员工的工资。(工资单位是元) 程序如下: Dim salary(7) As Integer Public Sub Money()

Dim hundred As Integer, totalhundred As Integer '100元票面数量、总数量 Dim fifty As Integer, totalfifty As Integer '50元票面数量、总数量 Dim ten As Integer, totalten As Integer '10元票面数量、总数量 Dim five As Integer, totalfive As Integer '5元票面数量、总数量 Dim one As Integer, totalone As Integer '1元票面数量、总数量 Dim totalsalary As Integer '工资总计 Dim i As Integer, temp As Integer totalhundred = 0 totalfifty = 0 totalten = 0 totalfive = 0 totalone = 0 totalsalary = 0 For i = 1 To 7 temp = ----1----

hundred = Int(temp / 100) temp = ----2---- fifty = Int(temp / 50) temp = temp - fifty * 50 ten = Int(temp / 10) temp = temp - ten * 10 five = Int(temp / 5) temp = temp - five * 5 one = ----3----

totalhundred = totalhundred + hundred totalfifty = totalfifty + fifty

totalten = totalten + ten totalfive = totalfive + five totalone = totalone + one totalsalary = ----4---- Next i

Form1.Print \共需100元\张\ Form1.Print \共需50元\张\ Form1.Print \共需10元\张\ Form1.Print \共需5元\张\ Form1.Print \共需1元\张\ Form1.Print \合计\元\End Sub

Public Sub SalaryData() salary(1) = 1398 salary(2) = 1765 salary(3) = 689 salary(4) = 1500 salary(5) = 832 salary(6) = 590 salary(7) = 1200 End Sub

9.已有一模块文件Modify.Bas。该模块中的 MaxLine 过程用于查找一个5行4列的二维数组中行平均值最大的行,并将该行所有数据调整到第一行的位置。

Modify.Bas模块中的DataProduce 过程用于产生原始数据;Average 过程用于计算各行的平均值;PrintArray过程用于打印二维数组和行平均值。 程序如下:

Dim a(1 To 5, 1 To 4) As Integer Dim ave(1 To 5) As Integer Public Sub MaxLine() Dim i As Integer Dim j As Integer Dim temp As Integer

Dim Line_no As Integer '最大平均值的行号 '找出最大平均值所在行 Line_no = 1 For i = 2 To 5

'****** 错误1 *******

If ave(Line_no) >= ave(i) Then

'****** 错误2 ******* Line_no = ave(i) End If Next i