VB程序设计学习与实验指导答案

更新时间:2023-06-07 14:06:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Visual Basic 程序设计学习与实验指导答案

上篇 学习指导

第1章 Visual Basic 概述

1. 事件 2. 查看对象 3. 工程

4. 视图 属性窗口 5. 窗体编辑器

第2章 面向对象程序设计初步

1. 控件 2. 事件 3. 类 属性 4. 属性 5. 略 6. Name

第3章 Visual Basic 语言基础

1. (a*sin(30/180*3.14)+c*(log(b)/log(10)))/((Abs(d)+1)*(e+f))+1

2. mod

3. X=Int(X) And Y=Int(Y) And X*Y>0

4. 4.Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400=0 5. x=Int((99-10+1)*Rnd+10) 6. 0 “” 7. 空格

8. 6,845.30 9. (1)8 (2)1 (3)abcd

(4)出错,类型不匹配 (5)False

(6)2008-6-29 (7)I likeVB (8)4 (9)4 4 (10)3 4 (11)10 -10 (12)-1 (13)aa (14)3 (15)0 (16)1 (17)C (18)5 (19)8 (20)34.54 (21)中国 (22)上海

(23)VISUAL BASIC (24)visual basic 10.

(1)x<-100 or x>100

(2)a=Int(a) And b =Int(b) Or a<0 And b<0 (3)x<=y or x>=z (4)a>0 And a<>Int(a) (5)a=0 xor b=0 (6)Len(S)<10 (7)UCase(S)=S

(8)Left(S,1)=”a” And Right(S,1)=”a” (9)Instr(S,”@”)<>0 (10)Trim(S)=S

(11)Date=#8/8/2008#

(12)Weekday(Date)=2

第4章 程序控制结构与算法基础

一.简单填空 1. Randomize

2. N=Int((99-10+1)*Rnd+10)

3. M=(Int((100-10+1)*Rnd+10))/10 4. Exit For 5. Exit Do

二.读程序写结果 1. 150 12

2. 22 23 -1 3. 5 3 0 4. 20 40 60

三.程序填空 1. Len(s) Mid(s,i,1)

c>=”A” And c<=”Z” c>=”a” And c<=”z” c>=”0” And c<=”9” n3=n3+1 2. 0

1 n-1 n Mod i=0 sum+i sum=n 3. 1000 CStr(n) CStr(n*n)

Right(s2,Len(s1))=s1 4. 100 200 2 N-1 Exit For count+1

count Mod 5=0 Print 5. sum=1

a*x^2/((2*n-1)*(2*n)) sum+a

Abs(a)<=0.0000001

第5章 数组的应用

1. 120 36 2. 10 31 7 3. 26 14 26 三.程序填空 1. A(i,j);

Picture1.Print A(i.1) 1 A(i,j) j

“第” & i & “行最大数是” & Max Data & “,第” & Maxj & “列” 2.

Text1.Text & A(i); k

preserve B(k) B(k)=A(i) 3.

Sqr(n - m) = Int(Sqr(n - m)) ReDim Preserve B(k) n

A(m) & "和" & B(m) 4.

Int((100-50+1)*Rnd+50) 1

B(i)+1

第6章 过程

四.读程序写结果 1. x=2,y=2 m=2 2. 9 4,5,9 27 3. 50 26 4. 5 64,5

5. 7,14 11,22 15,30 6. 29 29 3 7. 12 25

下篇 实验教程

实验2 Visual Basic 变量、函数与表达式的使用

实验2-1 算术运算符的使用 13 17 8 3 3 2 2 6 2 -2 -2 0

2007-10-15

3 2.857143 2.85714285714286

实验2-2 字符运算符的使用 200710 200710 2017

2007-10-1010 2007-10-20

出错,类型不匹配

实验2-3 关系运算符的使用 False False

False False False False False True False True

实验2-4 逻辑运算符的使用 True True False True False False True True False 5 -5 9

实验2-5 常用函数的使用 3.14 3.14

7.38905609893065

1 -1 .999999998205103 4

-1 1 0 .7055475 58

25 25 1250 0 A a 65 97 48 68 8 -9 8 -8 9 -9

aaa 4.5 aaa4.5

16 5 Visua 6.0

sua Basic Basic 6.0 abcde EFG

Basic Basic Basic Visual Basic 6.0 Basic 8 8 aaa dd

2011-3-15

2011-3-15 14:35:52 15 3 2011 3

001.73 1.73 1.73

17.32E-01 0173%

