以下程序的输出结果是( )。 Option Base 1 Private Sub Command1_Click() Dim a(10),p(3) as Integer k=5 For I-1 to 10 a(i)=I Next I For j=1 to3 p(i)=a(I*j) Next j For I=l to 3 k=k+ p (I)*2 Next I Print k End SubA.33B.28C.35D.37

题目

以下程序的输出结果是( )。 Option Base 1 Private Sub Command1_Click() Dim a(10),p(3) as Integer k=5 For I-1 to 10 a(i)=I Next I For j=1 to3 p(i)=a(I*j) Next j For I=l to 3 k=k+ p (I)*2 Next I Print k End Sub

A.33

B.28

C.35

D.37


相似考题
参考答案和解析
正确答案:A
解析:此题中共定义了两个数组:a(0,p(0,共用到了3次For循环。第1个For语句对数组a(i)赋值,a(1)…a(10)=1...10:第2个For语句,对p(1):1,p(2):4,p(3):9;第3个For语句,计算k的值,3次循环分别得到:5,15, 33。答案为A。
更多“以下程序的输出结果是( )。 Option Base 1 Private Sub Command1_Click() Dim a(10),p(3)as Integ ”相关问题
  • 第1题:

    有以下程序include using namespace std:class Base{private:char c;public:Base(cha

    有以下程序#include <iostream>using namespace std:class Base{private: char c;public: Base(char n) :c(n) {} ~Base ( ) { cout<<c; }}; class Derived : public Base{private: char c;public: Derived(char n):Base (n+1),c(n) {} ~Derived() { cout<<c; }};int main(){ Derived obj('x'); return 0;} 执行后的输出结果是

    A.xy

    B.yx

    C.x

    D.y


    正确答案:A
    解析:本题考核继承与派生中继承基类的数据成员与成员函数。在C++中,由于析构函数不能被继承,因此在执行派生类的析构函数时,基类的析构函数也将被调用。执行顺序是先执行派生类的析构函数,再执行基类的析构函数,其顺序与执行构造函数的顺序正好相反.在此题的程序中,在主函数main结束时,派生类Derived对象obj将被删除,所以就会调用对象的析构函数。先调用派生类的析构函数,输出x,然后调用基类的析构函数,输出y。

  • 第2题:

    有以下程序:include using namespace std;class Base{public:Base(){}virtual void w

    有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void who() { cout<<"Base Class"<<end1; } ~Base(){} }; class Derivel : public Base { public: void who() { cout<<"Derivel Class"<<end1; } }; class Derive2 : public Base { public: void who () { cout<<"Derive2 Class"<<end1; } }; int main () { Base *p; Derivel obj1; Derive2 obj2; p=&obj1; p=&obj2; p->who ( ); return 0; } 执行程序后的输出结果是( )。

    A.Base Class

    B.Derivel Class

    C.Derive2 Class

    D.程序编译时出错


    正确答案:C
    解析:本题考核虚函数的应用。本题中,先定义了一个基类Base,它含有一个虚成员函数who(),随后定义的类Derivel和Derive2都是基类Base的公有派生类。在主函数中定义了一个指向Base类的指针,它也被允许指向其派生类。在执行过程中,不断改变它所指向的对象,p->who就能调用不同的函数实现。这是因为使用了虚函数,因而进行动态联编。程序最后把指针p指向派生类Derive2的对象,由于函数who()在基类Base中是虚函数,所以系统调用Derive2中的who()函数,最后输出Derive2Class。

  • 第3题:

    有以下程序:inClUdeusingnamespacestd;ClassBase{public: Base(intx) {a=x; } voidsh

    有以下程序: #inClUde <iostream> using namespace std; Class Base { public: Base(int x) { a=x; } void show() { cout<<a; } private: int a; }; class Derived : public Base { public: Derived(int i) :Base(i+1),b(i){} void Show() { cout<<b; } private: int b; }; int main() { Base b(5),*pb; Derived d(1); pb=&d; pb->show(); return 0; } 运行后的输出结果是( )。

    A.1

    B.5

    C.2

    D.0


    正确答案:C
    解析:基类Base派生出派生类Derived,在主函数中,定义了基类对象b,基类指针pb,以及派生类对象d,并让基类指针pb指向派生类对象d。在C++中,当派生类的对象赋值给基类对象时,只能使用派生类对象中从基类继承的成员。所以最后执行语句“pb->show();”是调用基类的成员函数show(),输出a的值2。

  • 第4题:

    如下程序执行后的输出结果是【】。include using namespace std; class Base { public:

    如下程序执行后的输出结果是【 】。

    include <iostream>

    using namespace std;

    class Base

    {

    public:

    Base(int x,int y)

    {

    a=x;

    b=y;

    }

    void Show()

    {

    cout<<"Base: "<<a<< ',' <<b<<" ";

    }

    private:

    int a,b;

    };

    class Derived : public Base

    {

    public:

    Derived(int x, int y, int z) : Base(x,y),c(z) { }

    void Show()

    {

    cout<<"Derived:"<<c<<end1;

    }

    private:

    int c;

    };

    int main()

    {

    Base b(100,100),*pb;

    Derived d(10,20,30);

    pb=&b;

    pb->Show();

    pb=&d;

    pb->Show();

    return 0;

    }


    正确答案:Base:100100 Base:1020
    Base:100,100 Base:10,20 解析:本题考核对象指针的应用。主函数中通过对象指针pb.分别调用其类成员函数Show()和派生类成员函数Show()先后输出 Base:100,100Base:10,20。

  • 第5题:

    若有以下程序:include using namespace std;class Base{private: inta,b;public: Bas

    若有以下程序: #include <iostream> using namespace std; class Base { private: int a,b; public: Base(int x, int y) { a=x; b=y; } void disp () { cout<<a<<" "<<b<<end1; } }; class Derived : public Base { private: int c; int d; public: Derived(int x,int y, int z,int m) :Base(x,y) { c=z; d=m; } void disp () { cout<<c<<" "<<d<<end1; } }; int main() { Base b(5,5),*pb; Derived obj(1,2,3,4); pb=&obj; pb->disp(); return 0; } 执行程序后的输出结果是( )。

    A.1,2

    B.3,4

    C.2,3

    D.5,5


    正确答案:A
    解析:本题考核基类指针的使用。本题首先定义了一个基类Base和一个由Base派生出来的派生类Derived。在主函数中,定义了一个基类Base指针pb和基类对象b,还定义了派生类Derived的对象obj。然后将派生类对象obj的地址赋值给指向基类Base的指针pb。由于Derived是Base的子类型,因此允许上述赋值,但这时指针pb只能使用从基类Base继承的成员,即当pb指向obj对象时,pb->disp还是调用基类Base的成员函数disp。所以程序最后输出的对象d中对基类成员的初始化值,即1,2。

  • 第6题:

    有以下程序includeusing namespace std;class Base{private:char c;public:Base(char

    有以下程序 #include<iostream> using namespace std; class Base { private: char c; public: Base(char n):c(n){} ~Base() { cout<<c; } }; class Derived:public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj('x'); return 0; } 执行后的输出结果是

    A.xy

    B.yx

    C.x

    D.y


    正确答案:A
    解析:本题考核继承与派生中继承基类的数据成员与成员函数。在C++中,由于析构函数不能被继承,因此在执行派生类的析构函数时,基类的析构函数也将被调用。执行顺序是先执行派生类的析构函数,再执行基类的析构函数,其顺序与执行构造函数的顺序正好相反。在此题的程序中,在主函数main结束时,派生类Derived对象obj将被删除,所以就会调用对象的析构函数。先调用派生类的析构函数,输出x,然后调用基类的析构函数,输出y。