(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)_第1页
(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)_第2页
(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)_第3页
(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)_第4页
已阅读5页,还剩17页未读 继续免费阅读

付费下载

VIP免费下载

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

文档简介

1、浙江省高校计算机等级考试复习资料二级 VB 语言答案目录2009年春浙江省高等学校计算机等级考试二级VB 参考答案. 22008年秋浙江省高等学校计算机等级考试二级VB 参考答案. 32008年春浙江省高等学校计算机等级考试参考答案(二级VB) .42007年秋浙江省高等学校计算机等级考试参考答案(二级VB) .52007年春浙江省高等学校计算机等级考试参考答案(二级VB) .7VB 上机考试程序调试题样题(填空 )参考答案 .7VB 上机考试程序调试题样题(改错 )参考答案 .8VB 上机考试程序设计题样题参考答案 .92009 年春浙江省高等学校计算机等级考试二级 VB 参考答案试题 1试

2、题 6 请在各小题正确选项的对应位置处填“”(每小题3 分,共72 分)ABCDABCD(1)(13)(2)(14)(3)(15)(4)(16)(5)(17)(6)(18)(7)(19)(8)(20)(9)(21)(10)(22)(11)(23)(12)(24)试题 7( 28 分)Dim a() As Double, ave As Double, n As Integer, seit As DoublePrivate Sub Command1_Click() '输入数据 n 以及 n 个数。小计 10分Dim i As Integer' 1分n = Inputbox(&quo

3、t;n=")' 2分Redim a(n)' 3分For i = 1 To n' 4分a(i) = InputBox("a(" & i & ")=")Next iEnd SubPrivate Sub Command2_Click() '计算、显示平均值。小计 7分Dim i As Integer' 1分For i = 1 To n' 4分ave = ave + a(i)/nNext iText1.Text = ave' 2分End SubPrivate Sub Command

4、3_Click() '计算、显示标准差。小计11分Dim i As Integer' 1分For i = 1 To n' 5分seit = seit + (a(i) - ave) 2Next iseit = sqr(seit) / (n - 1)' 3分Tetx2.Text = seit' 2分End Sub2008 年秋浙江省高等学校计算机等级考试二级 VB 参考答案试题 1试题 6请在各小题正确选项的对应位置处填“”(每小题3 分,共 72 分)ABCDABCD(1)(13)(2)(14)(3)(15)(4)(16)(5)(17)(6)(18)(7)

5、(19)(8)(20)(9)(21)(10)(22)(11)(23)(12)(24)试题7( 28 分)编程,按 Command1后用通用对话框确定待输入的文件(格式如下, 各行中四个数据分别表示学生姓名以及三门功课成绩),将其中三门课成绩均及格的学生信息按同样的格式输出到文件"e:score.txt"。" 张三 ",77,86,93" 李四 ",77,86,93.Private Sub Command1_Click()'声明变量Dim name As String,k1 As Integer, k2 As Integer,

6、k3 As Integer(2 分)' 用控件 CommonDialog1 选择文件CommonDialog1.Action =1(2 分)'打开所选文件用于读数据,打开文件e:score.txt用于写数据Open CommonDialog1.FileName For Input As #1(2 分)Open "e:score.txt" For OutPut As #2(2 分)'读文件中数据并处理Do While Not Eof(1)(18 分)Input #1, name,k1,k2,k3循环结构6 分If k1>=60 And k2>

7、;=60 And k3>=60 Then _Input4分Write #1,name,k1,k2,k3条件 4分LoopWrite# 4 分( Print#扣 2 分Close #1: Close #2(2 分)End Sub2008 年春浙江省高等学校计算机等级考试参考答案(二级 VB )试题 1试题 6请在各小题正确选项的对应位置处填“”(每小题3 分,共 72 分)ABCDABCD(1)(13)(2)(14)(3)(15)(4)(16)(5)(17)(6)(18)(7)(19)(8)(20)(9)(21)(10)(22)(11)(23)(12)(24)试题 7(28 分 )编程,按

8、 Command1可输入有 10 个实数的数组,调用函数f 求他们的平均值V,然后输出其中与 V 之差的绝对值为最小的那个数组元素。请将答卷上函数过程f (包括形参列表) 、事件过程 Command1补充完整。Private Function f(b() As Single, n As Integer) As Single '2分Dim i As Integer'1分For i = 1 To n'5分f = f + b(i)Next if = f / n'2分End Function' 输入数据 (3 分 ) For i = 1 To 10a(i) =

9、InputBox("a(" & i & ")=")Next i'计算平均值v(3 分 )v = f(a, 10)' 将与 v 之差的绝对值为最小的那个数组元素赋值给x。x = a(1): d = Abs(a(1) - v)'2 分For i = 2 To 10If Abs(a(i) - v) < d Thend = Abs(a(i) - v)' 绝对值 2 分,其他6 分x = a(i)End IfNext iPrint x'2 分End Sub2007 年秋浙江省高等学校计算机等级考试参考答

10、案(二级 VB )试题 1试题 6请在各小题正确选项的对应位置处填“”(每小题 3 分,共72 分)ABCDABCD(1)(13)(2)(14)(3)(15)(4)(16)(5)(17)(6)(18)(7)(19)(8)(20)(9)(21)(10)(22)(11)(23)(12)(24)试题 7( 28 分)Dim a() As Single, n As IntegerPrivate Sub Form_Load()Command1.Caption = "数据输入 "(2分 )Command2.Caption = "计算 "(2分 )End SubPri

11、vate Sub Command1_Click() '数据输入Dim i As Integer(2分 )n = Text1.Text(2分 )ReDim a(n)(3分 )For i = 1 To na(i) = InputBox("")(5分 )Next iEnd SubPrivate Sub Command2_Click()Dim y As Single, i As Integer, x As Single(1分 )x = Text2.Text(1分 )y = a(1)(1分 )For i = 2 To ny = y + a(i) * x (i - 1)(7分

12、)Next iLabel3.Caption = y(2分 )End Sub2007 年春浙江省高等学校计算机等级考试参考答案(二级 VB )试题 16( 每小题3 分)BAABDCDBCCDCBDAAD B(21)C(22)A(23)A(24)DAB试题 7 (28 分)Private Function sum(Byval n As Integer) As Integersum=0: n=Abs(n)while n>0sum = sum + n mod 10: n=n10WendEnd FunctionPrivate Sub Command1_Click()Dim a(10) As In