实验3 实验3-1 三个数的交换 A=C C=B B=T B C

实验3-2 求周长和面积 Const PI=3.1415926 2*PI*R PI*R*R

Picture1.Cls Format(L, ".00") Format(M, ".00")

实验3-3 求分段函数的值 x=Val(Text1.Text) y=1+Sin(x) y=Log(x)

Text1.Text = "" Text2.Text = ""

算法基础及程序控制结构

实验3-4 求一元二次方程的根 Val(Text2.Text) Val(Text3.Text) b ^ 2 - 4 * a * c

"x1=" & (-b + Sqr(delt)) / (2 * a) "x2=" & (-b - Sqr(delt)) / (2 * a) Text2.Text = "" Text3.Text = "" End

实验3-5 判断素数 N Mod k = 0 k=N

N Mod i=0 k=2

实验3-6 求最大公约数和最小公倍数 M<N L=M L=N

M Mod k = 0 And N Mod k = 0 Text3.Text = k Exit For M>N L=M L=N

k Mod M = 0 And k Mod N = 0 Text4.Text = k Exit For

实验3-7 判断升序数、降序数 CStr(N) Len(S) – 1

Mid(S, k, 1) >= Mid(S, k + 1, 1) k = Len(S)

N = Val(Text1.Text) S = CStr(N)

For k = 1 To Len(S) - 1

If Mid(S, k, 1) <= Mid(S, k + 1, 1) Then Exit For Next k

k = Len(S)

实验3-8 判断回文数 1

Len(s)\2-1

Mid(S, k, 1) <> Mid(S, Len(S) - k + 1, 1) k = Len(S) \ 2 Mid(S, k, 1) + S1 S = S1

实验3-9 求级数的值 Val(Text1.Text) 0 1 x ^ n s * n

t / s <= 10 ^ -6 Text2.Text = y

实验3-10 查找数字串并求和 Text1.Text = "" Text2.Text = "" List1.Clear Text1.Text 0 False 0

While Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Flag = True

k = k * 10 + Mid(s, i, 1) i = i + 1 Flag = True sum + k

Text2.Text = sum

实验3-11 随机产生20个奇数 Int((99 - 10 + 1) * Rnd) + 10 a Mod 2 = 1 n Mod 5 = 0 Picture1.Cls

实验3-12 加密解密

Chr(Asc("a") + (Asc(c) - Asc("a") + 3) Mod 26)

c = Chr(Asc("A") + (Asc(c) - Asc("A") + 3) Mod 26) c & s2

Text2.Text Len(s2)

Mid(s2, i, 1)

c = Chr(Asc("a") + (Asc(c) - Asc("a") + 23) Mod 26) c = Chr(Asc("A") + (Asc(c) - Asc("A") + 23) Mod 26) c & s1 s1

Text1.Text = "" Text2.Text = ""

实验3-13 统计单词个数 Text1.Text 0

Mid(s, i, 1) <> " " And i <= Len(s) i = i + 1

Mid(s, start, i - start) n

Text1.Text = "" List1.Clear

实验4 数组的使用

实验4-1 一维数组的产生及输出 i = 1 To 20

Int((9 - 0 + 1) * Rnd + 0) i = 1 To 20 Print a(i); Print

i = 1 To 20

Picture1.Print a(i);

If i Mod 5 = 0 Then Picture1.Print i = 1 To 20

Text1.Text & Space(2) & a(i)

If i Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf v In a

If i Mod 5 = 0 Then Picture2.Print

实验4-2 选手得分

Int((50 - 10 + 1) * Rnd + 10) / 10 i = 1 To 6

sum = sum + score(i) max = score(1) min = score(1)

score(i) > max Then max = score(i) score(i) < min Then min = score(i) (sum - max - min) / 4

实验4-3 产生10个互不相同的整数 Int((999 - 10 + 1) * Rnd + 10) t Mod 10 = 5 Then Exit For n= n + 1 a(i) = t

For i = 1 To 10 Print a(i);

If i Mod 5 = 0 Then Print Next i

实验4-4 统计数字出现的次数 IsNumeric(S) = False Exit Sub Len(S)

c >= "0" And c <= "9" A(c) = A(c) + 1 A(k) <> 0 m = m + 1

实验4-5 排序 1 To 10

Int((99 - 10 + 1) * Rnd + 10) Text1.Text & A(n) & " " 1 To 9

i + 1 To 10 A(i) > A(j) T = A(j) A(j) = A(i) A(i) = T 1 To 9 10 - i

