有如下两个类定义: classXX{ private: doublexl; protected: doublex2; public: doublex3;
A.1
B.2
C.3
D.4
A.1
B.2
C.3
D.4
A.1
B.2
C.3
D.4
有如下类定义: classXX{ intxdata; public: XX(intn=0):xdata(n){} }; classYY:publicXX{ intydata; public: YY(intm=0,intn=O):XX(m),ydata(n){} }; YY类的对象包含的数据成员的个数是()。
A.1
B.2
C.3
D.4
请定义一个简单的数对类,该类包含两个双精度数。 我们可以通过SetA,SetB,GetA,GetB实现两个数据的设置和获取。 要求不能直接进行两个数据的访问,只能通过提供的方法访问。 例如,它能支持如下的使用(把数对用于保存二维坐标): int main() { DataPair point; point.setA(1.2); point.setB(4); cout<<"x="<<point.geta()<<"; y="<<point.getB(); }<br><p class=" answer">1、假定AB为一个类名,则如下声明语句调用了()次构造函数 AB a(4), b[5], *p;
A.5
B.6
C.7
D.9
A.其应用能正常结束
B.其应用会无限递归
C.类中不能包含成员指针 A* p
D.类成员定义中不能包含指向自身的指针
有如下类定义,请将Sample类的拷贝构造函数补充完整。
class Sample{
public:
Sample(){)
~Sample(){if(p)delete p;)
Sample(const Sample& s){
______
}
void SetData(int data) {p=new int(data);}
private:
int*p;
};
有如下程序:
}}}}include<iostream>
using namespace std;
class Pair{
int m;
int n;
public:
Pair(int i,int J):m(i),n(J){}
bool operator>(Pair P)const; //需在类体外给出定义
};
int main(){
Pair pl(3,4),p2(4,3),p3(4,5);
COUt<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
{
运算符函数operator>功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n.n大者为大。程序输出0101,下列对运算符重载函数的正确定义是
A.bool Pair::operator>(Pair P)const {if(m!=P.m)return m>P.m;return n>P.n;)
B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>P.m;return n>P.n;)
C.bool Pair::operator>(Pair P)const {if(m>P.m)return true;return 11>P.n;)
D.bool Pair::operator>(Pair P) {if(m>P.m)return true;return 11>P.n;}
有如下类定义,请将Sample类的复制构造函数补充完整。
class Sample{
public:
Sample(){ }
~Sample(){if(P)delete P;)
Sample(const Sample&s){______}
void SetData(int datA) {P=new int(datA) ;}
private:
int*P:
};
有如下程序: #include<iostream> using namespaee std; class Pair{ int m; int n; public: Pair(int i,int j):m(i),n(j){ } boot operator>(pair P)const;//需在类体外给出定义 }; int main(){ Pair pl(3,4),p2(4,3),p3(4,5); cout<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2); retum 0; } 运算符函数operator>的功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n,n大者为大。程序输出0101,下列对运算符重载函数的正确定义是
A.bool Pair::operator>(Pair P)eonst
B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>p.In;return n>p.n;} {if(m!=P.m)return m>p.m;return n>p.n;}
C.bool Pair::operator>(Pair P)eonst
D.bool Pair::operator>(Pair P) {if(m>p.m)return true;return n>p.n;} {if(Ul>p.m)return true;return n>p.n;}
A.A) A a = new A();
B.B) A a2;
C.C) A * p = new A();
D.D) A a1(3);
有如下两个类的定义: class AA{}; class BB{ AA vl,*v2; BB v3: int*v4: }; 其中有一个成员变量的定义是错误的,这个变量是
A.v1
B.v2
C.v3
D.v4
有如下两个类定义: class XX{ private: double X1; protected: double x2; public: doublex3; ); clase YY:protected XX{ private: doubley1; protected: doubley2; public: double y3; }; 在类YY中保护成员变量的个数是()。
A.1
B.2
C.3
D.4
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!