《2022年VB程序设计方案编程考试题及答案.docx》由会员分享,可在线阅读,更多相关《2022年VB程序设计方案编程考试题及答案.docx(12页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VB 程序设计编程考试卷及答案1. 输入 3 个数,输出最大的数Private Sub command1_click Dim maxFor i = 1 To 3n = ValInputBox 输入第 & i & 个数 If n max Then max = nEnd IfNextPrint 三个数中最大的数是 ; max End Sub2. 有一元二次方程:aX 2+bX+c=0 ,依次输入 a, b, c,判定此方程是否有实根Private Sub Command1_ClickDim a, b, c, n a = Text1b = Text2 c = Text3n = b * b - 4 *
2、 a * c If n = 0 ThenLabel4 = 方程有根 ElseLabel4 = 方程无根 End IfEnd Sub3. 输入一个百分制的成果,如大于等于60 ,就用消息框弹出,显示“恭喜!成果通过!”,如小于 60,就弹出消息框,显示“愧疚!成果没有通过!Private Sub Form_Load Text1 = End SubPrivate Sub Command1_ClickDim nn = Text1If n =60 ThenVal MsgBox 恭喜!成果通过! ElseVal MsgBox 愧疚!成果没有通过! End IfEnd Sub4. 输入一年份,判定它是否为
3、闰年,并显示有关信息;(判定闰年的条件是:年份能被4整除但不能被 100 整除,或者能被 400 整除)Private Sub Command1_Click Dim y%y = InputBox 请输入年份 If y Mod 4 = 0 And y Mod 100 0 Or y Mod 400 = 0 Then Val MsgBox 闰年! ElseVal MsgBox 平年! End IfEnd Sub5. 输入同学的百分制成果,转换输出为五级制成果,90 100 分转换为优秀, 80 89 转换为良好, 70 79 转换为中等, 60 69 转换为及格, 0 60 转换为不及格;Priva
4、te Sub Command1_Clicka = ValInputBox 请输入成果 If a 100 Then Print 超出范畴 If a = 90 And a = 80 And a = 70 And a = 60 And a 70 Then Print 及格 If a n1 Thenm = m1: n = n1Elsem = n1: n = m1End Ifr = m Mod nDo While r 0 m = nn = rr = m Mod nLoopPrint m n 的最大公约数是:; n End Sub8. 编程求 200-400 范畴内 5 的倍数或 7 的倍数之和; 一个数
5、假如同时是7 和 5 的倍数, 就只能加一次;Private Sub Command1_Click For i = 200 To 400If i Mod 5 = 0 Or i Mod 7 = 0 Then Sum = Sum + iEnd If Next iFor i = 200 To 400If i Mod 5 = 0 And i Mod 7 = 0 Then Sum = Sum - iEnd If Next iPrint 倍“数之和 =”; SumEnd Sub9. 运算 100300 之间全部能被 3 和 7 整除的数之和Private Sub Command1_Click Dim iS
6、um = 0For i = 100 To 300If i Mod 3 = 0 And i Mod 7 = 0 Then Sum = Sum + iEnd If Next i Print Sum End Sub10. 分别统计 1-100 中,满意 3 的倍数、 7 的倍数的数各有多少;Private Sub Command1_ClickDim i, s3, s7 s3 = 0s7 = 0For i = 1 To 100If i Mod 3 = 0 Then s3 = s3 + 1End If Next iFor i = 1 To 100If i Mod 7 = 0 Then s7 = s7 +
7、 1End IfNext iPrint 3 的倍数 ; s3 Print 7 的倍数 ; s7 End Sub11. 某次歌曲大奖赛,有7 个评委;假如分别输入7 个评委对某个参赛者的打分数,根据去掉一个最高分和一个最低分的运算方法,求出该参赛者的平均得分;Private Sub Command1_Click Dim max, a1 To 7, min, sFor i = 1 To 7ai = ValInputBox 输入第 & i & 个数 Next imax = a1 min = a1 s = a1For i = 2 To 7If ai max Then max = ai If ai mi
8、n Then min = ai s = s + aiNext is = s - min - max s = s / 5Print 平均分 ; s End Sub12. 输入一串字符,统计其中字母A 不区分大小写 显现的次数;Private Sub Command1_ClickDim c As String, a As Integer b = InputBox 请输入字符 For i = 1 To Lenbc = UCaseMidb, i, 1If c = A Then a = a + 1End If Next iPrint a 显现的次数: ; aEnd Sub13. 我国目前有 13 亿人口
9、,按人口年增长率0.8% 运算,多少年后我国人口将超过26 亿;Private Sub Command1_ClickDim a, i a = 13i = 0Do While a =2 )11 项;(斐波那契数列:F0=f1=1,Fn=Fn-1+Fn-2Private Sub Command1_Click Dim F11, i As LongF0 = 1F1 = 1For i = 2 To 10Fi = Fi - 1 + Fi - 2Next iFor i = 0 To 11 Print Fi ;Next iEnd Sub将输入的字符串以反序显示;例如:输入“Private Sub Comman
10、d1_ClickDim a, b, c, d, na = InputBox 输入字符串 n = LenaFor b = 1 To Intn 2 c = Mida, b, 1Mida, b, 1 = Mida, n - b + 1, 1 Mida, n - b + 1, 1 = cNext bPrint a End SubASDFGT ”,显示“ TGFDSA ”随机产生 10 个30,100内的整数,求最大值及所对应的下标Next z Next y Next x End Sub17.18.19.Private Sub Command1_Click Dim a1 To 10, mRandomiz
11、e For I = 1 To 10aI = IntRnd * 71 + 30 Print aINext IMax = a1For I = 2 To 10If aI Max Then Max = aI: m = I Next IPrint max= ; MaxPrint max 的下标为 ; m End Sub20. 随机产生 10 个30,100内的整数,求最大值、最小值和平均值;Private Sub Command1_Click Dim a1 To 10For i = 1 To 10ai = IntRnd * 71 + 30 Print aiNext iMax = a1 Min = a1
12、Avg = a1For i = 2 To 10If ai Max Then Max = ai If ai Min Then Min = ai Avg = Avg + aiNext iAvg = Avg / 10Print max= ; Max Print min= ; Min Print avg= ; Avg End Sub随机产生 10 个30,100内的整数,求最小值及所对应的下标;21.Private Sub Command1_Click Dim a1 To 10, mRandomizeFor I = 1 To 10aI = IntRnd * 71 + 30 Print aINext I
13、Min = a1For I = 2 To 10If aI Max Then Max = ai If ai Min Then Min = ai Avg = Avg + aiNext iAvg = Avg / 10Print max= ; Max Print min= ; Min Print avg= ; Avg End Sub24. 利用随机函数生成一个4 4 的矩阵 即二维矩阵 , 范畴是 20,50 内的整数 ,输出该矩阵全部数据之和Private Sub Command1_Click Dim a%4, 5, sumFor i = 1 To 4For j = 1 To 4ai, j = In
14、tRnd * 31 + 20Print ai, j ;sum = sum + ai, j Next jPrint 换行Next i已知有序数组a ,编程插入x( x 的值为89, 75, 63, 100, 20 ,31;14);数组a 中的元素分别为12 , 6, 4,Print sum= ; sum End Sub25.Private Sub Command1_Click Dim a, i%, k%, x%, n%a = Array4, 6, 12, 20, 31, 63, 75, 89, 100n = UBoundax = ValInputBox 请输入所要插入数 For k = 0 To
15、 nIf x ak Then Exit For Next kReDim Preserve an + 1For i = n To k Step -1 ai + 1 = aiNext iak = xFor i = 0 To n + 1 Print ai ;Next iEnd Sub26. 编写一函数,运算Double 类型一维数组全部元素的平均值;27. 编一子过程 ProcMin, 求一维数组 a 中的最小值,子过程的形参自己确定Private Sub command1_Click Dim a1 To 10, min, i%For i = 1 To 10ai = IntRnd * 101 Pri
16、nt ai ;Next iCall ProcMina, min PrintSub ProcMinb, min Dim i%min = bLBoundbFor i = LBoundb + 1 To UBoundb If bi min Then min = biNext i End Sub编一子过程 ProcMin, 求一维数组 a 中的最小值,子过程的形参自己确定;Private Sub Form_Click Dim a1 To 10, amin, i%For i = 1 To 10ai = IntRnd * 101 Print ai ;Next iCall ProcMina, amin PrintPrint amin = ; aminEnd SubSub ProcMinb, min Dim i%min = bLBoundbFor i = LBoundb + 1 To UBoundb If bi max Then max = biNext iEnd Sub30. 编写一个过程运算并输出区间100, 1000内全部素数的和 要求判定素数使用过程(函数或子过程)来实现;调用该过程;提示:只能被1 和自身整除的自然数称为素数;