人员)。考虑到通用性,这里只抽象出所有类型人员都具有的属性: name(姓名)、sex(性别) 、birthyear(出生年)birthmonth(出生月)"/>
设计一个用于人事管理的类People(人员)。考虑到通用性,这里只抽象出所有类型人员都具有的属性: name(姓名)、sex(性别) 、birthyear(出生年)birthmonth(出生月)
设计一个用于人事管理的类People(人员)。考虑到通用性,这里只抽象出所有类型人员都具有的属性: name(姓名)、sex(性别) 、birthyear(出生年)、birthmonth(出生月)、birthday(出生日) 、id(身份证号)、dept(所在部门)、salary(工资)等等。要求包括下列成员函数:人员信息的录入、人员信息的显示,以及修改和读取各属性信息的公有的成员函数,另外根据需要适当添加构造函数(包括默认的构造函数、带参数的构造函数和拷贝构造函数)和析构函数。实现并测试这个类。
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
class People
{
public:People();People(string _name,char _sex,int _birthyear,int _birthmonth,int _birthday,string _id,string _dept,float _salary);People(People &p);~People();void input();void display();string GetName(){ return name; }char GetSex(){ return sex; }int GetBirthyear(){ return birthyear; }int GetBirthmonth(){ return birthmonth; }int GetBirthday(){ return birthday; }string GetId(){ return id; }string Getdept(){ return dept; }float Getsalary(){ return salary; }void SetName(string _name){ name=_name; }void SetSex(char _sex){ sex=_sex; }void SetBirthyear(int _birthyear){ birthyear=_birthyear; }void SetBirthmonth(int _birthmonth){ birthmonth=_birthmonth; }void SetBirthday(int _birthday){ birthday=_birthday; }void SetId(string _id){ id=_id; }void SetDept(string _dept){ dept=_dept; }void SetSalary(float _salary){ salary=_salary; }
private:string name;char sex;int birthyear;int birthmonth;int birthday;string id;string dept;float salary;
};
People::People()
{name="";sex=' ';birthyear=0;birthmonth=0;birthday=0;id="XXXXXXXXXXXXXXXXX";dept="";salary=0.0;
}
People::People(string _name,char _sex,int _birthyear,int _birthmonth,int _birthday,string _id,string _dept,float _salary)
{name=_name;sex=_sex;birthyear=_birthyear;birthmonth=_birthmonth;birthday=_birthday;id=_id;dept=_dept;salary=_salary;
}
People::People(People &p)
{name=p.name;sex=p.sex;birthyear=p.birthyear;birthmonth=p.birthmonth;birthday=p.birthday;id=p.id;dept=p.dept;salary=p.salary;
}
People::~People()
{cout<<"People类析构函数被调用"<<endl;
}
void People::input()
{cout<<"请输入人员信息:"<<endl;cout<<"\t姓名:";cin>>name;cout<<"\t性别:";cin>>sex;cout<<"\t出生日期(格式:年 月 日):";cin>>birthyear;cin>>birthmonth;cin>>birthday;cout<<"\t身份证号码:";cin>>id;cout<<"\t所在部门:";cin>>dept;cout<<"\t工资:";cin>>salary;
}
void People::display()
{cout<<"人员信息如下:"<<endl;cout<<"\t姓名:"<<name<<endl;cout<<"\t性别:"<<sex<<endl;cout<<"\t出生日期:"<<birthyear<<"/"<<birthmonth<<"/"<<birthday<<endl;cout<<"\t身份证号码:"<<id<<endl;cout<<"\t所在部门:"<<dept<<endl;cout<<"\t工资:"<<salary<<endl<<endl;
}int main()
{People p1;p1.input();p1.display();People p2=p1;p2.display();People p3("Jerry",'F',2005,10,10,"420101200510101234","研发部",8000);p3.display();char name[15];int year,month,day;cout<<"修改姓名-请输入新的姓名:";cin>>name;p3.SetName(name);cout<<"修改后的新姓名是:"<<p3.GetName()<<endl;cout<<"修改出生年月日-请输入新的出生年月日:";cin>>year>>month>>day;p3.SetBirthyear(year);p3.SetBirthmonth(month); p3.SetBirthday(day); cout<<"修改后的新出生年月日是:"<<p3.GetBirthyear()<<"-"<<p3.GetBirthmonth()<<"-"<<p3.GetBirthday()<<endl<<endl;system("pause");return 0;
更多推荐
设计一个用于人事管理的类People(人员)。考虑到通用性,这里只抽象出所有类型人员都具有的属性: name(姓名)、sex(性别) 、birthyear(出生
发布评论