Private Sub Command1_Click()
Dim result As String, s As String, c As String
Dim n As Integer, i As Integer, j As Integer
s = Text1.Text
Text2.Text = ""
For i = 1 To Len(s)
If n >= 65 And n <= 90 Or n >= 97 And n <= 122 Then
End If
Next i
Text2.Text = result
j = 2
c = Mid(result, 1, 1)
Do While j <= Len(result)
If Mid(result, j, 1) < c Then c = Mid(result, j, 1)
Loop
Text3.Text =
n=Len(s) 's是待判断的字符串
k=0:j=n
For i=1 to n/2
Next i
If k=0 Then Label1.Caption="对称" Else Label1.Caption="不对称"
方框中的代码由以下三部分组成:
①j=j-1
②If c1 <> c2 Then k = k+1
③c1=Mid(s,i,1) : c2=Mid(s,j,1)
代码顺序正确的选项是( )
现有三次方程y=5x^3-55x^2+170x-130,其函数图象如图所示:
观察该函数图象发现函数有一实根在区域(1.2)之间,因此我们取两者的中点m=(1+2)/2代入方程进行检测发现f(1.5)=18.125。因为f(1.5)>0,因此区间应该往左移动,得下一个区间(1,1.5)然后继续进行检测。如果区间差值≤误差率,则认为该中点是方程的根。根据上述方法描述设计一个VB求解程序的根,要求单击求解按钮Command1,在文本框Text1中显示方程的根,部分程序如下。
PrivateSubCommand1_Click()
DimiAsDouble,jAsDouble,mAsDoubleDimrAsDouble,yAsDouble
i=1:j=2:y=1:r=j-iDoWhiley<>0Andr>0.00001
m=(i+j)/2
y=
Ify>0Then
j=m
ElseIfy<0Then
i=m
EndIf
Loop
Text1.Text=m
EndSub
Dim a(1 To 10) As Integer
Function Search(L As Integer, R As Integer) As Integer
M = (L + R) \ 2
If a(M) < a(M - 1) And a(M) > a(M + 1) Then
⑴
ElseIf a(M) > a(M - 1) And a(M) > a(M + 1) Then
⑵
ElseIf a(M) > a(M - 1) And a(M) < a(M + 1) Then
⑶
End If
End Function
Private Sub Command1_Click()
Label1.Caption = "“峰顶”值是:" + Str(Search(1, 10))
End Sub
上述程序中划线处可选语句为:
①Search = Search(M + 1 , R)
②Search = Search(L , M - 1)
③Search = a(M)
则(1)(2)(3)处的语句依次是( )
key = Val(Text 1.Text)
i = 1: j = 10
Text2.Text =""
Do While i<=j
m = Int((i+j)/2 + 0.5)
If key = a(m)Then Exit Do 'Exit Do 表示退出循环
If key < a(m)Then j=m-1 Else i = m + 1
Text2.Text =Text2.Text + Str(a(m))
Loop
数组元素a(1)到a(10)的值依次为“8,17,24,30,36,40,55,58,61,66”,文本框 Textl中输入的值是30,执行该程序段,文本框Text2中显示的是 ( )
Dim a(1 To 10) As Integer
Randomize
a(1) = Int(100 * Rnd) ‘先生成第1个数
For i = 2 To 10 ‘然后生成2到第10个
temp = Int(100 * Rnd)
Low = 1
high = i - 1
Do While Low <= high
m = (Low + high) \ 2
If temp >a(m) Then
①
Else
high = m - 1
End If
Loop
For j = i - 1 To Low Step -1 ‘从原来有数据的最后位置开始逐个数据后移
a(j + 1) = a(j)
Next j
②
Next i
则空缺处代码为( )
编写VB程序,实现上述算法。程序功能如下:运行程序时,在列表框List1中显示数组a中的原始数据,并在列表框List2中输出去重后的数组a中的数据,即相同的数据仅保留一个。同时在标签Label1中显示删除的数据总个数,运行效果如图所示,程序代码如下:
Const maxn=10
Dim a(1 To maxn)As Integer
Private Sub Form_Load( )
´maxn个数据在数组a中,并在列表框List1中显示
End Sub
Private Sub Command1_Click( )
Dim i As Integer, n As Integer ‘n用于存储当前查找的数字长度
Dim j As Integer, key As Integer ‘key用于存储本次查找的关键字的数据位置
key=1:n=maxn
Do While key<=n
i=n-1
Do While
‘①
i=i-1
Loop
If i=key Then ‘找到重复数据,删除;未找到,设定下一查找关键字
key=key+1
Else
For j=i To n-1
a(j)=a(j+1)
Next j
n=n-1
End If
Loop
For i= 1To n
List2.AddItem a(i)
Next i
Labell.Caption="共删除重复数据:"&___________&"个"
End Sub
Const n = 10
Dim a(1 To 10) As Integer
Private Sub Form _Load()
'读取一组正整数,存储在数组a中,并在列表框list1中显示。代码略
End Sub
Private Sub Command1_Click()
Dimi As Integer,m As Integer,low As Integer,high As Integer,temp As Integer
low=1:high=n
Do While
If a(low) Mod 2 = 1 Then
m =low
For i=low+1 To high
If a(i)Mod2=1 And a(i)<a(m) Then m=i
Next i
temp = a(m): a(m) = a(low): a(low) = temp
low= low + 1
Else
m =low
For i=low To high
If Then m=i
Next i
temp = a(m): a(m) = a(high): a(high) = temp
End If
Loop
For i=1 To n
List2.AddItem Str(a(i))
Next i
End Sub
|
原1-7号男生身高 |
171 172 180 174 176 179 178 |
|
筛选排序后序列 |
171 172 174 176 178 179 180 |
|
“造型设计”后序列 |
180 178 174 171 172 176 179 |
王林同学用VB编写模拟“节目造型”程序,功能如下:从数据库中导出所有学生编号、性别和身高数据;单击“筛选排序”按钮Command1,选出“男生”且按身高升序排列显示在文本框Text1中;单击“设计造型”按钮Command2,根据身高仿“V”字的造型进行有序排列,并将结果显示在文本框Text2 中。程序运行界面如图所示。举例说明如下:
Const n = 7
Dim h2(1 To n) As Integer
Dim height1(1 To n) As Integer, height 2 (1 To n) As Integer
Dim i As Integer, j As Integer, temp As Integer
Dim sex(1 To n) As Boolean ' 男生sex=true
Private Sub Form_Load()
'n名学生的身高和性别由数据库导出,分别存储在数组height1和sex中,代码略!
End Sub
Private Sub Command1_Click()
For i = 1 To n - 1
For j = n To i + 1 Step -1
IfThen
temp = height1(j): height1(j) = height1(j - 1): height1(j - 1) = temp
End If
Next j
Next i
For i = 1 To n
Text1.Text = Text1.Text + " " + Str(height1(i))
Next i
End Sub
Private Sub Command2_Click()
Dim left, right As Integer, i As Integer, mid As Integer
mid = Int((1 + n) / 2)
left = 0: right = 0
For i = 2 To n Step 2
right = right + 1
height2(mid + right) = height1(i)
left = left + 1
Next i
For i = 1 To n
Text2.Text = Text2.Text +“ “ + Str(height2(i))
Next i
End Sub
为实现以上功能,请在画线处填写正确代码。
程序描述:2公里(包括2公里)内,起步价为5元,超过2公里部分(不足整公里的,向上取整),每公里1.6元。
代码如下:
Import ① #引用math库
s= ② (input("请输入你要去目的地距离出发点的公里数:))
If ③ : #2公里(包括2公里)内
cost =5
else:
cost = 5+math.ceil(s-2) *1.6
print("你的打的费用是", cost,“元)
①处的语句是,②处的语句是,③处的语句是
①A.math B.Numpy C.time D.Matplotlib
②A.Float B.Int C.str D.Math
③A.s≤2 B.s<=2 C.s>2 D.s≥2
Dim i As Integer
i=10
Do While i <= 20
Print i*9
Loop
arr[M]和待查找数据Key比较
①arr[M]=Key,返回M的值
②若M位置的右侧有序,当待查找数据在右侧,则下次在右侧查找,否则在M左侧查找
③若M位置的左侧有序,当待查找数据在左侧,则下次在左侧查找,否则在M右侧查找
Function Search (key As Integer, L As Integer, R As Integer) As Integer
Do While L <=R And Search=- 1
M=(L+ R)\2
If arr(M)= key Then
Search= M
Else
If Then
If arr(L)<=key And key <arr(M) Then
R=M-1
Else
L=M+1
End If
Else
If Then
L=M+1
Else
R=M- 1
End If
End If
End If
Loop
End Function
| 1 2 3 4 5 6 7 8 9 | import numpy as np import matplotlip.pyplot as plt x=np.linspace(0,10, 100) y=np.sin(x) plt.title("sin(x)") plt.plot(x,y,color="r",linewindth="2") plt.show( ) |
以下图形哪一个是该程序绘制出来的( )
B .
C .
D .