有下列程序:Option Base 0Private Sub Command1_Click() Dim City As Variant x = Array("Visual

题目

有下列程序: Option Base 0 Private Sub Command1_Click() Dim City As Variant x = Array("Visual","Basic","Microsoft","Programming") Print x(2) End Sub 程序运行后,单击命令按钮,则在窗体上显示的内容是

A.Microson

B.错误提示

C.Visual

D.Basic

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

由Array函数建立的数组必须是Variant类型。()

此题为判断题(对,错)。


正确答案:正确

第2题:

在下列的程序的横线处填上适当的语句,使该程序的输出为12。include using namespace

在下列的程序的横线处填上适当的语句,使该程序的输出为12。

include<iostream.h>

using namespace std;

class Base

{

public:

int a,b;

Base(int i){a=i;}

};

class Derived:public Base

{

int a;

public:

Derived(int x):Base(x),b(x+1){};

void show()

{


正确答案:eoutBase::a。
eoutBase::a。 解析: 本题考查的是基类和派生类的构造函数。派生类构造函数的执行顺序:首先调用基类的构造函数,调用顺序按它们被继承时说明的顺序;然后调用子对象的构造函数,调用顺序按它们在类中说明的顺序;最后是派生类构造函数中的内容。本题要求结果是输出12,分析题目,首先调用基类的构造函数,然后是调用子对象的构造函数,横线处要求输出基类成员a的值,填入toutBase::a即可。

第3题:

有以下程序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。

第4题:

有以下程序: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。

第5题:

有以下程序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。

第6题:

在窗体上面一个名称为Commandl的命令按钮,然后编写如下程序: Option.Base 1 Private Sub Command1_Click() Dim a As Variant a=Array(1,2,3,4,5) Sum = 0 For i = 1 To 5 Sum=Sum+a(i) Next i x=Sum/5 For i=1 To 5 If a(i) >x Then Print a(i); Next i End Sub 程序运行后,单击命令按钮,在窗体上显示的内容是

A.1 2

B.1 2 3

C.3 4 5

D.4 5


正确答案:D
解析:本题主要考查考生对程序代码的阅读理解能力。用Array函数为数组a(5)赋值,其元素分别为1、2、3、4、5。第一个For i循环把a(i)数组中的元素逐个加到变量Sum上,然后求出Sum浮点除5的结果(为3),赋值给变量x。第二个Fori循环表示当a(i)大于3时,则用Print语句输出该元素。据此,正确答案为D。

第7题:

有以下程序 include using namespace std; class Base { int a; public: Base(int x)

有以下程序

include <iostream>

using namespace std;

class Base

{

int a;

public:

Base(int x){ a=x; }

void show(){ cout<<a; }

class Derived : public Base

{

int b;

public:

Derived(int i) :Base(i+1),b(i){}

void show() { cout<<b;

};

int main ()

{

Base b(5),*pb;

Derived d(1);

pb=&d;

pb->show ();

return 0;

}

运行后的打印结果是______。


正确答案:2
2 解析:本题考核基类指针与派生类指针的使用。本例程序中类Derived是从基类Base公有继承来的。main()中定义了基类对象b和一个基类指针pb,又定义了派生类Derived的对象d。由于Derived是Base的子类型,因此可以将派生类Derived的对象d的地址赋值给指向基类Base的指针pb,但这时指针pb只能使用从基类Base继承的成员。所以通过对象指针Pb调用的show函数是基类的成员函数show(),从而输出基类私有数据成员a的值2。

第8题:

有以下程序:include using namespace std; class Base { public: Base() { K=0; } int

有以下程序:

include<iostream>

using namespace std;

class Base

{

public:

Base()

{

K=0;

}

int x;

};

class Derivedl:virtual public Base

{

public:

Derivedl()

{

x=10;

}

};

class Derived2:virtua1 public Base


正确答案:20。
20。 解析: 本题中,虽然Derived1和Derived2由于引入了虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derived1中修改,还是在类Derived2中修改,都是直接对这惟一拷贝进行操作。本题程序执行语句“Derived obi;”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived1的构造函数使得x=10,再执行类Derived2的构造函数,使得x=20。最后输出x的值为20。

第9题:

有以下程序: included using namespace std; class Base { public: Base( ) { x=0; }

有以下程序:

included<iostream>

using namespace std;

class Base

{

public:

Base( )

{

x=0;

}

int x;

};

class Derived1:virtual public Base

{

public:

Derived1( )

{

x=10;

}

};

class Derived2:virtual public Base

{

public:

Derived2( )

{

x=20;

}

};

class Derived: public Derived1,protected Derived2

{ };

int main( )

{

Derived obj;

cout<<obj. x<<endl;

return 0;

}

该程序运行后的输出结果是______。


正确答案:20
20 解析:本题考核虚基类。本题中,虽然Derived 1和Derived 2都是由共同的基类x派生而来的,但由于引入虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derired 1中修改,还是在类Derived 2中修改,都是直接对这唯一拷贝进行操作。本题程序执行语句“Derived obj;”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived 1的构造函数使得x=10,再执行类Derived 2的构造函数,使得x=20。最后输出x的值为20。