声明一个Employee类-其中包括姓名、街道地址、城市和邮编等属性-以及chang-name()和

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

/*用C++实现的代码*/#includeiostreamusingnamespacestd;classEmployee{private:char*name,*address,*city,*postCode;public:Employee(char*_name,char*_address,char*_city,char*_postCode){name=_name;address=_address;city=_city;postCode=_postCode;}voidchange_name(char*_name){name=_name;}voiddisplay(){coutname:nameendl;coutaddress:addressendl;coutcity:cityendl;coutpostcode:postCodeendl;}};intmain(intargc,char*argv[]){Employee*e=newEmployee(zhangsan,changdd,beijing,100056);e-display();e-change_name(lisi);e-display();deletee;}#includestring.hclassemployee{protected:charname[10];//姓名charstreet[20];//街道地址charcity[10];//市charprov[10];//省charpost[7];//邮政编码intno;//记录序号public:employee(char[],char[],char[],char[],char[],int);voidchangename(charstr[]);voiddisplay();};employee::employee(charn[],chars[],charc[],charp1[],charp2[],intnum){strcpy(name,n);strcpy(street,s);strcpy(city,c);strcpy(prov,p1);strcpy(post,p2);no=num;}voidemployee::changename(charn[]){strcpy(name,n);}voidemployee::display(){cout输出记录noendl;cout姓名:nameendl;cout街道地址:streetendl;cout市:cityendl;cout省:provendl;cout邮政编码postendl;}voidmain(){employeeobj1(王华,中华路15号,武汉市,湖北省,430070,1);employeeobj2(杨丽,天津路30号,南京市,江苏市,210020,2);obj1.display();obj2.display();}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功