声明一个Employee类,其中包括姓名、街道地址、城市、和邮编等属性,包括change_name()和display()等函数;display()使用cout语句显示姓名、街道地址、城市、和邮编等属性,函数change_name()改变对象的姓名属性,实现并测试这个类。
要求:
1. Employee类中应包括缺省构造函数、拷贝构造函数、带默认形参值的构造函数、构造函数重载、析构函数。
2. 定义三个Employee类对象Person1, Person2, Person3,分别用缺省构造函数、带默认形参值的构造函数、拷贝构造函数初试化。
3. 定义一个Employee类指针对象Pointer, 分别用指针Pointer与对象Person1, 或Person2, 或Person3调用Employee类成员函数。
4. 程序采用多文件结构形式。
有谁帮忙做出来啊,急于要交作业啊!
--------------------next---------------------
******//employee.h//******
//头文件定义如下:
class employee
{
public:
employee();
employee(char * name1,char * streetad,char * city1 ,char * postnum);
employee( employee & emp);
~employee();
{
delete []name;
delete []streetadd;
delete []city;
delete []postnumber;
}
void change_name(char *);
void display() const;
{
cout<<"name:"<
cout<<"streetadd:"< cout<<"city:"< cout<<"postnumer:"<}
private:
char * name;
char * streetadd;
char * city;
char * postnumber;
};
******//employee.cpp//********
#include
#include"string.h"
employee::employee()
{
strcpy(name,"default");
strcpy(streetadd,"default");
strcpy(city,"default");
strcpy(postnumber,"default");
}
employee::employee(char * name1,char * streetad,char * city1 ,char * postnum)
{
name= new char[strlen(name1)+1];
strcpy(name,name1);
streetadd =new char[strlen(streetad)+1];
strcpy(streetadd,streetad);
city= new char[strlen(city1)+1];
strcpy(city,city1);
postnumer=new char[strlen(postnum)+1];
strcpy(postnumber,postnum);
}
employee::employee(employee &emp)
{
strcpy(name,emp.name);
strcpy(streetadd,emp.streetadd);
strcpy(city,emp.city);
strcpy(postnumber,enp.postnumber);
)
void employee:: change_name(char * name2)
{
strcpy(name,name2);
}
******//main.cpp//*********
#include
#include
#include"employee.h"
void main()
{
employee person1;
employee person2("wangming","beijing xilu 24","biejing","010");
employee person3(person2);
employee *pointer =new employee(person2);
pointer->disaply();
pointer->chang_ename("chengnan");
pointer->disaply();
}
--------------------next---------------------
阅读(1206) | 评论(0) | 转发(0) |