首页 > 公务员考试
题目内容 (请给出正确答案)
[主观题]

有如下类定义;class AA{int a;public:int getRef()const{ return &a; }//①int getValue()con

有如下类定义;

class AA{int a;public:int getRef()const{ return &a; }//①

int getValue()const{ return a; }//②

void set(int n)const{ a=n; }//③

friend void show(AA aa)const{ cout<<a; )//④};

其中的四个函数定义中正确的是()。

A.①

B.②

C.③

D.④

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“有如下类定义;class AA{int a;public:i…”相关的问题
第1题
有如下类定义: Class MyClass{ int value; public: MyClass(int n): value(n){}

有如下类定义: Class MyClass{ int value; public: MyClass(int n): value(n){} int getValue()const{return value;} }; 则类MyClass的构造函数的个数是

A.1个

B.2个

C.3个

D.4个

点击查看答案
第2题
根据下面类中Reverse 函数成员的原型和注释写出它的类外定义。class AA {int* a;int n;int MS

根据下面类中Reverse 函数成员的原型和注释写出它的类外定义。

class AA {

int* a;

int n;

int MS;

public:

void InitAA(int aa[], int nn, int ms) {

if(nn>ms) {cout<< "Error!"<< endl; exit(1);}

MS=ms;

n=nn;

a=new int[MS];

for(int i=0; i

}

AA* Reverse(); // 对于调用该函数的对象,将其a 数组中前n 个

// 元素值按相反的次序排列,返回指向该对象的指针。

};

点击查看答案
第3题
包容类(也称外围类)Contain和内嵌类(也称嵌套类)Embed定义如下: #include <iostream.h> class Contain { int x; protected: int z; public: class Embed { int y; public: Embed(){y=100;} int Embed__Fun(); }MyEmbed; int Contain__Fun(); }; 对上面的定义,正确的描述是

A.定义类Embed对象的语句是:Contain::Embed embed

B.类Contain的成员函数Contain_Fun()中可以用MyEmbed.y的方式访问类Embed的私有成员y

C.类Embed的成员函数Embed_Fun()中可以直接访问类Contain的私有成员x

D.类Embed的成员函数Embed_Fun()中可以直接访问类Contain的保护成员z

点击查看答案
第4题
已知一个类的定义如下:class My Class{……},请写出该类的一个无参构造方法的方法头和一个有参(参数为整型)构造方法的方法头。
已知一个类的定义如下:class My Class{……},请写出该类的一个无参构造方法的方法头和一个有参(参数为整型)构造方法的方法头。

点击查看答案
第5题
若类A的构造函数定义为 A(int aa=1, int bb=0) { a = aa; b = bb; } ,则执行:A x(4);后,x.a和x.b的值分别是()

A.1,0

B.1,4

C.4,0

D.4,1

点击查看答案
第6题
阅读下面程序,写出输出结果。#include using namespace std ; class A { int a, b; public :
阅读下面程序,写出输出结果。#include using namespace std ; class A { int a, b; public :

阅读下面程序,写出输出结果。

#include using namespace std ; class A { int a, b; public : A() { a = b = 0; }

A(int aa, int bb) { a = aa; b = bb; cout << a << ' ' << b << endl ; } }; int main() { A x, y(2,3);

return 0; }

点击查看答案
第7题
根据下面类中Give 函数的原型和注释写出它的类外定义。class Strings {char *s; // 指向动态分

根据下面类中Give 函数的原型和注释写出它的类外定义。

class Strings {

char *s; // 指向动态分配的字符串数组空间

int n; // 记录字符串长度

public:

Strings(char*str); // 构造函数,利用str 字符串长度初始化n,

// 利用str 字符串初始化s 所指的字符串空间

Strings(Strings& str); // 拷贝构造函数

Strings& Give(Strings& str); // 实现str 赋值给*this 的功能并返回*this

Strings Uion(Strings& str); // 实现*this 和str 中的字符串合并的

// 功能,把合并结果存入临时对象并返回

int Lenth() {return n;} // 返回字符串长度

void Print() {cout<<s<<endl;} // 输出字符串

};

点击查看答案
第8题
有如下程序:#inCludeusing nameSpace std;Class A{public:A(inti=0):r1(i){}void plint(){cout&l

有如下程序: #inClude using nameSpace std; Class A{ public: A(inti=0):r1(i){ } void plint(){cout<<‘E’<<r1<<‘-’;} void print()const{cout<<‘C’<<r1*r1<<‘-’;} void print(int X){cout<<‘P’<<r1*r1*r1<<‘-’;} prlvate: intrl; }; intmain(){ Aal; constA a2(4); a1.print(2); a2.print(); returh0; } 运行时的输出结果是()。

A.P8-E4

B.P8-C16-

C.P0-E4-

D.P0-C16-

点击查看答案
第9题
已知有下面类的说明:public class X5 extends x{private float f=10.6f;int i=16;static int s

A.x.f

B.this.si

C.super.i

D.super.f

点击查看答案
第10题
如下代码str1='abcd' print(type(str1[0]))的运行结果是()。

A、<class 'char'>

B、<class 'int'>

C、<class 'float'>

D、<class 'str'>

点击查看答案
第11题
请写出如下程序的输出结果:#include class R{public:R(int r1,int r2) {R1=r1;R2=r2;}void p
请写出如下程序的输出结果:#include class R{public:R(int r1,int r2) {R1=r1;R2=r2;}void p

请写出如下程序的输出结果:

#include class R{public:R(int r1,int r2) {R1=r1;R2=r2;}void print();

void print() const;private:int R1,R2;};void R::print(){cout<< R1<< ":"<< R2<< endl;

}void R::print() const{cout<< R1<< ";"<< R2<< endl;}void main(){R a(5,4);a.print();

const R b(20,52);b.print();}

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改