上海海事大学VB程序改错40题

更新时间:2024-05-17 13:53:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

第2题 (1.0分) 题号:129

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:该程序实现将输入的 0 - 255 之间的正整数转 ' 换成二进制数

'------------------------------------------------ Option Explicit

Private Sub Form_Click() Const n = 8

Dim a(n) As Integer, s As String, m As Integer, x As Integer x = Val(InputBox(\请输入一个 0 - 255 之间的正整数:\ Print x

'**********FOUND********** For m = 1 To n a(m) = x Mod 2 '**********FOUND********** x = x / 2 Next m s = \

For m = n To 0 Step -1 '**********FOUND********** s = Str(a(m)) Next m Print s End Sub 答案:

=======(答案1)======= For m = 0 To n

=======(答案2)======= x= x \\ 2

=========或========= x= int(x/2)

=======(答案3)======= s = s + Str(a(m)) 第3题 (1.0分) 题号:463

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:以下程序功能是输入三个数,由大到小排序。

'------------------------------------------------ Option Explicit Dim A As Integer Dim B As Integer Dim C As Integer

Private Sub Form_Click() Dim nTemp As Integer

A = Val(InputBox(\输入正整数\ B = Val(InputBox(\输入正整数\ C = Val(InputBox(\输入正整数\ '**********FOUND********** If A <= C Then nTemp = A A = B B = nTemp End If

'**********FOUND********** If B <= C Then nTemp = A A = C C = nTemp End If

'**********FOUND********** If A <= B Then nTemp = B B = C C = nTemp End If

Print \End Sub 答案:

=======(答案1)======= If A <= B Then =========或=========

If B >= A Then

=======(答案2)======= If A <= C Then =========或========= If C >= A Then

=======(答案3)======= If B <= C Then =========或========= If C >= B Then

第4题 (1.0分) 题号:127

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:下面程序可输出如下图形: ' * ' *** ' ***** ' ******* ' *********

'------------------------------------------------ Option Explicit

Private Sub Form_Click()

Dim m As Integer, n As Integer, s As String, i As Integer, j As Integer n = 4 m = 1 s = \

For i = 5 To 1 Step -1 '**********FOUND********** Print Spc(n)

For j = 1 To 2 * m - 1 Print s; Next j Print

'**********FOUND********** n = n + 1

'**********FOUND********** m = m - 1 Next i End Sub

答案:

=======(答案1)======= Print Spc(n); =========或========= Print Spc(i); =========或========= ? Spc(n);

=========或========= ? Spc(i);

=======(答案2)======= n = n - 1

=========或========= n = - 1+n

=======(答案3)======= m = m + 1

第5题 (1.0分) 题号:469

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:已知一个函数f(x)=1000*sin(x),利用绘图方法 ' 在图片框中显示其图形。结果如图1

'------------------------------------------------ Option Explicit

Private Const pi = 3.14159 Private Sub Command1_Click() '**********FOUND********** Dim x As Integer

Picture1.Scale (-pi, -1200)-(pi, 1200) '**********FOUND********** For x = -pi To pi Step pi '**********FOUND**********

Picture1.PSet (x, 1000 * pi * Sin(x)), vbRed Next x End Sub 答案:

=======(答案1)======= Dim x As Single =========或========= Dim x!

=======(答案2)=======

For x = -pi To pi Step pi / 180

=======(答案3)=======

Picture1.PSet (x, 1000 * Sin(x)), vbRed =========或=========

Picture1.PSet (x, Sin(x)*1000), vbRed 第6题 (1.0分) 题号:497

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:编程求一个十进制整数n的各位数字之和,设n为小于或等于5位的数。

'------------------------------------------------ Option Explicit

Private Sub Form_Click()

Dim N As Integer, Sum As Integer, S1 As String, S2 As String Dim i As Integer, Ch As String Sum = 0

N = InputBox(\输入整数n\ S1 = Str(N)

'**********FOUND********** S1 = RTrim(S1) For i = 1 To Len(S1)

'**********FOUND********** Ch = Mid(N, i, 1)

'**********FOUND********** Sum = Val(Ch) Next i

Print \该整数的各位数之和是:\End Sub 答案:

=======(答案1)======= S1 = Trim(S1) =========或=========

S1 = lTrim(S1)

=======(答案2)======= Ch = Mid(S1, i, 1)

=======(答案3)======= Sum = Sum + Val(Ch) =========或========= Sum = Sum + Val(Ch) 第7题 (1.0分) 题号:454

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:本程序的功能是随机产生的10个两位正整数,并进行递减排序。

'------------------------------------------------ Option Explicit

Private Sub CreateRND() Dim Temp As Integer Dim I As Integer Dim N As Integer Dim X(10) As Integer Dim J As Integer N = 10

Print \数据:\ For I = 1 To N

'**********FOUND********** X(I) = Int(Rnd() * 90) Print X(I); Next I Print

Print \排序:\ For I = 0 To N - 1 For J = I + 1 To N

'**********FOUND********** If X(I) > X(J) Then

'**********FOUND********** Temp = X(I) X(J) = X(I) X(I) = Temp End If Next J Print X(I);

Next I Print End Sub

Private Sub Command1_Click() CreateRND End Sub 答案:

=======(答案1)======= X(I) = Int(10 + Rnd() * 90) =========或========= X(I) = Int(10 + Rnd() * 90)

=======(答案2)======= If X(I) < X(J) Then =========或========= If X(I) <= X(J) Then =========或========= If X(J) > X(I) Then =========或========= If X(J) >= X(I) Then

=======(答案3)======= temp = X(J)

第9题 (1.0分) 题号:130

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:以下程序段用于计算5的N次方。

'------------------------------------------------ Option Explicit

Private Sub Form_Click()

Dim n As Integer, k As Integer, s As Long n = InputBox(\'**********FOUND********** k = 0

'**********FOUND********** s = 0

Do While k <= n s = s * 5 k = k + 1 '**********FOUND********** Next

Print \的\次方是\End Sub 答案:

=======(答案1)======= k=1

=======(答案2)======= s=1

=======(答案3)======= Loop

第11题 (1.0分) 题号:452

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:用自定义函数的方法求sum(x),求当-1≤x≤1时, ' sum(x)=x/2!+x^2/3!+x^3/4!+??+x^n/(n+1)!, ' 当x〉1或x〈-1时,函数值为0。当n〈=0时,输入数 ' 据错误。X、N都是由用户输入。

'------------------------------------------------ Option Explicit

Private Sub Command1_Click() Dim s As Single

Dim n As Integer, x As Single, k As Integer n = Val(InputBox(\ x = Val(InputBox(\ If n <= 0 Then

k = MsgBox(\数据输入错误!\数据输入\

Exit Sub End If

s = Sum(x, n) Print s End Sub

Function Sum(x As Single, n As Integer) Dim i As Integer, ss As Long ss = 1 Sum = 0

If x > 1 Or x < -1 Then '**********FOUND********** Exit Do Else

'**********FOUND********** For i = 2 To n ss = ss * i

'**********FOUND********** Sum = x ^ (i - 1) / ss Next i End If End Function 答案:

=======(答案1)======= exit Function

=======(答案2)======= For i = 2 To n + 1 =========或========= For i = 2 To 1+n

=======(答案3)=======

sum = sum + x ^ (i - 1) / ss 第14题 (1.0分) 题号:136

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:程序功能为打印下列图形: ' * ' ** ' *** ' **** ' *****

'------------------------------------------------ Option Explicit

Private Sub Form_Click() Cls

Dim i As Integer Dim j As Integer

'**********FOUND********** For i = 1 To 7

'**********FOUND********** For j = 1 To 5 Print \

'**********FOUND********** Loop Print Next i End Sub 答案:

=======(答案1)======= For i = 1 To 5

=======(答案2)======= For j = 1 To i

=======(答案3)======= Next j

=========或========= Next

第16题 (1.0分) 题号:461

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:产生30个小于100的成绩随机数,并统计出优、良 ' 、中等、及格、不及格数的个数,并计算出成绩属 ' 于优秀段的成绩平均分。

'------------------------------------------------ Option Explicit

Private Sub Form_Click()

Dim k%, a%, bjg%, jg%, zd%, lh%, yx As Integer

=========或========= t = (a + b + c ) / 2

=======(答案3)=======

s = Sqr(t * (t - a) * (t - b) * (t - c)) =========或=========

s = Sqr( t * (t - a) * (t - b) * (t - c) ) 第32题 (1.0分) 题号:475

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:本程序求3~100之间的所有素数(质数)并统计个数; ' 同时将这些素数从小到大依次写入顺序文件c:\\dataout.txt; ' 素数的个数显示在窗体Form1上。

'------------------------------------------------ Option Explicit

Private Sub Command1_Click()

Dim Count As Integer, Flag As Boolean Dim t1 As Integer, t2 As Integer '**********FOUND**********

Open \ Count = 0

For t1 = 3 To 100 Flag = True

For t2 = 2 To Int(Sqr(t1))

If t1 Mod t2 = 0 Then Flag = False Next t2

'**********FOUND********** If Flag = False Then Count = Count + 1

'**********FOUND********** Write #1, t2 End If Next t1

Form1.Print \素数个数\ Close #1 End Sub 答案:

=======(答案1)=======

Open \=========或=========

Open \

=======(答案2)======= If Flag Then

=========或========= If Flag=true Then

=======(答案3)======= Write #1, t1

=========或========= Write 1, t1

第33题 (1.0分) 题号:137

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:求s=72+102+132+??832的值。

'------------------------------------------------ Option Explicit

Private Sub Form_Click() Cls

Dim s As Long Dim i As Integer

'**********FOUND********** s = 1

'**********FOUND********** For i = 7 To 832 s = s + i

'**********FOUND********** loop 30 Print s End Sub 答案:

=======(答案1)======= s =0

=======(答案2)======= For i = 7 To 832 step 30

=======(答案3)======= Next i

=========或========= Next

第35题 (1.0分) 题号:131

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:下面程序用于将十个数字从小到大排序

'------------------------------------------------ Option Explicit Option Base 1

Private Sub Form_Click() Cls

Dim a(10) As Integer

Dim i As Integer, j As Integer, temp As Integer '**********FOUND********** For i = 0 To 10

If i Mod 2 = 0 Then a(i) = i Else a(i) = -i Print a(i); Next Print

For i = 1 To 10 For j = 1 To 10 - i '**********FOUND********** If a(j) < a(j + 1) Then

temp = a(j): a(j) = a(j + 1): a(j + 1) = temp End If

'**********FOUND********** Next i, j For i = 1 To 10 Print a(i); Next End Sub 答案:

=======(答案1)======= For i = 1 To 10

=======(答案2)======= If a(j) > a( j + 1 ) Then =========或=========

If a( j + 1 )

=======(答案3)======= Next j, i

第40题 (1.0分) 题号:141

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:输出40以内能够被3整除的数,要求输出结果为5 ' 个数一行。

'------------------------------------------------ Option Explicit

Private Sub Form_Click() Cls

Dim x As Integer Dim i As Integer

'**********FOUND********** i = 1

For x = 1 To 40

If (x / 3) = (x \\ 3) Then '**********FOUND********** Print x i = i + 1 End If

'**********FOUND********** If i Mod 3 = 0 Then Print End If Next x End Sub 答案:

=======(答案1)======= i = 0

=======(答案2)=======

Print x;

=======(答案3)======= if i mod 5=0 then

第42题 (1.0分) 题号:117

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:下面的程序段用于实现以下功能:建立一顺序文 ' 件,存放10名同学的学号和三门功课成绩,显示 ' 该文件内所有记录, 并同时显示其总分和平均分

'------------------------------------------------ Option Explicit

Private Sub Form_Click()

Dim no%, c1%, c2%, c3%, i As Integer '**********FOUND********** Open \For i = 1 To 10

no = InputBox(\请输入学号\ c1 = InputBox(\请输入数学成绩\ c2 = InputBox(\请输入语文成绩\ c3 = InputBox(\请输入外语\ Write #1, no, c1, c2, c2 Next i Close #1

'**********FOUND********** Open \For i = 1 To 10

'**********FOUND********** Print #1, no, c1, c2, c3

Print no, c1, c2, c3, c1 + c2 + c3, (c1 + c2 + c3) / 3 Next i Close #1 End Sub 答案:

=======(答案1)=======

Open \

=======(答案2)=======

Print \字符个数为:\数字个数为:\ Print \空格个数为:\其它个数为:\End Sub 答案:

=======(答案1)=======

Open App.Path & \=========或=========

Open \

=======(答案2)======= Do Until EOF(1) =========或========= Do While Not EOF(1)

=======(答案3)=======

ElseIf C >= \第56题 (1.0分) 题号:138

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:输出40以内能够被3整除的数,要求输出结果为 ' 5个数一行。

'------------------------------------------------ Option Explicit

Private Sub Form_Click() Cls

Dim x As Integer Dim i As Integer

'**********FOUND********** i = 1

For x = 1 To 40

If (x / 3) = (x \\ 3) Then '**********FOUND********** Print x i = i + 1 End If

If i Mod 5 = 0 Then Print End If

'**********FOUND********** step i End Sub 答案:

=======(答案1)======= i = 0

=======(答案2)======= Print x ;

=========或========= ? x ;

=======(答案3)======= Next x

=========或========= Next

第57题 (1.0分) 题号:465

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:用InputBox函数输入一个字符串,编写程序按与 ' 输入的字符相反的次序用Msgbox函数输出这个字 ' 符串。如输入字符串为\,则输出为\' gfedcba\,输出效果如图1。

'------------------------------------------------ Option Explicit

Private Sub Command1_Click()

Dim pristr As String, outstr As String Dim i As Integer

pristr = InputBox(\ '**********FOUND********** For i = 0 To Len(pristr) '**********FOUND**********

outstr = outstr + Mid(pristr, Len(pristr) - i) Next i

'**********FOUND**********

MsgBox outstr, , \End Sub

答案:

=======(答案1)======= For i = 0 To Len(pristr) - 1 =========或========= For i = 0 To -1+Len(pristr)

=======(答案2)=======

outstr = outstr + Mid(pristr, Len(pristr) - i, 1) =========或=========

outstr = Mid(pristr, Len(pristr) - i, 1)+outstr

=======(答案3)=======

MsgBox outstr, vbQuestion, \第59题 (1.0分) 题号:147

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:下面的程序用来产生并输出图示的杨辉三角。 ' 1 ' 1 1 ' 1 2 1 ' 1 3 3 1 ' 1 4 6 4 1 ' 1 5 10 10 5 1

'------------------------------------------------ Option Explicit

Public Sub readin(a() As Integer, n As Integer) Dim i, j As Integer For i = 1 To n

'**********FOUND********** a(i, n) = 1 a(i, 1) = 1 Next i

For i = 3 To n

'**********FOUND********** For j = 2 To n

a(i, j) = a(i - 1, j) + a(i - 1, j - 1) Next j Next i

End Sub

Public Sub printf(a() As Integer, n As Integer) Dim i, j As Integer For i = 1 To n

'**********FOUND********** For j = 1 To n

Print Tab(5 * j + 10); a(i, j); Next j Print Next i Print End Sub

Private Sub Form_Click() Dim x(10, 10) As Integer Call readin(x(), 6) Call printf(x(), 6) End Sub 答案:

=======(答案1)======= a(i, i) = 1

=======(答案2)======= For j = 2 To i - 1 =========或========= For j = 2 To -1 + i

=======(答案3)======= For j = 1 To i

第60题 (1.0分) 题号:146

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:用辗转相除法求两个整数的最大公约数。

'------------------------------------------------ Option Explicit

Function gcd(ByVal m As Integer, ByVal n As Integer) As Integer Dim r As Integer

r = m Mod n Do While r <> 0

'**********FOUND********** n = m n = r r = m Mod n Loop

'**********FOUND********** gcd = r End Function

Private Sub Form_Click()

Dim a As Integer, b As Integer, c As Integer a = InputBox(\输入一个整数\ b = InputBox(\输入一个整数\ a = Val(a) b = Val(b)

'**********FOUND********** Call gcd(a, b) Print a, b, c End Sub 答案:

=======(答案1)======= m = n

=======(答案2)======= gcd = n

=======(答案3)======= c = gcd(a, b)

第65题 (1.0分) 题号:492

'------------------------------------------------ '【程序改错】

'------------------------------------------------

'题目:输入两个正整数m和n,求其最大公约数。

'------------------------------------------------ Option Explicit

Private Sub Form_Click()

本文来源:https://www.bwwdw.com/article/1xq7.html

Top