vb課后習題答案.docx_第1頁
vb課后習題答案.docx_第2頁
vb課后習題答案.docx_第3頁
vb課后習題答案.docx_第4頁
vb課后習題答案.docx_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

習題34 (P126)Private Sub Command1_Click() Image1.Width = Image1.Width * 1.2 Image1.Height = Image1.Height * 1.2 End SubPrivate Sub Command2_Click() Image1.Width = Image1.Width / 1.2 Image1.Height = Image1.Height / 1.2End SubPrivate Sub Command3_Click() Image1.Width = Form1.Width Image1.Height = Form1.HeightEnd SubPrivate Sub Form_Load() Image1.Left = 0 Image1.Top = 0 Image1.Picture = LoadPicture(App.Path & back.jpg)End Sub習題35 (P126)Dim mleft As LongPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()mleft = Label1.Left + 100If mleft + Label1.Width Picture1.Width Then mleft = 0End IfLabel1.Left = mleftEnd Sub習題41 (P170)Private Sub Form_Load() Form1.Show Sum = 0 For i = 1 To 4 a = InputBox(請輸入數(shù)值型數(shù)據(jù)) Sum = Sum + a ave = Sum / 4 Next Print Sum; ave End Sub習題43 (P170)Private Sub Command1_Click() a = 5 b = 2.5 c = 7.8 pi = 3.14159265 y = pi * a * b / a + b * c Print y End Sub習題44 Private Sub Command1_Click() a = Val(Text1.Text) tian = a 86399 xiaoshi = (a - tian * 86400) 1439 fenzhong = (a - tian * 86400 - xiaoshi * 1440) 59 miao = a - tian * 86400 - xiaoshi * 1440 - fenzhong * 60 Text2.Text = tian & 天 & xiaoshi & 小時 & fenzhong & 分鐘 & miao & 秒 End Sub習題45Private Sub Command1_Click() Const g As Single = 9.81 t = InputBox(請輸入t的值) v0 = InputBox(請輸入v0的值) s = 1 / 2 * g * t * t + v0 * t Print Format(s, 0.#) End Sub習題46Private Sub Command1_Click() Sum = 0 For i = 2 To 100 Step 2 Sum = Sum + i Next Label1.FontSize = 20 Label1.Caption = 2+4+6+100= & Sum End Sub習題47Private Sub Command1_Click() Do a = InputBox(請輸入三角形的第一條邊長) a1 = Val(a) If a1 = -1 Then End End If b = InputBox(請輸入三角形的第二條邊長) b1 = Val(b) If b1 = -1 Then End End If c = InputBox(請輸入三角形的第三條邊長) c1 = Val(c) If c1 = -1 Then End End If If (a1 + b1 c1) And (a1 + c1 b1) And (b1 + c1 a1) Then s = a1 + b1 + c1 Exit Do Else Error1 = MsgBox(您輸入的數(shù)據(jù)不能組成三角形) End If Loop Label4.Caption = 您輸入的邊長分別為: & a1 & , & b1 & , & c1 & & 面積為: & s End Sub習題48Private Sub Command1_Click() If Text1.Text Then a = Text1.Text Select Case a Case Is = 200 s = 0 Case Is = 400 s = (a - 200) * 0.03 Case Is = 5000 s = (400 - 200) * 0.03 + (5000 - 400) * 0.04 + (a - 5000) * 0.05 End Select Text2.Text = s Else error1 = MsgBox(請輸入您的收入!) End If End SubPrivate Sub Form_Load() Text2.Locked = True End SubPrivate Sub Text1_Change() If Not IsNumeric(Text1.Text) Then error1 = MsgBox(請輸入數(shù)字) End If End Sub習題49Private Sub Text1_Change() a = Text1.Text Select Case a Case 0 Label2.Caption = 休息 Text1.SelStart = 0 Text1.SelLength = 1 Case 1, 3 Label2.Caption = 講計算機課 Text1.SelStart = 0 Text1.SelLength = 1 Case 2, 4 Label2.Caption = 講程序設計課 Text1.SelStart = 0 Text1.SelLength = 1 Case 5 Label2.Caption = 進修英語 Text1.SelStart = 0 Text1.SelLength = 1 Case 6 Label2.Caption = 政治學習 Text1.SelStart = 0 Text1.SelLength = 1 Case Else Error1 = MsgBox(您確認退出程序?, 52, 確認) If Error1 = 6 Then End Else Text1.SelStart = 0 Text1.SelLength = 1 End If End Select End Sub習題410Private Sub Command1_Click() For i = 1 To 9 Print Tab(30 - 3 * i); For j = 1 To i Print j; Next j For k = i - 1 To 1 Step -1 Print k; Next k Print Next iEnd Sub習題411Private Sub Command1_Click() For i = 1 To 30 For j = i To 30 For k = j To 30 If i * i + j * j = k * k Then Print Tab(10); i, Tab(23); j, Tab(36); k End If Next k, j, i End Sub習題412Private Sub Form_Click() Dim m As Integer, n As Integer m = CInt(Val(InputBox(請輸入計算范圍的初值) n = CInt(Val(InputBox(請輸入計算范圍的終值) For i = m To n s = 0 For j = 1 To i - 1 If i Mod j = 0 Then s = s + j End If Next j If s = i Then Print i Next iEnd Sub習題413Private Sub Form_Click()Dim a As String, c As StringDim b As Integera = InputBox(請輸入學生姓名)b = InputBox(請輸入學生成績)Select Case b Case Is = 39 c = Fail Case Is = 49 c = Poor Case Is = 59 c = Fair Case Is = 79 c = Good Case Else c = Very GoodEnd SelectPrint 姓名: & aPrint 成績: & bPrint 評語: & cEnd Sub習題414Private Sub Command1_Click() Dim a As Integer a = Val(Text1.Text) If a 99 Then error1 = MsgBox(您輸入的不是兩位正整數(shù),請重新輸入) Else For i = 10 To 99 a1 = a 10 + (a Mod 10) * 10 i1 = i 10 + (i Mod 10) * 10 If (a + i = a1 + i1) And (a1 9) And (i1 9) Then Label2.Caption = Label2.Caption & Chr(13) & a & + & i & = & a1 & + & i1 Form1.Height = Label2.Height + Label2.Top + 1000 End If Next End IfEnd Sub習題415Dim a, b, s As DoubleDim flag, com As IntegerPrivate Sub Command1_Click() If flag = 0 Then Text1.Text = Text1.Text & Command1.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command1.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command2_Click() If flag = 0 Then Text1.Text = Text1.Text & Command2.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command2.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command3_Click() If flag = 0 Then Text1.Text = Text1.Text & Command3.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command3.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command4_Click() If flag = 0 Then Text1.Text = Text1.Text & Command4.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command4.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command5_Click() If flag = 0 Then Text1.Text = Text1.Text & Command5.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command5.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command6_Click() If flag = 0 Then Text1.Text = Text1.Text & Command6.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command6.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command7_Click() If flag = 0 Then Text1.Text = Text1.Text & Command7.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command7.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command8_Click() If flag = 0 Then Text1.Text = Text1.Text & Command8.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command8.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command9_Click() If flag = 0 Then Text1.Text = Text1.Text & Command9.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command9.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command10_Click() If flag = 0 Then Text1.Text = Text1.Text & Command10.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command10.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command11_Click() If flag = 0 Then Text1.Text = Text1.Text & Command11.Caption a = Val(Text1.Text) Else Text1.Text = flag = 0 Text1.Text = Text1.Text & Command11.Caption a = Val(Text1.Text) End If End SubPrivate Sub Command12_Click() Select Case com Case 1 a = b + a Text1.Text = a flag = 1 Case 2 a = b - a Text1.Text = a flag = 1 Case 3 a = b * a Text1.Text = a flag = 1 Case 4 a = b / a Text1.Text = a flag = 1 End Select End SubPrivate Sub Command13_Click() b = a flag = 1 com = 1 End SubPrivate Sub Command14_Click() b = a flag = 1 com = 2 End SubPrivate Sub Command15_Click() b = a flag = 1 com = 3 End SubPrivate Sub Command16_Click() b = a flag = 1 com = 4 End Sub習題51 (P196)Private Sub Form_Click()Dim a(1 To 20)For i = 1 To 20a(i) = InputBox(請輸入第 & i & 個元素)Next iFor i = 1 To 20Print a(i); ;Next iPrintFor i = 1 To 10 t = a(i) a(i) = a(21 - i) a(21 - i) = tNext iFor i = 1 To 20Print a(i),Next iEnd Sub習題52Private Sub Form_Click()Dim a(1 To 10, 1 To 10)For i = 1 To 10 For j = 1 To 10 If i = j Then a(i, j) = 1 ElseIf i + j = 11 Then a(i, j) = 1 Else a(i, j) = 0 End If Next jNext iFor i = 1 To 10 For j = 1 To 10 Print a(i, j); Next j PrintNext iEnd Sub習題53Private Sub Form_Click()Dim a() As Integern = InputBox(請輸入n)m = InputBox(請輸入m)Print 數(shù)組為 & n & 行 & m & 列ReDim a(n, m)For i = 1 To n For j = 1 To m a(i, j) = InputBox(請輸入第 & i & 行 & j & 列) Next jNext iFor i = 1 To n For j = 1 To m Print a(i, j); Next j PrintNext is = 0For i = 1 To n For j = 1 To m s = s + a(i, j) Next jNext iv = s / (n * m)Print 平均值為: & vFor i = 1 To n For j = 1 To m If a(i, j) v Then Print 元素: & a(i, j) & 行號: & i & 列號: & j End If Next jNext iEnd Sub習題 54Private Sub Form_Click()Dim a(1 To 50, 1 To 4) As IntegerFor i = 1 To 50 For j = 1 To 4 a(i, j) = Int(Rnd * 90 + 10) Next jNext i顯示滿足條件的行For i = 1 To 50 For j = 1 To 4 If a(i, j) 90 Then For k = 1 To 4 Print a(i, k) & ; Next k Print Exit For End If Next jNext i顯示完整數(shù)組For i = 1 To 50 For j = 1 To 4 Print a(i, j) & ; Next j PrintNext iEnd Sub習題55Private Sub Form_Click()Dim n As Integer, m As IntegerDim a() As Integern = InputBox(請輸入行數(shù)n)m = InputBox(請輸入列數(shù)m)ReDim a(1 To n, 1 To m)For i = 1 To n For j = 1 To m a(i, j) = InputBox(請輸入第 & i & 行 & j & 列的元素) Next jNext iFor i = 1 To n For j = 1 To m Print Format(a(i, j), 000) & ; Next j PrintNext ian_num = 0For i = 1 To n hmax = a(i, 1) lhao = 1 For j = 1 To m If a(i, j) hmax Then hmax = a(i, j) lhao = j End If Next j lmin = a(i, lhao) For k = 1 To n If a(k, lhao) av * 1.1 Then Print a(i, 1), a(i, 2), a(i, 3), 一等獎 ElseIf a(i, 3) av * 1.05 Then Print a(i, 1), a(i, 2), a(i, 3), 二等獎 End IfNext iEnd Sub習題58Private Sub Form_Click()Dim a(1 To 10, 1 To 4)For i = 1 To 10 a(i, 1) = InputBox(請輸入第 & i & 個學生的姓名) a(i, 2) = Val(InputBox(請輸入第 & i & 個學生的語文成績) a(i, 3) = Val(InputBox(請輸入第 & i & 個學生的數(shù)學成績) a(i, 4) = (a(i, 2) + a(i, 3) / 2Next iPrint 姓名, 語文, 數(shù)學, 平均分For i = 1 To 10 For j = 1 To 4 Print a(i, j), Next j PrintNext iFor i = 10 To 2 Step -1 For j = 1 To i - 1 If a(j, 4) n Then Print 沒有找到該人 x = MsgBox(你是否還要繼續(xù)查找?, vbInformation + vbYesNo, 提問)LoopEnd Sub習題512Private Sub Form_Click()Dim a(1 To 10, 1 To 2)For i = 1 To 10 a(i, 1) = CStr(InputBox(請輸入運動員號) a(i, 2) = Val(InputBox(請輸入成績)Next iPrint 原始的順序Print 運動員號, 成績For i = 1 To 10 For j = 1 To 2 Print a(i, j), Next j PrintNext iFor i = 10 To 2 Step -1 For j = 1 To i - 1 If a(j, 2) a(j + 1, 2) Then t = a(j, 2) a(j, 2) = a(j + 1, 2) a(j + 1, 2) = t t = a(j, 1) a(j, 1) = a(j + 1, 1) a(j + 1, 1) = t End If Next jNext iPrint 排列的順序Print 名次, 運動員號, 成績For i = 1 To 10 Print i, For j = 1 To 2 Print a(i, j), Next j PrintNext iEnd Sub習題513Private Sub Form_Click()Dim a(11, 11)For i = 1 To 11 a(i, 1) = 1 a(i, i) = 1Next iFor i = 3 To 11 For j = 2 To 10 a(i, j) = a(i - 1, j - 1) + a(i -

溫馨提示

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

評論

0/150

提交評論