- 基础理论
- 数据及数据库技术
- 人工智能
- 算法理论
- 算法实例
- 面向对象程序设计 VB开发工具
- 算法实例的程序实现
- 算法及算法的表示方法
- 多媒体理论
- 基础软件操作
- 算法软件操作
- 多媒体软件操作
- 网络技术应用
在平面坐标系中,给定任意个点,求出这些点中与点(1,1)距离最远的点。小李编写出了相应功能的程序:在文本框Text1中输入这些点的坐标值(数据都用逗号分隔并以逗号结尾),单击“计算”按钮Cmd后,程序计算这些点到(1,1)的距离后,结果显示在列表框List1中,并且输出最大距离的点。程序运行界面如图所示。

(1)由图可知,窗体中的对象共有___________类;
(2)实现上述功能的VB程序如下,请在画线处填入合适的代码。
Private Sub Command1_Click()
v=Val(Mid(s,j,i-j))
j=__________
If k Mod 2=1 Then
x2=v
Else
y2=v
d=Sqr((x2-x1)^2+(y2-y1)^2)
If __________ Then
maxd=d
pos="(" & Str(x2)& "," & Str(y2)& ")"
End If
List1.AddItem"(" & Str(x2)& "," & Str(y2)& ")" & Str(d)
End If
k=k+1
End If
Next i
Label1.Caption="距离(1, 1)最远的点为"& pos &"距离为"& Str(maxd)
End Sub
(3)若文本框Text1中输入的内容为“31,41,26,51,1,56”,程序运行结束后,距离(1,1)最远的坐标点是_____________。

