更多“(28)下列程序的运行结果是。 Private Sub Command1_Click() a=1.5 b=1.5 Call fun(a,b) Print a,b ”相关问题
  • 第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题:

    下列程序的运行结果是( )。 Private Sub Command1_Click() a=1.5 b=1.5 Call fun(a,B) Print a,b End Sub Private Sub fun(x,y) x=y*y y=y+x End Sub

    A.2.25 3.75

    B.1.5 2.25

    C.1.5 0.75

    D.0.75 1.5


    正确答案:A
    解析: 分析程序,命令按钮中的调用函数语句执行过程为:Call fun(a,b)→x=y*y=1.5*1.5=2.25,y=y+x=1.5+2.25=3.75。因为这里的参数是默认类型,即传地址形式传递参数,所以a、b的值也改变为2.25、3.75。

  • 第3题:

    下述代码返回的结果是 x = -3.5 if x < 0: print(x+2) else: print(-1*x-5)

    A.1.5

    B.0

    C.-1.5


    val()

  • 第4题:

    若有以下程序: include usingnamespace std; class Sample { private: const int n;

    若有以下程序:

    include <iostream>

    using namespace std;

    class Sample

    {

    private:

    const int n;

    public:

    Sample(int i) :n(i) {)

    void print()

    {

    cout<<"n="<<n<<end1;

    }

    };

    int main()

    {

    sample a(10);

    a.print();

    return 0;

    }

    上述程序运行后的输出结果是【 】。


    正确答案:n=10
    n=10 解析:本题考核常成员数据的应用。类Sample中,定义了一个常数据成员n,所以构造函数只能通过初始化列表来初始化它。

  • 第5题:

    下列程序的输出结果是___________。x = 1 def fun(): global x x = 2 fun() print(x)

    A.2

    B.0

    C.1

    D.3


    1