VB第六章习题答案(上海立信会计学院)
vb6.0第六章 习题解答
习题六一、选择题答案Aadcc dc二、填空题答案1、a(I,j)+b(I,j)2、下标越界3、64、1 2 2 4 3 6第六章选择题部分解析3、sum表示a数组各元素的和X表示a数组元素和的平均值最后打印出a数组中大于平均值的元素Sum=1+2+3+4+5=15,x=3大于3的有4,55、倒着看文本框中显示什么?答:显示的是array1(1,3)+array2(2,3)的和接着往前看程序发现array1(i,j)=i+j所以array1(1,3)=1+3=4Array2(2,3)=2+3=5所以4+5=9二、填空题解析2、x数组最大元素是x(6)退出for循环时,i=7然后print x(i)相当于print x(7)但是没有x(7)这个元素,超出最大下标了。
若把print x(i)改为print x(a)则值是36第六章编程题1、Private Sub Form_Click()Dim a(1 To 20) As Integer, i As IntegerDim j As Integerj = 0 '用来表示小于60的个数Picture1.Print "产生的数组为:"Picture1.PrintPicture2.Print "其中小于60的元素有:"Picture2.PrintFor i = 1 To 20a(i) = Int(Rnd * 100 + 1)Picture1.Print a(i);If i Mod 10 = 0 Then Picture1.PrintIf a(i) < 60 Thenj = j + 1Picture2.Print a(i); " ";If j Mod 10 = 0 Then Picture2.PrintEnd IfNext iEnd SubPrivate Sub Form_Load()RandomizeEnd Sub2、Private Sub Form_Click()Dim a(1 To 10) As IntegerDim max As Integer, min As Integer, i As IntegerFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Picture1.Print a(i);If i Mod 5 = 0 Then Picture1.PrintNext imax = a(1)min = a(1)For i = 2 To 10If a(i) > max Then max = a(i)If a(i) < min Then min = a(i)Next iLabel1.Caption = "最大数为:" & maxLabel2.Caption = "最小数为:" & minEnd SubPrivate Sub Form_Load()RandomizeEnd Sub3、Dim a(1 To 20) As IntegerPrivate Sub Command1_Click()Dim x As Integer, flag As Integer, i As Integerflag = 0 '标志,表示数组中是否存在xx = InputBox("请输入x的值,为整数", "输入", 1) For i = 1 To 20If x = a(i) Thenflag = 1 'flag改变,说明存在Exit ForEnd IfNext iIf flag = 1 ThenPrint "数组中存在" & xPrint "位置:" & iElsePrint "数组中不存在" & xEnd IfEnd SubPrivate Sub Form_Click()Dim i As IntegerFor i = 1 To 20 '生成数组a(i) = Int(Rnd * 100) '题目没要求,随便的范围Next iFor i = 1 To 19 '冒泡排序For j = 20 To i + 1 Step -1If a(j) > a(j - 1) Thent = a(j)a(j) = a(j - 1)a(j - 1) = tEnd IfNext jNext iFor i = 1 To 20 '打印数组Print a(i);If i Mod 5 = 0 Then PrintNext iEnd SubPrivate Sub Form_Load()RandomizeEnd Sub4、Private Sub Form_Click()Dim a(1 To 15) As SingleDim i As Integer, c1 As Integer, c2 As Integer, c3 As Integer, avg As SingleFor i = 1 To 15a(i) = InputBox("请输入第" & i & "个学生的成绩", "输入成绩", 60)avg = avg + a(i)Next iavg = avg / 15For i = 1 To 15If a(i) > avg Then c1 = c1 + 1If a(i) < 60 Then c2 = c2 + 1If a(i) >= 90 Then c3 = c3 + 1Next iPrint "高于平均分的人数"; c1Print "<60的人数"; c2Print ">=90的人数"; c3End Sub5、Dim a(1 To 4, 1 To 4) As Integer, b(1 To 4, 1 To 4) As Integer, c(1 To 4, 1 To 4) As IntegerPrivate Sub Command1_Click()‘(2)题For i = 1 To 4For j = 1 To it = a(i, j)a(i, j) = a(j, i)a(j, i) = tNext jNext iPicture2.ClsPicture2.Print "a转置后:"Picture2.PrintFor i = 1 To 4For j = 1 To 4Picture2.Print a(i, j); " ";Next jPicture2.PrintNext iEnd SubPrivate Sub Command2_Click()‘(3)题Picture2.ClsMax = c(1, 1)t1 = 1t2 = 1For i = 1 To 4For j = 1 To 4If c(i, j) > Max ThenMax = c(i, j)t1 = it2 = jEnd IfNext jNext iPicture2.Print "max=", MaxPicture2.Print "c("; i; ","; j; ")"End SubPrivate Sub Command3_Click()‘(4)题Picture1.ClsPicture2.ClsFor i = 1 To 4For j = 1 To iPicture1.Print a(i, j); " ";Next jPicture1.PrintNext iFor i = 1 To 4For j = i To 4Picture2.Print Tab(j * 5); b(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command4_Click()‘(5)题Picture1.ClsFor i = 1 To 4t = a(1, i)a(1, i) = a(3, i)a(3, i) = tNext iFor i = 1 To 4For j = 1 To 4Picture1.Print a(i, j); " ";Next jPicture1.PrintNext i End SubPrivate Sub Command5_Click()‘(1)题Picture3.Print "c矩阵:"Picture3.PrintFor i = 1 To 4For j = 1 To 4c(i, j) = a(i, j) + b(i, j)Picture3.Print c(i, j); " ";Next jPicture3.PrintNext iEnd SubPrivate Sub Form_Load()ShowPicture1.Print "a矩阵:"Picture1.PrintPicture2.Print "b矩阵:"Picture2.PrintFor i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 40 + 30)b(i, j) = Int(Rnd * 35 + 101)Picture1.Print a(i, j); " ";Picture2.Print b(i, j); " ";Next jPicture1.PrintPicture2.PrintNext iEnd Sub。
大学VB实验答案
上海立信会计学院本科实验报告班级:学号:姓名:指导教师:系部:专业:实验时间:实验4 循环结构一、实验目的1.掌握For语句的使用2.掌握Do语句的各种形式的使用。
3.掌握如何控制循环条件,防止死循环或不循环。
二、实验要求1.在C:\下建立子文件夹“VB实验4”,按照题目要求,在该文件夹下为各题保存相应的文件,如本实验中的第一题,需保存的文件有:工程文件(41.vbp)、窗体文件(41.frm) 及可执行文件(41.exe),本实验中的第二题,需保存的文件有:工程文件(42.vbp)、窗体文件(42.frm) 及可执行文件(42.exe),其余实验依此类推。
2.撰写实验过程中出现了哪些问题、错误,你是如何解决的,做一个小结。
三、实验内容:1.编一程序利用单循环结构显示如图4-1所示的界面。
要求:循环体内显示的内容用String函数来实现,找出循环控制变量与String函数内字符个数的关系:即String(2*i-1,Trim(Str(i)))。
窗体显示字体默认、大小为小四,通过单击窗体触发程序运行。
图4-1Private Sub Form_Click()For i = 1 To 9Print Tab(15 - i); String(2 * i - 1, Trim(Str(i)))Next iEnd Sub2.计算π的近似值,π的计算公式为:)12()12()2(75653431222222+⨯-⨯⋅⋅⋅⨯⨯⨯⨯⨯⨯⨯=n n n π,要求:单击按钮同时显示当n=10、100、1000时的结果,利用Format 函数保留5位小数。
窗体中所有控件字体默认、大小为小四。
效果如图4-2所示。
图4-2Private Sub Command1_Click()pi = 2For i = 1 To 10pi = pi * (2 * i) ^ 2 / ((2 * i - 1) * (2 * i + 1))Next iPrint " n=10 ∏近似值="; Format(pi, "0.00000")pi = 2For i = 1 To 100pi = pi * (2 * i) ^ 2 / ((2 * i - 1) * (2 * i + 1))Next iPrint " n=100 ∏近似值="; Format(pi, "0.00000")pi = 2For i = 1 To 1000pi = pi * (2 * i) ^ 2 / ((2 * i - 1) * (2 * i + 1))Next iPrint " n=1000 ∏近似值="; Format(pi, "0.00000")End Sub3. 求Sn=a+aa+aaa+aaaa+…+aa …aaa(n 个a),其中a 是一个由随机数产生的1~9(包括1、9)中的一个正整数,n 是一个由随机数产生的4~9(包括4、9)中的一个正整数,产生随机数需使用Randomize 语句。
[VIP专享]VB第6章课后练习答案
第6章过程与函数一、填空题1.数组名作为过程或函数实参,相应的形参传递方式为____按地址传递____。
2.一维长整型数组a作过程形参写作:a() As Long,二维长整型数组b作过程形参写作:____b() As Long ____。
3.过程形参为整型,对应实参为5.64,传递给形参的值为____6____。
4.调用过程时对形参的改变不会导致相应实参变量的改变,则该形参采用____按值传递____方式。
5.调用过程时对形参的改变就是对相应实参变量的改变,则该形参采用____按地址传递____方式。
6.声明Single类型全局变量x,写作____Public x As Single(或 Publicx!)____;声明Integer类型静态变量x,写作____Static x As Integer(或 Static x%)____。
7.在窗体Form1的过程中引用窗体Form2中的全局变量y,写作____Form2.y____。
8.阅读如下代码,单击窗体后,窗体上的显示结果为____s = 2 s = 5 s =9____。
Dim i As Integer, n As IntegerPrivate Sub Form_Click()Dim i As IntegerFor i = 1 To 3s = sum(i): Print "s ="; s;Next iEnd SubPrivate Function sum(n As Integer)Static j As Integerj = j + n + 1: sum = jEnd Function二、选择题1.VB程序设计语言中,函数过程与子过程必须分别用关键字( C)声明。
(A)Private,Public (B)Public,Private(C)Function, Sub (D)Sub, Function2.要调用一个已经定义好的函数myfunction( ),用语句的方式调用函数,下列写法哪个是正确的(D)(A)Call myfunction (B)myFunction(C)myFunction ( ) (D)CallmyFunction( )3.定义过程时,如果在过程名前加关键字Private,则该过程为( A)。
VB课后练习答案.doc
VB课后练习答案P12第一章课后练习答案:一、选择题二、填空题第二章(P39)选择题答案:填空题答案:1.Cmdl, Click2.Text 1.Text二"Hello"P64第三章课后练习答案一、选择题二、填空题1.(Y Mod 4=0 And Y Mod 10000) Or Y Mod 400=0 2.a<>0 And b*2-4*a*c>=0 3.X Mod 5=0 And X Mod 2=0 或 Tnt(x/5)=X/5 And Int(X/2)=X/2 4. 注意:返回的均是字符型。
第四章课后答案:P79一、选择题答案为:$$41.50010二、填空题三、程序设计题(提示)1、鸡的头数为x,兔的头数为y,则可列方程式:\x-\- y = h (兀 * 2 + y * 4 =于求得x, y 的值再在窗体上输出结果。
2、 利用Format 格式函数,再通过窗体的Print 将格式化后的信息输出到窗体上。
3、 厶员I 的周长=2加" $岡的面积=加25、通过Inputbox 函数或用文本框输入三边和圆的半径a,b,c, r,利用公式:. a + b + cn 二 ---------2 S 三角形面积=Jh (h - - b )(h - c )P97第五章课后练习答案:第9题| D一、选择题答案D 改为:30二、填空题第]题Y Mod 4二0 And Y Mod 100二0 Or Y Mod 400二0 第2题笫3题笫4题Private Sub Command l_Click()X=Val(Textl.Text)Select Case XCase Is>200. Isv-10()Print “xv 100 Or x>200"Case ls<=0Y=l()()-XCase Isv二100Y=100+XCase Is<=200Y=400End SelectText2.Text=yEnd Sub三、程序设计题(提示)1、判断条件:假设一个整数为xX Mod 3=0 Or x Mod 5=0 或x/3=x\3 Or x/5=x\52、选项按钮的知识点在P182,利用该控件的Wlue属性判断是否选中该项。
vb6.0实验六习题与答案
vb6.0实验六习题与答案实验六专业_____________ 班级________年级________姓名______________学号_______________ 一、实验目的1、认识常用控件:单选按钮、复选框、框架、列表框、组合框、滚动条、滑动器(Slider)、时钟、图形控件;2、学习在窗体中创建常用控件2、学习在属性窗口和在程序代码中设置属性3、学习调用控件的方法4、学习编写各控件和鼠标与键盘的事件过程二、实验内容1、单选按钮、复选框、框架1)设置窗体F1的标题为“复选框、框架和单选按钮”;在窗体中设置复选框Ch1、Ch2 Ch1和Ch2的高度和宽度分别为360和1000;并程序运行时,Check2处于非少许状态。
框架Fr1包含单选按钮Op1和Op2。
2)设计窗体,要求①标题为“设置字体”;②在窗体中设置有边框的标签控件Label1,高度和宽度分别为450和3800,标题为“欢迎使用VB”,字号为“四号”,居中显示;③标题为“字体”框架包含两个标题分别为“楷体_GB2312”和“华文新魏”的单选按钮Op1和Op2;④标题为“斜体”框架包含两个标题分别为“是”和“否”的单选按钮。
⑤编写相应控件的事件过程,使得程序运行时,单击“楷体_GB2312”,标签控件的字体为楷体_GB2312,单击“华文新魏”,标签控件的字体为华文新魏;单击“是”,标签控件的字体为斜体,单击“否”,标签控件的字体取消斜体。
Private Sub Option1_Click()Label1.FontName = Option1.CaptionEnd SubPrivate Sub Option2_Click()Label1.FontName = Option2.CaptionEnd SubPrivate Sub Option3_Click() Label1.FontItalic = TrueEnd SubPrivate Sub Option4_Click() Label1.FontItalic = FalseEnd Sub3)在窗体是设置设置框Text1,其中文字为:黑体、四号、居中;设置单选按钮Option1和Option2,标题分别为“福州大学”和“阳光学院”,编写行当的事件过程,使得程序时,单击“福州大学”或“阳光学院”,在文本框中显示“福州大学”或“阳光学院”。
vb教程答案第六章
1.阅读程序,写出程序结果答: 6 7 92 5 81 3 42.提示:在交换首尾对称位置的数组元素时注意,循环的终值只能到数组的一半,而不能到数组的最大下标,否则会将数组元素值又还原成原来的数值。
程序界面如下图5-2所示:图5-2参考程序如下:Private Sub Command1_Click()Dim a(15) As Integer, i As Integer, j As Integer, t As Integer'给数组赋值,并输出在文本框1中For i = 1 To 15a(i) = Int(Rnd * 100) + 1Text1.Text = Text1.Text & Str(a(i))Next i'交换数组对称位置的数据For i = 1 To 7t = a(i)a(i) = a(16 - i)a(16 - i) = tNext i'输出交换后的数组内容For i = 1 To 15Text2.Text = Text2.Text & Str(a(i))Next iEnd Sub3.提示:可以对数组的每个元素与其后面的所有元素逐个进行比较,如果有相同的数,将后面出现的数值清为0,最后统计所有不为0的数据个数。
参考程序如下:Private Sub Command1_Click()Dim a(20) As Integer, i As Integer, j As Integer, k As Integer'给数组赋值,并输出在窗体上RandomizeFor i = 1 To 20a(i) = Int(Rnd * 100) + 1Print a(i);Next iPrint'统计有多少个不相同的数For i = 1 To 19For j = i + 1 To 20If a(j) = a(i) Then a(j) = 0Next jNext i'统计不相同的数,并输出在窗体上For i = 1 To 20If a(i) <> 0 Then k = k + 1Next iPrint "一共有" & k & "个不相同的数"End Sub4.本题的主要思路是:先给数组的20个数赋值并输出,然后按照求最大值的算法思想,先将前4个数之和赋给存放最大值的变量max,同时记录4个数中第一个数的下标,然后对剩下的每4个数求和,判断是否大于max,如果是,将新的最大值送给max,同时记录其首数据的下标,最后,只要输出四个相邻数之和的最大值,并输出这四个数即可。
【免费下载】计算机二级VB第6章选择题及答案
A、A
B、 B 8、有如下程序段:
Private Sub Form_Click()
Dim s%, t%, a%, b%
s = 1: t = 1
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > 0 Then s = s + 1
If a > b Then
Else
t=t+s
X = 3: Y = 5: z = 9 X=X+Y Y=X-Y If X + Y > Z - X Then z = X + Y If X + Y > Z - Y Then X = z + Y
对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术关,系电,力根通保据过护生管高产线中工敷资艺设料高技试中术卷资,配料不置试仅技卷可术要以是求解指,决机对吊组电顶在气层进设配行备置继进不电行规保空范护载高与中带资负料荷试下卷高问总中题体资,配料而置试且时卷可,调保需控障要试各在验类最;管大对路限设习度备题内进到来行位确调。保整在机使管组其路高在敷中正设资常过料工程试况中卷下,安与要全过加,度强并工看且作护尽下关可都于能可管地以路缩正高小常中故工资障作料高;试中对卷资于连料继接试电管卷保口破护处坏进理范行高围整中,核资或对料者定试对值卷某,弯些审扁异核度常与固高校定中对盒资图位料纸置试,.卷保编工护写况层复进防杂行腐设自跨备动接与处地装理线置,弯高尤曲中其半资要径料避标试免高卷错等调误,试高要方中求案资技,料术编试交写5、卷底重电保。要气护管设设装线备备置敷4高、调动设中电试作技资气高,术料课中并3中试、件资且包卷管中料拒含试路调试绝线验敷试卷动槽方设技作、案技术,管以术来架及避等系免多统不项启必方动要式方高,案中为;资解对料决整试高套卷中启突语动然文过停电程机气中。课高因件中此中资,管料电壁试力薄卷高、电中接气资口设料不备试严进卷等行保问调护题试装,工置合作调理并试利且技用进术管行,线过要敷关求设运电技行力术高保。中护线资装缆料置敷试做设卷到原技准则术确:指灵在导活分。。线对对盒于于处调差,试动当过保不程护同中装电高置压中高回资中路料资交试料叉卷试时技卷,术调应问试采题技用,术金作是属为指隔调发板试电进人机行员一隔,变开需压处要器理在组;事在同前发一掌生线握内槽图部内纸故,资障强料时电、,回设需路备要须制进同造行时厂外切家部断出电习具源题高高电中中源资资,料料线试试缆卷卷敷试切设验除完报从毕告而,与采要相用进关高行技中检术资查资料和料试检,卷测并主处且要理了保。解护现装场置设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。
VB第六章习题答案(上海立信会计学院)
上海立信会计学院班级:学号:姓名:指导教师:系部:专业:习题六p150一、简述子过程与函数过程的共同点和不同之处。
答:相同之处:都是功能相对独立的一种子程序结构,它们有各自的过程头、变量声明和过程体,在程序的设计过程中可以提高效率。
不同之处:(1)声明的关键字不同。
子过程为Sub,而函数过程为Function。
(2)了过程无值就无类型说明,函数过程有值因此有类型的说明(3)函数的过程名称同时是结果变量,因此在函数过程体内至少要对函数的过程名赋值一次数据,而子过程内不能赋值。
(4)调用的方式不同,子过程是一条独立的语句,可以用Call子过程名或省略Call直接以子过程名调用;函数的过程不是一条独立的语句,是一个函数值,必须参与表达式运算。
(5)通常,函数过程可以被子过程代替,只需要在调用的过程中改变一下过程调用的形式,并在子过程的形参表中增加一个地址传递的形参来传递结果。
二、什么是形参,实参什么是值引用地址引用地址应用对实参有什么限制答:形参:在定义过程时的一种假设的参数,只代表该过程的参数的个数、类型,它的名字不重要,没有任何的值,只表示在过程体内将进行的一种操作。
实参:在调用子过程时提供过程形参的初始值,或通过过程体处理后的结果。
值引用:系统将实际参数的值传到形参之后,实参与形参断开联系,过程中对于形参的修改不会影响到实际参数的变化。
地址引用:实参与形参共同使用一个存储单元,在过程中对形参进行修改,则对应的实际参数也同时变化。
在地址引用时,实参只能是变量,不能是常量或表达式。
三、指出下面过程语句说明中的错误:(1)Sub f1(n%) as Integer(2)Function f1%(f1%)(3)Sub f1(ByVal n%())(4)Sub f1(x(i) as Integer)答:(1)Sub子过程名没有返回值,因此就没有数据的类型(2)函数名与形参名称相同(3)形参n为数组,不允许声明为ByVal值传递(4)形参x(i)不允许为数组元素四、已知有如下求两个平方数和的fsum子过程:Public Sub fsum(sum%, ByVal a%, ByVal b%)sum = a * a + b * bEnd Sub在事件过程中若有如下变量声明:Private Sub Command1_Click()Dim a%, b%, c!a = 10:b = 20则指出如下过程调用语句的错误所在:(1)fusum 3, 4, 5(2)fsum c, a, b(3)fsum a + b, a, b(4)Call fsum(Sqr(c), Sqr(a), Sqr(b))(5)Call fsum c,a,b答:(1)furm子过程的第一个形参是地址传递,因此对应的实参3不能是常量(2)furm的第一个形参是整型而且是地址传递,对应的实参c是单精度,数据类型不匹配(3)furm的第一个形参是地址传递,因此对应的实参a+b不应当是表达式(4)furm的第一个形参是地址传递,因此对应的实参Sqr(c)不应当是表达式(5)用Call语句调用furm子过程时,必须用圆括号来描述实参六、要使变量在某事件过程中保留值,有哪几种变量声明的方法答:声明为static或者全局变量七、为了使某变量在所有的窗体中都能使用,应在何处声明该变量答:应在窗体\模块的通用声明段用Public关键字声明为全局变量。
第六章 虚拟变量回归模型
ˆ 3176 Y .83 503.17Di i se ( 233.04) (329.57) t (13.63) ( 1.53) r 2 0.189
以上回归结果中,截距的估计值恰好等于男性 食品支出的平均值,而2674恰好等于女性的平 均值,所以虚拟变量回归式是用来对两组均值 是否不同进行判断的工具。 虚拟变量回归式中,取0的一类被称为基准类、 基础类或者参照类。 3.为什么不引入两个虚拟变量? 对模型(1)如果设置两个虚拟变量,则存在 完全共线性,无法估计。所以,如果定性变量 有m种分类,则只需引入m-1个虚拟变量。
B2 代表了东北和中 B1 代表了南部地区的平均接受率, 所以, 北部地区与南部地区的差异,B3 代表了西部地区与南部地区 的差异。
2.模型的估计与假设检验
包含多分定型变量模型的估计和假设检验与以前没有什么 不同。例如,研究生接受率一例,利用Eviews回归得到:
其回归方程为:
Accepi 44.54 10.68D2i 12.50 D3i
E(Yi | Di 0) B1
E(Yi | Di 1) B1 B2
B2 由以上两式可以看出,B1 表示男性平均食品支出, 表示女性平均食品支出与男性的差异。B1 B2 表示 女性平均食品支出。由此,B2 称为差别截距系数。 通过以上的分析也可知,虚拟变量系数的含义与定量 变量系数的含义有很大不同。它表示两组某个变量均 值的差距,而不是变化量的意思。 2.ANOVA模型的估计与假设检验 ANOVA模型的估计与假设检验同定量变量模型没有差 异。比如,对男女食品消费支出一例(例:6-1)进行 估计可得到:
t (14.38) P (0.00) ( 2.67) (0.010) ( 2.25) (0.028)
vb习题答案(1-9章)最全的
第一章VB程序设计概述二、选择题CADAB ACDAB CBDBB第二章VB可视化编程基础二、选择题ABDCA CACBC DADAD BDBBB三、填空题1.可视2.LEFT TOP WIDTH HEIGHT3.按字母序4.查看代码5.工具、选项6.Form1 Font7.Multiline8.只读属性9.工程属性通用Form1.show10.tabindex 0第三章VB语言基础二、选择题BCADB ADBBC DBCBA DAABB三、填空题1.整型、长整型、单精度、双精度2.sin(30*3.14/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)3.160 今天是:3-224.False5.-4 3 -3 3 -4 46.“CDEF”7.(x mod 10)*10+x\108.(35\20)*20=20 ( 35 \ 20 ) * 20 = 209.x mod 3=0 or x mod 5=010.27.6 8.2 8 1 100 397 true false第四章VB程序控制结构二、选择题DBCAD ABCAB D25BAC CBACB DABBC三、填空题1.字符型整型2. 1 2 33.x>74.x<amin5.10246.117.128.6 I “*”;9.0 100 i+1 10.2*I 6 “*”;三、编程题1.Private Sub Form_Click()Dim n As Integer, i As Integer, s As Longs = 1n = Val(InputBox("请输入一个整数:"))For i = 1 To ns = s * iNext iMsgBox n & "!=" & sEnd Sub2.Private Sub Form_Click()Dim i%, k%For j = 3 To 100k = Int(Sqr(j))For i = 2 To kIf j Mod i = 0 Then Exit ForNext iIf i > k Theny$ = y$ & " " & jEnd IfNext jMsgBox y, , "显示质数"End Sub3.Private Sub Form_Click()Dim i%, s%For i = 1 To 100s = s + iNext iMsgBox "1+2+3+……+100=" & sEnd Sub4.Private Sub Form_Click()Dim x%, y%For x = 1 To 50For y = 1 To 33z = 100 - x - yIf 2 * x + 3 * y + 0.5 * z = 100 ThenPrint "小鸡、公鸡、母鸡分别为:"; x; y; z End IfNext yNext xEnd Sub5.Private Sub Command1_Click()Dim a%, b%, c%, p!, s!doa = Val(InputBox("请输入三角形的第一条边"))if a=-1 then exit dob = Val(InputBox("请输入三角形的第二条边"))c = Val(InputBox("请输入三角形的第三条边"))If a + b > c And a + c > b And b + c > a Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Print sElseMsgBox "你输入的三边不能构成三角形,请重新输入"End IfloopEnd Sub6. Private Sub Form_Click()Dim i As Integer, j As Integer,k as integerFor i = 1 To 8For k=1 to 8-iPrint spc(3);Next kFor j = 1 To 2 * i - 1Print i;Next jPrintNext iEnd Sub7. Private Sub Form_Click()Dim i As Integer, j As Integer, k As IntegerFor i = 1 To 30For j = 1 To 30For k = 1 To 30If i ^ 2 + j ^ 2 = k ^ 2 ThenPrint i & " ^ 2 + " & j & "^ 2 =" & k & "^ 2"End IfNext kNext jNext iEnd Sub8.Private Sub Form_Click()Dim x As Integer, a As Integer, b As Integer, c As Integer, ss As String ss = ""For x = 100 To 999a = Int(x / 100)b = Int((x - 100 * a) / 10)c = x - 100 * a - 10 * bIf a ^ 3 + b ^ 3 + c ^ 3 = x Thenss = ss & " " & xEnd IfNext xPrint ssEnd Sub9.Dim sr As Long, r As Singlesr = Val(InputBox("请输入收入:"))Select Case srCase Is < 200r = 0Case 200 To 400r = (sr - 200) * 0.04Case 400 To 5000r = sr * 0.04Case Is >= 5000r = sr * 0.05End SelectPrint "收入为" & sr & "时所缴纳的税为:" & rEnd Sub10.Private Sub Form_Click()Dim t As Single, wf As Singlet = Val(InputBox("请输入上网时间:"))Select Case tCase Is < 10wf = 50Case 10 To 60wf = t * 6Case Is >= 60wf = t * 4End SelectIf wf >= 200 Thenwf = 200End IfPrint "上网时间为" & t & "小时上网的费用为:" & wf End Sub11. Private Sub Form_Click()Dim yf As Integeryf = Val(InputBox("请输入月份"))Select Case yfCase 12, 1, 2MsgBox yf & "月份是冬季"Case 3, 4, 5MsgBox yf & "月份是冬季"Case 6, 7, 8MsgBox yf & "月份是冬季"Case 9, 10, 11MsgBox yf & "月份是冬季"Case ElseMsgBox "输入错误,请重新输入"End SelectEnd Sub12.if的方法Private Sub Form_Click()Dim x As Single, f As Singlex = Val(InputBox("请输入一个数"))If x < 0 Thenf = 2 * x - 1ElseIf x = 0 Thenf = 4 * xElseIf x > 0 Thenf = 7 * x - 5End IfPrint "f(" & x & ")=" & fEnd SubSelect case语句:Private Sub Form_Click()Dim x As Single, f As Singlex = Val(InputBox("请输入一个数"))Select Case xCase Is < 0f = 2 * x - 1Case 0f = 4 * xCase Is > 0f = 7 * x - 5End SelectPrint "f(" & x & ")=" & fEnd Sub第五章数组一、选择题DCACD DBCDC BADAD二、填空题1.名称Index2.preserve3.变体4.235.1 2 3 1 4 16.1 2 3 2 4 67. max max=arr1(i)三、编程题1.Option Base 1Private Sub Form_Click()Dim a(10) As Integer, i%, temp%For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个整数")) Next iPrint "原来各元素的值为:"For i = 1 To 10Print a(i);Next iFor i = 1 To 5temp = a(11 - i)a(11 - i) = a(i)a(i) = tempNext iPrintPrint "交换后各元素的值为:"For i = 1 To 10Print a(i);Next iEnd Sub2.Option Base 1Private Sub Form_Click()Dim a As Variant, b As Variant, c As Variant, i%a = Array(2, 8, 7, 6, 4, 28, 70, 25)b = Array(79, 27, 32, 41, 57, 66, 78, 80)ReDim c(8)For i = 1 To UBound(a)c(i) = a(i) + b(i)Next iFor i = 1 To UBound(c)Print c(i);Next iEnd Sub3.Option Base 1Private Sub Form_Click()Dim a() As Variant, i%, j%, n%, m%, max%, hh%, lh%n = Val(InputBox("请输入一个整数:"))m = Val(InputBox("请输入一个整数:"))ReDim a(n, m)For i = 1 To n - 1For j = 1 To m - 1a(i, j) = Int(Rnd * 101 + 50)If max < a(i, j) Then max = a(i, j): hh = i: lh = jNext jNext iPrint "最大值为:"; max; "所在的行号为:"; hh; "所在的列号为:"; lh End Sub4.Option Base 1Private Sub Form_click()Dim a(50) As Integer, b(9) As Integer, i%, j% For i = 1 To 50a(i) = Int(Rnd * 90 + 10)j = Int(a(i) / 10)b(j) = b(j) + 1Next iFor j = 1 To 9Print b(j);Next jEnd Sub5.Option Base 1Private Sub Command1_Click(Index As Integer) Select Case IndexCase 0Text3 = Val(Text1) + Val(Text2)Case 1Text3 = Val(Text1) - Val(Text2)Case 2Text3 = Val(Text1) * Val(Text2)Case 3Text3 = Val(Text1) / Val(Text2)End SelectEnd Sub6.Private Sub Form_click()Dim s!, i&, j&i = 3s = 1j = 0Doj = j + 1s = s + (-1) ^ j / ii = i + 2Loop While 1 / i > 10 ^ (-6)Print 4 * sEnd Sub7.Option Base 1Private Sub Form_click()Dim a(40) As Long, i As Integera(1) = 1a(2) = 1For i = 3 To 39a(i) = a(i - 1) + a(i - 2)Next iFor i = 1 To 40Print a(i);Next iEnd Sub8.冒泡法:Option Base 1Private Sub Form_click()Dim a(10) As Single, ok As Boolean, i%, j%, x!For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Print a(i);Next iFor i = 10 To 2 Step -1ok = TrueFor j = 1 To i - 1If a(j) > a(j + 1) Thenx = a(j)a(j) = a(j + 1)a(j + 1) = xok = FalseEnd IfNext jIf ok Then Exit ForNext iPrintPrint "冒泡排序的结果为:"For i = 1 To 10Print a(i);Next iEnd Sub选择法:Option Base 1Private Sub Form_click()Dim a(10) As Single, p!, i%, j%, min!For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Print a(i);Next iFor i = 1 To 9p = iFor j = i + 1 To 10If a(j) < a(p) Then p = jNext jIf p <> i Thenmin = a(i)a(i) = a(p)a(p) = minEnd IfNext iPrintPrint "排序后的结果为:"For i = 1 To 10Print a(i);Next iEnd Sub第六章过程一、选择题CDBAB DBCCC ABCBD CDB二、填空题1.sub function2.形式实际3.内存的同一地址4.myf(a%,b() as integer ) as Boolean5.值传递地址传递6.lbound ubound7.局部8.通用任何过程9.2 5 9 10.2411.2 12.30 7013.-1三、编程题1. Option Base 1Private Sub Form_Click()Dim m1%, m2%, b() As IntegerFor i = 3 To 7 Step 2ReDim b(i)For j = 1 To ib(j) = Int(Rnd * 90 + 10)Print b(j);Next jm1 = b(1)m2 = b(1)Call mm(m1, m2, b())PrintPrint "最大值为:"; m1Print "最小值为:"; m2Next iEnd SubPublic Sub mm(max%, min%, a() As Integer) Dim i%For i = LBound(a) To UBound(a)If a(i) > max Then max = a(i)If a(i) < min Then min = a(i)Next iEnd Sub2.sub过程:Public Sub jc(n%, s&)Dim i%s = 1For i = 1 To ns = s * iNext iEnd SubPrivate Sub Form_click()Dim s&, a%, b%, c%, s1&a = Val(InputBox("请输入一个整数:"))b = Val(InputBox("请输入一个整数:"))c = Val(InputBox("请输入一个整数:")) Call jc(a, s1)s = s1 + sCall jc(b, s1)s = s1 + sCall jc(c, s1)s = s1 + sPrint a & "!+" & b & "!+" & c & "!=" & s End SubFunction过程:Public Function jc(n%) As LongDim i%, s%s = 1For i = 1 To ns = s * iNext ijc = sEnd FunctionPrivate Sub Form_click()Dim s&, a%, b%, c%, s1&a = Val(InputBox("请输入一个整数:"))b = Val(InputBox("请输入一个整数:"))c = Val(InputBox("请输入一个整数:"))s1 = jc(a) + jc(b) + jc(c)Print a & "!+" & b & "!+" & c & "!=" & s1 End Sub3.Public Sub jo(n As Integer)If n Mod 2 = 0 ThenPrint "false"ElsePrint "true"End IfEnd Sub4.Private Sub Form_click()Dim b(1 To 100) As Integer, i%For i = 1 To 100b(i) = Int(Rnd * 100 + 1)Next iCall sort(b())For i = 1 To 100If i Mod 10 = 0 Then PrintPrint b(i);Next iEnd SubPublic Sub sort(a() As Integer)Dim n%, ok As Boolean, k As Integern = UBound(a)For i = 1 To n - 1ok = TrueFor j = 1 To n - iIf a(j) > a(j + 1) Thenk = a(j): a(j) = a(j + 1): a(j + 1) = k: ok = False End IfNext jIf ok Then Exit ForNext iEnd Sub5.Private Sub Form_click()Dim b(1 To 10) As Integer, i%For i = 1 To 10b(i) = Val(InputBox("请输入第" & i & "个整数")) Next iCall sort(b())Print "排序后的结果"For i = 1 To 10Print b(i);Next iEnd SubPublic Sub sort(a() As Integer)Dim n%, p%, k As Integern = UBound(a)For i = 1 To n - 1p = iFor j = i + 1 To nIf a(j) < a(p) Then p = jNext jIf p <> i ThenMin = a(i)a(i) = a(p)a(p) = MinEnd IfNext iEnd Sub6.Public Sub gys(m%, n%)Dim r%, t%If m <> 0 And n <> 0 ThenIf m < n Thent = m: m = n: n = tEnd Ifr = m Mod nDo While r <> 0m = nn = rr = m Mod nLoopEnd IfEnd Sub7.Public Sub ws(n%, s%)Dim k%, i%For i = 1 To n - 1If n Mod i = 0 Then s = s + iNext iEnd SubPrivate Sub Form_click()Dim m%, sum%, c$For m = 1 To 999sum = 0Call ws(m, sum)If sum = m Then c = c & sum & " " Next mMsgBox cEnd Sub8.Public Function ef(a(), k%, wz%) As Integer Dim i%, low%, mid%, top%low = LBound(a)top = UBound(a)Do While low <= topmid = (low + top) / 2If k > a(mid) Thenlow = mid + 1ElseIf k = a(mid) Thenwz = midExit FunctionElsetop = mid - 1End IfLoopwz = -1End Function9.Function MaxGY(x As Integer, y As Integer) Dim Temp As IntegerTemp = x Mod yIf Temp = 0 ThenMaxGY = yElseMaxGY = MaxGY(y, Temp)End IfEnd FunctionPrivate Sub Form_click()Dim m%, n%m = Val(InputBox("请输入第一个整数:"))n = Val(InputBox("请输入第二个整数:")) Print "最大公约数是:"; MaxGY(m, n)End Sub10. Function Ss(n%)If n = 1 ThenSs = 10ElseSs = Ss(n - 1) + 2End IfEnd FunctionPrivate Sub Form_click()Dim r%, x%r = 5x = Ss(5)Print "第5个小孩的岁数为:"; xEnd Sub第七章应用程序界面设计一、选择题BCDCA CDBBD CADAA CADBD DAAAB CAA二、填空题1.form1.show unload form12.form2.show form1.hide3.属性方法事件4、工程属性工程属性5.子窗体主窗体6、keypress list(i) additem7.0 list1.listindex list1.listcount-18、1000 true time() 9、AA10、下拉式组合框、简单组合框和下拉式列表框第八章VB图形操作一、选择题DCCDA CDAAA BABBC CAAA二、填空题1、不会也不会 2.、Scaleheight Scalewidth3、(300,-150)4、右上5、twip6、0~157、B 8、-2π~09、逆10、drawwidth11、右上12、move13、cls 14、坐标原点、坐标度量单位、坐标轴的长度与方向15、VB程序设计vbprogramming三、编程题1、Private Sub Command1_Click()Const pi = 3.14159P1.Circle (Val(Text1), Val(Text2)), Val(Text3)End SubPrivate Sub Command2_Click()P1.ClsText1 = ""Text2 = ""Text3 = ""End Sub2、Private Sub Form_Load()Pic1.Picture = LoadPicture("F:\VB程序设计\上课课件\tea.jpg")End SubPrivate Sub Pic1_Click()Pic2.Picture = Pic1.PicturePic1.Picture = LoadPicture("")End Sub3、Dim a1!, b1!Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) a1 = Xb1 = YEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Circle (a1, b1), Sqr((a1 - X) ^ 2 + (b1 - Y) ^ 2)End Sub4、Dim a1!, b1!Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Thena1 = Xb1 = YEnd IfEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 ThenLine (a1, b1)-(X, Y), vbGreen, BFEnd IfEnd Sub5、Private Sub Form_Click()Scale (-200, 200)-(200, -200)Dim i!For i = 0 To 140 Step 20Line (-i - 10, i + 10)-(i + 10, -i - 10), , BNext iEnd Sub第9章vb文件操作一、选择题BDDCC BBAAB二、填空题1、驱动器列表框、目录列表框和文件列表框2、change 3\file1.path=dir1.path4、name “D:\old.doc” as “c:\new.doc”5、dir1.path=drive1.drive file1.path=dir1.path6、filecopy “d:\text.doc”,”e:\text.doc”7、eof 8、input not eof(1)9、for inputFor outputnot eof(1)str1Close #110、pattern 11、空12、字节。
第6-10章 VB课后参考答案
第6章习题参考答案一、判断题题号 1 2 3 4 5 6答案√√×√√×二、选择题题号 1 2 3 4 5答案 D C A D B三、程序填空题1.(1)nsp=true(2) m mod i=0(3) p1 and p2(4) p1=nsp(i)2.(1)number(i,7)(2) (int n, int m)(3) number=number*10+m四、程序阅读1. a=9 b=42.(1) 362516941(2)1499413.64. 1 4 6五、编写程序1.Public Function fact(x As Integer) As Single '求x!Dim f As Single, i As Integerf = 1For i = 1 To xf = f * i '累积Next ifact = fEnd FunctionPrivate Sub Form_Click()Dim n%, m%, y!Dom% = Val(InputBox("m="))n% = Val(InputBox("n="))Loop Until m >= n And n >= 0y = fact(m) / (fact(n) * fact(m - n))Print yEnd Sub2 private sub Insertfun(a%(), y%)Dim i as integer,n as integern=ubound(a)Redim preserve a(n+1)For i=ubound(a)-1 to 0 step -1If y <a(i) thena(i+1)=a(i)If i=0 then a(i)=yElsea(i+1)=yexit forend ifnext i3. '判断是否为回文函数Private Function Judge(str As String) As BooleanDim i As IntegerJudge = True '假设为回文For i = 1 To Len(str) \ 2 '依次判断对应位置的两个字符,只要有一组不等即不是回文If Mid(str, i, 1) <> Mid(str, Len(str) + 1 - i, 1) ThenJudge = FalseExit FunctionEnd IfNext iEnd Function4.Private Sub Form_Click()Dim n%,x!n = Val(InputBox("n="))x = Val(InputBox("x="))Print fe(n, x) '调用求值函数过程End Sub'求值函数过程Public Function fe(n%, x!) As SingleDim i As Integer, t As Singlefe = 1: t = 1For i = 1 To nt = t * x / i 't为通项fe = fe + tNext iEnd Function5.。
vb6.0练习题及答案
vb6.0练习题及答案第一篇:vb6.0练习题及答案一、选择题1.在设计应用程序时,可以查看到应用程序工程中的所有部分的窗口是()。
A.窗体设计.代码C.属性D.工程资源管理器窗口 >> 答案:d2.窗体的Load事件的触发时机是()。
A.用户单击窗体时B.窗体被加载时C.窗体显示之后D.窗口被卸载时 >> 答案:b3.与传统的程序设计语言相比,Visual Basuc最突出的特点是()。
A.结构化程序设计B.程序开发环境C.事件驱动编程机制D.程序调试技术答案:C4.VB6.0集成开发环境的主窗口不包括()。
A.标题栏 B.菜单栏 C.状态栏 D.工具栏答案:c5.如果对象的名称为Mytext,而且对象有一个属性Text,那么在代码中引用该属性的正确格式是()。
A.T ext.Mytext B.Mytext.text C.Mytext.(Text)D.Mytext*Text答案:b6.下列可以激活属性窗口的操作是()。
A.用鼠标双击窗体的任何部位B.执行“工程”菜单中的“属性窗口”命令 C.按Ctrl+F4 D.按F4键答案: b d7.假定已在窗体上画了多个控件,并有一个控件是活动的,为了在属性窗口中设置窗体的属性,预先应制造的操作是()。
A.单击窗体上没有控件的地方 B.单击任一个控件 C.不执行任何操作 D.双击窗体的标题栏答案:a8.如果在文本框中键入字符时,只显示某个字符,如星号(*),应设置文本框的()属性。
A.Caption B.PasswordChar C.Text D.Char答案:b9.如果想让文本框中的内容在运行时不能编辑,需将文本框的()属性设置为True。
A.Locked B.MultiLine C.TabStop D.Visible答案:a10.对于定时器(Timer)控件,设计其定时是否开启的属性是()。
A.Index B.Tag C.Enabled D.Left答案:c11.要在窗体Form1内显示“myfrm”,使用的语句是()。
最新VB程序设计课后习题答案资料
VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。
2、当正常安装VB6.0后,误把Windows子目录删除。
当重新安装Windows后,是否需要再次安装VB6.0 ?答:要重新安装的。
因为安装VB6.0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6.0。
3、Visual Basic 6.0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本。
4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。
5、Visual Basic 6.0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图”一>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码”按钮。
6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。
试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存。
先保存窗体文件(.frm),再保存工程文件(.vbp)。
若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。
7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB98& 安装Visual Basic 6.0后,帮助系统是否也已安装?答:没有。
VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。
9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。
VB 课后习题参考答案
第1章 习题参考答案一、思考题 略二、选择题1. C2. B第2章 习题参考答案一、判断题二、填空题1. 窗体font2. 不能在代码中设置 3. selstart 4. Locked5. TabIndex 、 0 6. vbModal 或 17. Activate 、 Deactivate 8.PictureBox 和 Frame -三、选择题第3章 习题参考答案一、思考题1、double2、 xyC@abc , 15eyd , Is , #END X8[P]3、变量有 (1) (4) (6) (8),常量有 (2)字符串型 (3)逻辑型 (5)字符串型 (7)字符串型 (9)日期型 (10)实型 4、 fe d cb a++5、 (1) 26 (2) 3.75 (3) 36、写出下列Visual Basic 表达式的值:(1) False (2) True (3) True (4) False (5) True(6) True (7) False (8) False7、将下列命题用Visual Basic布尔表达式表示:(1) z>x and z>y (2) abs(a)<=abs(b+2) or a > b+2(3) p mod q=0 (4) x<-5 or x>-2 and x<2 or x>5(5) x<z and y>z or x>z and y<z (6) a<b and a mod 2=08、写出下列函数的值:(1) -4 (2) 换行符(3) –3 (4) -1 (5) hello(6) ello (7) 16 (8) “-459.65” (9) 5二、填空题1.整型、长整型、双精度型、双精度型2.(X mod 10)*10+X\103.sin(1/4*3.14)+sqr(x+2*exp(y))/abs(x-y)4.(a+b)/(c*d-sqr(1-a^2))5.x mod 5=0 or x mod 9=06.False7.-3 、 2 、-2 、 28.CDEF9.x>0 and y>0 or x<0 and y<0 或x*y>010.s>=”A” and s<=”Z” or s>=”a” and s<=”z”三、选择题四、编程题1、Private Sub Form_Click()Dim x%, Ten%, hundred%x = Val(Text1.Text)Ten = (x \ 10) Mod 10hundred = x \ 100Print "百位数是: " & hundredPrint "十位数是: " & TenEnd Sub2Private Sub Form_Click()Dim char As String * 1Form1.CurrentX = Rnd * Form1.ScaleWidthForm1.CurrentY = Rnd * Form1.ScaleHeightchar = Chr(Int(Rnd * 16) + 65)Print charEnd Sub第4章习题参考答案一、判断题二、选择题三、程序阅读写出下列各段程序执行后的输出结果。
计算机VB第6章课后参考答案思考题与习题
第6章思考题与习题一.思考题(解略)1.在Windows程序中,用户和计算机程序的交互过程主要表现在哪些方面?在VB中是通过什么途径提供用户交互的?2.如何实现弹出式菜单的设计和执行?3.在这本章我们介绍了剪切板的一些概念,如何在VB程序中使用剪切板?如果不是文本文件,那么应该如何使用剪切板?4.在键盘事件中,KeyPress和KeyDown及KeyUp之间有什么区别?在什么情况下使用KeyPress事件?5.如何确定鼠标是哪个按钮被按下?如果多个程序都使用鼠标,系统应该如何设计?6.如果需要编写一个程序,判断输入的单词是否是VB的关键字,那么应当如何设计这个程序?二.填空题1.mouseup*2.产生对象.Dragover事件*3.一个对象的DragMode属性要么是1,要么是0,它在属性窗口或程序代码中被设置。
4.MouseMove5.指针类型,17 996,Shift*7.拖放8.move9.KeyPress,对应按键的ASCII码。
KeyDown或KeyUp,Shift10.Click,当前窗体的输出位置11.右键,菜单12.AL T13.Visible,Enabled14.Click,115.Enabled False16.连接符”-”17.518.Clipboard.Clear19.文本,Clipboard.GetText20.PopupMenu,Call PopupMenu 菜单名称上机实验一.在一个窗体上放置一个文本框,向该文本框输入0~15(其他数提示为输入错误,要求重新输入),根据在文本框中的数字显示不同的鼠标指针。
Private Sub Text1_Change()If V al(Text1.Text) >= 0 And V al(Text1.Text) <= 15 ThenMe.MousePointer = V al(Text1.Text)ElseMsgBox "数据输入错误,请输入0-15的数"Text1.SelStart = 0Text1.SelLength = Len(Text1.Text)End IfEnd Sub二.设计一个程序,从键盘上读入一个字符,如果是在0~9,a~z之间,直接存入该字符到窗口中的文本框中,并给出它们对应的ASCII码,如果是A~Z,则将其转换为小写后在文本框中显示原来的字符和转换后小写的字符及其ASCII码,如果是其他字符,直接在文本框中显示提示信息“您输入亚的是字母和数字以外的符号”。
VB程序设计课后习题答案
VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。
2、当正常安装VB6。
0后,误把Windows子目录删除。
当重新安装Windows后,是否需要再次安装VB6。
0?答:要重新安装的。
因为安装VB6。
0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6。
0。
3、Visual Basic 6。
0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本.4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。
5、Visual Basic 6。
0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图"—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码"按钮。
6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。
试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存.先保存窗体文件(.frm),再保存工程文件(.vbp)。
若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。
7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6。
0后,帮助系统是否也已安装?答:没有。
VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。
9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。
vb课后习题答案(红色参考书)
第一章VB开发环境与VB概述习题答案习题一、选择题1. B2. A3. A4. B5. D6. B7 A.8. A9. C10.B11. C12. D13. A14. D第二章常用控件与界面设计习题答案习题一、选择题1. C2.B3.C4.A5.A6.B7.B8.B9.C 10.C 11.B 12.B 13.D 14.A 15.B 16.B 17.B 18.C 19.C 20.D21.B 22.B 23.B 24.C 25.C26.C27. A28. B29.B 30.C 31.B 32.C 33.B 34.B35.D 36.B 37.D 38.D 39.B40.A 41.B 42.A 43.B44.B 45.D 46.A 47.A 48.B49.D 50.C 51.D 52.D 53.C54.D 55.D 56.C 57.A 58.C 59.C 60.B 61.B第三章实验与习题实验实验3_1‘算术运算Private Sub Command1_Click()Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6Dim x As Single, y As Single, z As Single, m As Singlex = 2: y = 1: z = 1: m = 1List1.ClearList1.AddItem a / (b + c / b)List1.AddItem (x + Sqr(x ^ 2 + 1)) ^ (1 / 3)List1.AddItem ((2 * y) / (a * x + b * y) * (a * x - b * y))List1.AddItem 1 + 1 / (1 + 1 / m)List1.AddItem 1 / 2 * (d / 3) ^ (2 * x)List1.AddItem Log(y + Cos(x) ^ 2)List1.AddItem Abs((Exp(x) + Sin(x) ^ 3) / (x + y))List1.AddItem Log((Exp(x * y) + Abs(1 / Tan(z) + Cos(x) ^ 3)) / (x + y - z))List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10)) / Sqr(x + y + 1)List1.AddItem Log(a) / Log(b)End Sub‘关系运算Private Sub Command2_Click()List1.ClearList1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12)List1.AddItem "ABCRG" >= "abcde"List1.AddItem Int(134.69) >= CInt(134.9)List1.AddItem 78.9 / 32.77 <= 97.5 / 43.87 And -45.4 > -4.98List1.AddItem Str(32.345) = CStr(32.345)End Sub‘逻辑运算Private Sub Command3_Click()Dim x As Integer, y As IntegerDim C1 As Integer, C2 As Integer, C3 As IntegerC1 = 70: C2 = 80: C3 = 90x = 9: y = -2List1.ClearList1.AddItem x + y < 10 And x - y > 0List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)List1.AddItem x = 0 Xor y = 0List1.AddItem C1 + C2 + C3 >= 255 Or C1 > 90 And C2 > 90 And C3 > 80End Sub实验3_2略实验3_3略实验3_4‘零售结算Private Sub Command1_Click()Dim dj As Single, sl As Single, je As Single, n As IntegerLabel1.Caption = "金额:"dj = InputBox("请输入商品的单价:", "单价框")sl = InputBox("请输入商品的数量:", "数量框", 1)je = dj * sln = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果")If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"End Sub‘产生随机数Private Sub Command2_Click()Dim m As Integer, n As IntegerDim x1 As Integer, x2 As Integer, x3 As Integerm = Val(Text1.Text): n = Text2.TextRandomizex1 = Int(Rnd * (n - m + 1) + m)x2 = Int(Rnd * (n - m + 1) + m)x3 = Int(Rnd * (n - m + 1) + m)Label4.Caption = "结果为:" & Str(x1) & Str(x2) & Str(x3)End Sub‘求逆序数Private Sub Command3_Click()Dim a As Integer, h As Integer, t As Integer, n As IntegerRandomizea = Int(Rnd * (999 - 100 + 1) + 100)h = Mid(CStr(a), 1, 1)t = Mid(CStr(a), 2, 1)n = Right(CStr(a), 1)Label5.Caption = a & "-->" & Format(n * 100 + t * 10 + h, "000")End Sub实验3_5略习题选择题1.D2.B3.B4.D5.B6.D7.D8.B9.C 10.A11.D 12.D 13.D 14.C15.D16.D17B18.A19.D20.B21.D 22.C 23.D 24.A 25.A 26.B 27.A 28.A 29.C 30.A31.B 32.C 33.A 34.D 35.A 36.B 37.B38.B39.C40.D41.B42.C43.B44.D 45.C 46.C 47.A 48.D 49.B 50.A51.C 52.B 53.D 54.D 55.D56.DA7.B58.A59.A60.A61.B62.B 63.C 64.A 65.B 66.B 67.D 68.A 69.A 70.A 71.C72.B 73.B 74.D75.D 76.C 77.B 78.D 79.A 80.D 81.C 82.B 83.D 84.B 85.B 86.B 87.A 88.D 89.C填空题1、2 -32768~327672、整型长整型单精度双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))x>0 And y>0 Or x<0 And y<0c>=”a” And c<=”z” Or c>=”A” And c<=”Z”x>=10 And x<20x<z Xor y<z5、False 2 True False True True True True6、188 200100 68.56 8765547、a=1 b=1a=2 b=1a=3 b=1a=4 b=18、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =09、He Said, “Good morning”. 10、EDEF11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))12、a+b+c+d (a+b+c+d)/4 sum aver13、(f-2*h)/2 (4*h-f)/2简答题1、略2、Private Sub Form_Click()Const g = 9.8Dim V0 As Single, t As SingleDim S As SingleV0 = InputBox("请输入V0的值:")t = InputBox("请输入时间t的值:")S = (1 / 2) * g * t ^ 2 + V0 * tMsgBox ("位移量为:" & S)End Sub3、Private Sub Command1_Click()Dim l As Single, w As Single, h As SingleDim s As Singlel = Text1.Textw = Text2.Texth = Text3.Texts = (l * w + l * h + w * h) * 2Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1 方法一:x<=5 ; y 方法二:Is<=2 ;Case Else实验4-2 Shape1.BackColor=vbRed; Inter=15; Inter=Inter-1; Inter 实验4-3 b<c b=a a=k实验4-4 方法二:s*n ; t/s<10^-5实验4-5 方法一:m>=10^-4 ; (-1)^(n+1)*m实验4-6 x2=x3 ; <10^-6实验4-7实验4-8 i+2*j+5*k=10 ; n实验4-9 题目一:a) 5 b)i=16 p=12 n=5 c)i=9 p=8 n=1 题目二:120 10实验4-10 N=1 ;S=N& "*3 " & "+1 "实验4-11 Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St实验4-12 i\100 ; (i Mod 100)\10习题一、选择题1.C2.C3.A4.D5.A6.B7.B8.D9.B二、填空题1.Is=0 ; 1 To 10 ; Is >10 2. 9 3. 3 ; 4 15 4. this is a book ;This Is A Book 5. 3 ; 3 ; 3 5 6. 32 0 7. 4 8. 15 19. 1 ; 401 ;104 10. 1 2 3 ;1 3; 1 11. (3)12. 2 0 24 13. 10 14 14. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False 16. abs(t)<10^(-7) ; s+t17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1) S=S+118. Mid(n,i,1)>Mid(n,i+1,1) 19. "输入n";N/I=0 ;Print I第五章数组实验5_1 Int(90 * Rnd) + 10 a(i) = a(21 - i) a(21 - i) = t5_2 k = x Mod 10 i = i + 15_3 s5_4 max < a(i, j) row = I col = j5_5 1 ReDim Preserve prime(m) prime(j)5_6 d Mod 25_7 Exit For a(j + 1) = a(j)5_8 N – I A(j) = A(j + 1)5_9 A(i, 1) J Min = Max Not Flag5_10 ch >= "0" And ch <= "9" P = P & ch ReDim Preserve C(k)5_11 Private Sub Form_Click()Dim x As Integer, i As Integer, k As Integer, j As IntegerDim a() As Integerx = InputBox("输入正整数x=")i = 2Print x; "的质因子为:";Do While x >= iIf x Mod i = 0 Thenk = k + 1ReDim Preserve a(k)a(k) = ix = x \ iElsei = i + 1End IfLoopFor j = 1 To UBound(a)Print a(j);Next jEnd Sub习题一选择题1.A2.C3.D4.C5.B6.D7.D8.B9.D 10.B 11.B 12.D二填空题1. Variant2. ReDim A(N) A(1) If M < A(I) Then M = A(I)3. Int(26 * Rnd) + 65 Chr(t) i + 1 To 10 A(i) > A(j)4. InStr(s, ",") Right(s, Len(s) - n) s5. 4 5 6 6 5 4 3 2 16. T – 1 I + 17. k = 6 - i – j max = m 8. j = a j = j - 39. i + 1 i = i + 1 10. 2 3 7三编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("ê?è?m")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IFor I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As Integer Dim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopLoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As Integer A(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IText3.Text = SEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = Val(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub第六章参考答案实验实验6-11、Exit Do2、Y(X)3、X >= -1实验6-2 【题目二】42 、26、8实验6-3 1、s1, key 2、s As String 3、ch >= "a" And ch <= "z"4、Mid(s, i, 1) = Chr(Asc(ch) + k - 26)思考:解密函数Private Sub dec(s As String, k As Integer) '解密过程Dim i As Integer, ch As String * 1For i = 1 To Len(s)ch = Mid(s, i, 1)If "A" <= ch And ch <= "Z" ThenIf Asc(ch) - k < Asc("A") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfElseIf ch >= "a" And ch <= "z" Then '多分支格式,ch介于小写a与z之间If Asc(ch) - k < Asc("a") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfEnd IfNext iEnd Sub实验6-41、b() As Integer, st As String2、L <= R3、ReDim Preserve b(R)4、L = L + 1辗转相除法求最大公约数函数Private Function Gcd(ByVal p As Integer, ByVal q As Integer) As IntegerDim r As Integerr = p Mod qDo While r <> 0p = qq = rr = p Mod qLoopGcd = qEnd Function实验6-5 【题目一】age = age(n - 1) - 3【题目二】1、(Left + Right) / 2 2、Left = Mid + 1实验6-6 1、3 -1 2、7 4 3、3 -1 4、7 0 实验6-7 【题目一】1、Sqr(2 + t) 2、Abs(a - 1) < eps【题目二】1、Dim X As Integer 2、"S(" & I & ")=" & S(I)3、(j * i + 1)习题参考答案一选择题1.B2.D3.C4.C5.C6.B7.B8.B9.A 10.D 11.D 12.A 13.A 14.A 15.B 16.B 17.D18.C19.D20.B21.C 22.C 23.B 24.A 25.D 26.D 27.A 28.B二、填空1(1)形式、(2)实在2(1)按地址传递、(2)ByVal3(1)窗体模块、(2)标准模块、(3)类模块4(1) 6 5(1)4 20 1016(1) 6 26 、(2)-2 987(1)10 6 、(2) 5 -58(1) 6 5 、(2)8 79(1)11 、(2)710(1)Fun(i) 、(2)Fun=p11(1) 4 、(2)20.712(1)29 、(2)28.713(1)k = j 、(2)b() As Integer14(1)gec 、(2)ge 、(3) 315(1)p1 = True And p2 = True 或p1 And p2 、(2)p1 = p2 –2 、(3)Isp = True 、(4)m Mod i = 016(1)Convert(st) 、(2)Len(s) 、(3)"A" To "F" 、(4)k = k + p * h17(1)isualVi 、(2)sualVisu18(1)s + a 、(2)n + 1 、(3)x As Single, n As Integer 、(4)p * (x + i) / ((2 * i - 1) * i * x)三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean Dim K As IntegerReDim A(1)A(1) = 50———————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean) Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As Integer Dim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByVal idx As Integer Dim Ub As Integer, Counter As Integer, K As IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub5、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1、编程验证任一大于2的偶数可以表示成两个素数之和。
VB课后习题答案汇总
课后习题参考答案第1章Visual Basic 6.0一、判断题1--5:√×√×√6――10:××√×√11――13:√××二、选择题1――5:ADBBB 6――10:.CACDB三、填空题1、图片框和框架2、对象3、控件屏幕4、Load5、Load Activate四、程序设计题1、Private Sub Command1_Click()Print Text1.TextEnd SubPrivate Sub Command2_Click()EndEnd Sub2、Private Sub Command1_Click()Form1.FontSize = Form1.FontSize + 3Print "青春无悔"End SubPrivate Sub Command2_Click()FontSize = FontSize - 3Print "青春无悔"End SubPrivate Sub Command3_Click()Form1.FontBold = TruePrint "青春无悔"End SubPrivate Sub Command4_Click()FontBold = FalsePrint "青春无悔"End Sub3、Private Sub Command1_Click()Text1.Visible = FalseEnd SubPrivate Sub Command2_Click()Text1.Visible = TrueText1.FontName = "楷体_gb2312"Text1.FontSize = 15Text1.Text = "我学会了创建一个应用程序了!"End Sub第二章判断题:1~5错错错错错第3章顺序结构程序设计一、思考题略二、程序阅读题1.A=2 B=1 C=22.123.BABCBACBC4. 1 2 False5.1-12-123-1234-三、选择题1.B2.D3.B4.B5.D6.C四、程序设计题1.Private sub form_click()Dim r!,s!R=val(inputbox(“r=”))S=3.14159*r*rPrint “s=”;sEnd sub2.Private sub form_click() Dim x as singleX=val(inputbox(“x=”))Print fix(x*x*1000)/1000,fix(sqr(x)*1000)/1000End sub第4章选择结构程序设计一、判断题1.错2.错3.错4.错5.对二、选择题1.A 2. D 3.A 4.B 5.A 6.A三、程序阅读题1.X=3 y=72.w=4w=13w=135w=313.X_`a12 Uvw&4.12 9四、程序填空题1.(1) chr(keyascii) (2) chr(keyascii)=”)” (3)count1=count1-1 (4)count1=0 (5)count1>02.(1) max (2)min (3)c>max (4)c<min3.(1)x mod 3=2 and x mod 5=3 and x mod 7=4 then(2)text1.setfocus (3) text1.selstrat=0 (4)text1.sellength=len(text1.text)五、1.Private Sub Command1_Click()Dim y As Integery = Val(InputBox("y="))If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Print "是闰年"ElsePrint "不是闰年"End IfEnd SubPrivate Sub Command1_Click()Dim y As Integer,y1 as stringy = Val(InputBox("y="))If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Y1= "是闰年"ElseY1= "不是闰年"End If? y,y1End SubPrivate Sub Command1_Click()Dim y As Integer,y1 as stringy = Val(InputBox("y="))Y1= "不是闰年"If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Y1= "是闰年"End If? y,y1End Sub2.Private Sub Command1_Click()Dim a%, b%, c%, x!,s!a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c="))If a + b > c And a + c > b And b + c > a Thenx = (a + b + c) / 2s = Sqr(x * (x - a) * (x - b) * (x - c))Print "s="; sElsePrint "不是三角形,重输a,b,c"End IfEnd SubPrivate Sub Command1_Click()Dim a%, b%, c%, x!,s!,t%a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c=")) ‘a,b,c=3,4,5t=0If a + b > c And a + c > b And b + c > a Thenx = (a + b + c) / 2s = Sqr(x * (x - a) * (x - b) * (x - c))t=1End IfIf t=0 then“不是“endifEnd Sub3.Private Sub Command1_Click()Dim x!, y!x = Val(InputBox("x="))y = x * x - x – xIf x < 0 And x <> -3 Theny = x * x + x - 6ElseIf 0 <= x And x < 10 And x <> 2 And x <> 3 Then y = x * x - 5 * x + 6End IfPrint "x="; x, "y="; yEnd SubPrivate Sub Command1_Click()Dim x!, y!x = Val(InputBox("x="))If x < 0 And x <> -3 Theny = x * x + x – 6elseIf 0 <= x And x < 10 And x <> 2 And x <> 3 Theny = x * x - 5 * x + 6elsey=x^2-x-1End IfPrint "x="; x, "y="; yEnd SubPrivate sub form_click()Dim y%,z%,dj%,p!,t!Y=val(inputbox(“月”))Z= val(inputbox(“订票数”))Dj= val(inputbox(“票价”))Select case ycase 7,8,9If z>=20 then p=0.15 else p=0.05case 1 to 5,10,11If z>20 then p=0.3 else p=0.2Case elseP=0.2End selectT=z*dj*p? tend sub5.private sub form_click()dim m1%,m2%,m3%,dj$m1=val(inputbox(“m1=”)): m2=val(inputbox(“m2=”)): m3=val(inputbox(“m3=”))if (m1+m2+m3)/3>=95 or ( a=100 and b=100 and c>=80) or ( a=100 and c=100 and b>=80) or ( c=100and b=100 and a>=80) thendj=”一等”elseif (m1+m2+m3)/3>=90 or ( a=100 and b>=75 and c>=75) or ( b=100 and a>=75 and c>=75) or ( c=100 and b>=75 and a>=75) thendj=”二等”elseif a>=75 and b>=75 and c>=75 then dj=”三等” else dj=”没有” endif ? “dj=”;dj end sub第5章 循环结构程序设计1.判断题×√√√××√×2.选择题BBBBCC 3.填空题(1)7(2)Do/Loop For/Next While/Wend (3)-364.程序阅读题(1) (2)(3)4 (4)5.程序填空题(1)①sign=1 ②For i=2 to 19(2)①Len(str1) ②length-1 ③Mid(str1,i,2) ④Sum=0(3)①I mod 7=5 and i Mod 5 = 3 And i Mod 3=2 ②i<1000(4)①last_one = last_two ②last_two = this_one ③i=i+1 ④i-2(5)①I>int(sqr(m)) ②Int(Sqr(n-m))6.编程题(1)Private Sub Form_Click()Dim i As Integer, j As IntegerDim s As Double, Sum As Doubles = 188688646886424688642 1 2 3 4Sum=10# # # # # ## # # # ## # # ## # ## ##For i = 1 To 11 Step 2For j = 1 To is = s * jNext jSum = Sum + sNext iPrint SumEnd Sub(2)Private Sub Form_Click()Dim m%, n%, mn%, r%, t%m = Val(InputBox("m="))n = Val(InputBox("n="))If n <= 0 Or m <= 0 ThenMsgBox "数据有误"EndEnd Ifmn = m * nIf m < n Thent = m: m = n: n = tEnd IfDo While (n <> 0)r = m Mod n: m = n: n = rLoopForm1.Print "最大公约数="; mForm1.Print "最小公倍数="; mn / m End Sub(3)Private Sub Form_Click()Dim i%, j%For i = 1 To 5Print Spc(20 - i);For j = 1 To 2 * i - 1Print Trim(Str(i));Next jPrintNext iFor i = 4 To 1 Step -1Print Spc(20 - i);For j = 1 To 2 * i - 1Print Trim(Str(10 - i));PrintNext iEnd Sub(4)Private Sub Form_Click()Dim x As IntegerDim y As IntegerDim z As IntegerFor x = 0 To 100For y = 0 To 100 - xz = 100 - x - yIf 5 * x + 3 * y + z / 3 = 100 Then Print x, y, zNext yNext xEnd Sub(5)Private Sub Form_Click()Dim x As Single, y As Single, a As Single, i As Integerx = Val(InputBox("输入x:"))a = 1: y = a: i = 0While a >= 0.00001i = i + 1: a = a * x / i: y = y + aWendPrint "y="; yEnd Sub第六章答案一、判断题1.错2.错3.错4.错(可以为小数,不过仍然是当作整数来处理)5.错6.错二、选择题1.C2.C3.A4.D三、程序填空1.(1)N-1 (2)T = A(J): A(J) = A(J + 1): A(J + 1) = T(3)Print A(I)2.(1)a(i, j) = 1(2)Print四、程序阅读1.52.1 2 3 41 2 3 41 2 3 41 2 3 41 1 1 12 2 2 23 3 3 34 4 4 43.(前面空4个空格)1 12 11 102 13 16 93 14 15 84 5 6 7第7章过程判断题:1、对2、错3、错4、错5、对6、对7、错选择题:1.B 2、D 3、D 4、C 5、A程序阅读题:1、y=5 a=52、n=1z=4y=15 a=10n=2z=7y=30 a=15n=3z=103、32 644、2 2 216648644645、A1=10 B1=20A2=20 B2=10程序填空题:1、(1)hwstring(str) (2)"" (3)As Boolean(4)n=len(strtxt) (5) True (6)False2.(1)Xsch(Nman,Nkcen) (2)n(3)sum=sum+x(i,j) (4)tt/n (5)x(i,m+1)<1.2*ver and x(i,m+1)>=1.1*ver 3.(1)number(i)(2)Byval n as Integer (3)number= number+7*10^ (i-1)4.(1)temp=1 (2)temp (3)nFactor( i ) (4)sum 程序设计题:1、具体程序为:Function Maxnum(ByRef a() As Integer, ByVal n As Integer) As IntegerDim i As IntegerMaxnum = a(1)For i = 2 To nIf a(i) > Maxnum Then Maxnum = a(i)Next iEnd FunctionFunction Avenu(ByRef a() As Integer, ByVal n As Integer) As SingleDim i As Integer, sum As IntegerFor i = 1 To nsum = sum + a(i)Next iAvenu = sum / nEnd FunctionSub Sortrnum(ByRef a() As Integer, ByVal n As Integer)Dim i As Integer, j As Integer, k As IntegerDim temp As IntegerFor i = 1 To nk = iFor j = i + 1 To nIf a(k) > a(j) Then k = jNext jIf i <> k Thentemp = a(i)a(i) = a(k)a(k) = tempEnd IfNext iEnd SubPrivate Sub Form_Click()Dim b(10) As Integer, i As IntegerFor i = 1 To 10b(i) = InputBox("请输入整数", "输入")Next iCall Sortrnum(b(), 10)Print "从小到大排序为:"For i = 1 To 10Print b(i);NextPrintPrint "最大数为:"; Maxnum(b(), 10)Print "平均数为:"; Avenu(b(), 10)End Sub2、具体程序为:Function fe(n%, x!) As SingleDim temp As Single, i As Integerfe = 1temp = 1For i = 1 To ntemp = temp * x / ife = fe + tempNext iEnd FunctionPrivate Sub Form_Click()Dim n As Integer, x As Singlen = Val(InputBox("请输入n", "输入"))x = Val(InputBox("请输入x", "输入"))Print "e的值为:"; fe(n, x)End Sub3、具体程序为:Sub sort(a() As Single, n As Integer)Dim i As Integer, j As Integer, k As Integer Dim temp As SingleFor i = 1 To nk = iFor j = i + 1 To nIf a(k) < a(j) Then k = jNext jIf i <> k Thentemp = a(i)a(i) = a(k)a(k) = tempEnd IfNext iEnd SubPrivate Sub Form_Click()Dim a(10) As Single, i As IntegerFor i = 1 To 10a(i) = Val(InputBox("请输入数据", "输入")) Next iCall sort(a(), 10)Print "从大到小为:"For i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext iEnd Sub第8章常用控件参考答案:一、判断题1、×2、×3、√4、√5、×6、×7、×8、×9、× 10、×11、× 12、√ 13、× 14、√ 15、√二、单选题1、A2、B3、A4、C5、B6、D7、A8、B9、C 10、C11、A 12、A 13、C 14、B 15、A三、填空题1、Autosize WordWrap2、Enabled Visible3、文本框和列表框4、拖动滚动框5、Change6、Command1.Setfocus7、Timer8、MaxLength 9、AddItem 10、定时器屏蔽12345.五、程序填空题1、(1) Label1.left (2) –Label1.Width2、(1) List1.ListIndex<0 (或者List1.ListIndex = -1)(2) List1.RemoveItem List1.ListIndex(3) Text1.Text=”” (4) List1.AddItem Text1.Text3、(1) 1 to 2*I-1 (2) Command2.Enabled=True(3) Command2.Enabled=False4、(1) ndec<>0 (2) ndec mod 16 (3) ai=ndec(4) end (5) ai & shex (6)shex5、(1) Timer1.Enabled=True (2) x \ 3600 (3) (x-h*3600)\60(4) x=x+16、(1) m<len(str1)/2 (2) mid (str1,m+1,1) (3)mid (str1,len(str1)-m,1)六、程序设计题1、P rivate Sub Command1_Click()If Text1.Text = "" ThenMsgBox "请先输入添加项"ElseList1.AddItem Text1.TextEnd IfEnd SubPrivate Sub Command2_Click()If List1.ListIndex < 0 Then ‘或者if list1.listindex=-1 then MsgBox "请选择一删除项"ElseList1.RemoveItem List1.ListIndexEnd IfEnd SubPrivate Sub Command3_Click()If List1.ListIndex < 0 ThenMsgBox "请选择一修改项"ElseText1.Text = List1.TextEnd IfCommand4.Enabled = TrueEnd SubPrivate Sub Command4_Click()Dim a As IntegerIf List1.Text = Text1.Text ThenMsgBox "请先修改此项"Elsea = List1.ListIndexList1.RemoveItem List1.ListIndexList1.AddItem Text1.Text, aEnd IfEnd SubPrivate Sub Form_Load()Command4.Enabled = FalseEnd Sub2、D im a As IntegerPrivate Sub Command1_Click()a = Int(Rnd * 100) + 1End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Static i As IntegerIf KeyAscii = 13 ThenIf Val(Text1.Text) > a ThenLabel1.Caption = "太大了,请重输"i = i + 1ElseIf Val(Text1.Text) = a ThenLabel1.Caption = "恭喜你,你答对了!"i = 0Command1_ClickElseLabel1.Caption = "太小了,请重输!"i = i + 1End IfIf i > 10 ThenMsgBox "你失败了!"EndEnd IfEnd IfEnd Sub3、Private Sub Command1_Click()Dim n As Integer: n = Len(Text1.Text)Dim s(1 To 1000) As String, i As Integer, j As Integer, t AsString, a As StringFor i = 1 To ns(i) = Mid(Trim(Text1.Text), i, 1)Next iFor i = 1 To n - 1For j = i + 1 To nIf s(i) > s(j) Thent = s(i): s(i) = s(j): s(j) = tEnd IfNext j, iFor i = 1 To n: a = a + s(i): Next iPrint aCommand1.Enabled = False: Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click(): End: End SubPrivate Sub Form_Load()Text1.MaxLength = 200Command2.Enabled = False: Command1.Enabled = TrueEnd Sub4、Dim a(1 To 1000) As String, b(1 To 1000) As String, c(1 To 1000) As Double, d(1 To 1000) As DoublePrivate Sub Combo1_click()Text1.Text = a(Combo1.ListIndex + 1)Text2.Text = b(Combo1.ListIndex + 1)Text3.Text = c(Combo1.ListIndex + 1)Text4.Text = d(Combo1.ListIndex + 1)End SubPrivate Sub Command1_Click()Combo1.AddItem Text1.Texta(Combo1.ListCount) = Text1.Textb(Combo1.ListCount) = Text2.Textc(Combo1.ListCount) = Val(Text3.Text)d(Combo1.ListCount) = Val(Text4.Text)End SubPrivate Sub Command2_Click()For i = Combo1.ListIndex + 1 To Combo1.ListCount - 1a(i) = a(i + 1)b(i) = b(i + 1)c(i) = c(i + 1)d(i) = d(i + 1)Next ia(i) = ""b(i) = ""c(i) = 0d(i) = 0Combo1.RemoveItem Combo1.ListIndexText1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Form_Load()Dim i As IntegerCombo1.AddItem "张三"Combo1.AddItem "李四"Combo1.AddItem "王五"a(1) = "张三": a(2) = "李四": a(3) = "王五"b(1) = "浙江林学院": b(2) = "浙江工业大学": b(3) = "浙江大学"c(1) = 311300: c(2) = 310027: c(3) = 310014d(1) = 63742212: d(2) = 88394277: d(3) = 88326531End Sub5、Private Sub Check1_Click()If Check1.Value = 1 ThenLabel1.FontBold = TrueElseLabel1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check1.Value = 1 ThenLabel1.FontItalic = TrueElseLabel1.FontItalic = FalseEnd IfEnd SubPrivate Sub Option1_Click()Label1.FontName = "宋体"End SubPrivate Sub Option2_Click()Label1.FontName = "楷体_gb2312"End Sub6、Private Sub Command1_Click()Dim a As String, i As Integer, n As IntegerDim s As Integer, q As Integer, l As Integern = Len(Text1.Text)For i = 1 To na = Mid(Text1.Text, i, 1)If a >= "a" And a <= "z" Thens = s + 1 '大写个数ElseIf a >= "A" And a <= "Z" Thenq = q + 1 '小写个数ElseIf a >= "0" And a <= "9" Thenl = l + 1End IfNext iText2.Text = sText3.Text = qText4.Text = lEnd SubPrivate Sub Form_Load()Text1.SetFocusEnd Sub7、Private Sub Form_Click()Dim i As Integer, j As Integer, t As IntegerFor i = 0 To List1.ListCount - 1List3.AddItem List1.List(i)Next iList1.ClearDo While List2.ListCountList3.AddItem List2.List(0)List2.RemoveItem 0LoopFor i = 0 To List3.ListCount - 2For j = i + 1 To List3.ListCount - 1If List3.List(i) > List3.List(j) Thent = List3.List(i): List3.List(i) = List3.List(j): List3.List(j) = tEnd IfNext j, iEnd SubPrivate Sub Form_Load()Dim i As Integer, n As Integern = InputBox("")For i = 1 To nList1.AddItem Int(Rnd * 90) + 10List2.AddItem Int(Rnd * 90) + 10Next iEnd Sub第9章对话框和菜单1.判断题:×√√(题中应把flag改为flags)√√××√√× ××√××2.选择题:DDCCD BDCCB3.填空题1.-2.一级子菜单3.将顶级菜单设置为不可见4.popupmenu pmenu,0,x,y5.showfont6.工程、部件7.click8.代码窗口,click9.下拉式,弹出式打开/另存为、颜色,字体、打印、帮助4. 程序阅读题打开对话框2、*.txt3、allfiles*.exe*.txt*.doc4、Checking,No File Selectd,重试(R),取消5. 程序填空题“c:\winnt”commondialog1.showopen,loadpicture(commondialog1.filename)6. 程序设计题1、界面如图:代码如下:Private Sub Command1_Click()CommonDialog1.FileName = ""CommonDialog1.Flags = 4096CommonDialog1.Action = 1If CommonDialog1.FileName = "" ThenMsgBox "No File Selectd", 5 + vbExclamation, "Checking"ElseList1.AddItem CommonDialog1.FileNameEnd IfEnd Sub2、代码如下:Private Sub a_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub b_Click()CommonDialog1.Flags = 1CommonDialog1.ShowFontText1.FontSize = CommonDialog1.FontSizeEnd SubPrivate Sub c_Click()CommonDialog1.Flags = 1CommonDialog1.ShowFontText1.FontName = CommonDialog1.FontNameEnd SubPrivate Sub d_Click()EndEnd Sub第10章 图形操作和图形控件一、判断题×√×××√×√××二、选择题BAADACAA三、填空题(1)pic1.Circle (pic1.ScaleLeft + pic1.ScaleWidth / 2, pic1.ScaleTop + pic1.ScaleHeight / 2), 700(2)在图片框picture1中,以(800,1000)为圆心画一个半径为500的圆(3)Form1.Scale (-200, 250)-(300, -100)(4)Autosize stretch四、程序阅读题1、窗体宽和高的1/4为起点,画一个边长为1000的正方形,并画出其正向对角线2、在图片框中交替画出实心和空心的矩形,空心矩形是黄色边框。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
上海立信会计学院
班级:学号: 姓名:指导教师:
专业:
习题六p150
-、简述子过程与函数过程的共同点和不同之处。
答:相同之处:都是功能相对独立的一种子程序结构,它们有各自的过程头、变量声明和过程体,在程序的设计过程中可以提高效率。
不同之处:
(1)声明的关键字不同。
子过程为Sub,而函数过程为
Funct ion。
(2)了过程无值就无类型说明,函数过程有值因此有类型的说明
(3)函数的过程名称同时是结果变量,因此在函数过程体
内至少要对函数的过程名赋值一次数据,而子过程内不能赋
值。
(4)调用的方式不同,子过程是一条独立的语句,可以用
Cal I子过程名或省略Call直接以子过程名调用;函数的过
程不是一条独立的语句,是一个函数值,必须参与表达式运算。
(5)通常,函数过程可以被子过程代替,只需要在调用的
过程中改变一下过程调用的形式,并在子过程的形参表中增加一个地址传递的形参来传递结果。
二、什么是形参,实参?什么是值引用?地址引用?地址应用
对实参有什么限制?
答:形参:在定义过程时的一种假设的参数,只代表该过程的参数的个数、类型,它的名字不重要,没有任何的值, 只表示在过程体内将进行的一种操作。
实参:在调用子过程时提供过程形参的初始值,或通过过程体处理后的结果。
值引用:系统将实际参数的值传到形参之后,实参与形参断开联系,过程中对于形参的修改不会影响到实际参数的变化。
地址引用:实参与形参共同使用一个存储单元,在过程中对形参进行修改,则对应的实际参数也同时变化。
在地址引用时,实参只能是变量,不能是常量或表达式。
三、指出下面过程语句说明中的错误:
Sub f1 (n%) as Integer
Function f1%(f1%)
Sub fl (ByVa I n% 0)
Sub fl(X(i) as Integer)
答:(1) Sub子过程名没有返回值,因此就没有数据的类型
(2)函数名与形参名称相同
(3)形参n为数组,不允许声明为By Vai值传递
(4)形参x(i)不允许为数组元素
四、已知有如下求两个平方数和的fsum子过程:
Publ ic Sub fsum (sum%, ByVaI a%, ByVaI b%)
sum =a*a+b*b
End Sub
在事件过程中若有如下变量声明:
Pr ivate Sub Commandl Cl ick()
Dim a%, b%,
AHA12GAGGAGAGGAFFFFAFAF
a = 10:
b = 20
则指出如下过程调用语句的错误所在:
fusum 3, 4, 5
f sum c, a, b
f sum a + b, a, b
Cal I f sum (Sqr (c), Sqr (a), Sqr (b))
Cal I f sum c, a, b
答:(1) furm子过程的第一个形参是地址传递,因此对应的
实参3不能是常量
(2) furm的第一个形参是整型而且是地址传递,对应的实
参C是单精度,数据类型不匹配
(3) furm的第一个形参是地址传递,因此对应的实参a+b
不应当是表达式
(4)furm的第一个形参是地址传递,因此对应的实参Sqr (c) 不应当是表达式
(5)用Cal I语句调用furm子过程时,必须用圆括号来描
述实参
六、要使变量在某事件过程中保留值,有哪几种变量声明的方法?答:声明为static或者全局变量七、为了使某变量在所有的窗体中都能使用,应在何处声明该变量?
答:应在窗体\模块的通用声明段用Publ ic关键字声明为全
局变量。
八、在同一模块、不同过程中声明的相同变量名,两者是否表示同一个变量?两者之间有没有联系?答:不能作为同一个变量应用, 没任何联系,各自在过程中有效如有侵权请联系告知删除,感谢你们的配合!。