更多"补充完整下面的类定义: const double PI=3.14; c"的相关试题:
[填空题]补充完整下面的类定义:
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:
Cylinder(double radius=0,double height=0);
Circle(radius),h(height)
Virtual double Area( )return 2*PI*r*(r+h); //计算圆柱体的表面积
;
[填空题]补充完整下面的类定义:
const double PI=3.14;
class Circle{ //圆形物体的抽象基类
protected:
double r; //半径
public:
Circle(double radius=0):r(radius){ }
______; //计算圆形物体表面积的纯虚函数声明
};
class Cylinder:public Circle{//圆柱体类
double h; //高度
public:
Cylinder(double radius=0,double height=0);
Circle(radius),h(height){ }
Virtual double Area( ){return 2*PI*r*(r+h);}//计算圆柱体的表面积
};
[填空题]补充完整下面的类定义:
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;}
};
[填空题]
类Sample的构造函数将形参data赋值给数据成员data。请将类定义补充完整。
class Sample{
public:
Sample(int data=0);
Private:
Int data;
};
Sample::Sample(int data){
【10】
}
[填空题]请将下列类定义补充完整。
class Base{public:void fun( ){cout<<"Base::fun"<<end;}};
class Derived:public Base
{
public:
void fun( )
{
【13】 //显式调用基类的fun函数
cout<<"Derived::fun"<<endl;
}
};
[填空题]请将下列类定义补充完整。
class Base public: void fun( )cout<<"Base::fun"<<end1; ;
class Derived:public Basepublic:
void fun( ) 【15】 //显式调用基类的fun函数
cout<<"Derived:: fun"<<end1;;
[填空题]请将下列类定义补充完整,横线处应填加语句______。
class TestClasspublic:void fun( )cout<<"Base::fun"<<end1;;
class TestClass1:public TestClass
public:
voidfun( )
______;//显示调用基类的fun函数
cout<<"TestClass1::fun"<<end1;
;
[填空题]
补充完整下面的类定义:
class XCH{
char*a;
public:
XCH(char*aa){ //构造函数
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;)
}
[填空题]请将下列类定义补充完整。
classBasepublic:void fun( )cout<<“Base::fun”<<endl;;
class Derived:public Base
public:
void fun( )
______//显式调用基类的fun函数
cout<<“Derived::fun”<<endl;;
[填空题]有如下类定义,请将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;
};
[单项选择]有如下类定义
class Test{
char a; const char b;
public:Test(char c){a=c;b=c;} //第1行
void f(char a)const{this->a=a;} //第2行
void g(char b){this->b=b;} //第3行
char h( )const{return a;} //第4行
};
编译时没有错误的行是
A. 第1行
B. 第2行
C. 第3行
D. 第4行
[填空题]补充完整下面的模板定义:
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函数的类外定义
[填空题]
补充完整下面的模板定义:
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函数的类外定义
[填空题]
请将下面程序补充完整。
public class PowerCalc{
public static void main(String[]args){
double x=5.0;
System. out. println(x+"to the power 4 is"+power(x, 4));
System. out. println("7. 5 to the power 5 is"+power(7.5, 5));
System. out. println("7.5 to the power 0 is"+power(7.5, 0));
System. out. println("10 to the power -2 is"+power(10, -2));
}
static double 【11】 (double x, int n){
if(n>1)
return x * power(x, n-1);
else if(n<0)
return 1.0/power(x, -n);
else
return n==0 1.0:x;
}
}
[填空题]下面是一个类的定义,试将程序补充完整。
class Test
String s;
【12】 int a =66;
Test(String s1)
s=s1;
static int geta( )
return a;