有如下程序:Private type stu X as string Y as integerEnd typePrivate Sub Command1_Click() D

题目

有如下程序:

Private type stu

X as string

Y as integer

End type

Private Sub Command1_Click()

Dim a as stu

a.x=”ABCD”

a.Y=12345

print a

End Sub

程序运行时出现错误,错误的原因是

A)Type定义语句没有放在标准模块中

B)变量声明语句有错

C)赋值语句不对

D)输出语句print不对

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

第1题:

有如下程序:includeusing namespace std;class Base{private:char c;piblic:Base(cha

有如下程序: #include<iostream> using namespace std; class Base { private: char c; piblic: 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题:

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

有以下程序: #include<iostrearn> 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; }

A.x=10,y=20

B.x=20,y=30

C.x=30,y=20

D.x=30,y=30


正确答案:B
解析:本题考核静态数据成员和静态成员函数的应用。类sample中定义两个私有成员x和y,其中y为静态数据成员。并定义函数print()为静态成员函数。在主函数中,定义对象s1(10)时,通过构造函数使对象s1的私有成员x=10,静态数据成员y=10。定义s2(20)时,通过构造函数使对象s2的私有成员x=20,静态数据成员y=10+20=30。程序最后调用静态成员函数print输出对象s2的私有成员x的值20,对象s1、s2共享的静态数据成员y的值30。

第3题:

有如下程序: include using namespace std; class Monitor{ public: Monitor(cha

有如下程序:

include<iostream>

using namespace std;

class Monitor{

public:

Monitor(char t):type(t){ }

void Print( )const

{cout<<"The type of monitor is"<<type< private:

char type;

};

class Computer{

public:

Computer(int i,char C) :______{}

void Print( )const

{eout<<"The computer is"<<id<<endl;mort.Print( );}

private:

int id;

Monitor mon;

};

int main( ){

const Computer myComputer(101,'B');

myComputer.Print( );

return 0;

}

请将程序补充完整,使程序在运行时输出:

The computer is 101

The type of monitor is B


正确答案:id(I)mon(C)
id(I),mon(C) 解析:带参构造函数的定义格式(在类外部声明)为:
类名::构造函数名([参数表]):数据成员名1(初始值1),数据成员名2(初始值2)……在类中声明为:
构造函数名([参数表]):数据成员名1(初始值1),数据成员名2(初始值2)……
在compute中有两个数据成员,所以在构造函数中应该对这两个数据成员id和mon初始化,初始化mon创建一个对象,参数为构造函数的形参c。

第4题:

有以下程序:include using namespace std;define PI 3.14class Point{ private:int

有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; }

A.314

B.157

C.78.5

D.153.86


正确答案:A
解析:本题考核派生类的定义和应用。本程序设计了一个点类Point,包含了横、纵两个坐标数据x和y,由它派生出了圆类Circle,并加入了新的数据成员,即一个半径r和一个求圆面积的函数成员area。在主函数main中,首先定义了一个圆Circle类的对象c1,并通过它的构造函数初始化其数据成员。由此可知,其半径r的值为10,所以其面积为PI*10'10=314,即对象c1的函数成员area的返回值为314。

第5题:

有以下程序:include include using namespace std;class Y;class X{private

有以下程序: #include <iostream> #include <string> using namespace std; class Y; class X { private: int x; char *strx; public: X(int a, char *str) { x=a; strx=new char[strlen(str)+1]; strcpy(strx,str); } void show(Y &ob) ; }; class Y { private: int y; char *stry; public: Y(int b,char *str) { y=b; stry=new char[strlen(str)+1]; strcpy(stry, str); } friend void X: :show(Y &ob) ; }; void X: :show(Y &ob) { cout<<strx<<", "; cout<<ob, stry<<end1; } int main ( ) { X a(10,"X"); Y b (20, "Y"); a. show(B) ; return 0; } 执行后的输出结果是( )。

A.X,Y

B.a,b

C.X,X

D.Y,Y


正确答案:A
解析:本题考核类的定义和友元函数的应用。①该程序中,类X的成员函数show()在类Y中说明为友元,因此,在该友元成员show()中可以访问类Y的私有成员stry。②成员函数show()的功能就是输出类X的私有成员strx和Y对象ob的私有成员stry,③主函数main()中定义了X类的一个对象a和Y类的一个对象b,并且都进行了初始化。然后调用对象a的成员函数show,输出对象a中私有成员strx中的内容和对象b中私有成员stry中的内容,即字符串stringX和stringY。

第6题:

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

第7题:

有如下程序:include using namespace std;class Base{private:charc;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。

第8题:

有如下程序: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<<“print1”<<endl; } void print()const { cout<<”prin

A.printl

B.print2

C.printl print2

D.程序编译时出错。


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

第9题:

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

第10题:

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

有如下程序:#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