《上海海事大学VB题库—程序填空.docx》由会员分享,可在线阅读,更多相关《上海海事大学VB题库—程序填空.docx(160页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、程序填空K第1题2I1程序填空(1分)(题号:59)【程序填空】 功能:输入一个数,若大于0,则显示+;若小于0, , 则显示若等于0,则显示零。Private Sub Commandl_Click()x = Val(Text 1 .Text)Select Case x,*SpycE* *?Label 1.Caption = +Case Is 0Label 1.Caption =Case 0 或 Case Else 或 Case Is = 0K第2题1r程序填空(1分)(题号:60)【程序填空】助能:输入任何一个英文字母X,若X的值为,则显示X的大写字母;,若x的值为则显示x的小写字母; 若x
2、的值为其它的值,则显示xa (如输入的X的值是g,则显示ga)oPrivate Sub Command l_Click() x = Text I.Text ,*spaf *,* * *SpCE* *Case ?Label 1 .Caption = UCase(x)Case “m“,”o”,”p“ To “zLabel 1.Caption = LCase(x)Case Else,*SpcE* *?End SelectEnd Sub答案:1) .Select Case x2) .“a,“c”,”d“To“f3) .Label!.Caption = Trim(x) + a 或 Label 1.Cap
3、tion = x + aMK第3题程序填空(1分)(题号:36)U程序填空】功能:以下程序的功能如(图l)oPrivate Sub Form_Click()Dim a%, b%, c%, d!Dim xl,x2Dim p, q, ra = InputBox(请输入a的值”) b = Inpu出ox(”请输入b的值”) c = InputBox。请输入c的值”) d=b*b-4*a*cp = -b/ (2 * a)If d = 0 Then,*SpcE* *If ? Then r=Sqr(d)/(2* a) xl = p + r x2 = p - rElse xl = p x2 = p,*Spy
4、CE* *?Print ,xl=H;xl,x2=n; x2 ,*SpcE* *q = Sqr(-d) / (2 * a)Print xl=; p; +“; q; “i“,“x2=; p; /; q; “iEnd IfEnd Sub答案:1) .d0 或0= 90 ThenLabel 1.Caption 二优秀” ,*Sp/CE* * Elself ? ThenLabel 1.Caption =良好Elself x = 60 Then,*SpcE* *,*SpyCE* *LabelLCaption= 不及格”End IfEnd Sub答案:1) .x=75 或 75= 90nl = nl + 1
5、Case Is = 80n2 = n2 + 1Case Is = 70n3 = n3 + 1Case Is = 60n4 = n4 + 1Case Elsen5 = n5 + 1,*SpcE* *?score = Val(InputBox(msg, msgtitle) WendPrint nl, n2, n3, n4, n5,totalEnd Sub答案:1) . score =0 And* score = 100 或 0v=score And* score v= 100 或 0=score 或 score =0 And* 100=score2) .score3) .End SelectR第9
6、题程序填空(1分)(题号:56)【程序填空】功能:输入数字17,显示其对应是星期儿(例:输入1,显示星期日, 如果输入其它内容,一律显示“输入错误”)Private Sub Commandl_Click() dim x as integer dim y as string x=val(textl.text)*SP/CE* *?case 1y=”今天是星期日case 2y=星期一“case 3y=星期二case 4y=星期三case 5y=星期四case 6,*SpcE* *?case 7y=星期六,*SpcE* *?y= 输入错误end selectText2.Text = yEnd Sub答
7、案:1) .select case x2) .y=星期五”3) .Case ElseR第10题程序填空(1分)(题号:41)【程序填空】 下面过程max()用于求3个数中最大值,利用这个过程求5个数中最大值。Private Sub Form_Click()Print 5 个数 34、124、68、73、352 的最大值是:” maxi = max(34, 124,68),*SpyCE* *maxi = ?Print maxiEnd SubPublic Function max(ByVal a%, By Vai b%, By Vai c%),*SpycE* *If ? Thenm = aElse
8、m = bEnd If,* *SpcE* *If ? Thenmax = mElsemax = cEnd IfEnd Function答案:1) .max(maxl, 73, 352)2) .ab 或 b c 或 c v mK第11题程序填空(1分)(题号:43)“程序填空】功能:下面的程序段用于实现以下功能:利用冒泡法将一组整数 从小到大排序。Private Sub Form_Click()Const n = 15Dim a(l To n) As Integer, work As BooleanDim i As Integer, j As Integer, x As Integer Rand
9、omizeFor i = 1 To na(i) = Int(90 * Rnd) + 10Next iFor i = 1 To nPrint a(i);Next iPrint*SP/CE* *For i = n To 2 ?work = TrueForj = 1 To i - 1Ifa(j)a(j+ I) Thenx = a(j): a(j) = a(j + 1): a(j + 1) = x,* *SpycE* *?End IfNext j,*SpycE* *If work Then ?Next iFor i = 1 To nPrint a(i);Next iEnd Sub答案:1) .Step
10、 -12) . work = False 或 work=0 或 not work = true3) .Exit ForK第12题程序填空(1分)(题号:37)【程序填空】功能:以下程序用于判断一个正整数(23)是否为素数。Private Sub Form_Click()n = InputBox(请输入一个正整数(23) ”)k = Int(Sqr(n)i = 2swit = 0t*SpyCE* *Do While i = k And ?*SP/CE* *If ? Thenswit = 1Else,* *SpcE* *?End IfLoopIf swit = 0ThenPrint n; 是一个素
11、数”ElsePrint n; “不是素数”End If答案:1) .2) .3) .End Subswit = 0n Mod i = 0 或 n/i = ni 或 n/i = int(n/i)i =+ 1K第13题程序填空J (1分)(题号:55)【程序填空】 ,功能:过程suixian可以判断某一个数字是否是水仙花数,利用该过程找出三位数中所有水仙花数。所谓“水仙花数”是指一个3位数,其各位数字立方和等于该数本身。Private Sub Form_Click()Dim i As IntegerFori = 100To 999*SpyCE* *?Next iEnd SubPublic Sub
12、suixian(x As Integer)Dimi%,j%, k%*SP/CE* * i= ?j = (x - i * 100) 10k = x-i* 100-j* 10,*SpcE* *If ? Then Print xEnd Sub答案:1) . suixian (i) 或 call suixian (i) 或 suixian i2) . x 100 或 int(x/100)3) . x = i A + j A 3* + k 八 3 或 x = i*i*i + k *k*kK第14题程序填空(1分)(题号:50)【程序填空】 功能:从键盘上输入一串字符,以”?”结束,统计输入字符中的*大、
13、小写字母和数字的个数。Private Sub Form_Click()Dim ch$, nl%, n2%, n3%nl =0n2 = 0n3 = 0ch = lnputBox(请输入一个字符”),*SpycE* *Do While ?Select Case chCase a” To Vnl = nl + 1*SP/CE* *Case ?n2 = n2 + 1Case “0“To“9“n3 = n3 + 1End Selectch = InputBox(请输入一个字符),*SpyCE* *?Print nl, n2, n3End Sub答案:1) . ch ?或 not ch = ?或 not
14、?=ch2) .”A“To“Z“3) .LoopR第153程序填空(1分)(题号:54)“程序填空】 功能:本程序用于实现:从键盘接收-数字,判断其是否在数组,中,如果在数组中则将其删除,否则显示该数字不在数组,中。Private Sub Form_Click()Dim a(10) As Integer, x As IntegerFori = 1 To 10a(i) = Int(Rnd * 90) + 10Print a(i);Next iPrintx = InputBox(请输入要删除的整数”)Fori = 1 To 10*5f(2E* *If a(i) = x Then ?Next i,*
15、SpcE* *If ? ThenFor k = i To 9* SpCE* *Next kPrint ”删除后的数组:For i = 1 To 9Print a(i);Next iElsePrint”该数字不在数组中”End IfEnd Sub答案:1) .Exit For2) .ii3).a(k) = a(* k + 1)R第16题程序填空(1分)(题号:48)“程序填空】 功能:利用下面的过程求m!和m*nPrivate Sub Form_Click()Dim m As Integer, n As Integerm = 2n = 3* *SpycE* *?End SubPrivate Su
16、b find(x As Integer, y As Integer)Dim s, i As Integer,*SpycE* *?For i = 1 To xq = q * i * *SpyCE* *P= ?Next iPrint s, p答案:1) .2) .3) .End Subfind m, n 或 call find(m,n) s = 1 或 s = l:p=O p*+*y 或 x*yK第17题1程序填空J (1分)(题号:58)【程序填空】 功能:求A,B,C三个数的最大值。Private Sub Command l_Click() A = Val(Textl.Text) ,*SpcE
17、* *?C = Val(Text3.Text)If A B And A CThen MAXDATE = A,* * *SpycE* *Elself ? ThenMAXDATE = BElse * *SP/CE* *End IfLabel 1.Caption = MAXDATE & ”是最大值”答案: !). 2). 3).End SubB = Val(Text2.Text) 或 b=val(tex BC 或 CC and 或 cb and* abMAXDATE = CK第18题X程序填空(1分)(题号:42)【程序填空】功能:以下程序段利用随机函数生成15个10-100之间的整数, 然后用选择
18、法将其从小到大排序。Private Sub Form_Click()Const n = 15Dim a(l To n) As IntegerDim i As Integer, j As Integer, t As Integer, min As Integer RandomizeFor i = 1 To n,*SP/CE* * a(i)= ?Next iFor i = 1 To nPrint a(i);Next iPrintFor i = 1 To n -1Forj = i + 1 To nIf a(j) a(t) Then t = jNext j,*SpycE* *If ? Thenmin
19、= a(i): a(i) = a(t): a(t) = minEnd IfNext iFor i = 1 To nPrint a(i);Next i答案:1) .2) .3) .End SubInt( I00 * Rnd) + 10t=io 或 tt 或 not t=i 或 not i=tK第19题D程序填空(1分)(题号:44)【程序填空】 功能:以下程序的功能如(图1)。Private Sub Form_Click()Dim s As Single, m As Integer, p# s = 1For m = 1 To 10 ,*SpyCE* * p= ?s = s + 1 / pNext
20、 mPrint sFunction n(k%)p = 1For m = 1 To k,*SpcE* * p = ?Next m,* *SpcE* *?End Function答案:1) .n(m)2) .p* *m3) .n = pKM 20 J2程序填空(1分)(题号:592)下面的程序段用于打印出以下图形TT*,*,*,*Private Sub Form_Click()Dimi%,j%, k%For i = 3 To 0 Step -1Forj = 0To2*iPrint n 0;Next j*SPyCE* *Fork = 5To ?Print *”;Next kPrintNext iFo
21、ri = 0To3Forj = 0To2*i + 2,* *SpcE* *?Next jFor k = 0 To 4 - 2 * iPrint n*;Next k?Next iEnd Sub答案:1) .24力 1StepEl2) .Print或?3) .Print 或?K第21题程序填空(1分)(题号:595)【程序填空】功能:窗体上建立了一个文本框Textl(输入口令)和一个命令按钮Command】(检查)。 判断密码是否正确,并显示相应提示,在加载窗体时设置密码框最大长度为8,密码显示字符为“*”dim x as stringPrivate Sub Command 1 _Click()
22、x = Textl.Text ,*SpycE* * Ifx ? 12345678 ThenMsgBox(欢迎你用机!”) ElseMsgBox (对不起,口令错”)End IfTextl.Text=,M, Textl.SetFocusPrivate Sub Form_Load()Textl.Text 二”,*SpyCE* *Textl. ? =8,* * * * * * *SpCE* * * *Textl. ?End Sub答案:1) .Max LengthPasswordChar2) .3) .K第22题1程序填空J (1分)(题号:38)【程序填空】功能:下面的程序段,用于实现在一个nXm
23、的矩阵中,找出值最,大的元素所在的行和列,并输出其值及行号和列号。Private Sub Form_Click()Dim mat() As IntegerDim n as integer, m As Integern = Val(InputBox(请输入矩阵的行数”)m = Val(InputBox(请输入矩阵的列数,),*SpyCE* *?For i = 1 To nForj = 1 To mmat(i,j) = InputBox(请输入数组元素值”) mat(i, j) = Val(mat(i, j)Next jNext iPrint”所建立的矩阵为”For i = 1 To nForj
24、= 1 To mPrint mat(i, j);Next jPrintNext iMax = mat(l, 1)For i = 1 To nFor j = 1 To m* *SpcE* *If ? ThenMax = mat(i, j)col =j,*spce* *?End IfNext jNext iPrintPrim ”矩阵最大的元素的值为:mat(row, col) Print”它所在的行号为:”;row;”列号为:”;col End Sub答案:1) . ReDim mat(n, m) As Integer 或 ReDim mat(n, m)2) . Max Max3) . row =
25、 IK第23题程序填空(2分)(题号:45)【程序填空】助能:下面的程序段用于求矩阵相乘C=A mXn 的矩阵。Private Sub Form_Click()Const m = 4, p = 3, n = 2Dim a( 1 To m, 1 To p) As IntegerDim b( 1 To p, 1 To n) As IntegerDim c(l To m, 1 To n) As IntegerDim i As Integer, j As Integer, k As Integer, sum As IntegerFor i = 1 To mFor k = 1 To pa(i, k) =
26、 iNext kNext iFor i = 1 To pFor k = 1 To nb(i, k) = iNext kNext iFor i = 1 To mFor j = 1 To n* *SpcE* *?For k = 1 To p,*SpyCE * sum = sum + ?Next k,*SpycE* *c(i,j) = ?1Next j, iPrint”输出矩阵”For i = 1 To mFor k = 1 To nPrint c(i, k),Next kPrintNext iEnd Sub答案:1) .sum = 02) .a(i, k)b(kj)3) .sumK第24题程序填空
27、(2分)(题号:52)【程序填空】 功能:卜面的程序段用于打印出以下图形*Private Sub Form_Click()Dimi%,j%, k%Fori = 0To3Forj = 0To2-iPrint n M;Next j* *SpyCE* *For k = 1 To ?Print *”;Next kPrintNext iFor i = OTo 2Forj = OToi,*SpycE* *?Next jFor k = 0To4-2*iPrint *”;Next k,*SpcE* *?Next iEnd Sub答案:1) .Z * i+2) .Print;或 form 1.print;或?3
28、) . Print 或 form 1.Print 或?K第25题。程序填空(2分)(题号:47)【程序填空】 助能:以下程序段用于实现:输入两个正整数m和n,求其最大公因数和最小公倍数。Private Sub Form_CIick()Dim a%, b%, numl%, num2%, temp numl =InputBox(请输入一个正整数”) num2 = InputBox(请输入一个正整数) ,*SpcE* *If ? Thentemp = numl: numl = num2: num2 = temp End Ifa = numlb = num2,*Sp/CE* *Do While ?te
29、mp = a Mod b a = b* S C E * *LoopPrint”最大公因数为aPrint ”最小公倍数为:;numl * num2 / a答案:1) .2) .b=03) .End Subnuml numlb 0 或 b0 或 0b 或 temp0 或 temp0 或 0 x,* *SpycE* *?i = i- 1Loop,*SpycE* *Ifi0Then ?For i = 1 To 9Print a(i);Next iEnd Sub答案:1) .a(0) = x2) . a(i+ 1) = a(i)或 a( 1+i) = a(i)3) . a(i+l) = x 或 a(l+i) = x第1题程