VB第4章F-(1)_第1页
VB第4章F-(1)_第2页
VB第4章F-(1)_第3页
VB第4章F-(1)_第4页
VB第4章F-(1)_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

习题 一、 选择题 1. 设分段函数y(x)的表达式为:y,则能正确实现该分段函数计算的语句为(D)。 A. If x0 Then yx1 B. yx1 yx1 If x0 D. If x0 Then yx1 y x1 Else Else yx1 yx1 End If End If2. 有如下程序段: xcase1 tInputBox(“请输入一个数:”) Select Case t Case Is0 Yxcase1 Case Is0 Yxcase2 Case Else Yxcase3 End Select Print xcase; Y若输入1,输出结果为(A)。 A. 14 B. 13 C. 12 D. 113. 下列循环语句执行后,X的值等于(A)。X5For i1 To 20 Step 2 X X i 5 Next iXi A. 21 B. 22 C. 23 D. 244. 执行以下程序段时,(C)。x1Do While x0 xx*x Print x;Loop A. 循环体将执行1次 B. 循环体将执行0次 C. 循环体将执行无限次 D. 系统将提示语法错误5. 设窗体中包含一个命令按钮Command1,一个标签Label1,并有以下的事件过程。程序运行后,单击Command1按钮,标签中显示的内容是(C)。Private Sub Command1_Click()Dim i As Integer,n As Integeri1: n0Do While i 6 Print num; num num 2.4 LoopEnd Sub程序运行后,单击命令按钮,则窗体上显示的内容是(B)。 A. 13.45.8 B. 135 C. 147 D. 无数据输出8. 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:Private Sub Command1_Click() Dim a As Integer, s As Integer a 8 s 1 Do s s a a a1 Loop While a 0Then Print 左括号多于右括号; Count1; 个 Else Print 右括号多于左括号; Count1; 个 End If End IfEnd Sub3. 输入任意长度的字符串,要求将字符顺序倒置,例如“ABCDEFG”变换为“GFEDCBA”。 Private Sub Command1_Click() Dim a$, n%, i%, c$ a InputBox(输入字符串) n Len(a) For i 1 To Int(n / 2) c Mid(a, i, 1) Mid(a, i, 1) = Mid(a, n + 1 - i, 1) Mid(a, n + 1 - i, 1) = c Next i Print aEnd Sub三、 阅读程序,写出程序运行结果1. Dim x$, n%, a% n20 Do while n0 an mod 2 nn 2 xChr(48a) & x Loop Print x101002. a$ * : b$ $ For i 1 to 4 If i Mod 2 0 Then x$ String(Len(a$) i , b$) Else x$ String(Len(a$) i , a$) End If Print x$;Next i*$*$3. For i1 To 9 For j = 1 To 2*i-1 If i Mod 2 = 0 Then Print Str$(i); Else Print cStr$(i);Next jPrint Next i1 2 2 233333 4 4 4 4 4 4 4555555555 6 6 6 6 6 6 6 6 6 6 67777777777777 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8999999999999999994. Dim a%, i%, j% a0 For i1 to 5 For j2 to 2 aaij Next j Print a; Next i Print Print i,j,a5 15 30 50 75 6 3 75四、 程序设计题1. 设计一个窗体,输入一个3位整数,将它反向输出。例如输入123,输出为321。 Val StrReverse CStr采用函数Private Sub Command1_Click() Dim a$, b$ a = InputBox(输入一个3位整数) b = StrReverse(a) Me.FontSize = 18 Print bEnd Sub采用循环Private Sub Command1_Click() Dim a$, b$, i% a = InputBox(输入一个3位整数) For i = 1 To 3 b = Mid(a, i, 1) + b Next FontSize = 18 Print bEnd Sub2. 从键盘输入任意一个实数,用Print方法在窗体上同一行显示其平方和平方根,要求每个数保留3位小数。 format Sqr Private Sub Command1_Click() Dim a As Single, b As Single, c! a = Val(InputBox(请输入一个实数) b = a 2 c = Sqr(a) FontSize = 20 Print a & 的平方为: & Format(b, #.000) Print a; 的平方根为:; Format(c, #.000)End Sub3. 计算下列分段函数值:y If 语句 / Select Case 语句Private Sub Form_Click() Dim x As Double, y# x = Val(InputBox(请输入一个数) If x -5 Then y = Sin(x) 2 + Cos(x) ElseIf x 5 Then y = x / 2 + (x * x + 5) / 2 * x ElseIf x 10 Then y = (3 * x) (1 / 3) ElseIf x = 15 Then y = Log(x) Else y = Sin(x) 2 + Cos(x) End If FontSize = 20 Print y=; yEnd Sub4. 某商场对顾客所购买的商品实行打折销售,标准如下(商品价格用Price来表示):求所售商品的实际销售价格。 If 语句 / Select Case 语句Private Sub Form_Click() Dim Price As Single, n As Single Price = Val(InputBox(请输入商品价格) Select Case Price Case Is 200 n = Price Case Is 500 n = Price * (1 - 0.03) Case Is 1000 n = Price * (1 - 0.05) Case Is 2500 n = Price * (1 - 0.08) Case Is 5000 n = Price * (1 - 0.1) Case Else n = Price * (1 - 0.14) End Select FontSize = 18 Me.AutoRedraw = True Print 价格为 & Price & 的商品,打折后实际价格为; nEnd Sub5. 产生50个1100之间的随机整数,显示所有小于60的数。 For 语句 + Rnd + If 语句 + MsgBoxOption ExplicitPrivate Sub Form_Click() Dim n As Integer, m As Integer, k As Integer FontSize = 18 Randomize Cls For n = 1 To 50 m = Int(100 * Rnd + 1) If m 60 Then Print m, k = k + 1 If k Mod 5 = 0 Then 控制每行打印的数字个数 Print End If End If NextEnd Sub6. 由键盘输入一个正整数,找出大于或等于该数的第一个素数。Private Sub Command1_Click() Dim n As Integer, i As Integer, m As Integer, k As Integer n = Val(InputBox(请输入一个正整数:, 提示) k = n Do i = 2 m = Sqr(k) Do While i = m And k Mod i 0 i = i + 1 Loop If i m Then MsgBox 大于或等于 & n & 的第一个素数是: & k: Exit Do k = k + 1 LoopEnd Sub 另,Option ExplicitPrivate Sub Form_Click() Dim n As Integer, m As Integer, i As Integer, b As Boolean n = Val(InputBox(请输入一个正整数:, 提示) m = n Do i = 2 Do While m Mod i 0 And i m i = i + 1 If i = m Then b = True Exit Do End If Loop m = m + 1 Loop Until b FontSize = 18 Me.AutoRedraw = True Print 大于或等于; n; 的第一个素数为:; m - 1End Sub7. 设s1,求与8最接近的s的值及与之对应的n值。Private Sub Command1_Click() Dim s#, n%, m# Do m = s n = n + 1 s = s + 1# / n Loop While s = 8 If 8 - m s - 8 Then s = m: n = n - 1 MsgBox 与8最接近的s的值为: & s & vbCrLf & 相对应的n的值为: & nEnd Sub或Private Sub Command1_Click() Dim s, n&, m m = CDec(m) s = CDec(s) Do m = s n = n + 1 s = s + 1 / n Loop While s = 8 If 8 - m s - 8 Then s = m: n = n - 1 MsgBox 与8最接近的s的值为: & s & vbCrLf

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论