13、teger, b(10) As Integer, i As IntegerFor i = 1 To 10a(i) = InputBox("a(" & i & ")=" ): b(i) = sum(a(i)Next iFor i=1 To 8: Printf a(i); " " :Next iPrintFor i=1 To 8: Printf b(i); " " :Next iEnd SubVB 上机考试程序调试题样题(填空 )参考答案题 11. dalt>02. dalt=0 3. Sqr(-

14、dalt)题 21.start= Space(21 - i) 2.Count = 19 -2 * i 3.Form1.Print start; 4.Form1.Print题 31.52. num3. Trim(i);题 41.number(i)2.n as integer3.number=number*10+7题 51.12. -13. x=(x+1)*2题 61.22. b = False 3. k = k + 14. b或 b = True题 71.do while x<4 or x mod 2<>0 2.if isprime(i) and isprime(x-i) th

15、en3.isprime=true4.if x mod I=0 then题 81. n+12. n Mod 3=1 and n Mod 5=1 and n Mod 7=1 3. While countN<5题 91.Not isLeapYear(year) 2.y Mod 4 <> 03. y Mod 100 = 0 4. y Mod 400<> 0题 101.trim(str(i)2.trim(str(i2) 3.x1=right(x2,len(x1)题 111. i100 2. i mod 10 3.i=hundred3+ten3+one3题 121. i,n

16、2.if i=s then3.for I=2 to x-1或 for i=2 to x2 4.a(k)=i题 131. s = 1 2. Do While s < 1E+163. i = i + 1题 141. s < 10002. x3. n + 14. n - 2题 151.sign=-1 2.19 3.sign=-sign题 161.temp=1 2.temp 3.nfactor(i) 4.sum题 171. 1 To Len(a) 2. n + fact(p)3. fact = y题 181.len(oldsen) 2.lastchar=" " 3.mi

17、d(oldsen,i,1) 4.ucase(char)题 191. salary(i)2. temp - hundred * 1003. temp 4. totalsalary +salary(i)题 201.Len(str1)2.length-1 3.mid(str1,I,2)4.sum=0VB 上机考试程序调试题样题(改错 )参考答案题 11.for i=9 to 1 step 12. Form1.Print Trim(Str(i); 3. End Sub题 21.for two=1 to n-one2.ifone+two*2+five*5=60then 3.nexttwo 4.next

18、one题 31.dim k as single2.for i=1 to 100 step23.k=-1/(i+1)题 41.cmn=nfactor(m)/(nfactor(n)*nfactor(m-n)2.nfactor=temp 3.End function题 51.length=len(str1)2. strright=mid(str1,k,1)3. strleft=mid(str1,length-k+1,1) 4. If strleft<>strright Then题 61.case is>r 2.Loop until times>5或 Loop While ti

19、mes <= 53.Form1.print“正确答案为” & str(r)题 71.n=len(Hex) 2.temp=Mid(Hex,n-i,1)3.Form1.print Hex +“转换为十进制数为” + str(Dec)或 Form1.print Hex & “转换为十进制数为” & Dec 或 Form1.print Hex ; “转换为十进制数为” ; Dec题 81. For i = 0 To 9 2. n = Int(Rnd * 90) + 103. MsgBox "偶数个数: " & count题 91.a(i)=in

20、t(Rnd*100) 2.p=a(i) mod 10 3.x(p)=x(p)+14.Form1.print“个位数为” +str(p)+”共” +str(x(i) + "个"题 101.Swap a(j),a(i) 2.Loop while i<n3.for j=1 to i-14.Public Sub Swap(a as integer,b as integer)题 111.Ifave(Line_no)<ave(i)then2.Line_no=i3.a(1,j)=a(Line_no,j)4.sum=sum+a(i,j)题 121.If i<>j a

21、nd i<>6-j then 2.Form1.print a(I,j);space(3);3.form1.print :form1.printVB 上机考试程序设计题样题参考答案1. 新建一个工程,完成“加法器”程序的设计。参考答案:Private Sub Command1_Click()Text3.Text = Str(Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = &

22、quot;"Text1.SetFocusEnd SubPrivate Sub Form_Load()Form1.Caption = " 加法器 "' 文本框清空Text1.Text = ""Text2.Text = ""Text3.Text = ""' 设置文本框右对齐Text1.Alignment = 1Text2.Alignment = 1Text3.Alignment = 1' 屏蔽对 Text3 的编辑Text3.Locked = TrueLabel1.Caption =

23、"+"Command1.Caption = ""Command2.Caption = "清空 "End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If (KeyAscii < 48) Or (KeyAscii > 57) ThenKeyAscii = 0End IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)If (KeyAscii < 48) Or (KeyAscii > 57) Then

24、KeyAscii = 0End IfEnd Sub2. 新建一个工程,完成“健康称”程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()Dim bzh As Singlebzh = Val(Text1.Text) - 105If Val(Text2.Text) > bzh * 1.1 ThenLabel5.Caption = " 偏胖,注意饮食"ElseIf Val(Text2.Text) < bzh * 0.9 ThenLabel5.Caption = "偏瘦,增加营养"ElseLabel5.Capt

25、ion = "正常,继续保持"End IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 Then ' 输入非数字 KeyAscii=0End IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 Then ' 输入非数字 KeyAscii=0End IfEnd Sub3. 新建一个工

26、程,完成应用程序的设计,具体要求如下:参考答案:Private Sub Command1_Click()If Form1.WindowState = 0 ThenCommand1.Caption = "最小化 (&B)"Form1.WindowState = 2Command1.Left = (Form1.Width - Command1.Width) / 2Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2ElseForm1.WindowState = 0Command1.Caption = "

27、;最大化 (&L)"Command1.Left = (Form1.Width - Command1.Width) / 2Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2End IfEnd Sub4. 新建一个工程,完成“判断质数”应用程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()Dim n As Integer, i As Integern = Text1.TextFor i = 2 To Sqr(n)If n Mod i = 0 Then Exit ForNext

28、iIf i > Sqr(n) ThenLabel2.Caption = Label2.Caption + " 是质数 "ElseLabel2.Caption = Label2.Caption + " 不是质数 "End IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 ThenKeyAscii = 0MsgBox(" 输入的不是数字, 无法计算 ")End IfEnd Sub5. 新建一个

29、工程,完成“计算平均成绩”应用程序的设计。具体要求如下:参考答案:Private Sub Text1_Change()Text4.Text = Str(Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) / 3)End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 ThenKeyAscii = 0n = MsgBox(" 输入的不是数字, 无法计算 ")End IfEnd SubPrivat

30、e Sub Text2_Change()Text4.Text = Str(Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) / 3)End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 ThenKeyAscii = 0n = MsgBox(" 输入的不是数字, 无法计算 ")End IfEnd SubPrivate Sub Text3_Change()Text4.Text = Str(Va

31、l(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) / 3)End SubPrivate Sub Text3_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 ThenKeyAscii = 0n = MsgBox(" 输入的不是数字, 无法计算 ")End IfEnd SubPrivate Sub Text4_Change()Text4.Locked = TrueEnd Sub6. 新建一个工程,完成“收款计算”程序的设计。具体要求如下:参

32、考答案:Private Sub Command1_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.setfocusEnd SubPrivate Sub Command2_Click()Text3.Text = Str(Val(Text1.Text) * Val(Text2.Text)End Sub7. 新建一个工程,完成“编辑”程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()'将文本框选中的内容复制到剪粘板中Clip

33、board.SetText Text1.SelTextEnd SubPrivate Sub Command2_Click()Clipboard.SetText Text1.SelTextText1.SelText = ""End SubPrivate Sub Command3_Click()Text1.SelText = Clipboard.GetText()'将要粘贴的内容复制到光标所在处End SubPrivate Sub Command4_Click()'Text1.seltext=”End Sub删除Private Sub Form_Load()Fo

34、rm1.Caption = "编辑 "Form1.BorderStyle = 1Command1.Caption = "Command2.Caption = "Command3.Caption = "Command4.Caption = "复制 "剪切 "粘贴 "删除 "End Sub8. 新建一个工程,完成“密码检验”程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()EndEnd SubPrivate Sub Form_Load()Label2.Vis

35、ible = FalseLabel2.AutoSize = TrueText1.PasswordChar = "*"End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Static times As Integer '统计第几次输入密码'按回车键后进行密码检验If KeyAscii = 13 ThenIf Text1.Text = "1234567" ThenLabel2.Caption = "欢迎光临!"Label2.Visible = TrueElseIf t

36、imes < 2 ThenLabel2.Caption = "密码不符,请再输入一遍!"Label2.Visible = TrueText1.Text = ""ElseLabel2.Caption = "非法用户,请退出程序!"Text1.Text = ""Text1.Enabled = FalseEnd IfEnd Iftimes = times + 1End IfEnd Sub9. 新建一个工程,完成应用程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()If Te

37、xt1.Text = Text2.Text And Text1.Text = "admin" ThenIf Text3.Text = Text4.Text And Text3.Text <> "" ThenMsgBox (" 密码修改成功")ElseMsgBox (" 请重新输入新密码")End IfElseMsgBox (" 请重新输入用户名或密码")End IfEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub For

38、m_Load()Text1.TabIndex = 0Text2.TabIndex = 1Text3.TabIndex = 2Text4.TabIndex = 3Command1.TabIndex = 4Command2.TabIndex = 5End Sub10. 新建一个工程,完成应用程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()Dim ss As StringFor i = 1 To Len(aa(Text1.Text)ss = aa(Text1.Text) Print Mid(ss, i, 1) Next i Command1.Enabled

39、 = FalseEnd SubPrivate Sub Command2_Click()EndEnd SubFunction aa(ss As String) As StringDim x()As IntegerDim tempAs IntegerReDim x(Len(ss)For i = 1 To Len(ss)x(i) = Asc(Mid(ss, i, 1)Next iFor i = 1 To Len(ss)For j = 1 To Len(ss)If x(i) < x(j) Thentemp = x(i)x(i) = x(j)x(j) = tempEnd IfNext jNext

40、iFor i = 1 To Len(ss)aa = aa & Chr(x(i)Next iEnd Function11. 新建一个工程,完成“替换”程序的设计。具体要求如下:参考答案:Private Sub command1_Click()' 查找替换文本Dim i%, len1%, len2%Dim findstr As Stringfindstr = Text2.Textfindstrlen = Len(findstr)' 待查文本长度text1len = Len(Text1.Text)' 文本长度For i = 1 To text1lenIf InStr(

41、Text1.Text, findstr) Thenstart = InStr(Text1.Text, findstr)Text1.SetFocusText1.SelStart = start - 1Text1.SelLength = findstrlenText1.SelText = Text3.Text' 替换文本End IfNext iEnd Sub12. 新建一个工程,完成应用程序的设计。具体要求如下:参考答案:Private Sub Command1_Click()EndEnd SubPrivate Sub Form_Load()Command1.Caption = "

42、; 结束 "End SubPrivate Sub Option1_Click()If Option1.Value = True ThenText1.Text = " 今天是 " & WeekdayName(Weekday(Date)End IfEnd SubPrivate Sub Option2_Click()If Option2.Value = True ThenText1.Text = " 今天是 " & Year(Date) & " 年 "End IfEnd SubPrivate Sub Opt

43、ion3_Click()If Option3.Value = True ThenText1.Text = " 今天是 " & Month(Date) & "月 "End IfEnd SubPrivate Sub Option4_Click()If Option4.Value = True ThenText1.Text = " 今天是 " & Day(Date) & "日 "End IfEnd Sub13.新建一个工程,完成“字体修饰”程序的设计。具体要求如下:参考答案:Private

44、 Sub Check1_Click(Index As Integer)If Check1(0).Value = 1 ThenLabel1.FontBold = TrueElseLabel1.FontBold = FalseEnd IfIf Check1(1).Value = 1 ThenLabel1.FontItalic = TrueElseLabel1.FontItalic = FalseEnd IfEnd SubPrivate Sub Option1_Click(Index As Integer)If Option1(0).Value = True ThenLabel1.FontName

45、= "宋体 "ElseLabel1.FontName = "楷体 _GB2312"End IfEnd Sub14. 新建一个工程,完成“点餐”程序的设计。具体要求如下:参考答案:Private Sub Check1_Click(Index As Integer)If Check1(Index).Value Then '若当前复选框被选中 , 文本框被启用 , 同时获得焦点 Text1(Index).Enabled = TrueText1(Index).SetFocusEnd IfEnd SubPrivate Sub Command1_Click(

46、)Dim a%, b%, c%, sum%If Check1(0).Value Thena = Val(Text1(0).Text)End IfIf Check1(1).Value Thenb = Val(Text1(1).Text)End IfIf Check1(2).Value Thenc = Val(Text1(2).Text)End Ifsum = a * 13 + b * 18 + c * 25MsgBox "一共 " & sum & "元 ", , "总价 "End SubPrivate Sub Form_

47、Load()Form1.Caption = "点餐 "Form1.BorderStyle = 1Command1.Caption = "确定 "Frame1.Caption = "菜单 "Check1(0).Caption = "儿童套餐馆 13元 "Check1(1).Caption = "标准套餐 18元"Check1(2).Caption = "商务餐 25元 "Label1(0).Caption = "份数 "Label1(1).Caption =

48、 "份数 "Label1(2).Caption = "份数 "Check1(0).Value = 0Check1(1).Value = 0Check1(2).Value = 0Text1(0).Enabled = FalseText1(1).Enabled = FalseText1(2).Enabled = FalseEnd SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 Then ' 输入非数字

温馨提示

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

评论

0/150

提交评论