设计一个用于人事管理的类People(人员)。考虑到通用性,这里只抽象出所有类型人员都具有的属性: name(姓名)、sex(性别) 、birthyear(出生年)birthmonth(出生月)

编程入门 行业动态 更新时间:2024-10-18 20:22:59

设计一个用于人事管理的类People(<a href=https://www.elefans.com/category/jswz/34/1768716.html style=人员)。考虑到通用性,这里只抽象出所有类型人员都具有的属性: 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(出生

本文发布于:2024-03-08 19:03:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1721950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:人员   通用性   考虑到   人事管理   抽象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!