补充完整下面的类定义:class XCH{char*a;public:XCH(char*a A) { //构造函数a=new char[strlen(aA) +1];strcpy(a,aA) ;}XCHoperator=(const XCHx){//重载赋值函数delete[ ]a;a=new char[strlen(x.A) +1];strcpy(a,x.A) ;______;}~XCH( ){delete[ ]a;}};

补充完整下面的类定义:

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;}

};


相关考题:

使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示雇员的Employee类,但类Em-ployee的定义并不完整。请按要求完成下列操作,将类TC的定义补充完整。 (1)定义私有数据成员name、street、city、zipcode和age分别用于表示姓名、街道、城市、邮编、年龄,除年龄是整型外,其余都是char型的数据。请在注释1之后添加适当的语句。 (2)完成默认构造函数TC的定义,使其把参数传递给私有数据成员name、streel、city、zipcode和age。请在注释2之后添加适当的语句。 (3)完成成员函数aherName(char*newName)的定义。请在注释3之后添加适当的语句。 (4)完成成员函数IsEqual(char*ename)的定义,实现当name相等时返回真,否则返回假的功能。请在注释4之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 试题程序: includeiostream.h includestring.h) defineMAXLEN20 classTC { private: //********、******** intage; public: TC(char*newName,char*newStreet,char* newCt,char*newZp,intnewAge); voidalterName(char*newName); voiddisplay(); boolIsEqual(char*ename); }; TC::TC(char*newName,char*newStreet,char* newCt,char*newZp,intnewAge) { //********2******** age=newAge; } voidTC::alterName(char*newName) { //********3******** } boolTC::IsEqual(char*ename) { //********4******** } voidTC::display() { coutname""street""; coutcity""zipcode""ageendl; } voidmain(void) { TCemployee[4]= { TC("张三","海淀区复兴路l号","北京","000001",18), TC("李四","海淀区复兴路2号","北京","000002",19), TC("王五","海淀区复兴路3号","北京","000003",20), TC("赵六","海淀区复兴路4号","北京","000004",21) }; for(inti=0;i4;i++) employee[i].display(); cout"\n修改\"李四\"的名字为\"李小四\"\n"endl; for(intj=0;j4;j++) { if(employee[j].IsEqual("李四")) { employee[j].aherName("李小四"); employee[j].display(); break; } } }

( 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;}};

使用VC6打开考生文件夹下的工程test17_3,此工程包含一个源程序文件test17_3.cpp,其中定义了用于表示点的类Point和表示内容的类Text以及二者的派生类CircleWithText,但它们的定义并不完整。请按要求完成下列操作,将它们的定义补充完整。(1)定义类Point的构造函数,请使用参数列表的形式将成员函数x和y分别初始化为参数x1和y1的值。请在注释“//**1**。”之后添加适当的语句。(2)完成类Text的构造函数Text(char *str)的定义,将char型的str指向的内容赋值给text并且输出str所指向的内容,请在注释“//**2**”之后添加适当的语句。(3)定义类CircleWithText的构造函数CircleWithText(int cx,int cy,char *msg),int型的cx和cy用于赋值给x和y,char型的指针*msg用于赋值给text,请在注释“//**3**”之后添加适当的语句。输出结果如下:Point:3 4hello注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件test17_3.cpp清单如下:include <iostream.h>include <string.h>class Point{int x,y;public://**1**{cout<<"Point:"<<x<<' '<<y<<'\n';}~Point(){}};class Text{char text[100];public:Text(char *str){//**2**}~Text () { }};class CircleWithText:public Point,public Text{public://**3**{}~CircleWithText() {}};void main(){CircleWithText cm(3,4,"hello");}

