《VB程序基础编程.docx》由会员分享,可在线阅读,更多相关《VB程序基础编程.docx(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、VB程序基础编程 VB 期末考试编程题覆盖范围: 第一题要求(12 分): 不用过程,覆盖以下算法: 1 求随机 10 个整数的最大值、最小值、平均值以及和; 2 求水仙花数; 3 一百零一元买一百零一鸡问题; 4 求 1010 以内的全部完数; 5 求各位数字之和; 6 求最小公倍数; 7 求逆序数; Private Sub Command3_Click() Dim s As String, i As Integer, j As Integer, n As Integer s = Text2.Text n = 0 For i = 1 To Len(s) - 1 For j = i + 1 T
2、o Len(s) If Mid(s, i, 1) > Mid(s, j, 1) Then n = n + 1 End If Next Next Print n End Sub 8 级数有限项求和问题; 9 求质因子问题; 10 字符统计。 Private Sub Command5_Click() Dim s As String, i As Integer, n As Integer, ch As String s = Text2.Text n = 0 For i = 1 To Len(s) ch = Mid(s, i, 1) If ch >= 0 And ch <= 9 Th
3、en n = n + 1 End If Next Print n End Sub 其次题要求(18 分): 指定编写过程并调用此过程,覆盖以下算法: 1 判定素数过程; Function f 素数(ByVal n As Integer) As Boolean Dim i As Integer For i = 2 To n - 1 If n Mod i = 0 Then Exit Function Next f 素数 = True End Function 2 求最大公约数过程; Function f 最大公约数(ByVal x As Integer, ByVal y As Integer) A
4、s Integer Dim i As Integer For i = x To 1 Step -1 If x Mod i = 0 And y Mod i = 0 Then f 最大公约数 = i Exit Function End If Next End Function 3 冒泡排序过程; Sub s 冒泡法(x() As Integer) Dim i As Integer, j As Integer, c As Integer, n As Integer For i = UBound(x) - 1 To LBound(x) Step -1 n = 0 For j = LBound(x) T
5、o i If x(j) > x(j + 1) Then c = x(j) x(j) = x(j + 1) x(j + 1) = c n = n + 1 End If Next If n = 0 Then Exit Sub Next End Sub 4 依次查找过程; Function f 依次查找(x() As Integer, ByVal n As Integer) As Integer Dim i As Integer For i = LBound(x) To UBound(x) If x(i) = n Then f 依次查找 = i Exit Function End If Nex
6、t End Function 5 推断回文数过程; Function f 回文数(ByVal x As Long) As Boolean Dim s As String, ch As String, i As Integer, r As String s = CStr(x) r = For i = 1 To Len(s) ch = Mid(s, i, 1) r = ch r Next If r = s Then f 回文数 = True End Function 6 递归函数求阶乘; Function f 阶乘(ByVal n As Integer) As Double If n = 0 Or
7、 n = 1 Then f 阶乘 = 1 Else f 阶乘 = n * f 阶乘(n - 1) End If End Function 7 递归函数求 Fibonacci 数列; Function fib(ByVal n As Integer) As Long If n = 1 Or n = 2 Then fib = 1 Else fib = fib(n - 1) + fib(n - 2) End If End Function 8 矩阵靠边元素之和; 9 矩阵不靠边元素之和; Function f 靠边元素之和(x() As Integer) As Long Dim i As Intege
8、r, j As Integer For i = LBound(x, 1) To UBound(x, 1) For j = LBound(x, 2) To UBound(x, 2) If i = LBound(x, 1) Or i = UBound(x, 2) Or j = LBound(x, 2) Or j = UBound(x, 2) Then f 靠边元素之和 = f 靠边元素之和 + x(i, j) End If Next Next End Function Function f 不靠边元素之和(x() As Integer) As Long Dim i As Integer, j As
9、 Integer For i = LBound(x, 1) To UBound(x, 1) For j = LBound(x, 2) To UBound(x, 2) If Not (i = LBound(x, 1) Or i = UBound(x, 2) Or j = LBound(x, 2) Or j = UBound(x, 2) Then f 不靠边元素之和 = f 不靠边元素之和 + x(i, j) End If Next Next End Function 10 矩阵转置。 Sub s 转置(x() As Integer, y() As Integer) Dim i As Integer, j As Integer For i = LBound(y, 1) To UBound(y, 1) For j = LBound(y, 2) To UBound(y, 2) y(i, j) = x(j, i) Next Next End Sub 其它题型: 单选题 40 题,每题 1 分共 50 分,填空题 10 空,每空 1 分,共 20 分。 第5页 共5页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页第 5 页 共 5 页
限制150内