江苏省二级VB改错题真题解析.ppt_第1页
江苏省二级VB改错题真题解析.ppt_第2页
江苏省二级VB改错题真题解析.ppt_第3页
江苏省二级VB改错题真题解析.ppt_第4页
江苏省二级VB改错题真题解析.ppt_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、江苏省二级VB改错题解析,宿迁学院 计算机科学系 王学军,2008年(秋)01,本程序的功能:随机生成一个有n个元素的数组(n由InputBox函数输入),找出其中的最大元素并将它删除,再输出删除后的数组。,2008年(秋)01,Option Explicit Option Base 1 Dim a() As Integer, n As Integer Private Sub Command1_Click() Dim i As Integer n = InputBox(请输入数组元素个数, , 10) ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 100

2、) + 1 Text1 = Text1 & Str(a(i) Next i Call Lookup(a) For i = 1 To UBound(a) Text2 = Text2 & Str(a(i) Next i End Sub Private Sub Lookup(a() As Integer) Dim Maxv As Integer, maxp As Integer, i As Integer Maxv = a(1): maxp = 1 For i = 2 To n If a(i) Maxv Then Maxv = a(i): maxp = i End If Next i Call mo

3、ve_f(a, maxp) End Subk,Private Sub move_f(a() As Integer, k As Integer) Dim i As Integer For i = k+1 To UBound(a) a(i) = a(i + 1) Next i ReDim a(UBound(a) - 1) End Sub,Preserve,k to UBound(a)-1,2008年(秋)02,本程序的功能:查找80150范围内的特殊十进制数,其特点是该十进制数对应的八进制数为回文数。例如,十进制数105对应的八进制数为151,151属于回文数,所以105就是符合要求的数。,200

4、8年(秋)02,Option Explicit Private Sub Command1_Click() Dim i As Integer, hw As String, fg As Boolean Dim st As String For i = 80 To 150 fg = False Call hw8(i, hw, fg) If fg Then st = CStr(i) & = & hw & &O List1.AddItem st End If Next i End Sub Private Sub hw8(n As Integer, hw As String, f As Boolean)

5、Dim k As Integer, st() As String * 1, i As Integer hw = Do k = k + 1 ReDim Preserve st(k) st(k) = n Mod 8 hw = st(k) & hw n = n 8 Loop Until n st(UBound(st) - i + 1) Then Exit For Next i f = True End Sub,ByVal n,n = 0,Exit Sub,2008年(秋)03,本程序的功能是将密文解密。密文中被非数字字符分隔的连续的数字是五进制数,每个五进制数对应一个明文字符的ASCII代码。例如,

6、五进制数242对应的ASCII代码值是72,也就是字母“H”,密文本尾以非数字字符结束。,2008年(秋)03,Option Explicit Option Base 1 Private Sub Command1_Click() Dim mw As String, st As String, i As Integer Dim p As String, t() As String, k As Integer mw = Text1 For i = 1 To Len(mw) p = Mid(mw, i, 1) st = If p = 0 And p 0 Then k = k + 1 ReDim t(

7、k) t(k) = st End If Next i For i = 1 To UBound(t) k = convert(t(i) st = st & Chr(k) Next i Text2 = st End Sub,Preserve,Step -1,Private Function convert(p As String) As Integer Dim i As Integer, k As Integer, n As Integer For i = Len(p) To 1 n = n + Val(Mid(p, i, 1) * 5 k k = k + 1 Next i convert = n

8、 End Function,2008年(秋)04,本程序的功能是:查找8001200范围内的所有具有两个相同数字的素数。例如,811、877等都是符合要求的数据。,2008年(秋)04,Option Explicit Private Sub Command1_Click() Dim i As Integer For i = 800 To 1200 If validate(i) And prime(i) Then List1.AddItem i End If Next i End Sub Private Function prime(n As Integer) As Boolean Dim i

9、As Integer For i = 2 To Sqr(n) If n Mod i = 0 Then Exit For Next i prime = True End Function,Preserve,Function,Private Function validate(n As Integer) As Boolean Dim num() As Integer, k As Integer Dim i As Integer, j As Integer Do k = k + 1 ReDim num(k) num(k) = n Mod 10 n = n 10 Loop Until n = 0 k

10、= 0 For i = 1 To UBound(num) - 1 For j = i + 1 To UBound(num) If num(i) = num(j) Then k = k + 1 Next j Next i If k = 1 Then validate = True End Function,ByVal n,2008年(秋)05,本程序的功能是:查找100以内有三个不同质因子的所有整数。,2008年(秋)05,Option Explicit Option Base 1 Private Sub Command1_Click() Dim i As Integer, j As Integ

11、er Dim a() As Integer, s As String For i = 2 To 100 Call zys(i, a) If UBound(a) = 3 Then s = i & 的质因子: For j = 1 To UBound(a) s = s & Str(a(j) Next j List1.AddItem s End If Next i End Sub,ReDim Preserve a(i),x = 1,Private Sub zys(x As Integer, a() As Integer) Dim i As Integer, j As Integer j = 2 Do

12、If x Mod j = 0 Then i = i + 1 ReDim a(i) a(i) = j x = x j Do While x Mod j = 0 x = x j Loop Else j = j + 1 End If Loop Until x = 0 End Sub,ByVal x,2008年(秋)06,本程序的功能是:在自然数序列中,依次找出指定个数的连续合数。例如,输入n=5,则可得到24、25、26、27、28。所谓合数是指除了1和自身整除之外,还可被其他数整除的数(函数np的功能是判断一个数是否是合数)。,2008年(秋)06,Option Explicit Option B

13、ase 1 Private Sub Command1_Click() Dim k As Integer, n As Integer, i As Integer Dim hs() As Integer n = Text1 k = 2 Do Until i = n If np(k) Then i = i + 1 ReDim hs(i) hs(i) = k ElseIf i n Then i = 0 End If Erase hs k = k + 1 Loop For i = 1 To n Text2 = Text2 & Str(hs(i) Next i End Sub,Preserve,For,P

14、rivate Function np(n As Integer) As Boolean Dim i As Integer For i = 2 To n-1 If n Mod i = 0 Then Exit Function Next i If i = n - 1 Then np = True End Function,2008年(秋)07,本程序的功能是:依次求出输入字符串中所有由相同字符组成的子串的长度。,2008年(秋)07,Option Explicit Private Sub Command1_Click() Dim s As String, st() As String, i As Integer s = Text1 Call stati(s, st) For i = 1 To UBound(st) List1.AddItem Left(st(i), 1) & - & Len(st(i) Next i End Sub,stati,Mid(s, i ,1),Private Sub statii(s As String, st() As String) Dim i As Integer, k As Integer Dim p As String * 1, a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论