《大一计算机课后习题答案.docx》由会员分享,可在线阅读,更多相关《大一计算机课后习题答案.docx(30页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、3.4Private Sub Command 1 _Click()Image 1.Width = Image 1.Width * 1.2Image 1 .Height = Image 1.Height * 1.2End SubPrivate Sub Command2_Click()Image 1 .Width = Image 1 .Width / 1.2Image 1.Height = Image 1.Height / 1.2End SubPrivate Sub Command3_Click()Image 1 .Width = Form 1. WidthImage 1.Height = For
2、m 1.HeightEnd SubPrivate Sub Form_Load()Image 1.Left = 0Image l.Top = 0Image 1.Picture = LoadPicture(App.Path & back.jpg) End Sub5 Formla I: S放大缩小全屏3. 5Dim mleft As LongPrivate Sub Command 1 _Click()Timer 1.Enabled = TrueEnd SubQ FormlCD30以内满是勾股定理的数值组合4.12Private Sub Form_Click()Dim m As Integer, n
3、As Integerm = CInt(Val(InputBox(”请输入计算范围的初值”) n = CInt(Val(InputBox(请输入计算范围的终值”) For i = m To ns = 0For j = 1 To i - 1If i Mod j = 0 Then s=s+jEnd IfNext jIf s = i Then Print iNext iEnd Sub4.13Private Sub Form_Click()Dim a As String, c As StringDim b As Integera=InputBox,请输入学生姓名”) b=InputBox(”请输入学生成
4、绩”) Select Case bCase Is = 39c = Fail”Case Is = 49c = PoorCase Is = 59c 二“ Fair”Case Is = 79c 廿Good”Case Elsec = Very Good11End SelectPrint姓名:&aPrint”成绩:&bPrint”评语:” &cEnd Sub4.14Private Sub Command 1 _Click()Dim a As Integera = Val(Textl.Text)If a 99 Thenerror 1二MsgBox(您输入的不是两位正整数,请重新输入”)ElseFori =
5、 10 To 99al=a10 + (aModl0)*10il = i10 + (i Mod 10)* 10If(a + i = al +il)And (al 9) And (il 9) ThenLabel2.Caption = Label2.Caption & Chr(13)&a& i & ”廿 & al & ilForm 1.Height = Label2.Height + Label2.Top + 1000End IfNextEnd IfEnd Sub:输入一个两位的正整数查找符合条件的对调数4.15Dim a, b, s As DoubleDim flag, com As Intege
6、rPrivate Sub Commandl_Click()If flag = 0 ThenText 1.Text = Text 1.Text & Command 1 .Caption a = Val(Textl.Text)ElseTextl.Text = nnflag = 0Text 1.Text = Textl.Text & Command 1 .Caption a = Val(Textl.Text)End IfEnd SubPrivate Sub Command2_Click()If flag 二 0 ThenTextl.Text 二 Textl.Text & Command2.Capti
7、on a = Vai (Textl.Text)ElseTextl.Text = ,nflag = 0Textl.Text = Textl.Text & Command2.Caption a = Vai (Textl.Text)End IfEnd SubPrivate Sub Command3_Click()If flag = 0 ThenText 1.Text = Textl.Text & Command3.Caption a = Val(Textl.Text)ElseTextl.Text = nnflag = 0Text 1.Text = Text 1.Text & Command3.Cap
8、tion a = Val(Textl.Text)End IfEnd SubPrivate Sub Command4_Click()If flag = 0 ThenText 1.Text = Text 1.Text & Command4.Captiona = Vai (Text 1.Text)ElseTextl.Text = nnflag = 0Textl.Text = Textl.Text & Command4.Caption a = Vai (Textl.Text)End IfEnd SubPrivate Sub Command5_Click()If flag = 0 ThenTextl.T
9、ext = Textl.Text & Command5.Caption a = Vai (Textl.Text)ElseTextl.Text = ,1nflag = 0Textl.Text = Textl.Text & Command5.Caption a = Val(Textl.Text)End IfEnd SubIf flag = 0 ThenText 1.Text = Text 1.Text & Command6.Caption a = Vai (Text 1.Text)ElseTextl.Text = nnflag = 0Textl.Text = Textl.Text & Comman
10、d6.Caption a = Val(Textl.Text)End IfEnd SubPrivate Sub Command7_Click()If flag = 0 ThenTextl.Text = Textl.Text & Command7.Caption a = Val(Textl.Text)ElseTextl.Text =nnflag = 0Textl.Text = Textl.Text & Command7.Caption a = Val(Textl.Text)End IfEnd SubPrivate Sub Command8_Click()If flag = 0 ThenTextl.
11、Text = Textl.Text & Command8.Caption a = Val(Textl.Text)ElseTextl.Text =flag = 0Text 1 .Text = Textl.Text & Command8.Caption a = Val(Textl.Text)End IfEnd SubPrivate Sub Command9_Click()If flag = 0 ThenTextl.Text = Textl.Text & Command9.Captiona = Val(Textl.Text)ElseTextl.Text = nnflag = 0Text 1.Text
12、 = Text 1.Text & Command9.Captiona = Val(Textl.Text)End IfEnd SubPrivate Sub Command 10_Click()If flag = 0 ThenText 1.Text = Text 1.Text & Command 10.Caption a = Val(Textl.Text)ElseText 1 .Text =”flag = 0Text 1.Text = Text 1.Text & Command 10.Caption a = Vai (Text 1.Text)End IfEnd SubPrivate Sub Com
13、mand 1 l_Click()If flag = 0 ThenText 1.Text = Text 1.Text & Command 11 .Caption a = Vai (Text 1.Text)ElseText 1 .Text 二”flag = 0Text 1.Text 二 Text 1.Text & Command 11 .Caption a = Vai (Text 1.Text)End IfEnd SubPrivate Sub Command 12_Click()Select Case coma = b + aText 1.Text = aflag = 1Case 1 a = b
14、- aText 1.Text = aflag = 1Case 2 a = b * aText 1,Text = aflag = 1Case 3 a = b / aText 1.Text = aflag = 1End SelectEnd SubPrivate Sub Command 13_Click()b = aflag = 1 com = 1End SubPrivate Sub Command 14_Click()b = aflag = 1com = 2End SubPrivate Sub Command 15_Click()b = aflag = 1com = 3End Subb = a f
15、lag = 1 com = 4End SubPrivate Sub Form_Click()Dim a(l To 20)For i = 1 To 20a(i) = InputBox(请输入第 & i & “个元素”)Next iFor i = 1 To 20Print a(i); ”;Next iPrintFor i = 1 To 10t = a(i)a(i) = a(21 - i)a(21 - i) = tNext iFor i = 1 To 20Print a,Next iEnd SubPrivate Sub Form_Click()Dim a(l To 10, 1 To 10)For i
16、 = 1 To 10For j = 1 To 10If i = j Thena(i,j)= 1Elself i + j = 11 Thena(i,j)= 1Elsea(i, j) = 0End IfNext jNext iFor i = 1 To 10For j = 1 To 10Print a(i, j);Next jPrintNext iEnd SubPrivate Sub Form_Click()Dim a() As Integern = InputBox( 请输入 nn)m = InputBox(请输入 m”)Print ”数组为“ &n& ”行”&m& ”列”ReDim a(n, m
17、)For i = 1 To nFor j = 1 To ma(ij) = InputBox(”请输入第“ & i & ”行” &j & ”列”)Next jNext iFor i = 1 To nFor j = 1 To mPrint a(i, j);Next jPrintNext is = 0For i = 1 To nFor j = 1 To ms = s + a(i,j)Next jNext iv = s / (n * m)Print”平均值为:” &vFor i = 1 To nFor j = 1 To mIf a(i, j) v ThenPrint元素:&a(i,j)&”行号:&i&
18、”列号:n&jEnd IfNext jNext iEnd SubPrivate Sub Form_Click()Dim a(l To 50, 1 To 4) As IntegerFor i = 1 To 50For j = 1 To 4a(i,j) = Int(Rnd*90+ 10)Next jNext i显示满足条件的行For i = 1 To 50For j = 1 To 4Ifa(iJ)90 ThenFor k = 1 To 4Print a(i, k) & H ”;Next kPrintExit ForPrivate Sub Command2_Click()Timer 1.Enable
19、d = FalseEnd SubPrivate Sub Timerl_Timer()mleft = Label 1.Left + 100If mleft + Label 1 .Width Picture 1.Width Then mleft = 0End IfLabel 1 .Left 二 mleftEnd Sub5 Forml欢迎您屋;Private Sub Form_Load()Forml .ShowFor i = 1 To 4a = InputBox(请输入数值型数据”)Sum 二 Sum + aave = Sum / 4NextPrint Sum; aveEnd SubEnd IfNe
20、xt jNext i显示完整数组For i = 1 To 50For j = 1 To 4Print a(ij)&n;Next jPrintNext iEnd SubPrivate Sub Form_Click()Dim n As Integer, m As IntegerDim a() As Integern = InputBox(”请输入行数n)m = InputBox(请输入列数m”)ReDim a(l To n, 1 To m)For i = 1 To nFor j = 1 To ma(ij) = InputBox(”请输入第“ & i & ”行”&j & ”列的元素”) Next j
21、Next iFor i = 1 To nFor j = 1 To mPrint Format(a(i, j), n000n) & ” n;Next jPrintNext ian_num = 0For i = 1 To nhmax = a(i, 1)Ihao = 1For j = 1 To mIf a(i, j) hmax Then hmax = a(i, j) Ihao = jEnd IfNext jImin = a(i, Ihao)For k = 1 To nIf a(k, Ihao) av* 1.1 ThenPrint a(i, 1), a(i, 2), a(i, 3), “一等奖”Els
22、elf a(i, 3) av * 1.05 ThenPrint a(i, 1), a(i, 2), a(i, 3), “二等奖”End IfNext iEnd SubPrivate Sub Form_Click() Dim a( l To 10, 1 To 4) For i = 1 To 10a(i, 1) = InputBox(”请输入第“ & i & ”个学生的姓名”) a(i, 2) = Val(InputBox(请输入第“ & i & “个学生的语文成绩”) a(i, 3) = Val(InputBox(请输入第“ & i & ”个学生的数学成绩”) a(i, 4) = (a(i, 2
23、) + a(i, 3)/ 2Next iPrint “姓名“,“语文“,“数学“,“平均分”For i = 1 To 10For j = 1 To 4Print a(i,j), Next j PrintNext iFori = 10 To 2 Step-1For j = 1 To i - 1Ifa(j,4)n Then Print ”没有找到该人”x = MsgBox(你是否还要继续查找?二 vblnformation + vbYesNo,提问) Loop End Sub5.12Private Sub Form_Click()Dim a(l To 10, 1 To 2)Fori = 1 To
24、10a(i, 1) = CStr(InputBox(请输入运动员号”)a(i, 2) = Val(InputBox(”请输入成绩”)Next iPrint ”原始的顺序”Print ”运动员号“,“成绩”For i = 1 To 10Forj = 1 To2Print a(ij),Next jPrintNext iFor i = 10 To 2 Step -1For j = 1 To i - 1Ifa(j,2)a(j + 1,2) Then t = a(j, 2) a(j,2) = a(j + l,2) a(j + l,2) = t t = a(j, 1) a(j, l) = a(j + 1,
25、 1) a(j+ 1, l) = tEnd IfNext jNext iPrint”排列的顺序”Print “名次”,“运动员号“,“成绩”For i = 1 To 10Print i,Forj = 1 To 2Print a(ij),Next jPrintNext iEnd Sub5.13Private Sub Form_Click() Dim a(ll, 11)For i = 1 To 11a(i, 1)= 1a(i, i)= 1Next iFor i = 3 To 11Forj = 2To 10a(i,j) = a(i- 1J - l) + a(i- 1 J) Next jNext iF
26、or i = 1 To 11For j = 1 To iPrint Format(a(i, j),Next jPrintNext iEnd Sub6.4Private Sub Form_Click()Dim i As LongFor i = 1 To 1000If Automorphic(i) Then Print iNext iEnd SubPrivate Function Automorphic(n As Long) As BooleanDim t As Long, 1 As Integer1 = Len(CStr(n)t = n * nAutomorphic = Right(CStr(t
27、), I) = CStr(n)End Function6.6Private Sub Form_Click()For i = 1 To 20Print i & ”的立方为: & m_pf(i)Next iEnd SubPrivate Function m_pf(x)m_pf = x * x * xEnd Function6.8Private Sub Form_Click()Dim a As Integera = InputBox(请输入一个整数”)If is_bin(a) ThenPrint ”偶数”ElsePrint ”奇数End IfEnd SubPrivate Sub Form_Load(
28、)End SubPrivate Function is_bin(n As Integer) As BooleanIf n Mod 2 = 0 Thenis_bin = TrueElseis_bin = FalseEnd IfEnd Function6.9Const pi = 3.1415926Private Sub Form_Click()Print ”余下的面积为: & C_S(10) - C_S(5) - C_S(3)End SubPrivate Function C_S(r As Single) As SingleC_S = pi * r * rEnd Function6.10Priva
29、te Sub Form_Click()Print ”第五人的年龄为: & n_age(5)End SubPrivate Function n_age(n As Integer) As IntegerIf n = 1 Thenn_age = 10Elsen_age = n_age(n -1) + 2End IfEnd Function练习题答案第一章一选择:ccbbdbbda = 5b = 2.5c = 7.8pi = 3.14159265y = pi*a*b/a + b*cPrint yEnd Sub5 Forml计算4.4Private Sub CommandlClick()a = Vai
30、(Textl. Text)tian = a 86399xiaoshi = (a - tian * 86400) 1439fenzhong =(a - tian * 86400 - xiaoshi * 1440) 59miao = a - tian * 86400 - xiaoshi * 1440 - fenzhong * 60Text2. Text = tian & 天 & xiaoshi & 小时 & fenzhong &分钟 & miao& 秒End Sub二填空1、学习版、专业版、企业版2 、 alt+f43 、 .vbp . frm 4、固定、浮动 5、 ABCD vb program
31、ming 6、属性窗口、运行 7、对象、过程8、窗体模块、标准模块、类模块 第二章一、选择 bbbbdd 二、填空 1(x+y)+z)*80-5* (c+d)2 cos(x)*(sin(x)+l) 32*a*(7+b)4 8*exp (3)*log(2)5 goodmorninggoodmorning6 25、 8、 2001、7第三章 一、选择题Cbda(d . 3 或 both) cbccdbcbbabdcc (第五题俩选项) 二填空 1 autosize 2 textl. setfocuse 3 0、04 picturel. picture=loadpicture( yygif ) 5
32、stretch 6 interval7 enabled8 简单组合框、下拉式组合框、下拉式列表框、style9 下拉式列表框10 条目1、条目311 欢迎您到中国来、welcome to china 第四章一、 选择题bccbcbcbdababdabacb二、 填空1 2542=57 2 beijingO 3002.452.44924.49e-0. 1-2.449549 10 115 836 37 Y=iif (x=0, 0, iif (x=10, 5+2*x, iif (x6或x=7或x=79 x=0x cl) And (al + cl bl) And (bl + cl al) Then s = al + bl + cl Exit DoElseError 1 = MsgBox (您输入的数据不能组成三角形)End IfLoopLabel4. Caption =您输入的边长分别为: & al & , & bl & / & cl & & 面积为: & s5 Forml计算4.8Private