试题

试题 试卷

logo

题型:综合题 题类:常考题 难易度:困难

浙江省杭州市建人高复2018-2019学年高三上学期信息技术12月月考试卷

回文字符串是一个对称的字符串,它从左到右读和从右到左读是完全一样的。如“abcba”和“abccba”都是回文字符串,“abc”不是回文字符串。小王编写了一个验证回文字符串的VB程序,功能如下:在文本框Text1里输入一个字符串,单击命令按钮Command1,在文本框Text2中显示验证结果:是回文字符串显示“yes”,否则显示“no”。程序运行界面如图所示。
(1)、在设计程序界面时,要窗体Form1的标题栏上显示“判断回文字符串”,应修改Form1的属性。
(2)、实现上述功能的VB程序如下,请在划线处填入合适代码。 

  

Private Sub Command1_Click()

Dim st As String

Dim i As Integer, j As Integer

Dim flag As Boolean

 

j = Len(st)

i = 1

flag = True

Do While flag And i <= j

 If Mid(st, i, 1) = Mid(st, j, 1) Then

        i = i + 1

         

     Else

        flag = False

End If

 Loop

If  Then 

      Text2.Text = "yes"

Else

      Text2.Text = "no"

End If

End Sub 

举一反三
【加试题】小王设计了一个算法试图求出平面坐标系中最左点出发,从左往右途经所有点到达最右点的路径值和,编写了一个VB程序功能如下:在文本框Text1中输入需随机生成的坐标点数量,单击“生成”按钮Command1后,在列表框List1中生成相应数量的坐标点(坐标值为大于等于1小于10的实数 ,保留一位小数),在文本框Text2中输出路径值。程序界面如图所示。

实现上述功能的VB程序如下,但划线部分代码有错,请改正。

Private Sub Command1_Click()

  Dim x(1 To 100) As Single, y(1 To 100) As Single

  Dim tmp As Single, length As Single, sum As Single, x1 As Single, y1 As Single

  Dim i As Integer, j As Integer, k As Integer

Randomize 

List1.Clear

  k = Val(Text1.Text)

  For i = 1 To k

      x(i) = Int(Rnd * 90) / 10 + 1

      y(i) = Int(Rnd * 90) / 10 + 1

      List1.AddItem "X:" + Str(x(i)) + "   " + "Y:" + Str(y(i))

  Next i

  For i = 1 To k - 1

      For j = 1 To k - i

          If x(j) > x(j + 1) Then

              x(i)=x(i) + x(j)

              x(j) = x(i) - x(j)

              x(j) = x(i) + x(j)   ‘①

              tmp = y(j)

              y(j) = y(j + 1)

              y(j + 1) = tmp

          End If

      Next j

  Next i

  sum = 0: length = 0

  For i = 1 To k - 1

      x1 = (x(i) - x(1)) ^ 2     ‘②

 '变量y1计算方法同x1,代码略

      length = Sqr(x1 + y1)

      sum = sum + length

  Next i

  Text2.Text = Str(Int(sum * 10) / 10)

End Sub

①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#} 

返回首页

试题篮