使用VC6打开考生文件夹下的工程test4_3。此工程包含一个源程序文件test4_3.cpp,其对一个学校的教师和考生情况进行了描述。由于教师和考生之间有相同的信息,如姓名、年龄等,所以可抽象出一个基类person,考生类student和教师类teacher作为person类的派生类。请按要求完成下列操作,将程序中的类定义补充完整。(1)定义基类person的私有数据成员name和age,分别用于表示姓名和年龄,name为字符指针,age为血型的数据。请在注释“//**1**”之后添加适当的语句。(2)完成基类person的重载构造函数person(char *mint a)的定义,把数据成员name,age分别初始化为参数n,a的值,请在注释“//**2**”之后添加适当的语句。(3)根据主函数main中对s1的声明,定义派生类student的构造函数。在注释“//**3**”之后添加适当的语句。(4)完成派生类teacher成员函数void setinf(ehar *n,int a,char *d,char *1)的定义,其功能为记录教师的姓名、年龄、院,系与职称信息。请在注释“//**4**”之后添加适当的语句。输出结果如下:刘雷(45)destructor蒋军(23)destructor注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件test4_3.cpp清单如下:include<iostream.h>class person{//**1**public:person(){}person(char *n,int a){//**2**}void setname(char *n){name=n;)void setage(int a){age=a;}~person(){cout<<name<<"("<<age<<")destructor"<<endl;)};class student:public person{char *department;int code;public://**3**{department=d;code=c;}};class teacher:public person{char *department;char *level;public:teacher(){}void setinf(char *n,int a,char *d,char *1){//**4**department=d;level=1;}};void main(){student s1("蒋军",23,"计算机学院",2);teacher t1;t1.setinf("刘雷",45,"计算机学院","教授");}

请将下面的程序补充完整,使得程序输出“飘是张娜的书”。includeusing namespace stdclass Book{public:Book(char*str)|strcpy(title,str);______void Printlnfo(){cout<<title<<endl;}protected:char title[50];};class MyBook:public Book{public:MyBook(char*s1,char*S2=“张娜”):______strcpy(owner,s2);}virtual void PrintInfo(){cout<<title<<“是”<<owner<<“的书”<<endl;}private:charowner[10];};int main(){Book*ptr=new MyBook(“飘”);ptr-Printlnfo();return 0;}

根据程序中的注释将下列缺失部分补充完整。class A{char*a;public:A():a(0){}A(char*aa){ //把aa所指字符串复制给a所指向的存储空间a= 【 】 char[strlen(aa)+1];strcpy(a,aa);}~A(){delete[]a;}}

补充完整下面的类定义:class XCH{char*a:public:XCH(char球an){ //构造函数a=new char[strlen(aft)+1];strcpy(a,aA);}XCHoperator=(const XCHx){ //重载赋值函数delete[]a;a=new char[strlen(X.A)+1];strcpy(a,x.A);【 】}一XCH(){delete[]a;}};

已知String类定义如下:class String{public:String(const char *str = NULL); // 通用构造函数String(const String another); // 拷贝构造函数~ String(); // 析构函数String perater =(const String rhs); // 赋值函数private:char *m_data; // 用于保存字符串};尝试写出类的成员函数实现。

使用VC6打开考生文件夹下的工程test18_3,此工程包含一个源程序文件test18_3.cpp,其中定义了用于表示雇员的类 Employee,但类Employee的定义并不完整。请按要求完成下列操作,将类Employee的定义补充完整。(1)补充类Employee的构造函数,请使用字符串函数将数据成员name,address,city,province和zipcode分别初始化为参数*nm,*addr,*city,*prov和*zip的值。请在注释“//**1**”之后添加适当的语句;(2)完成类Employee的成员函数ChangeName(char * newName)的定义,将newName指向的内容赋值给数据成员name,请在注释“//**2**”之后添加适当的语句;(3)完成类Employee的成员函数Display()的定义,先使用指针buffer动态申请一个char型的200单位大小的空间,然后使用字符串函数将数据成员name和address依次复制其中,最后返回该指针buffer,将请在注释“//**3**”之后添加适当的语句。输出结果如下:王东建国路大街105号注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件test18_3.cpp清单如下:include <iostream.h>include <string.h>class Employee{protected:char name[20];char address[100];char city[20];char province[20];char zipcode[10];public:Employee(char *nm, char *addr,char *city, char *prov, char *zip);void ChangeName(char *newName);char *Display();};Employee::Employee(char *nm, char *adr, char *cit, char *prov, char *zip){//**1**strcpy(city, cit);strcpy(province,prov);strcpy(zipcode,zip);}void Employee::ChangeName(char * newName){//**2**}char *Employee::Display(){//**3**strcat(buffer, address);return buffer;}void main(){Employee emp("李华","建国路大街105号","石家庄","河北","103400");emp. ChangeName ("王东");cout<<emp.Display()<<end1;}