资源描述
一、操作题,每题 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 = Else1text1.texts(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()Label1.Caption = 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(Text1.Text) pj = Val(Text2.Text)fy =0End Iffy If w =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 = Text1.Texts = For i = 1 To Len(x) = Mid(x, i, 1) If Asc(y) 57 Then s = s + 1 End IfNext iLabel1.Caption = 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 = txtPt.Text 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 txtCt.Text = ctEnd Sub
展开阅读全文