学进去-教育应平等而普惠
试题
类型:操作题
难度系数:0.40
所属科目:高中信息技术
在平面坐标系上分布着n个点,从这n个点的集合中取出4个点,使之构成一个正方形,要求正方形的边长与x轴、y轴平行。程序界面如图所示,点击“生成”按钮,自动产生n个点的坐标,这n个点按x坐标值升序排列,x坐标相同时按y坐标值升序排列。

点击“查找”按钮,查找所有符合要求的正方形。算法思路:枚举正方形对角线上的线段端点A、C(即保证线段AC与x轴呈斜45度的夹角),通过A、C点,计算出正方形另-条对角线上的线段端点B、D,再查找B、D是否存在,若存在,则说明该正方形可以生成。
(1)能够在List1中显示“OK”的语句是__________(单选,填字母:A.List1.Addtem"OK"/ B.List1.Caption="OK"/C.List1.AddItem="OK")
(2)实现上述功能的VB程序如下,请在划线处填入合适的代码。
(3)程序中加框处代码有错,请改正。
Dim n As Integer, x(1000) As Integer, y(1000) As Integer
Private Sub Command2_Click()
’生成n个点的坐标,并按要求排序,代码略
’第i个点的坐标保存在x(i)和y(i)并显示在List1中
End Sub
Private Sub Command2_Click()
   Dim i As Integer, j As Integer
   For i = 1 To n
For j = i + 1 To n
   If Then_____
       If search(x(i), y(j)) = True And search (( ) ) = True Then
          ’将4个坐标点显示在List2中,代码略
          cnt = cnt + 1
       End If
   End If
Next j
Next i
List2.AddItem “总共有” + Str(cnt) + “个符合要求的正方形”
End Sub
Function search(sx As Integer, sy As Integer) As Boolean
   Dim L As Integer, R As Integer, m As Integer
   search = False: L = 1: R = n
   Do While L <= R
m = (L + R)\2
If sx < x(m) Or _____       Then
   R = m – 1
ElseIf sx > x(m) Or sx = x(m) And sy > y(m) Then
   L = m + 1
Else
   Search = True: Exit Do
End If
   Loop
End Function
编辑解析赚收入
收藏
|
有奖纠错

同类型试题

优质答疑

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

用户名称
2019-09-19

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

用户名称
2019-09-19
我要答疑
编写解析
解析:

奖学金将在审核通过后自动发放到帐

提交
我要答疑
我要答疑:
提交