VB填空練習(xí)答案_第1頁(yè)
VB填空練習(xí)答案_第2頁(yè)
VB填空練習(xí)答案_第3頁(yè)
VB填空練習(xí)答案_第4頁(yè)
VB填空練習(xí)答案_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、一.選擇結(jié)構(gòu)'-'功能:用輸入對(duì)話(huà)框輸入x,根據(jù)如圖公式計(jì)算對(duì)應(yīng)的y,在窗體上輸出y的值。'-Private Sub Command1_Click() '*SPACE* Dim x As Single, 【?】 As Single '*SPACE* x = Val(【?】("Please input x :", "輸入X的值") If x = 10 Then '*SPACE* 【?】 ElseIf x > 10 Then '*SPACE* y = Sqr(x) 【?】 Else y = 2 *

2、 x 3 + 6 End If Print yEnd Sub (答案) Y InputBox y = 0 + Sin(x)'-'功能:下面的事件過(guò)程判斷文本框Text1中輸入的數(shù)所在區(qū)間,并在文本框Text2中輸出判斷結(jié)果'-Private Sub Command1_Click() Dim int1 As Integer '*SPACE* 【?】 = Val(Text1.Text) Select Case int1 Case 0 Text2.Text = "值為0" '*SPACE* Case 【?】 Text2.Text = &qu

3、ot;值在1和10之間(包括1和10)" '*SPACE* Case Is > 【?】 Text2.Text = "值大于10" Case Else Text2.Text = "值小于0" End SelectEnd Sub (答案1) int1 1 To 10 10二.一般'-'功能:本程序功能為,第一次單擊窗體,F(xiàn)orm1的輸出結(jié)果為 2 5 9'-Private Function sum(n As Integer) '*SPACE* 【?】 j As Integer j = j + n + 1

4、 sum = jEnd FunctionPrivate Sub Form_Click() Dim i%, s% '*SPACE* For 【?】 = 1 To 3 '*SPACE* s = 【?】 Form1.Print s; Next iEnd Sub (答案) Static I sum(i)'-'功能:窗體上建立了一個(gè)文本框Text1("輸入口令")和一個(gè)命令按鈕Command1("檢查")。' 判斷密碼是否正確,并顯示相應(yīng)提示' 在加載窗體時(shí)設(shè)置密碼框最大長(zhǎng)度為8,密碼顯示字符為“*”'-di

5、m x as stringPrivate Sub Command1_Click() x = Text1.Text '*SPACE* If x 【?】 "12345678" Then MsgBox ("歡迎你用機(jī)!") Else MsgBox ("對(duì)不起,口令錯(cuò)") End If Text1.Text = "" Text1.SetFocusEnd SubPrivate Sub Form_Load() Text1.Text = "" '*SPACE* Text1.【?】 = 8 &#

6、39;*SPACE* Text1.【?】 = "*" End Sub (答案) = MaxLength PasswordChar'-'功能:在窗體上畫(huà)一個(gè)標(biāo)簽(名稱(chēng)為 Label1 )和一個(gè)計(jì)時(shí)器(名稱(chēng)為 Timer1 ),然后編寫(xiě)如下幾個(gè)事件過(guò)程:要求:每一秒鐘Label1更新顯示一次系統(tǒng)時(shí)間'-Private Sub Form_Load() Timer1.Enabled = False '*SPACE* Timer1.Interval = 【?】End SubPrivate Sub Form_Click() '*SPACE* Ti

7、mer1.Enabled = 【?】 End SubPrivate Sub Timer1_Timer() '*SPACE* Label1.Caption = 【?】 End Sub (答案) 1000 True Now 或 Time '-'功能:寫(xiě)出程序運(yùn)行后,單擊窗體,F(xiàn)orm1上顯示的內(nèi)容' sum 函數(shù)的功能為累加求和' isum = 1' isum = 3' isum = 6' isum = 10' isum = 15'-Private Sub Form_Click() Dim I As Integer,

8、isum As Integer '*SPACE* For I = 1 To 【?】 isum = sum(I) '*SPACE* Form1.Print "isum " 【?】 Next IEnd SubPrivate Function sum(n As Integer) Static j As Integer '*SPACE* 【?】 j + n sum = jEnd Function (答案) 5 & isum j =三.級(jí)數(shù)'-'功能:以下程序段用于求n!'-Private Sub Form_Click() Di

