有如下程序:Private Sub Command1_Click()a$="A WORKER IS HERE"x=Len(a$)For i=1 To x - 1b$=Mid$(a$, i, 3)If b$="WOR" Then S=S + 1NextPrint SEnd Sub单击命令按钮,程序运行结果为A.1B.2C.3D.5

题目

有如下程序:

Private Sub Command1_Click()

a$="A WORKER IS HERE"

x=Len(a$)

For i=1 To x - 1

b$=Mid$(a$, i, 3)

If b$="WOR" Then S=S + 1

Next

Print S

End Sub

单击命令按钮,程序运行结果为

A.1

B.2

C.3

D.5


相似考题
参考答案和解析
正确答案:A
解析:此题考查字符串函数与循环语句的嵌套使用,S用来记录找到指定字符串的次数,在"A WORKER IS HERE"中只出现一次,所以返回值是1。
更多“有如下程序: Private Sub Command1_Click()a$="A WORKER IS HERE" x=Len(a$) For i=1 To x - 1 ”相关问题
  • 第1题:

    若有以下程序:include using namespaces std;class A{public: A (){} A (int i) {x1=

    若有以下程序: #include <iostream> using namespaces std; class A { public: A (){} A (int i) { x1=i; } void dispa() { cout<<"xl="<<xl<<" , "; } private: int x1; }; class B : public A { public: B (){} B (int i):A(i+10) { x2=i; } void dispb() { dispa (); cout <<"x2="<<x2<<end1; } private: int x2; }; int main () { B b(2); b.dispb (): return 0; } 程序运行后的输出结果是( )。

    A.x1=10,x2=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C
    解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数宋初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数,使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对子对象初始化的构造函数。本题中,在派生类B的构造函数中,调用基类A的构造函数对基类A的数据成员x1进行了初始化。

  • 第2题:

    若有以下程序:includeusing namespaces std;class A{public:A(){}A(int i){x1=i; } v

    若有以下程序: #include<iOStream> using namespaces std; class A { public: A(){} A(int i) { x1=i; } void dispa() { cout<<"X1="<<x1<<",": } private; int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<end1; } private: int x2; }; . int main() { B b(2); b.dispb() return 0; } 程序运行后的输出结果是( )。

    A.x1=10,x2=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C
    解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数来初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对于对象初始化的构造函数。

  • 第3题:

    若有以下程序:include using namespace std;class A{public:A() { }A(int i){x1=i;}v

    若有以下程序: #include <iostream> using namespace std; class A { public: A() { } A(int i) { x1=i; } void dispa0 { cout<<"x1="<<x1<<","; } private: int x1; }; class B: public A { public: B() { } B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<endl; } private: int x2; }; int main() { B b(2); b.dispb(); return 0; } 程序运行后的输出结果是( )。

    A.x1=10,x2=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C

  • 第4题:

    若有以下程序:includeusing namespaces std;class A{public: A(){} A(int i) {xl=i;

    若有以下程序: #include<iostream> using namespaces std; class A { public: A(){} A(int i) { xl=i; } void dispa() { cout<<"x1="<<x1<<","; } private: int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<endl; } private: int x2; }; int main{) { B b(2); b.dispb(): return 0; } 程序运行后的输出结果是

    A.x1=10,x2=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C
    解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数来初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对子对象初始化的构造函数。

  • 第5题:

    若有以下程序:include using namespaces std;class A {public: A(){} A(int i) {x1=i

    若有以下程序: #include <iostream> using namespaces std; class A { public: A(){} A(int i) { x1=i; } void dispa() { cout<<'x1="<<x1<<","; } private: int x1; }; class B: public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<end1; } private: int x2; }; int main() { B b(2); b.dispb(): return 0; } 程序运行后的输出结果是

    A.x1=10,x2=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C
    解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数来初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对子对象初始化的构造函数。