上海海事大学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()
正在阅读:
上海海事大学VB程序改错40题05-17
驯龙骑士观后感04-02
安全应急灯检查记录表08-05
中医基础理论08-11
八年级物理上册第四章第二节光的反射教学设计(新版)新人教版 (1)03-08
20世纪以来的银行危机及原因分析01-08
LH-16通信协议_v2.4正式公布版05-01
伤寒论重点条文08-24
申请美国EB-5投资移民有些什么条件06-09
半年度宣传工作总结6篇03-26
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 海事
- 改错
- 上海
- 程序
- 大学
- 最新北师大版小学三年级下册数学全册教案教学设计(最新
- 空分联动试车方案
- 理财规划师试题及答案二级专业 第七章 综合理财规划测试一(第五
- 3牛顿运动定律
- 小学一年级语文下册各单元测评题
- 贸大金融学考研历程
- 2019年建设工程防汛防台专项应急预案2
- 集体备课管理制度
- 一年级经典诵读教案
- 高层办公楼设计任务书
- 大管基础部分辅机题库
- 十三五(2016-2020年)膜气体分离系统行业市场发展现状及投资决
- 抱一抱妈妈
- 基于单片机的温度液晶显示应用3 - 图文
- 制造业成本控制问题研究
- 大地测量学期末考试题
- 最新版PEP五年级下册Unit5教案
- 2017-2023年中国化工设计市场深度研究与投资风险报告(目录)
- 中国红十字会救护员培训教学大纲
- 小学五年级数学下册暑假作业(强烈推荐)49