(1)由图可知,窗体中的对象共有___________类;
(2)实现上述功能的VB程序如下,请在画线处填入合适的代码。
Private Sub Command1_Click()
Dim I,k As Integer
Dim x1,y1,x2,y2 As Single
Dim v As Singie,maxd As Single
Dim s As String,pos zb As String
List1.Clear
s=Text1.Text
x1=1:y1=1
t="":k=1:j=1
List1.AddItem"坐标点"&"距离"
For i=1 To Len(s)
If Mid(s,i,1)="," Thenv=Val(Mid(s,j,i-j))
j=__________
If k Mod 2=1 Then
x2=v
Else
y2=v
d=Sqr((x2-x1)^2+(y2-y1)^2)
If __________ Then
maxd=d
pos="(" & Str(x2)& "," & Str(y2)& ")"
End If
List1.AddItem"(" & Str(x2)& "," & Str(y2)& ")" & Str(d)
End If
k=k+1
End If
Next i
Label1.Caption="距离(1, 1)最远的点为"& pos &"距离为"& Str(maxd)
End Sub
(3)若文本框Text1中输入的内容为“31,41,26,51,1,56”,程序运行结束后,距离(1,1)最远的坐标点是_____________。
某排序算法,VB代码如下:
i=1
Do While i<=5
If i = 0 or a(i – 1)<= a(i) Then
i=i+1
Else
t=a(i):a(i)=a(i-1):a(i-1)=t
i=i-1
End If
Loop
数组元素a(0)到a(5)依次为:“0,41,22,53,99,36”,经过该程序段处理后,数组元素a(3)的值为( )
i=1
Do While i<=5
If i = 0 or a(i – 1)<= a(i) Then
i=i+1
Else
t=a(i):a(i)=a(i-1):a(i-1)=t
i=i-1
End If
Loop
数组元素a(0)到a(5)依次为:“0,41,22,53,99,36”,经过该程序段处理后,数组元素a(3)的值为( )
A.36 | B.53 | C.41 | D.22 |
某对分查找算法的VB程序段如下:
i=1:j=6:n=0:f=False
key=Val(Text1.Text)
Do While i<=j and Not f
n=n+1
m=Fix((i+j)/2)
If key=a(m)then f=True
If key<a(m)then j=m-1 Else i=m+1
Loop
数组元素a(1)到a(6)的值依次为“12,19,27,31,46,55”,文本框Text 1中输入“31”后运行该程序,则以上程序段运行结束后,下列说法不正确的是( )
i=1:j=6:n=0:f=False
key=Val(Text1.Text)
Do While i<=j and Not f
n=n+1
m=Fix((i+j)/2)
If key=a(m)then f=True
If key<a(m)then j=m-1 Else i=m+1
Loop
数组元素a(1)到a(6)的值依次为“12,19,27,31,46,55”,文本框Text 1中输入“31”后运行该程序,则以上程序段运行结束后,下列说法不正确的是( )
A.变量i的值为4 |
B.变量j的值为4 |
C.变量m的值为4 |
D.变量n的值为3 |
“不重复数”的特征是任何相邻两个数位上的数字都不相同。如1101是重复数,1201是不重复数。判断某数是不是重复数的VB程序段如下:
s = Text1.Text
(1)
i = 1: flag = True
Do While i <= n - 1 And flag
If (2) Then flag = False
i = i + 1
Loop
If (3) Then
Label1.Caption = "重复数"
Else
Label1.Caption = "不重复数"
End If
上述程序中方框处可选语句为:
①flag=False
②n=Len(s)
③Mid(s,i,1)=Mid(s,i+1,1)
则(1)、(2)、(3)处语句依次是( )
s = Text1.Text
(1)
i = 1: flag = True
Do While i <= n - 1 And flag
If (2) Then flag = False
i = i + 1
Loop
If (3) Then
Label1.Caption = "重复数"
Else
Label1.Caption = "不重复数"
End If
上述程序中方框处可选语句为:
①flag=False
②n=Len(s)
③Mid(s,i,1)=Mid(s,i+1,1)
则(1)、(2)、(3)处语句依次是( )
A.②、③、① | B.①、③、② | C.②、①、③ | D.③、②、① |
以下两个VB程序段,其中变量m和n为正整数,下列说法不正确的是( )
程序1: If m<n Then t=m:m=n:n=t End IfDo While m Mod n<>0 r=m Mod n m=n n=r Loop Text1.Text=Str(n) | 程序: 2n2 Do Whife m 程序2 Do While m<>n Do While m>n m=m-n Loop Do While n>m n=n-m Loop Loop Textl.Text=Str(n) |
A.“程序1”和“程序2”中的代码实现相同的功能 |
B.若变量m和n的值为25,35,则“程序1”代码运行后文本框Text1显示“5” |
C.“程序2”中的输出语句改为Textl.Text=Str(m),会影响文本框Textl显示的内容 |
D.若变量m和n的值为11,7,则“程序2”代码运行后文本框Text1显示“1” |
小王设计制作了一个VB程序用于获取英文单词,然后背诵这些英文单词。为了使背诵英文单词更有效率,小王决定要显示的英文单词要由相同的英文字幕组成。
程序执行过程如下:程序运行后,先从数据库中获取单词,然后单击“分析单词”按钮,查找出由相回字母组成的英多单词保留下来显示,例如:获取的英文单词有:tea,pea,eta,eat,help,three,there。通过分析得知tea,eta和eat是由相同字母组成的英文单词,three和there是由相同字母组成的英文单词,则这五个英文单词保留下来,显示在label1中。如图所示:

VB部分程序如下,请将程序补充完整:
Dim wordcharsort (1 To 3000)As String'存储每个英文单词字母排序后的内容
Dim words (1 To 3000) As string'存储由相同字母组成的英文单词
Dim wordscount As Integer
Dim Getwords (1 To 3000) As String
Private Sub Form_Load()
'从数据库中获取3000个英文单词存储到数组 Getwords中,代码略
End Sub
Private Sub Command1_ Click()
For j=i+1 To 3000
If wordcharsort(j)<wordcharsort(k) Then k=j
Next j
If i<>k Then
t1= wordcharsort(i):wordcharsort(i)= wordcharsort(k):wordcharsort(k)=tl
___________
End if
Next i
For key=1 To 3000
wordscount= search( wordcharsort(key),key, wordscount)
Next key
For i=1 To wordscount
Label1. Caption= Labell. Caption+" "+words(i)
Next i
End sub
'查找相同字母组成的英文单词,存储在 words数组中
Function search(a As String, b As Integer, c As Integer)As Integer
For j=1 To c
If words(j)=Getwords(b) Then flag=True
Next j
If flag=False Then
Words(c)=Getwords(b)
__________
End if
End If
Next i
search=c
End function
'对英文单词中的字母进行排序
Function rank(s As String)As String
tmp=c(kk):c(kk)=c(kk-1):c(kk-1)=tmp
End if
Next kk
Next k
For j=1 To Len(s)
rank -rank & c(i)
Next j
End function
程序执行过程如下:程序运行后,先从数据库中获取单词,然后单击“分析单词”按钮,查找出由相回字母组成的英多单词保留下来显示,例如:获取的英文单词有:tea,pea,eta,eat,help,three,there。通过分析得知tea,eta和eat是由相同字母组成的英文单词,three和there是由相同字母组成的英文单词,则这五个英文单词保留下来,显示在label1中。如图所示:

