const double PI=3 .14;
class Circle{ // 圆形物体的抽象基类
protected:
double r; // 半径
public:
C.ircle ( double radius=0 ) : r ( radius ) {}
( 13 ) ; // 计算圆形物体表面积的纯虚函数声明
};
class Cylinder:public Circle { // 圆柱体类
double h; // 高度
public:
C.ylindr ( double radius=0, doubli height=0 ) :
C.ircle ( radius ) , h ( height ) {}
Virtual double Area () { // 计算圆柱体的表面积
return 2*PI*r* ( r+h ) ;
}
};
[试题]( 14 )补充完整下面的类定义:class XCH{char* a;public:XCH ( char* as ) { // 构造函数a=new char[strlen ( aa ) +1];strcpy ( a,aa ) ;}XCH& perator= ( const XCH& x ) // 重载赋值函数D.elele []a;A.=new char[strlen ( x.a ) +l];strcpy ( a, x .a )( 14 ) ;}~XCH () {delete []
[主观题]补充完整下面的类定义: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;}};
[主观题]补充完整下面的模板定义: template£¯£¯Type为类型参数 class Xtwo{£¯£¯由两个Type类型补充完整下面的模板定义: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
[单选题]已知有定义:const int D=5;int i=1;double f=0.32;char c=15;则下列选项错误的是A.++i;B.D--;C.c++;D.--f;
[试题]( 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;el
[单选题]已知有定义 const int D=5; int i=1; double f=0.32; char c=15; 则下列选项错误的是A.++i;B.D--;C.c++;D.--f;
[主观题]下面是一个类的定义,试将程序补充完整。class A{String s;____int a=66;A.(String sl){s=sl;}static int geta(){return a;}}
[判断题] 使用语句Const pi来定义一个符号常量,pi可以在这条语句之后进行赋值。A . 正确B . 错误
[单选题]请将下列类定义补充完整。class Base{public:void fun(){tout<<"Base::fun"<<endl;}};class Derived:public Base{public:void fun(){______//显示调用基类的fun函数cout<<"Derived::fun"<<endl;};
[试题]( 13 )有如下复数类的声明,请补充完整。class complex{double real; // 实部double imag; // 虚部public:complex(double x , double y){real=x;imag=y;}perator+(complex c){// 重载加法运算符 “ + ”return complex(___________)}};