当前位置: 答案解析 / 算法与程序设计 / 算法及程序语言基础 / 运算符、基本运算与表达式
  • 1. (2021高三上·浙江月考) 符合产生随机整数n,其范围为(100≤n≤200)的VB表达式是(    )
    A . int(Rnd * 100)+ 100 B . int(Rnd * 100)+101 C . int(Rnd* 101)+100 D . int(Rnd* 101)+101
举一反三换一批
  • 1. 贝贝有n个桃子,吃完后每三个桃核可以换一个桃子,编写一个程序计算贝贝总共能够吃到几个桃子。
    1. (1) 若贝贝总共有7个桃子,则他最后可以吃到个桃子。
    2. (2) 修改程序中的错误。

      程序代码如下:

      Private Sub Command 1_Click()

      Dim n As Integer,ans As Integer

      n =Val(Text1.Text)

      ans = n

      Do While n>3    ‘

       ans = ans + n\3

       n = n\3     ‘

      Loop

      Label2.Caption = “总共能吃到的桃子数为:” + Str(ans)+“个”

      End Sub

  • 2. 在平面坐标系中,给定一组有序的点。从原点出发,依次用线段连接这些点,构成一条折线。要求编写一个“计算折线长度”的程序,功能如下:在文本框Textl中依次输入这些点的坐标值(数据都用逗号分隔并以逗号结尾),单击“计算”按钮Cmd后,程序计算这条折线的长度,结果显示在Label1中。例如,三个点的坐标为(5,10),(8,12),(6,17),输入格式如图所示。


    1. (1) Cmd对象属于类(单选,填字母:A .Form / B .Label/C .TextBox/D .CommandButton).
    2. (2) 实现上述功能的VB程序如下,请在划线处填入合适的代码。

      Private Sub Cmd_Click()

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

      Dim x1 As Single,yl As Single,x2 As Single,y2 As Single

      Dim d As Single,Totald As Single,v As Single,s As String

      s=   ①  

      x1=0:y1=0   '出发点为坐标原点

      k=1:j=1:Totald=0

      For i=1 To Len(s)

        If Mid(s,i,1)="," Then

          v=Val(Mid(s,j,i-j))'提取坐标值,保存在变量ν中

          j=i+1

          lf    ②    Then

            x2=v

          Else

            y2=v

            d=Sqr((x2-x1)^2+(y2-y1)^2)

            Totald=Totald+d

            x1=x2:y1=y2

          End If

          k=k+1

        End If

      Next i

      Label1.Caption=Str(Totald)

      End Sub

    3. (3) 运行该程序,输入题干中的数据,程序执行到循环结束时,变量k为
  • 3. (2019高三上·浙江月考) 某 VB 段程序如下:

    s = Text1.Text

    For i = 1 To Len(s) c = Mid(s, i, 1)

       

    s1 = s1 + c Next i Text2.Text = s1

    程序运行时,在文本框Text1中输入“ABC123xyz”,在文本框Text2中输出“bcd123yza”,则加框①处的代码为(  )

    A.

    A . If c >= "A" And c <= "Z" Then c = Chr(Asc(c)+ 32) If c >= "a" And c <= "z" Then m = (Asc(c) - Asc("a") + 1) Mod 26 c = Chr(m + Asc("a")) End If B . If c >= "A" And c <= "Z" Then c = Chr(Asc(c) + 32) ElseIf c >= "a" And c <= "z" Then m = (Asc(c) - Asc("a") + 1) Mod 26 c = Chr(m + Asc("a")) End If C . If c >= "A" And c <= "Z" Then c = Chr(Asc(c)+32) If c >= "a" And c <= "z" Then m = (Asc(c) - Asc("a") ) Mod 26+1 c = Chr(m + Asc("a")) End If D . If c >= "A" And c <= "Z" Then c = Chr(Asc(c) + 32) ElseIf c >= "a" And c <= "z" Then m = (Asc(c) - Asc("a")) Mod 26 + 1 c = Chr(m + Asc("a")) End If