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); }
};
(14)补充完整下面的类定义: class XCH{ char* a; public:
XCH(char* as) { //构造函数 a=new char[strlen(aa)+1]; strcpy(a,aa); }
XCH& operator=(const XCH& x) //重载赋值函数 Delele []a;
A=new char[strlen(x.a)+l]; strcpy(a, x .a) 【14】; }
~XCH() {delete []a;} };
(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之乘积 };
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库2008年9月至10年9月全国计算机等级考试二级C++笔试试题及答案(19)在线全文阅读。
相关推荐: