下列程序的运行结果是______。Sub abcd(ByValn As Integer) n=n+5 End Sub Private Sub Form_Clic

题目

下列程序的运行结果是______。

Sub abcd(ByValn As Integer)

n=n+5

End Sub

Private Sub Form_Click()

nx%=3

Callabcd(nx%)

Printnx%

End Sub

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

第1题:

有以下程序:include using namespace std;class sample{private: int n;public: samp

有以下程序: #include <iostream> using namespace std; class sample { private: int n; public: sample(){} sample (int m) { n=m; } sample add(sample s1,sample s2) { this->n=s1.n+s2.n; return (*this); } void disp() { cout<<"n="<<n<<end1; } }; int main () { sample s1(10) ,s2(5),s3; s3.add(s1,s2); s3.disp(); return 0; } 程序运行后,输出的结果是( )。

A.n=10

B.n=5

C.n=20

D.n=15


正确答案:D
解析:本题考核this指针的应用。本程序中,sample类的add成员函数中使用了this指针,this指针指向当前对象自身,该成员函数中的语句“this->n=s1.n+s2.n;”用于修改当前对象的数据成员n的值,语句“return(*this);”用于返回当前对象自身,即对当前对象进行了修改。对于主函数调用add()成员函数语句“s3.add(s1,s2);”。此时,this指针指向的是对象s3,执行该语句前,s3的数据成员n未赋值,执行完该语句后,就修改了s3的私有成员n的值,使其为15。

第2题:

若有以下程序: 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,所以构造函数只能通过初始化列表来初始化它。

第3题:

有下列程序 program aa; var n:integer; b:real; begin t:=1;b:=1;n:=2; repeat b:=b*n; t:=t+b; n:=n+1 until n>19 end 该程序运行后,变量t中的值是下列哪个公式的结果( )。

A20!

B19!

C1!+2+…19!

D1!+2!+…20!


正确答案:D

第4题:

有以下程序:include using namespacestd;class sample{private:int n:public:sample

有以下程序: #include <iostream> using namespace std; class sample { private: int n: public: sample () {} sample(int m) { n=m; } sample add(sample s1, sample s2) this->n=s1.n+s2.n; return (*this); } void disp () { cout <<"n="<<n<<end1; } }; int main() sample s1(1)0,s2(5),s3; s3.add(s1,s2); s3.disp(); return 0; } 程序运行后,输出的结果是

A.n=10

B.n=5

C.n=20

D.n=15


正确答案:D
解析:本题考核this指针的使用。类成员函数add中通过this指针实现私有数据成员n的赋值。

第5题:

若有以下程序: #include 〈iostream〉 using namespace std; class sample { private: int n; public: sample(){} sample(int m) { n=m; } void addvalue(int m) { sample s; s.n=n+m; *this=s; } void disp() { cout〈〈"n="〈〈n〈〈end1; } }; int main() { sample s(10); s.addvalue(5); s.disp(); return 0; } 程序运行后的输出结果是( )。

A.n=10

B.n=5

C.n=15

D.n=20


正确答案:C
解析:本题考核this指针的应用。本程序中sample类定义了一个addvalue非静态成员函数。addvalue()函数的原型是:voidaddvalue(sample*this,intm);,该函数的第1个参数是执行该类对象的一个指针,即this指针。由于这个参数是系统隐含的,所以在定义该成员函数时并没有看到这样一个参数。在成员函数的定义体中,可以通过this访问这一参数。程序的最后输出结果是15。

第6题:

若有以下程序:includeusing namespace std;class sample{private:int n;public:sampl

若有以下程序: #include<iostream> using namespace std; class sample { private: int n; public: sample(){} sample(int m) { n=m; } void addvalue(int m) { sample s; s.n=n+m; *this=s; } void disp() { cout<<"n"=<<n<<end1; } }; int main() { sample s(10); s.addvalue(5); s.disp(); return 0; } 程序运行后的输出结果是

A.n=10

B.n=5

C.n=15

D.n=20


正确答案:C
解析:本题考核this指针的应用。上述程序中sample类定义了一个addvalue非静态成员函数。addvalue函数的原型是:voidaddvalue(sample*this,intm);,该函数的第一个参数是执行该类对象的一个指针即this指针。由于这个参数是系统隐含的,所以我们在定义该成员函数时并没有看到这样一个参数。在成员函数的定义体中,可以通过this访问这—参数。上述程序的最后输出结果是15。

第7题:

有以下程序:include using namespace std;class sample {private: iht n;public: sam

有以下程序: #include <iostream> using namespace std; class sample { private: iht n; public: sample(){} sample(int m) { n=m; } void addvalue(int m) { sample s; s.n=n+m; *this=s; } void disp() { cout<<"n="<<n<<end1; } }; int main() { sample s(10); s.addvalue(5); s.disp(); return 0; } 程序运行后的输出结果是

A.n=10

B.n=5

C.n=15

D.n=20


正确答案:C
解析:本题考核this指针的应用。上述程序中sample类定义了一个addvalue非静态成员函数。addvalue函数的原型是:voidaddvalue(sample*this,intm);,该函数的第一个参数是执行该类对象的一个指针即this指针。由于这个参数是系统隐含的,所以我们在定义该成员函数时并没有看到这样一个参数。在成员函数的定义体中,可以通过this访问这一参数。上述程序的最后输出结果是15。

第8题:

下面程序段的运行结果是()。(注:└┘代表空格)include "stdio.h"main(){ char s[6]s="abcd"printf("\"%s\"\n", s)}

A."abcd"

B."abcd└┘"

C.\"abcd\"

D.编译出错


答案:D

第9题:

有以下程序:include using namespace std;class sample{private:intn;public:sample(

有以下程序:#include <iostream>using namespace std;class sample{private: int n;public: sample() {} sample(int m) { n=m; } sample add(sample s1,sample s2) { this->n-s1.n+s2.n; return (*this); void disp() { cout <<"n="<<n<<end1; } };int main (}{ sample s1(10),s2(5),s3; s3.add(s1,s2); s3.disp (); return 0;}程序运行后,输出的结果是

A.n=10

B.n=5

C.n=20

D.n=15


正确答案:D
解析:本题考核this指针的应用。上述程序中,sample类的add成员函数中使用了this指针,this指针指向当前对象自身,该成员函数中的语句:this->n=s1.n+s2.n;,用于修改当前对象的数据成员n的值,语句:return(*this);用于返回当前对象自身,即对当前对象进行了修改。对于main()函数调用add成员函数语句“s3.add(s1,s2);”。此时,this指针指向的是对象s3,执行该语句前,s3的数据成员n未赋值,执行完该语句后,就修改了s3的私有成员n的值,使其为15。

第10题:

下列程序,显示的运行程序结果是*** for i in range(1,4,1): print("*",end="")


s=3 当k=7时,执行case7,s++,s的值为1。当k=6时,直接break出switch结构;当k=5时,执行case5,s+=2,s的值为3;当k=4时由于不满足for循环的条件,所以结束循环,所以输出的s的值为3。注意:循环语句和条件的嵌套使用。