9、m sum As Integer, n As Integer n = InputBox("請(qǐng)輸入一個(gè)正整數(shù)") sum = 0 For i = 1 To n'*SPACE* sum =【?】 Next i Print sumEnd SubPrivate Function mul(ByVal x As Integer) Dim s As Integer, i As Integer s = 1'*SPACE* For i = 1 To 【?】 s = s * i Next i'*SPACE* 【?】End Function (答案) sum + mul(

10、i) x mul = s'-'功能:由輸入對(duì)話(huà)框輸入n(n必須為大于零且小于30的自然數(shù)), 計(jì)算下列表達(dá)式的值,并在標(biāo)簽框Label1上顯示。 sum=1/2+1/6+ . +1/(k*(k+1) (k<=n)'-Private Sub Form_Click() Dim n As Integer, sum As Double, k As Integer n = Val(InputBox("n=", "請(qǐng)輸入自然數(shù)n(n>0 且n<30)") '*SPACE* Do While n <= 0 【?】

11、 n >= 30 n = Val(InputBox("n=", "請(qǐng)重輸入") Loop sum = 0 k = 0 Do '*SPACE* k =【?】 sum = sum + 1 / (k * (k + 1) '*SPACE* Loop Until 【?】 Label1.Caption = "Sum=" + Str(sum) End Sub (答案) Or k + 1 k >= n四.數(shù)字關(guān)系'-'功能:過(guò)程suixian可以判斷某一個(gè)數(shù)字是否是水仙花數(shù),利用該過(guò)程找出三位數(shù)中所有水仙花

12、數(shù)。' 所謂"水仙花數(shù)"是指一個(gè)3位數(shù),其各位數(shù)字立方和等于該數(shù)本身。 '-Private Sub Form_Click()Dim i As IntegerFor i = 100 To 999'*SPACE* 【?】Next iEnd SubPublic Sub suixian(x As Integer)Dim i%, j%, k%'*SPACE*i =【?】j = (x - i * 100) 10k = x - i * 100 - j * 10'*SPACE*If 【?】 Then Print xEnd Sub (答案) call

13、suixian (i) x 100 x = i 3 + j 3 + k 3五.數(shù)組'-'功能:下面的程序段,用于實(shí)現(xiàn)在一個(gè)nXm的矩陣中,找出 值最大的元素所在的行和列,并輸出其值及行號(hào)和列號(hào)。'-Private Sub Form_Click()Dim mat() As IntegerDim n as integer, m As Integern = Val(InputBox("請(qǐng)輸入矩陣的行數(shù)")m = Val(InputBox("請(qǐng)輸入矩陣的列數(shù)")'*SPACE*【?】For i = 1 To n For j = 1

14、 To m mat(i, j) = InputBox("請(qǐng)輸入數(shù)組元素值") mat(i, j) = Val(mat(i, j) Next jNext iPrint "所建立的矩陣為"For i = 1 To n For j = 1 To m Print mat(i, j); Next j PrintNext iMax = mat(1, 1)For i = 1 To n For j = 1 To m'*SPACE* If 【?】 Then Max = mat(i, j) col = j'*SPACE* 【?】 End If Next jN

15、ext iPrintPrint "矩陣最大的元素的值為:" mat(row, col)Print "它所在的行號(hào)為:" row; "列號(hào)為:" colEnd Sub (答案) ReDim mat(n, m) As Integer mat(i, j) > Max row = I'-'功能:本程序利用二分法查找某數(shù)字n是否在已排序的數(shù)列當(dāng)中,' 若在其中則輸出其在數(shù)列中的位置,否則輸出-1。'-Option Base 1Sub birsearch(a(), ByVal low%, ByVal high

16、%, ByVal key, index%) Dim mid As Integer mid = (low + high) 2 If a(mid) = key Then '*SPACE* 【?】 Exit Sub ElseIf low > high Then index = -1 Exit Sub End If If key < a(mid) Then '*SPACE* high = 【?】 Else low = mid + 1 End If '*SPACE* Call birsearch(a(), low, high, 【?】, index)End SubPr

17、ivate Sub Command1_Click() Dim b() As Variant, index As Integer b = Array(5, 13, 19, 21, 37, 56, 64, 75, 80, 88, 92) n = Val(Text1) Call birsearch(b, LBound(b), UBound(b), n, index) Print indexEnd Sub(答案) index = mid mid 1 key'-'功能:?jiǎn)螕簟安迦霐?shù)據(jù)”按鈕后,輸入一個(gè)整型數(shù)據(jù),' 該數(shù)據(jù)會(huì)被插入到一個(gè)有序的數(shù)組a(1 to 10)中,插入該數(shù)據(jù)后

18、數(shù)組還是有序的。'-Option Base 1Private Sub Command1_Click() Dim a%(1 To 10), i%, k%, m% Print "原數(shù)列是" For i = 1 To 9 a(i) = (i - 1) * 3 + 1 Print a(i); Next i Print m = Val(InputBox("輸入要插入的數(shù)據(jù)") For k = 1 To 9 '*SPACE* If (m < a(k) Then 【?】 Next k For i = 9 To k Step -1 '*SP

19、ACE* a(【?】) = a(i) Next i '*SPACE* a(k) = 【?】 Print "插入" m; "后的數(shù)列是:" For i = 1 To 10 Print a(i); Next i PrintEnd Sub(答案) Exit For i+1 m'-'功能:寫(xiě)出程序運(yùn)行時(shí)單擊窗體后,F(xiàn)orm1上的輸出結(jié)果' x(1) = 8' x(2) = 6' x(3) = 4' x(4) = 3' x(5) = 1'-Private Sub Form_Click() Di

20、m x(5) As Integer '*SPACE* Dim i, j, t,【?】 As Integer x(1) = 8 x(2) = 3 x(3) = 1 x(4) = 6 x(5) = 4 For i = 1 To 4 For j = i + 1 To 5 '*SPACE* If x(i) 【?】 x(j) Then t = x(i): x(i) = x(j): x(j) = t Next j, i '*SPACE* For k = 1 To 【?】 Form1.Print "x(" k; ")=" x(k) Next k

21、End Sub(答案) K < 5'-'功能:以下程序段用于輸出楊輝三角:結(jié)果樣式如圖1'- Private Sub Form_Click()Const n = 10Dim arr(n, n) As IntegerFor I = 1 To n arr(I, I) = 1'*SPACE* 【?】Next IFor I = 3 To n For j = 2 To I - 1'*SPACE* arr(i, j) =【?】 Next jNext IFor I = 1 To n For j = 1 To I'*SPACE* ? 【?】& &q

22、uot; " Next j PrintNext IEnd Sub(答案) arr(i, 1) = 1 arr(i - 1, j - 1) + arr(i - 1, j) arr(i, j)六.文件'-'功能:本程序執(zhí)行后,最終在窗體上打印數(shù)字7。'-Private Sub Command1_Click() Dim a As String '*SPACE* Open App.Path & "abc.bat" For 【?】 As #1 n = 8 For I = 1 To n Print #1, I + 1 Next I Cl

23、ose #1 '*SPACE* Open App.Path & "abc.bat" For 【?】 As #1 For I = 1 To n Input #1, a If I Mod 5 = 0 Then '*SPACE* Print CInt(a) + 【?】 End If Next I Close #1End Sub(答案) Output Input 1'-'功能:本程序求3100之間的所有素?cái)?shù)(質(zhì)數(shù))并統(tǒng)計(jì)個(gè)數(shù);' 同時(shí)將這些素?cái)?shù)從小到大依次寫(xiě)入順序文件 dataout.txt;' 素?cái)?shù)的個(gè)數(shù)顯示在窗體Form1

24、上。'-Private Sub Command1_Click() Dim count As Integer, flag As Boolean Dim t1 As Integer, t2 As Integer '*SPACE* Open App.Path & "dataout.txt" For Output As 【?】 count = 0 For t1 = 3 To 100 '*SPACE* flag = 【?】 For t2 = 2 To Int(Sqr(t1) If t1 Mod t2 = 0 Then flag = False Next

25、 t2 If flag Then '*SPACE* count = 【?】 Write #1, t1 End If Next t1 Form1.Print "素?cái)?shù)個(gè)數(shù)" count Close #1End Sub(答案) #1 True count + 1'-'功能:窗體中有兩個(gè)List列表,及4個(gè)按鈕。程序功能,單擊“產(chǎn)生隨機(jī)數(shù)”按鈕,隨機(jī)產(chǎn)生20個(gè)隨機(jī)數(shù)填入List1中' “保存”按鈕 作用是將數(shù)組內(nèi)容寫(xiě)到文件中' “讀出”按鈕 作用是將文件內(nèi)容讀到數(shù)組中' “結(jié)束”按鈕 作用是結(jié)束程序'-Dim d(1 To 2

26、0) As IntegerPrivate Sub Command1_Click() '"產(chǎn)生隨機(jī)數(shù)" Dim i As Integer List1.Clear For i = 1 To 20 '*SPACE* d(i) = Int(1 + 99 *【?】) List1.AddItem d(i) Next iEnd SubPrivate Sub Command2_Click() '"保存" Dim i As Integer Open App.Path & "MyFile3.txt" For Output

27、As #1 For i = 1 To 20 '*SPACE* Write 【?】, d(i) Next i Close #1End SubPrivate Sub Command3_Click() '"讀出" Dim x As String Open App.Path & "MyFile3.txt" For Input As #1 List2.Clear '*SPACE* Do While Not 【?】 Input #1, x List2.AddItem x Loop Close #1End SubPrivate Sub

28、Command4_Click() '"結(jié)束" EndEnd Sub(答案) Rnd #1 EOF(1)'-'功能: 本程序?qū)崿F(xiàn)功能:將順序文本文件 “MYFILE.TXT” 的' 內(nèi)容一個(gè)字符一個(gè)字符地讀入文本框txtTest中'-Private Sub Form_Click() Dim InputData As String * 1 txtTest.Text = "" '*SPACE* Open App.Path & "MYFILE.TXT" For 【?】 As #1 

29、9;*SPACE* Do While 【?】 EOF(1) ' Do While Not 【?】 Input #1, InputData '*SPACE* txtTest.Text = txtTest.Text + 【?】 Loop Close #1End Sub(答案) Input Not InputData七.雜項(xiàng)'-'功能:程序輸出結(jié)果為:n=3 x=42 y=9'-Private Sub Command1_Click() Dim n, x, y As Integer '*SPACE* n = 0: x =【?】: y = 0 Do Whi

30、le x < 20 '*SPACE* n = n 【?】 y = x + y x = x * (x + 1) '*SPACE* 【?】 Form1.Print "n=" & Str(n) Form1.Print "x=" & Str(x) Form1.Print "y=" & Str(y)End Sub(答案) 1 + 1 Loop'-'功能:利用下面的過(guò)程求m!和m*n'-Private Sub Form_Click()Dim m As Integer, n As

31、 Integer m = 2 n = 3'*SPACE* 【?】End SubPrivate Sub find(x As Integer, y As Integer) Dim s, i As Integer'*SPACE* 【?】 For i = 1 To x s = s * i'*SPACE* p=【?】 Next i Print s, pEnd Sub(答案3) call find(m,n) s = 1 p + y'-'功能:以下程序段用于實(shí)現(xiàn)矩陣轉(zhuǎn)置,即將一個(gè)n×m的矩陣的行和列互換'-Private Sub Form_Click

32、()Const n = 3Const m = 4Dim a(n, m), b(m, m) As IntegerFor I = 1 To n For j = 1 To m a(I, j) = Int(Rnd * 90) + 10 Next j'*SPACE*【?】For I = 1 To n For j = 1 To m'*SPACE* 【?】 Next jNext IPrint "矩陣轉(zhuǎn)置前"For I = 1 To n For j = 1 To m Print a(I, j); Next j'*SPACE* 【?】Next IPrint "

33、;矩陣轉(zhuǎn)置后"For I = 1 To m For j = 1 To n Print b(I, j); Next j PrintNext IEnd Sub(答案) Next I b(j, i) = a(i, j) Print '功能:下面的程序段用于打印出以下圖形'' *' *' *' *' *' *' *''-Private Sub Form_Click()Dim i%, j%, k%For i = 3 To 0 Step -1 For j = 0 To 2 * i Print " &

34、quot; Next j'*SPACE* For k = 5 To 【?】 Print "*" Next k PrintNext iFor i = 0 To 3 For j = 0 To 2 * i + 2'*SPACE* 【?】 Next j For k = 0 To 4 - 2 * i Print "*" Next k'*SPACE* 【?】Next iEnd Sub(答案) 2 * i - 1 Step -1 Print " " Print'-'功能:?jiǎn)螕舸绑w打印內(nèi)容如圖 '-Private Sub Form_Click(

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論