VB部分程序如下,请将程序补充完整:
Dim wordcharsort (1 To 3000)As String'存储每个英文单词字母排序后的内容
Dim words (1 To 3000) As string'存储由相同字母组成的英文单词
Dim wordscount As Integer
Dim Getwords (1 To 3000) As String
Private Sub Form_Load()
'从数据库中获取3000个英文单词存储到数组 Getwords中,代码略
End Sub
Private Sub Command1_ Click()
Dim key As Integer
For i=1 To 3000
Wordcharsort(i)=rank(Getwords(i))Next i
For i=1 To 3000-1
k=iFor j=i+1 To 3000
If wordcharsort(j)<wordcharsort(k) Then k=j
Next j
If i<>k Then
t1= wordcharsort(i):wordcharsort(i)= wordcharsort(k):wordcharsort(k)=tl
___________
End if
Next i
For key=1 To 3000
wordscount= search( wordcharsort(key),key, wordscount)
Next key
For i=1 To wordscount
Label1. Caption= Labell. Caption+" "+words(i)
Next i
End sub
'查找相同字母组成的英文单词,存储在 words数组中
Function search(a As String, b As Integer, c As Integer)As Integer
For i=1 To 3000
flag=False
If a=wordcharsort(i) And______ ThenFor j=1 To c
If words(j)=Getwords(b) Then flag=True
Next j
If flag=False Then
Words(c)=Getwords(b)
__________
End if
End If
Next i
search=c
End function
'对英文单词中的字母进行排序
Function rank(s As String)As String
Dim c(l To 45) As String
wordscount=1
For xk=1 To 45
c(xk)=" "Next xk
For j=1 To Len(s)
c(j)= _______Next j
For k=1 To Len (s)-1For kk=Len(s) To k+1 Step-1
If Asc(c(kk))<Asc(c(kk-1))Thentmp=c(kk):c(kk)=c(kk-1):c(kk-1)=tmp
End if
Next kk
Next k
For j=1 To Len(s)
rank -rank & c(i)
Next j
End function
对一段字符(仅包含大小写字母和数字)加密,加密规则为:①字母和数字都往后循环顺移3位,如“a”变为“d”,“y”变为“b”;“0”变为“3”,“7”变为“0”②加密后字母在前,数字在后③字母按逆序排列,数字按顺序排列,如输入明文“ab7Z8x3”,这密文为“aCed4016”。
小王利用VB程序实现这一加密功能,程序界面和代码如下所示:
(1)根据程序代码分析,“加密”按钮的名称是_____________________________。
(2)根据加密规则,明文“9G78fbY5”,则密文为__________________________。
(3)请在画线处填入合适的代码:

Private Sub Com_ jm_ Click()
Dim x As String, ch As String, cl As String
Dim sl As String, s2 As String, s As String
Dim i As Integer, n As Integer, y As Integer
x= Text1. Text
n=Len(x)
For i=1 To n
ch= Mid(x, i, 1)
If ch >= "0" And ch <= "9" Then
①_____________
s2=s2 & y
Elself ch >="a" And ch<="z" Then
y=(Asc(ch)-Asc("a")+3)Mod 26
②_______________
s1=c1+s1
Else
y=(Asc(ch)- Asc("A")+3) Mod 26
c2=Chr(Asc("A")+y)
s1=c2+s1
End If
Next i
③________
Text2 Text=s
End sub
小王利用VB程序实现这一加密功能,程序界面和代码如下所示:
(1)根据程序代码分析,“加密”按钮的名称是_____________________________。
(2)根据加密规则,明文“9G78fbY5”,则密文为__________________________。
(3)请在画线处填入合适的代码:

