题目
(13 )补充完整下面的类定义:
const double PI=3 .14;
class Circle{ // 圆形物体的抽象基类
protected:
double r; // 半径
public:
Circle (double radius=0 ) : r (radius ) {}
【 13 】 ; // 计算圆形物体表面积的纯虚函数声明
};
class Cylinder:public Circle { // 圆柱体类
double h; // 高度
public:
Cylindr (double radius=0, doubli height=0 ) :
Circle (radius ) , h (height ) {}
Virtual double Area () { // 计算圆柱体的表面积
return 2*PI*r* (r+h ) ;
}
};
第1题
补充完整下面的类定义:
class XCH{
char*a;
public:
XCH(char*a A) { //构造函数
a=new char[strlen(aA) +1];
strcpy(a,aA) ;
}
XCH&operator=(const XCH&x){//重载赋值函数
delete[ ]a;
a=new char[strlen(x.A) +1];
strcpy(a,x.A) ;
______;
}
~XCH(){delete[ ]a;}
};
第2题
(14 )补充完整下面的类定义:
class XCH{
char* a;
public:
XCH (char* as ) { // 构造函数
a=new char[strlen (aa ) +1];
strcpy (a,aa ) ;
}
XCH& perator= (const XCH& x ) // 重载赋值函数
Delele []a;
A=new char[strlen (x.a ) +l];
strcpy (a, x .a )
【 14 】 ;
}
~XCH () {delete []a;}
};
第3题
补充完整下面的类定义:
class XCH{
char*a:
public:
XCH(char球an){ //构造函数
a=new char[strlen(aft)+1];
strcpy(a,aA);
}
XCH&operator=(const XCH&x){ //重载赋值函数
delete[]a;
a=new char[strlen(X.A)+1];
strcpy(a,x.A);
【 】
}
一XCH(){delete[]a;}
};
第4题
(15 )补充完整下面的模板定义:
template<class Type> //Type 为类型参数
class Xtwo{ // 由两个 Type 类型的数据成员构成的模板类
Type a;
Type b;
public:
Xtwe (Type aa=0, Type bb=0 ) : a (aa ) , b (bb ) {}
int Ccmpare () {// 比较 a 和 b 的大小
if (a>b ) returm 1;
else if (a==b ) return 0;
else return -1;
}
Type Snm () {return a+b;} // 返回 a 和 b 之和
Type Mult () ; // 函数声明,返回 a 和 b 之乘积
} ;
Template<class Type>
【 15 】 : : Mult () {return a*b;} //Mult 函数的类外定义
第5题
补充完整下面的模板定义:
template<class Type> //Type为类型参数
class Xtwo{ //由两个Type类型的数据成员构成的模板类
Type a;
Type b;
public:
Xtwo(Type aa=0,Type bb=0):a(aA) ,b(bB) { }
int Compare(){ //比较a和b的大小
if(a>B) return 1;
else if(a==B) return 0;
else return-1;
}
Type Sum(){return a+b;} //返回a和b之和
Type Mult(); //函数声明,返回a和b之乘积
};
template<class Type>
______ ::Mult(){return a*b;} //Mult函数的类外定义
第6题
补充完整下面的模板定义:
template<class//Type> //Type为类型参数
class Xtwo{//由两个Type类型的数据成员构成的模板类
Type a;
Type b;
public:
Xtwo(Type aa=O,Type bb=O):a(a.A),b(bB){}
int Compare(){//比较a和b的大小
if(a>B)retum 1;
else if(a==@B)@return 0;
else return-1:
f
}
Type Sum();{return a+b;}//返回a与b的和
Type Mult(); //函数声明,返回a和b的乘积
};
template<class Type>
【 】::Mult(){return a*b;}//Mult函数的类外定义
第7题
(13 )在 MyClass 类的定义中,对赋值运算符 = 进行重载。请将画线处缺失的部分补充完整。
【 13 】 MyClass::operator=(const MyClass& rhs)
{
if (this == &rhs) return *this;
value = rhs.value;
return *this;
}
第8题
第9题
第10题
数的定义补充完整。
class Rational{
public:
Rational(int aa, int qq):a(aa),q(qq){ }
friend 【 14 】 operator<<(ostream &out, Rational &x)
{
return (out<<x.a<< ' / ' <<x.q);
}
private:
int a,q;
};
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!