vb新操作题含答案 .doc
一、操作题,每题 10分,6 题共60分【第4题】打开文件“考生文件夹175工程1.vbp”,完善Command1_Click事件及s函数代码并保存。实现功能:用递归法求1+2+3+100的值,结果输出在窗体上。Public Function S(n As Integer) As Integer If n = 1 Then S = Else S = + S(n - 1)1n100 End IfEnd FunctionPrivate Sub Command1_Click() Dim Sum As Integer Sum = S() Print "Sum=" & CStr(Sum)End Sub【第5题】打开文件“考生文件夹851工程1.vbp”,完善程序实现如下功能并保存:花果山上有一洞,小猴每次采取跳1阶或者跳3阶的办法从山下跳跃上台阶进洞,编程在Text1中输入台阶数,在Label1中显示有多少种不同的跳法。正确的运行结果如下图所示,调试时输入的台阶数最大不要超过35!Function s(n As Integer) As LongIf n = 1 Or n = 2 Then s = Else1s(n) If n = 3 Then s = 2 Else s = s(n - 1) + s(n - 3) End IfEnd IfEnd FunctionPrivate Sub Command1_Click()Dim n As Integern = Val()on = Str()End Sub【第6题】打开文件“考生文件夹861年龄问题.vbp”,完善程序实现如下功能并保存:有5个人坐在一起,第5个人说他比第4个人小3岁;第4个人说他比第3个人小3岁;第3个人说他比第2个人小3岁;第2个人又说他比第1个人小3岁;第1个人说他是38岁。编写程序,计算出第5个人的年龄并显示。Private Sub cmdDisplay_Click() Print "第5人的年龄:" age()End Subn38End IfFunction age(n As Integer) As Integer If n = 1 Then age = Else age = age(n - 1) - 3 End Function【第3题】打开文件“考生文件夹89工程1.vbp”,完善Command1_Click事件代码并保存。乘坐飞机的经济舱时,免费托运行李一般不得超过20公斤,超重每公斤按全票价的1.5%计算。实现功能:输入行李重量及经济舱全票价后,点击按钮,计算出行李托运费用,输出到对应文本框中。Private Sub Command1_Click() Dim w As Integer '行李重量 Dim pj As Integer '机票价格 Dim fy As Single '托运费用 w = Val() pj = Val()fy =0End Iffy If w <= 20 Then Else fy = (w - 20) * pj * 0.015 = End Sub【第4题】打开文件“考生文件夹122工程1.vbp”,完善Command1_Click事件代码并保存。王晓珊家距离学校s1(千米),某天她和李明各自同时从家里步行出发上学,王晓珊步行速率v1(千米/小时),李明步行速率v2(千米/小时),结果他们同时到达学校。实现功能:输入s1、v1、v2,在窗体上输出李明家与学校之间的距离s2。Private Sub Command1_Click()s1/v1v2s2 Dim s1 As Single Dim s2 As Single Dim v1 As Single Dim v2 As Single Dim t As Single s1 = Val(InputBox("请输入王晓珊家离学校的距离:") v1 = Val(InputBox("请输入王晓珊步行速度:") v2 = Val(InputBox("请输入李明步行速度:") t = s2 = * t Print End Sub【第6题】打开“考生文件夹772”中的文件“工程1.vbp”,完善Command1_Click事件代码并保存。实现功能:某商场正在搞促销活动,买300元送200元,例如:某顾客购买商品449元,返还顾客200元,不满300元的零头不送。在文本框中输入一个正整数,计算返还的金额并显示在标签上,如样张所示。texta300captionsPrivate Sub Command1_Click() Dim a As Integer Dim s As Integer a = Val(Text1.) s = () * 200 Label1. = Str()End Sub【第1题】打开文件“考生文件夹373操作2.vbp”,完善程序实现以下功能并保存。找出100以内的质数对(若两个质数的差为2则称为质数对),并成对显示结果。其中,函数IsP(m)判断参数m是否为质数。Public Function IsP(m) As Boolean Dim i As Integer _(1)_ For i = 2 To Int(Sqr(m) If _(2)_ Then IsP = False Isp=true M mod 2=0 I-2 Next iEnd FunctionPrivate Sub Command1_Click() Dim i As Integer, p1 As Boolean, p2 As Boolean p1 = IsP(3) For i = 5 To 100 Step 2 p2 = IsP(i) If p1 and p2 Then Print _(3)_ , i p1 = p2 Next iEnd Sub【第8题】打开文件“考生文件夹859玫瑰花数.vbp”,完善程序实现如下功能并保存:如果一个4位数等于它的各位数字的4次方和,则这个4位数称为“玫瑰花”数,例如1634就是一个玫瑰花数。试编程求出所有的玫瑰花数,结果如下图所示。Private Sub cmdDemoRose_Click() 1 m4 next i Dim i As Integer Dim s As Integer Dim m As Integer For i = 1000 To 9999 s = 0 For j = To 4 m = Mid(i, j, 1) s = s + Next j If i = s Then Print i End Sub【第8题】打开文件“考生文件夹863细胞分裂.vbp”,完善程序实现如下功能并保存:有一种细胞每3分钟分裂一次,每次分裂时每个细胞分裂成2个,30分钟后有2048个细胞。问开始时有多少个细胞?Private Sub cmdDivision_Click() x>=0 y+x y/z 2048 step -1 f(0) Dim f(10) As Integer ' 30分钟共分裂10次 Dim i As Integer f(10) = For i = 9 To 0 Step f(i) = f(i + 1) / 2 Next i Print End Sub【第1题】打开文件“考生文件夹375操作4.vbp”,完善程序实现以下功能并保存。从键盘输入若干个数直到输入负数为止,统计所有非负数的平均值并输出。Private Sub Command1_Click() Dim x As Single, y As Single Dim z As Integer x = InputBox("输入一个数:") Do while _(1)_ y=_(2)_ z = z + 1 x = InputBox("输入一个数:") Loop If z = 0 Then z = 1 End If y=_(3)_ Print "平均值为:" yEnd Sub【第1题】打开文件“考生文件夹372操作1.vbp”,完善程序实现以下功能并保存。Private Sub Command1_Click() Dim s As Single Dim a As Integer, b As Integer, c As Integer, k As Integer 1 a b s = 0 a = _(1)_ b = 1 For k = 1 To 20 s = s + a / b c = _(2)_ a = _(3)_ b = c + a Next k Print sEnd Sub【第7题】打开文件“Z:114工程1.vbp”, 完善Form_Click事件代码并保存。完善程序,求1/1+1/2+2/3+21/34+前20项的值。Private Sub Command1_Click() Dim s As Integer Dim a As Integer Dim b As Integer Dim k As Integer s = 0 a = 1 b = 1 a+b s+b/a a+b For k = 1 To 10 s = s + a / b a = s = b = Next k Print sEnd Sub【第3题】打开文件“考生文件夹374操作3.vbp”,完善程序实现以下功能并保存。输出数组的最大值。Private Sub Command1_Click() Dim arr1, Max As Integer arr1 = Array(12, 435, 76, 24, 78, 54, 866, 43) max 0 max=arr1(i) _(1)_= -32768 For i = _(2)_ To 7 If arr1(i) > Max Then _(3)_ Next i Print "最大值是: " MaxEnd Sub【第4题】打开文件“考生文件夹376操作5.vbp”,完善程序实现如下功能并保存:在所有的两位整数中,输出个位数字和十位数字不相同的整数及个数。Private Sub Command1_Click() Dim n As Integer, a As Integer, b As Integer, x As Integer n = 0 For a=_(1)_ For b = 0 To 9 1 to 9 a*10+b n If a <> b Then x=_(2)_ Print x; n = n + 1 End If Next b Print Next a Print "总个数:"_(3)_End Sub【第9题】打开文件“考生文件夹850工程1.vbp”,完善程序实现如下功能并保存:在文本框text1中输入一段含有数字的短文(如样张),编写程序查找统计非数字字符的个数,并在label1中显示。Private Sub Command1_Click()Dim x As String, y As StringDim s As Integer, i As Integer 0 y sx = s = For i = 1 To Len(x) = Mid(x, i, 1) If Asc(y) < 48 Or Asc(y) > 57 Then s = s + 1 End IfNext ion = Str()End Sub【第10题】打开文件“考生文件夹857恺撒密码.vbp”,完善程序实现如下功能并保存:公元前60年,古罗马统帅“朱利叶斯·恺撒”(Caesar)第一个用当时发明的“恺撒密码”书写军事文书,进行战时通信。恺撒加密法简而言之,就是字母替换加密,每一个字母用字母表中该字母后的第三个字母代替。即明文:ABCDEFGHIJKLMNOPQRSTUVWXYZ密文:DEFGHIJKLMNOPQRSTUVWXYZABC编写程序,将明文加密输出。例如:输入:How are you!输出:Krz duh brx!Private Sub cmdCode_Click() Dim pt As String ' 明文 Dim ct As String ' 密文 Dim n As Integer ' 字母在字母表中的序号 Dim ch As String Dim i As Integer pt = ch asc(ch)-asc("A") ct+ch ct = "" For i = 1 To Len(pt) ch = Mid(pt, i, 1) Select Case Case "A" To "Z" n = Asc(ch) - Asc("A") n = (n + 3) Mod 26 ch = Chr(n + 65) Case "a" To "z" n = n = (n + 3) Mod 26 ch = Chr(n + 97) End Select ct = Next i = ctEnd Sub