VB上机考试习题以及答案.doc

上传人:h**** 文档编号:1172361 上传时间:2018-12-15 格式:DOC 页数:10 大小:106.50KB
下载 相关 举报
VB上机考试习题以及答案.doc_第1页
第1页 / 共10页
VB上机考试习题以及答案.doc_第2页
第2页 / 共10页
VB上机考试习题以及答案.doc_第3页
第3页 / 共10页
VB上机考试习题以及答案.doc_第4页
第4页 / 共10页
VB上机考试习题以及答案.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、VB 上机考试1、利用随机函数产生 25 个 100 到 999 之间的整数,构成 55 的矩阵,输出该矩阵。Dim a(1 To 5, 1 To 5)Private Sub Form_Click()RandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * (999 - 100 + 1) + 100)Print a(i, j);Next jPrintNext iEnd Sub2、利用随机函数产生 25 个 10 到 99 之间的整数,求其平均值(要求保留 3 位小数,第 4 位四舍五入)。Private Sub Form_Click()F

2、or i = 1 To 25a = Int(Rnd * (99 - 10 + 1) + 10)Print a;s = s + aNext iPrintAvg = s / 25Print AvgEnd Sub3、在窗体上按下鼠标的右键,记录其坐标。Private Sub Form_Load()Label1.BorderStyle = 1Label1.Alignment = 2End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 2 Th

3、enLabel1.Caption = X Next iPrintFor i = 1 To 25 - 1For j = 1 To 25 - iIf a(j) a(j + 1) Then tmp = a(j): a(j) = a(j + 1): a(j + 1) = tmpNext jNext iFor i = 1 To 25Print a(i);Next iEnd Sub5、利用随机函数产生 50 个 1,6 之间的整数, 分别统计出 1 的个数,2 的个数,3 的个数,4 的个数,5 的个数和 6 的个数。Dim a(1 To 6)Private Sub Form_Click()For i =

4、 1 To 6a(i) = 0Next iFor j = 1 To 50x = Int(Rnd * (6 - 1 + 1) + 1)a(x) = a(x) + 1Next jFor i = 1 To 6Print i “次“Next iEnd Sub6、在文本框中输入一些英语单词,统计空格的个数。Dim n%, x As String, s%Private Sub Form_Click()n = Len(Text1.Text)x = Text1.TextFor i = 1 To nIf Mid(x, i, 1) = “ “ Then s = s + 1Next iPrint “共出现了“ ma

5、xPrint “在数组中是第“; loc; “个数“End Sub14、利用随机函数产生并显示 10 个 4 位数的正整数,找出其中的最小数。Option ExplicitDim i%, min%, loc%Dim a(1 To 10) As IntegerPrivate Sub Form_Click()RandomizeForm1.ClsFor i = 1 To 10a(i) = Int(Rnd * (9999 - 1000 + 1) + 1000)Print a(i)Next imin = 9999For i = 1 To 10If a(i) min Then min = a(i): lo

6、c = iNext iPrint “最小的数是“; minPrint “在数组中是第“; loc; “个数“End Sub15、当按下鼠标左键时,窗体的背景色变为红色;松开鼠标左键时,窗体的背景色变为绿色。Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 Then Form1.BackColor = vbRedEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Intege

7、r, X As Single, Y As Single)If Button = 1 Then Form1.BackColor = vbGreenEnd Sub16、编制一个时钟程序,如下图:Option ExplicitPrivate Sub Form_Load()Label1.BackColor = vbWhiteLabel1.BorderStyle = 1Label1.Alignment = 2Timer1.Enabled = TrueTimer1.Interval = 1000End SubPrivate Sub Timer1_Timer()Label1.Caption = TimeEn

8、d Sub17、从键盘输入 10 个数,按输入的顺序和按输入顺序相反的顺序输出。Option ExplicitDim i%Dim a(1 To 10) As SinglePrivate Sub Form_Click()For i = 1 To 10a(i) = Val(InputBox(“请输入第“ Next iPrintFor i = 10 To 1 Step -1Print a(i);Next iEnd Sub18、计算圆面积的程序。程序运行时,单击窗体,然后在下图所示的输入框中输入圆的半径,即可在窗体上显示计算出的圆面积。Option ExplicitDim r%, a As Singl

9、eConst pi As Single = 3.14159Private Sub Form_Click()r = Val(InputBox(“请输入圆半径“ r; “的圆面积为“; aEnd Sub19、编写一个时钟程序,当选择“24 小时”时,以 24 小时的方式显示如 A,当选择“12 小时”时,以 12 小时的方式显示如 B。Private Sub Form_Load()Timer1.Interval = 1000End SubPrivate Sub Timer1_Timer()Select Case TrueCase Option1.ValueLabel1.Caption = Time

10、Case Option2.ValueLabel1.Caption = Format(Time, “HH:MM:SS AM/PM“)End SelectEnd Sub20、设计一个程序,用户界面如图所示。程序运行后,用户在文本框中输入一段文字,然后按需要单击选择框,用以改变文本的字体、字型、颜色以及大小。Option ExplicitPrivate Sub Check1_Click()If Check1.Value = 1 ThenText1.FontName = “黑体“ElseText1.FontName = “宋体“End IfEnd SubPrivate Sub Check2_Click

11、()If Check2.Value = 1 ThenText1.FontUnderline = TrueElseText1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Check3_Click()If Check3.Value = 1 ThenText1.FontSize = 20ElseText1.FontSize = 9End IfEnd SubPrivate Sub Check4_Click()If Check4.Value = 1 ThenText1.ForeColor = vbGreenElseText1.ForeColor = vbB

12、lackEnd IfEnd SubPrivate Sub Command1_Click()Text1.Text = “End SubPrivate Sub Command2_Click()EndEnd Sub20 做出 2 个周期的正弦波形. Private Sub Form_Click()Dim i%, x#, y#Const pi As String = 3.1415926Form1.Scale (-2 * pi, 1.2)-(2 * pi, -1.2)Form1.Line (-2 * pi, 0)-(2 * pi, 0)Form1.Line (0, 1.2)-(0, -1.2)For x

13、 = -2 * pi To 2 * pi Step 0.01y = Sin(x)Form1.PSet (x, y)Next xEnd Sub21 以窗体为中心,产生 1000 个半径颜色随机的同心圆.Private Sub Form_Click()For i = 1 To 1000x = Form1.ScaleWidth / 2y = Form1.ScaleHeight / 2r = Int(Rnd * y)c = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd)Form1.Circle (x, y), r, cNextEnd Sub22.九九乘法表Private Su

14、b Form_Click()Dim i%, j%Form1.Caption = “九九乘法表 “Print Tab(48); CaptionPrint Tab(48); “-“For i = 1 To 9For j = 1 To iPrint Tab(j - 1) * 12 + 1); i; “*“; j; “=“; i * j;Next jPrintNext iEnd Sub23 求最大公约数和最小公倍数Private Sub Command2_Click()Text1.Text = “End SubPrivate Sub command1_Click()Dim m%, n%, r%, t%m = Val(Text1.Text)n = Val(Text2.Text)If m n Then t = m: m = n: n = tt = m * nDor = m Mod nm = nn = rLoop Until r = 0Text3.Caption = “公约数:“ & mText4.Caption = “公倍数“ & t / mEnd Sub24.用随机函数产生 50 个两位数,保存于一个一维数组中,要求找出其中的最大值,最小值及所在位置.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 试题真题

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。