欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    VB上机试题及答案.doc

    • 资源ID:34460727       资源大小:107KB        全文页数:19页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    VB上机试题及答案.doc

    上机操作练习题1某数组有20个元素,其值为随机产生的两位整数。现要求将前10个元素与后10个元素对换。即第1个元素与第20个元素互换,第2个数与第19个元素互换,第10个元素与第11个元素互换。在窗体上输出数组原来各元素的值与对换后各元素的值。Option explicitDim a(1 to 20) as integer, I as integer, j as integer, t as integerPrivate Sub Form_Load()ShowPrint "原始数组是:"RandomizeFor i = 1 To 20 a(i) = Int(Rnd * 90) + 10 Print a(i); If i Mod 10 = 0 Then PrintNext iPrintPrint "现在数组是:"For i = 1 To 10 j = 21 - i t = a(i): a(i) = a(j): a(j) = tNext i For i = 1 To 20 Print a(i); If i Mod 10 = 0 Then Print Next iEnd Sub2从数组中删除一个数。先定义一个一维数组,大小、数组的值自定。从键盘上输入一个数,若这个数在数组当中,就把它删除;若这个数不在数组中,提示“该数不在数组中”注意:1)如果数组中存在多个与该数相同的元素,每一个都能删除;2)能实现多次删除Private Sub Form_Load()ShowReDim a(9) As Integerm = 1Print "原来数组为:"For i = 0 To 9 a(i) = InputBox("请输入第" & m & "个数:") Print a(i); m = m + 1Next iPrintn = InputBox("查找的数是:")i = 0: flag = FalseDo If a(i) = n Then j = i: flag = True For k = j To UBound(a) - 1 a(k) = a(k + 1) Next k ReDim Preserve a(UBound(a) - 1) i = i - 1End If i = i + 1Loop While (i <= UBound(a)If flag = False Then MsgBox n & "不在该数组中"ElsePrint "删除" & n & "后的数组是:" For i = 0 To UBound(a) Print a(i); Next iEnd IfEnd Sub3数组a中存放着升序排列的数据,使用array赋值,将inputbox输入的新数插入到数组中,插入后数组仍有序。注意:要求利用动态数组,能够实现多次插入Private Sub Form_Load()Shown = 8: ReDim a(n)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) Then Exit ForNext iFor k = n To i + 1 Step -1 a(k) = a(k - 1)Next ka(k) = mFor i = 1 To n Print a(i);Next iPrintEnd Sub46个评委为4位歌手打分,分数介于1-100之间。去掉一个最高分,一个最低分,求出每位选手的最后得分。将4位歌手得分从高到低排列输出,同时输出该选手的编号。如: 歌手3 95分 歌手 1 87分 歌手 4 80分 歌手 2 70分Option Base 1Private Type geshou xuhao As String fenshu(6) As Integer score As Integer pingjun As IntegerEnd TypeDim singer(1 To 4) As geshouPrivate Sub Command1_Click()For i = 1 To 4 For j = 1 To 6 singer(i).fenshu(j) = Int(Rnd * 100) singer(i).xuhao = "歌手" & i NextNext Call paixuEnd SubPrivate Sub paixu()Dim p As geshou For i = 1 To 4 For j = 1 To 5 For k = j To 6 If singer(i).fenshu(j) > singer(i).fenshu(k) Then t = singer(i).fenshu(j) singer(i).fenshu(j) = singer(i).fenshu(k) singer(i).fenshu(k) = t End If Next NextNextFor i = 1 To 4 For j = 2 To 5 singer(i).score = singer(i).score + singer(i).fenshu(j) Next singer(i).pingjun = singer(i).score / 4Next For i = 1 To 3 For j = i To 4 If singer(i).score < singer(j).score Then p = singer(i): singer(i) = singer(j): singer(j) = p End If NextNextFor i = 1 To 4 Print singer(i).xuhao & "得分:" & singer(i).pingjunNextEnd SubPrivate Sub Form_Load()End Sub10个评委给10个选手打分Private Sub Form_Load()Shown = UBound(b)For i = 1 To 10 For j = 1 To 10 a(i, j) = Val(InputBox("请第" & j & "位评委给第" & i & "位选手打分:")Next jNext iFor i = 1 To 10 max = a(i, 1): sum = 0 min = a(i, 1): ave = 0 For j = 1 To 10 If a(i, j) > max Then max = a(i, j) If a(i, j) < min Then min = a(i, j) sum = sum + a(i, j) Next j ave = (sum - max - min) / (n - 2) b(i) = aveNext iFor i = 1 To n - 1 For j = i + 1 To n If b(i) < b(j) Then t = b(i): b(i) = b(j): b(j) = t End If Next jNext iPrint "选手的得分由高到低为:"For i = 1 To 10 Print b(i);Next iEnd Sub5编写函数求一元二次方程ax2+bx+c=0的解。注意:要求考虑方程有两相等实根、两不等实根和两个虚根的情况。Dim a As Single, b As Single, c As SingleDim s As Singlea = InputBox("请输入a")b = InputBox("请输入b")c = InputBox("请输入c")s = b 2 - 4 * a * cIf s < 0 Then MsgBox ("方程无解")ElseIf s = 0 Then Print -b / 2 * aElse Print (-b) + Sqr(s) / 2 * a & " " & (-b) - Sqr(s) / 2 * aEnd IfEnd Sub6. 任意输入一组字符,统计出大写字母多少个,小写字母多少个,数字多少个?要求用过程实现。Call tongji(a, n, m, o) Print "数字:" & n & Chr(13) & "小写:" & m & Chr(13) & "大写:" & oEnd SubPrivate Sub tongji(a As String, n As Integer, m As Integer, p As Integer)For i = 1 To Len(a) If Asc(Mid(a, i, 1) > 47 And Asc(Mid(a, i, 1) < 58 Then n = n + 1 ElseIf Asc(Mid(a, i, 1) > 96 And Asc(Mid(a, i, 1) < 123 Then m = m + 1 ElseIf Asc(Mid(a, i, 1) > 64 And Asc(Mid(a, i, 1) < 91 Then p = p + 1 End IfNextEnd Sub7随机产生一个5*5的矩阵,将主对角线和次对角线元素都置为1,并求出矩阵的四周元素之和,显示在列表框中。Option Base 1Private Sub Form_Load()Dim a(5, 5) As IntegerDim s As IntegerFor i = 1 To 5 For j = 1 To 5 If i = j Or i = 6 - j Then a(i, j) = 1 Else a(i, j) = Int(Rnd * 1000) End If Text1.Text = Text1.Text & " " & a(i, j) s = s + a(i, j) Next Text1.Text = Text1.Text & vbCrLf & vbCrLfNextList1.AddItem (s)End Sub8编写一个函数,能将字母按下列规律译成密码:A<->Z a<->zB<->Y b<->y即第1个字母与第26个字母互换,第i个字母与第(26-i+1)个字母互换。在文本框中任意输入一个字符串,调用该函数将密码显示在另一个文本框中。Private Sub Command1_Click()Dim s1 As Strings1 = Text1.Text Text2.Text = convert(s1)End SubPrivate Function convert(s1 As String) As StringFor i = 1 To Len(s1) If Asc(Mid(s1, i, 1) < 91 And Asc(Mid(s1, i, 1) > 64 Then convert = convert & Chr(91 - Asc(Mid(s1, i, 1) + 64) ElseIf Asc(Mid(s1, i, 1) < 123 And Asc(Mid(s1, i, 1) > 96 Then convert = convert & Chr(123 - Asc(Mid(s1, i, 1) + 96) End IfNextEnd Function9编写2个函数,分别求两个正整数的最大公约数和最小公倍数,用户任意输入两个数,采用函数嵌套调用,该函数将它们在窗体显示。Private Sub Form_Load()Text1 = "": Text2 = ""End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocusEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)Dim m As Integer, n As Integer, r As Integer, t As Integer, xClsIf KeyAscii = 13 Then m = Text1.Text n = Text2.Text If m < n Then t = m: m = n: n = t End If r = m Mod n While r <> 0 m = n: n = r: r = m Mod n Wend Print If m < 0 Or n < 0 Then x = MsgBox("请输入正数", vbCritical + vbOKCancel) If x = vbCancel Then End Else Text1 = "": Text2 = "" Text1.SetFocus End If Else Print Text1.Text & "和" & Text2.Text & "的最大公约数是:" n End IfEnd IfEnd Sub10. 编写计算阶乘的Function过程,利用ex的下列公式计算e(直到最后一项小于10-6为止)的近似值。ex1+x/1!+x2/2!+x3/3!+xn/n! Option ExplicitPrivate Sub Form_Load()ShowDim x As Integer, n As Integer, s As Doublex = InputBox("请输入一个数:")n = 1: s = 1Do s = s + x n / (jiecheng(n) n = n + 1Loop Until x n / (jiecheng(n) < 10 (-6)Print sEnd SubPublic Function jiecheng(n As Integer) As DoubleDim i As Integer, s As Doubles = 1For i = 1 To n s = s * iNext ijiecheng = sEnd Function11输入整数N,显示具有N行的杨辉三角形,要求按正三角形的形式在图片框中显示。Option ExplicitPrivate Sub Form_Load()WindowState = 2ShowDim a(), n As Integer, i As Integer, j As Integer, g As Integer, e As Integern = InputBox("请输入一个数:")ReDim a(n, n)e = 80For i = 1 To n e = e - 5: g = e For j = 1 To n If j > i Then a(i, j) = 0 Else If i = j Then a(i, j) = 1 Else a(i, j) = a(i - 1, j) + a(i - 1, j - 1) End If End If If a(i, j) = 0 Then Exit For Else Picture1.Print Tab(g); a(i, j); g = g + 10 End If Next j Picture1.PrintNext iEnd SubPrivate Sub Picture1_Click()End Sub12编写一个过程,输出以下菱形图形: A BBB CCCCC DDDDDDD CCCCC BBB A主程序输入一个奇数(>3),调用过程在窗体上输入图形。Private Sub Command1_Click()Dim n As Integern = InputBox("")If n Mod 2 = 0 Or n <= 3 Then MsgBox ("错误")Else Call draw(n)End IfEnd SubSub draw(n As Integer)For i = 1 To (n + 1) / 2 s = Chr(64 + i) Print Tab(41 - i + 1); String(2 * (i - 1) + 1, s)Nextc = 1For j = (n - 1) / 2 To 1 Step (-1) c = c + 1 s = Chr(64 + i - c) Print Tab(41 - i + c + 1); String(2 * (j - 1) + 1, s)NextEnd Sub13编写一个将十进制转换为二进制字符串输出的函数。调用函数计算用户输入一个十进制数,在文本框中输出二进制值。注意:输入数据为负数,应该将符号位输出如 -13 结果 -1101Option Base 1Dim a()Private Function convert(y) As StringDim i As Integeri = 1ReDim a(i)x = Abs(y)Do While x <> 0ReDim Preserve a(i) a(i) = x Mod 2 If a(i) = 1 Then x = (x - 1) / 2 Else x = x / 2 End If i = i + 1Loop ReDim Preserve a(UBound(a)If y < 0 Then For i = 1 To UBound(a) convert = convert & a(i) Next convert = "-" & convertElse For i = 1 To UBound(a) convert = convert & a(i) NextEnd IfEnd FunctionPrivate Sub Command1_Click()Dim y As Integer Text1.Text = "" y = InputBox("请输入十进制数字") Text1.Text = convert(y)End SubPrivate Sub Form_Load()End Sub14输入一个整数N,产生N个随机数(范围110*N),然后采用任何2种算法实现由小到大的排序。将排序前后的数据显示出来。Option Base 1Private Sub Command1_Click()Dim a() As Integer, n As Integer n = InputBox("请输入数列项数") ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 10 * n + 1) Print a(i); Next Print ReDim Preserve a(n) For i = 1 To n - 1 For j = i + 1 To n If a(i) > a(j) Then t = a(i): a(i) = a(j): a(j) = t End If Next Next ReDim Preserve a(n) For i = 1 To n Print a(i); NextEnd SubPrivate Sub Command2_Click()Dim a() As Integer, n As Integer n = InputBox("请输入数列项数") ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 10 * n + 1) Print a(i); Next Print ReDim Preserve a(n)For i = 1 To n - 1 For j = 1 To n - i If a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t End If NextNext ReDim Preserve a(n) For i = 1 To n Print a(i); NextEnd SubPrivate Sub Form_Load()End Sub15编写程序,在窗体上输出3100之间的所有素数。要求每行显示4个数。Private Sub Command1_Click()Dim f As Boolean, c As IntegerFor i = 3 To 100 f = False For j = 2 To Int(Sqr(i) If i Mod j = 0 Then f = True: Exit For End If Next If f = False Then Print i; c = c + 1 If c Mod 4 = 0 Then Print End IfEnd IfNextEnd SubPrivate Sub Form_Load()End Sub16把文本框1、文本框2指定的范围内的所有素数添加到列表框中,并选中列表框数据中最后一位是9的所有数据(设定selected属性),把它们的和值输出。Public a As IntegerPrivate Function fact(n) As Long If n = 1 Then fact = 1 ElseIf n = 2 Then fact = 1 Else: fact = fact(n - 2) + fact(n - 1) End IfEnd FunctionPrivate Sub Command1_Click()n = InputBox("请输入n")Print fact(n)End SubPrivate Function s(n) As Longs1 = 1: s2 = 1For i = 1 To n - 2 s = s1 + s2: t = s2: s2 = s: s1 = tNextEnd FunctionPrivate Sub Command2_Click()n = InputBox("请输入n")Print s(n)End Sub17. 编写2个函数,分别采用递归法和递推法求斐波纳契数列的第n个月的兔子数,n使用inputbox输入,调用函数的结果在窗体上显示。Private Sub Command1_Click()List1.ClearDim i As IntegerFor i = Val(Text1.Text) To Val(Text2.Text) If isprime(i) = True Then List1.AddItem (i) c = c + 1 If i Mod 10 = 9 Then List1.Selected(c - 1) = True s = s + i End If End IfNext Print sEnd SubFunction isprime(n As Integer)isprime = TrueFor i = 2 To n - 1 If n Mod i = 0 Then isprime = False Exit For End IfNextEnd Function18 Dim sum As LongPrivate Sub Command1_Click() Dim i As Integer, j As Integer, a(40) As Long a(1) = 1 a(2) = 1 For i = 3 To 40 a(i) = a(i - 1) + a(i - 2) Next i sum = 0 For j = 1 To 40 sum = sum + a(j) Next jEnd SubPrivate Sub Command2_Click() Open "out18.txt" For Output As #1 Print #1, "数列1,1,2,3,5,8的前四十项的之和是:" Print #1, sum Close #1End Sub1. 百钱买百鸡Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As IntegerFor a = 1 To 34 For b = 1 To 20 If 3 * a + 5 * b + (100 - a - b) / 3 = 100 Then Print a; Print b; Print 100 - a - b End If Next bNext aEnd Sub2. 分钱作业Private Sub Command1_Click()Dim a As Single,b as single,c as singlea = Text1.Textb = Fix(a / 100)Print "100元:"Print bc = a - 100 * bb = Fix(c / 50) Print "50元:" Print b c = c - b * 50b = Fix(c / 20) Print "20元:" Print b c = c - 20 * b*b = Fix(c / 0.05) Print "0.05元:" Print b c = c - 0.05 * bb = Fix(c + 0.005) / 0.02) Print "0.02元:" Print b c = c - 0.02 * bb = Fix(c / 0.01) Print "0.01元:" Print bEnd Sub3. 最大公约数、最小公倍数Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As Integer, c As Integer, t As Integera = InputBox("请输入第一个数:")b = InputBox("请输入第二个数:")If a < b Then c = b b = a a = cEnd Ift = a Mod bDo While t <> 0 a = b b = tt = a Mod bLoopIf b = 1 Then MsgBox ("无最大公约数")Else MsgBox ("最大公约数是:" & b)End IfEnd SubPrivate Sub Command2_Click()Dim a As Integer, b As Integer, c As Integer, t As Integer, m As Integer, n As Integera = InputBox("请输入第一个数:")b = InputBox("请输入第二个数:")If a < b Then c = b b = a a = cEnd Ift = a * bm = a Mod bDo While m <> 0 a = b b = mm = a Mod bLoopn = t bMsgBox ("最小公倍数是:" & n)End Sub4. 输出九九表Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As IntegerPrintFor a = 1 To 9 For b = 1 To a Print Tab(b * 9); a & "*" & b; "=" a * b; Next b PrintNext aEnd Sub5. 排序Option ExplicitOption Base 1Dim a(1 To 10) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerRandomizeFor i = 1 To 10aaa: a(i) = Int(Rnd() * 90 + 10) For j = 1 To i - 1 If a(i) = a(j) Then GoTo aaa End If Next j Next iFor i = 1 To 10 Print a(i);Next iPrintEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, t As IntegerFor i = 1 To 9 For j = 1 + i To 10 If a(i) > a(j) Then t = a(j) a(j) = a(i) a(i) = t End If Next jNext iFor i = 1 To 10 Print a(i);Next iPrintEnd SubPrivate Sub Command3_Click()Dim i As Integer, j As Integer, t As IntegerFor i = 1 To 9 For j = 1 To 10 - i If a(j) > a(j + 1) Then t = a(j + 1) a(j + 1) = a(j) a(j) = t End If Next jNext iFor i = 1 To 10 Print a(i);Next iPrintEnd Sub6. 求平方根Option ExplicitPrivate Sub Command1_Click()Dim a As Double, b As Double, c As Double, i As Doublea = 0c = Text1.Textb = cDo While Abs(a + b) / 2) 2 - c) > 10 (-5)i = (a + b) / 2 If i 2 - c > 0 Then b = i ElseIf i 2 - c = 0 Then Exit Do Else a = i End IfLoopMsgBox (i)End Sub7. 闰年Option ExplicitPrivate Sub 计算_Click()Dim i As Integeri = InputBox("请输入一个年份")If i Mod 4 = 0 And i Mod 400 = 0 Then If i Mod 100 <> 0 Then MsgBox "NOT" Else MsgBox "YES" End IfElse MsgBox "NOT"End IfEnd Sub8. 三角Option ExplicitPrivate Sub Command1_Click()Dim a As Sing

    注意事项

    本文(VB上机试题及答案.doc)为本站会员(豆****)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开