VB重点整理.doc_第1页
VB重点整理.doc_第2页
VB重点整理.doc_第3页
VB重点整理.doc_第4页
VB重点整理.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

11级金融二班VB重点整理三、程序题1.最大公约数与最小公倍数在通用的声明部分Dim m As Integer, n As Integer, max_zhi As Integer, min_zhi As Integer在Command1的click事件中Private Sub Command1_Click() m = Val(InputBox(请输入m的值) n = Val(InputBox(请输入n的值) If m n Then min_zhi = n Else min_zhi = m End If For I = min_zhi To 1 Step -1 If (m Mod I) = 0) And (n Mod I) = 0) Then MsgBox Str(m) + 和 + Str(n) + 的最大公因子为: + Str(I) Exit For End If Next IEnd Sub在Command2的click事件中Private Sub Command2_Click() m = Val(InputBox(请输入m的值) n = Val(InputBox(请输入n的值) max_zhi = IIf(m n, m, n) For I = max_zhi To m * n If (I Mod m) = 0) And (I Mod n) = 0) Then MsgBox Str(m) + 和 + Str(n) + 的最小公倍数为: + Str(I) Exit For End If Next IEnd Sub2金字塔系列正金字塔:在Command1的click事件中Private Sub Command1_Click() Cls For I = 1 To 9 Print Spc(9 - I); For h = 1 To I Print Trim(Str(h); Next h For k = I - 1 To 1 Step -1 Print Trim(Str(k); Next k Print Next IEnd Sub倒金字塔:在Command2的click事件中Private Sub Command2_Click() Cls For I = 9 To 1 Step -1 Print Spc(9 - I); For h = 1 To I Print Trim(Str(h); Next h For k = I - 1 To 1 Step -1 Print Trim(Str(k); Next k Print Next IEnd Sub斜金字塔1:在Command3的click事件中Private Sub Command3_Click() Cls For I = 1 To 9 For h = I To 1 Step -1 Print Trim(Str(h); Next h Print Next I For m = 9 To 1 Step -1 For n = m - 1 To 1 Step -1 Print Trim(Str(n); Next n Print Next mEnd Sub斜金字塔2:在Command4的click事件中Private Sub Command4_Click() Cls For I = 1 To 9 Print Spc(9 - I); For j = 1 To I Print Trim(Str(j); Next j Print Next I For I = 8 To 1 Step -1 Print Spc(9 - I); For j = 1 To I Print Trim(Str(j); Next j Print Next IEnd Sub3、勾股定理中三个数的关系是:a2+b2=c2。编写程序,输出30以内的满足上述关系的整数组合,例如3,4,5就是一个整数组合。在form的click事件中Private Sub Form_Click() For I = 1 To 30 For m = I + 1 To 30 For n = m + 1 To 30 If I 2 + m 2 = n 2 Then Print I; m; n End If Next n, m, IEnd Sub4、如果一个数的因子之和等于这个数本身,则称这样的数为完全数。例如,整数28的因子为1,2,4,7,14,其和1+2+4+7+14=28,因此28是个完全数。编写一个程序,从键盘上输出正整数N和M,求出M和N之间所有的完全数在form的click事件中Private Sub Form_Click() Dim m As Integer, n As Integer, sum_1 As Integer Dim str_msg As String m = Val(InputBox(请输入m的值) n = Val(InputBox(请输入n的值) max_zhi = IIf(m n, m, n) min_zhi = IIf(m n, m, n) min_zhi = IIf(m max_jz Then max_jz = jz(I, j) no_h = I no_l = j End If Next j Next I Print 最大数值为: + Trim(Str(max_jz); Spc(5); 位于第 + Trim(Str(no_h) + 行,第 + Trim(Str(no_l) + 列End Sub7.设有如下人员名册:姓名性别年龄文化程度籍贯张得功男24大学本科河北李得胜男30高中毕业北京王丽女25研究生山东试编写一个程序,对该名册进行检索。程序运行后,只要在键盘上输入一个人名后,就可以在屏幕上显示出这个人的情况。要求:(1) 使用动态数组,输入的人数可以根据实际情况改变(2) 当检索名册中不存在人名时,输出相应的信息(3) 每次检索结束后,询问是否继续检索,根据输入的信息确定是否结束程序。在通用的声明部分Option Base 1Dim array_hmc() As Variant, m As Integer, bz As Integer控制按钮保存即command1的click事件Private Sub Command1_Click() m = m + 1 ReDim Preserve array_hmc(5, m) array_hmc(1, m) = Trim(Text1.Text) array_hmc(2, m) = Trim(Text2.Text) array_hmc(3, m) = Val(Trim(Text3.Text) array_hmc(4, m) = Trim(Text4.Text) array_hmc(5, m) = Trim(Text5.Text) Command4_ClickEnd Sub控制按钮查找即command2的click事件Private Sub Command2_Click() bz = 0 For I = 1 To m If array_hmc(1, I) = Trim(Text1.Text) Then Cls Print array_hmc(1, I); Spc(5); array_hmc(2, I); Spc(5); _ array_hmc(3, I); Spc(5); array_hmc(4, I); Spc(5); array_hmc(5, I) bz = 1 goon_yon = MsgBox(是否继续查找, vbQuestion + vbOKCancel + vbDefaultButton1, 提示) If goon_yon = vbOK Then Text1.Text = Text1.SetFocus End If End If Next I If bz = 0 Then MsgBox 找不到该成员信息,请重新输入, vbCritical + vbOKOnly, 提示 Text1.Text = Text1.SetFocus End IfEnd Sub控制按钮结束即command3的click事件Private Sub Command3_Click() EndEnd Sub控制按钮清空即command4的click事件Private Sub Command4_Click() Text1.Text = Text2.Text = Text3.Text = Text4.Text = Text5.Text = Text1.SetFocusEnd Sub8.“杨辉三角”编写程序,输出n=10的杨辉三角形在form的click事件中Private Sub Form_Click() Dim yhsj(10, 10) As Integer For I = 0 To 10 For j = 0 To I If I = j Or j = 0 Then yhsj(I, j) = 1 Else yhsj(I, j) = yhsj(I - 1, j - 1) + yhsj(I - 1, j) End If Next j, I For m = 0 To 10 For n = 0 To m Print Trim(Str(yhsj(m, n) _ + Space(4 - Len(Trim(Str(yhsj(m, n); Next n Print Next mEnd Sub9.编写程序,求S=A!+B!+C!,阶乘的计算分别用sub过程和function过程两种方案实现。在通用的声明部分Dim sum_1_1 As Long, sum_1_2 As Long, sum_1_3 As Long, sum_1 As Long在sub的cal-1过程中Sub cal_1(ByVal num As Integer, ByRef result_1 As Long) result_1 = 1 For I = num To 1 Step -1 result_1 = result_1 * I Next IEnd Sub在function的cal-2过程中Function cal_2(ByVal num As Integer) cal_2 = 1 For I = num To 1 Step -1 cal_2 = cal_2 * I Next IEnd Function在控制按钮调用sub过程即command1的click事件中Private Sub Command1_Click() a = InputBox(请输入a的值) b = InputBox(请输入b的值) c = InputBox(请输入c的值) a = CInt(a): b = CInt(b): c = CInt(c) Call cal_1(a, sum_1_1) Call cal_1(b, sum_1_2) Call cal_1(c, sum_1_3) sum_1 = sum_1_1 + sum_1_2 + sum_1_3 Picture1.Print Trim(Str(a) + ! + +; Trim(Str(b) + ! + +; Trim(Str(c) + ! + = + Str(sum_1)End Sub在控制按钮调用function过程即command2的click事件中Private Sub Command2_Click() a = InputBox(请输入a的值) b = InputBox(请输入b的值) c = InputBox(请输入c的值) a = CInt(a): b = CInt(b): c = CInt(c) sum_2 = cal_2(a) + cal_2(b) + cal_2(c) Picture1.Print Trim(Str(a) + ! + +; Trim(Str(b) + ! + +; Trim(Str(c) + ! + = + Str(sum_2)End Sub10.求解一元二次方程ax2+bx+c=0的过程,要求a、b、c及解x1、x2都以参数传送的方式与主程序交换数据,输入a、b、c和输出x1、x2,的操作放在主程序中在通用的cal-fc过程中Private Sub cal_fc(ByVal a_1 As Double, ByVal b_1 As Double, ByVal c_1 As Double, ByRef g1 As Double, ByRef g2 As Double) g1 = (0 - b_1) + Sqr(b_1 2 - 4 * a_1 * c_1) / (2 * a_1) g2 = (0 - b_1) - Sqr(b_1 2 - 4 * a_1 * c_1) / (2 * a_1)End Sub在form的click事件中Private Sub Form_Click() Dim x1 As Double, x2 As Doubleagain: a = InputBox(输入a的值) b = InputBox(输入b的值) c = InputBox(输入c的值) a = Val(a): b = Val(b): c = Val(c) If b 2 4 * a * c Then MsgBox 该方程没有实根!请重新输入, vbCritical + vbOKOnly, 提示 GoTo again Else x1 = 0: x2 = 0 Call cal_fc(a, b, c, x1, x2) Print x1=; x1, x2=; x2 End IfEnd Sub11.斐波那契数列的第一项为0,第二项为1.。以后的各项都是前两项的和,编写程序,求斐波那契数列第N项的值在通用的cal-1过程中Function cal_f(ByVal num As Integer) n_1 = 0 n_2 = 1 For I = 3 To num n = n_1 + n_2 n_1 = n_2 n_2 = n Next I cal_f = nEnd Function在form的click事件中Private Sub Form_Click() num_in = InputBox(要输出斐波那契数列第几项的值?) Print 斐波那契数列第 + Str(num_in) + 项的值为: + Str(cal_f(CInt(num_in)End Sub12.设a为一整数,如果能使a2=xxa成立,那么称a为守形数,例如5的平方等于25,25的平方等于625,则5和25都是守形数。试编写一个function过程automorphic,其形参为一正整数,判断其是否为守形数,然后用该过程查找1-1000内所有的守形数在通用的automorphic过程中Function automorphic(ByVal num As Long) As Boolean If Right(Trim(Str(num 2), Len(Trim(Str(num) = Trim(Str(num) Then automorphic = True Else automorphic = False End IfEnd Function在form的click事件中Private Sub Form_Click() For I = 1 To 1000 If automorphic(I) Then Print Str(I) + 2= + Str(I 2) End If Next IEnd Sub13.税务部门征所得税,规定如下:(1)收入在200元以内的,免征;(2)收入在200-400元内,超过200元的部分纳税3%(3)收入超过400元的部分,纳税4%(4)当收入达5000元或超过时,纳税5%编写程序实现上述操作。通用的声明部分Dim income as single,tax as singleCommand1的click事件Private Sub command1_Click()Income=val(inputbox(“请输入收入”)Select case Case is 5000 Tax=(income-5000)*0.05+4600*0.04+200*0.03End selectIf tax=0 then Msgbox“免征”ElseMagbox str(tax)End ifSub14.起泡程序1、冒泡排序法在通用的声明部分Option Base 1 Dim num() As Integer Dim m As Integer在command1的click事件中Private Sub Command2_Click() Picture1.Print 原始序列: 输出原始的顺序 For k = 1 To m Picture1.Print num( + Trim(Str(k) + )= + Str(num(k) Next k Picture1.Print Picture1.Print For h = m To 2 Step -1 使用冒泡法排序 For I = 1 To h - 1 If num(I) num(I + 1) Then t = num(I + 1) num(I + 1) = num(I) num(I) = t End If Next I Next h Picture1.Print 排序以后: For k = 1 To m Picture1.Print num( + Trim(Str(k) + )= + Str(num(k) Next kEnd SubPrivate Sub Command3_C

温馨提示

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

评论

0/150

提交评论