Private Sub Com_ jm_ Click()
Dim x As String, ch As String, cl As String
Dim sl As String, s2 As String, s As String
Dim i As Integer, n As Integer, y As Integer
x= Text1. Text
n=Len(x)
For i=1 To n
ch= Mid(x, i, 1)
If ch >= "0" And ch <= "9" Then
①_____________
s2=s2 & y
Elself ch >="a" And ch<="z" Then
y=(Asc(ch)-Asc("a")+3)Mod 26
②_______________
s1=c1+s1
Else
y=(Asc(ch)- Asc("A")+3) Mod 26
c2=Chr(Asc("A")+y)
s1=c2+s1
End If
Next i
③________
Text2 Text=s
End sub
数组a和数组b中元素的个数分别为n1和n2,现在从a,b两个数组中选取最小的n1个数据并按升序排列保存到a数组中。示例1:a={1},b={5,3},则a={1};示例2:a={3,1},b={2,4},则a={1,2}。实现上述功能的VB程序段如下:
Private Sub Form _ Load( )
′数组a,b存储整数,代码略
End sub
Private Sub Command1_Click( )
Dim i As Integer,j As Integer, k As Integer, t As Integer, flag As Boolean
flag- True
For i=1To ①
j=n2
k=i
For j=n1Toi+1Step-1
If a(k)<= b(1) And k <> i Then
Next i
For i=1 To nl
Listl AddItem Str(a(i))
Next i
End sub
请回答问题:
(1)要使程序运行时,清空列表框List1的内容,可在 Form Load事件过程中添加语句:_____(单选,填字母:
(2)请将程序代码①②处补充完整。
①_______________________
②_______________________
(3)程序代码方框处,flag为_______时,表示b数组该遍加工需要进行_______排序(选填:冒泡/选择)。
Private Sub Form _ Load( )
′数组a,b存储整数,代码略
End sub
Private Sub Command1_Click( )
Dim i As Integer,j As Integer, k As Integer, t As Integer, flag As Boolean
flag- True
For i=1To ①
j=n2

If b(j)< b(j-1) Then t=b(j: b(j)=b(j-1): b(j-1)=t
j=j-1
Loopk=i
For j=n1Toi+1Step-1
If a(j)<a(k) then k-j
Next jIf a(k)<= b(1) And k <> i Then
t=a(k):a(k)=a(i): a(i)=t
flag=False
Elself② Thent=a(i):a(i)=b(1):b(1)=t
flag=True
End IfNext i
For i=1 To nl
Listl AddItem Str(a(i))
Next i
End sub
请回答问题:
(1)要使程序运行时,清空列表框List1的内容,可在 Form Load事件过程中添加语句:_____(单选,填字母:
A.List1.Caption=""/ | B.List1.Clear/ | C.List1. Additem"")。 |
①_______________________
②_______________________
(3)程序代码方框处,flag为_______时,表示b数组该遍加工需要进行_______排序(选填:冒泡/选择)。
数组元素a(1)~a(n)升序排列,存储整数且数值的范围为[1,n-1](n≥2),其中仅有两个相邻的数组元素的数值发生了重复。小王为找出重复数组元素的前、后位置设计了一个程序,实现该功能的VB程序段如下:
in=1;j=n
Do While(1)
m=(i+j)\2
If a(m)=m Then
Loop
Labell.Caption="相邻重复两数的前、后位置余别是:"+str(i)+"和"Stri(j)"
上述程序段3个划线处(1),(2),(3)的代码分别为( )
in=1;j=n
Do While(1)
m=(i+j)\2
If a(m)=m Then
(2)
Else(3)
End IfLoop
Labell.Caption="相邻重复两数的前、后位置余别是:"+str(i)+"和"Stri(j)"
上述程序段3个划线处(1),(2),(3)的代码分别为( )
A.(1)i+1<=j (2)i=m (3)j=m |
B.(1)i+1<j (2)i=m (3)j=m |
C.(1)i+1<j (2)i=m+1 (3)j=m-1 |
D.(1)i=j (2)i=m+1 (3)j=m-1 |
下列关于程序设计中查找算法的描述,正确的是( )
A.顺序查找和二分法查找都是常用的查找算法 |
B.二分法查找一定优于顺序查找 |
C.顺序查找一定优于二分法查找 |
D.当数据有序时,不适用二分法查找 |