假定有以下程序: Private Sub Form. Click( ) a=1:b=a Do Until a>=5 x=a*b Print b;X a=a+b b=b+a Loop End Sub 程序运行后,单击窗体,输出结果是( )。A.1 1 2 3B.1 1 2 4C.1 1 3 8D.1 1 3 6

题目

假定有以下程序: Private Sub Form. Click( ) a=1:b=a Do Until a>=5 x=a*b Print b;X a=a+b b=b+a Loop End Sub 程序运行后,单击窗体,输出结果是( )。

A.1 1 2 3

B.1 1 2 4

C.1 1 3 8

D.1 1 3 6


相似考题
更多“假定有以下程序: Private Sub Form. Click( ) a=1:b=a Do Until a>=5 x=a*b Print b;X a ”相关问题
  • 第1题:

    有如下程序: include using namespace std; class TestClass { private: int x,y; pu

    有如下程序: #include<iostream> using namespace std; class TestClass { private: int x,y; public: TestClass (int i,int j) { x=i; y=j; } void print() { cout<<"print1"<<end1; } void print()const { cout<<"print2"<<end1; } }; int main() { const TestClass a(1,2); a.print(); return 0; } 该程序运行后的输出结果是( )。

    A.print1

    B.print2

    C.print1 print2

    D.程序编译时出错


    正确答案:B
    解析:由主函数main入手,定义TestClass型的常对象a,然后调用对象a中的成员函数print()。因为在C++中,如果一个对象被声明为常对象,则不能调用该对象中的非const型的成员函数。所以,这里调用的是对象中的const型成员函数“void print()const”,输出为print2。

  • 第2题:

    有以下程序:include include using namespace std;class point{private:doubl

    有以下程序:#include <iostream>#include <math>using namespace std;class point{private: double x; double y;public: point(double a, double b { x=a; y=b; friend double distance (point a, point b ; };double distance(point a, point b return sqrt((a. x-b. x )*(a. x -b. x )+ (a. x -b. x)*(a. x-b. x));}int main (){ point p1 (1,2); point p2(5,2); cout<<distance (p1, p2)<<end1; return 0;} 程序运行后的输出结果是

    A.1

    B.5

    C.4

    D.6


    正确答案:C
    解析:本题考核友元函数的应用。分析程序:类point中定义了两个私有成员x和y,以及一个友元函数distance。从而,函数distance可以访问类point中的任何成员。在函数distance中,返回值为sqrt ((a. x- b. x)*(a. x-b. x)+(a. y-b. y)*(a. y-b. y))。由此可知,函数distance的功能是计算a、b两点之间的距离。在主函数main中,先定义两点:p1(1,2)和p2(5,2)。然后调用函数distance计算两点之间的距离为4,所以程序最后输出为4。

  • 第3题:

    写出下面程序的运行结果,了解do-while语句的使用。 public class cs5 { public static void main(String[] args) { int x = 23; do{ System.out.print(x--); }while(x>20); } }


    C

  • 第4题:

    有以下程序:include using namespace std;class sample{private: int x; static int

    有以下程序:#include <iostream>using namespace std;class sample{private: int x; static int y;public: sample(int a); static void print(sample s);};sample:: sample(int a){ x=a; y+=x;}void sample:: print(sample s){ cout<<"x="<<s. x<<",y="<<y<<end1;}int sample:: y=0;int main(){ sample s1(10); sample s2(20); sample:: print(s2); return 0;}程序运行后的输出结果是( )。

    A.x=10,y=20

    B.x=20,y=30

    C.x=30,y=20

    D.x=30,y=30


    正确答案:B

  • 第5题:

    有下列程序:includeusing namespace std;class TestClass{private:int x,y;public:Te

    有下列程序: #include<iostream> using namespace std; class TestClass { private: int x,y; public: TestClass (int i,int j) { x=i; y=j; } void print() { cout<<"printl"<<endl; } vo

    A.print1

    B.print2

    C.pfint1 print2

    D.程序编译时出错


    正确答案:B
    解析: 由主函数main入手,定义TestClass型的常对象a,然后调用对象a中的成员函数print()。因为在C++中,如果一个对象被声明为常对象,则不能调用该对象中的非const型的成员函数。所以,这里调用的是对象中的const型成员函数“void print ()const”,输出为print2。