A(j) > A(j + 1) T = A(j + 1) A(j + 1) = A(j) A(j) = T 1 To 10

Text3.Text = Text3.Text & A(i) & " " 10

T = A(i) 0 j

i - 1

k + 1 1 To 10

Text4.Text = Text4.Text & A(i) & " "

实验4-6 二维数组的产生及输出 1 To 4 1 To 5

Int((9 - 0 + 1) * Rnd + 0) 1 To 4 1 To 5

Print A(i, j); Print 1 To 4 1 To 5

Picture1.Print A(i, j); Picture1.Print 1 To 4 1 To 5

Text1.Text = Text1.Text & A(i, j) & " " Text1.Text = Text1.Text & vbCrLf

实验4-6 查找最大和最小元素及其位置 1 To 3 1 To 4

A(i, j) = Int((99 - 10 + 1) * Rnd + 10) Picture1.Print A(i, j); Picture1.Print A(1, 1), 1, 1 A(1, 1), 1, 1 A(i, j) i j

A(i, j) < min A(i, j) i j

"最大元素" & "A(" & maxi & "," & maxj & ")=" & max "最小元素" & "A(" & mini & "," & minj & ")=" & min

实验4-7 矩阵转置 Dim A() As Integer "请输入N的值"

ReDim A(N, N) As Integer For i = 1 To N

For j = 1 To N

A(i, j) = Int((99 - 10 + 1) * Rnd + 10) Text1.Text = Text1.Text & A(i, j) & " " Next j

Text1.Text = Text1.Text & vbCrLf Next i

t = A(i, j)

A(i, j) = A(j, i) A(j, i) = t For i = 1 To N

For j = 1 To N

Text2.Text = Text2.Text & A(i, j) & " " Next j

Text2.Text = Text2.Text & vbCrLf Next i

实验5 过程

实验5-1 孪生素数和降序素数 Dim i As Integer For i = 2 To N - 1

If N Mod i = 0 Then Exit Function Next i

Prime = True

Dim a As Integer Dim b As Integer a = N \ 10 b = N Mod 10 If a > b Then DecNumber = True Else

DecNumber = False End If 10 To 100

Prime(i) = True And Prime(i + 2) = True List2.AddItem i & "和" & i + 2

DecNumber(i) = True And Prime(i) = True List3.AddItem i

实验5-2 求多项式和 k = 1

a = f(x, k) S + a

k = k + 1

Single As Single

Dim i As Integer, a As Single a = (x + 1) / x For i = 2 To k

a = a * (x + i) / ((2 * i - 1) * x) Next i a

实验5-3 进制转换

Asc(C) - Asc("A") + 10 Left(S, k - 1) Mid(S, k + 1)

Change(Mid(S2, i, 1)) * N ^ (0 - i) T1 + T2 Tran(8, S) Tran(16, S)

Not (C >= "0" And C <= "7" Or C >= "A" And C <= "F" Or C = ".")

实验5-4 Armstrong数

i As Long, a As Long, b As Long Combo1.Text

实验5-5

Option Base 1

Dim a(5) As Integer Dim b(5) As Integer b(i) = i * i + 1

Text2.Text = Text2.Text & b(i) & " " 1 To 5 1 To 5

Gcd(a(i), b(j)) = 1 Gcd = K Exit For

实验5-6 Create(a) Output(a) Sort(a) Output(a)

GetMaxMin(a, MaxData, MinData) MaxData MinData Average(a)

Int((99 - 10 + 1) * Rnd + 10)

1 To UBound(a) a(i);

a(i) > a(j) t = a(j) a(j) = a(i) a(i) = t

2 To UBound(a) a(i) > M M = a(i) a(i) < N N = a(i)

s = s + a(i)

Average = s / UBound(a)

实验6 界面设计

实验6-1 用户登陆 MsgBox "请登录!"

PassWordInput=TxtPassW.Text

UserIdInput=UserId And PassWordInput=PassWord CmdReset_Click

实验6-2 学籍登记 OptXb(0).Value = True

List1.AddItem Space(4) & xh & Space(6) & xm & Space(6) & xb & Space(12) & xy & Space(16) & zy & Space(4) List1.RemoveItem List1.ListIndex

实验6-3 字体格式设置 Select Case OpFont Check2.Value = 1 OpColor = Index OpFont = Index

实验6-4 兴趣调查 List1.AddItem Item End

Select Case Index Item = Text1.Text

实验6-5 调色板

本文来源:https://www.bwwdw.com/article/c3i1.html

Top