《vb期末考试程序设计的题目.doc》由会员分享,可在线阅读,更多相关《vb期末考试程序设计的题目.doc(7页珍藏版)》请在课桌文档上搜索。
1、word第一X:4. 设计一个程序,实现加、减、乘、除运算,当单击“加法命令按钮时,程序运行界面如图2.20所示。同样,单击其他命令按钮时,实现其他运算,等式中的运算符号要相应变化。代码如下: Private Sub mand1_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub mand2_Click()Text3.Text = Val(Text1.Text) - Val(Text2.Text)Label1.Caption = -End SubPrivate Sub mand3_Click()Text
2、3.Text = Val(Text1.Text) * Val(Text2.Text)Label1.Caption = *End SubPrivate Sub mand4_Click()Text3.Text = Val(Text1.Text) / Val(Text2.Text)Label1.Caption = End Sub第三章: 3. 计算如下分段函数值: 方法1) private sub mand1_click()Dim x As single ,y As singleX=val (Text 1.Text)If x.=-5 ThenY=x/2+(x*x+5)/(2*x)Else if x1
3、0 ThenY=(3*x)(1/3)Else if x=15 ThenY=log(x)Else Y=sin(x)2+cos(x)End ifText2.Text =str(y)End sub第四章:1. 将一个数组的元素按逆序重新存放,例如,原来存放顺序为:8,6,5,4,1。要求改为1,4,5,6,8。Option Base 1Private Sub Form_Click()Dim a()Dim t As Integera = Array(8, 6, 5, 4, 1)FontSize = 24For i = 1 To 5 Print a(; i; )=; a(i)Next iFor i =
4、1 To 5 2 t = a(i) a(i) = a(6 - i) a(6 - i) = tNext iPrint 逆序后For i = 1 To 5 Print a(; i; )=; a(i)Next iEnd Sub2. 利用随机函数,模拟投币结果。设共投币100次,求“两个正面、“ 两个反面、“一正一反3种情况各出现多少次?Private Sub Form_Click()Dim a(3) As Integer, x As Integer, y As Integera(1) = 0a(2) = 0a(3) = 0For i = 1 To 100Randomize x = Int(2 * R
5、nd) y = Int(2 * Rnd) If x = 0 And y = 0 Then 两个正面 a(1) = a(1) + 1 ElseIf x = 1 And y = 1 Then 两个反面 a(2) = a(2) + 1 Else 一正一反 a(3) = a(3) + 1 End IfNext iFontSize = 24Print 两个正面的次数; a(1)Print 两个反面的次数; a(2)Print 一正一反的次数; a(3)PrintEnd Sub第六章:1. 设计一个选课程序,其运行界面如图7.20所示。课程有两组:一是限选课,3门课中只能选一门;二是任选课,可以选多门。选
6、课后,单击“确认按钮,在右边的文本框中显示选课结果。Private Sub mand1_Click()If Option1.Value = True ThenElseIf Option2.Value = True ThenEnd IfIf Check1.Value = 1 ThenEnd IfIf Check2.Value = 1 ThenEnd IfIf Check3.Value = 1 ThenEnd IfEnd Sub3. 设计一个系统主窗体,其运行界面如图7.22所示,其中的“图书管理信息系统字样从右到左缓缓地循环移动,窗体背景图案可以任意指定。Private Sub Form_Loa
7、d()Form1.Picture = LoadPicture(c:tupiansky.jpg)Label1.Caption = 图书管理系统Label1.FontName = 隶书Label1.ForeColor = vbBlueLabel1.FontSize = 30Label1.FontItalic = TrueLabel1.BackStyle = 0Timer1.Interval = 100End SubPrivate Sub Timer1_Timer()If Label1.Left = Form1.Width ThenLabel1.Left = Label1.Left + 200Else Label1.Left = -3000End IfEnd Sub4.设计一个窗体,其运行界面如图7.23所示。窗口中有图像框、一个滚动条和一个文本框。滚动条变化X围是010,当单击滚动条时,图像框中图片的大小随之发生改变,且在文本框中显示滚动条的数值。图像框image1名称为im 滚动条 名称为 hPrivate Sub Form_Load()Im.Stretch = TrueH.Max = 10H.Min = 0Im.Picture = LoadPicture(c:1.jpg)End SubPrivate Sub H_Change()End Sub7 / 7