#include <iostream>
#include <cstring>
using namespace std;
void menu()//定义菜单函数
{
cout << endl;
cout << "---------------------------人事档案管理系统---------------------------" << endl << endl;
cout << "\t\t\t 1:添加职员具体信息" << endl;
cout << "\t\t\t 2:按姓名查找职员信息" << endl;
cout << "\t\t\t 3:按编号查找职员信息" << endl;
cout << "\t\t\t 4:按姓名删除职员信息" << endl;
cout << "\t\t\t 5:按编号删除职员信息" << endl;
cout << "\t\t\t 6:显示人事管理系统中所有职员信息" << endl;
cout << "\t\t\t 7:清空人事管理系统中所有职员信息" << endl;
cout << "\t\t\t 8:统计人事管理系统中的职员总数" << endl;
cout << "\t\t\t 0:退出人事档案管理系统" << endl;
cout << "**********************************************************************" << endl;
}
class Person {//普通人
public:
char name[30];
char sex[20];
char age[20];
};
//职工职位
class PersonPosition :virtual public Person {//Person为虚基类
public:
char position[20];//职位
PersonPosition() {
//Null
}
~PersonPosition() {
//Null
}
};
//操作时间
class OperationTime :virtual public Person {//Person为虚基类
public:
char engage_time[100];//聘用时间
char add_time[100];//记录时间
OperationTime() {
//Null
}
~OperationTime() {
//Null
}
};
//职工基本信息
class Worker :public PersonPosition, public OperationTime {//继承PersonPosition、OperationTime类,多重继承。
private:
char num[20];//编号
char address[500];//地址
char tel[100];//手机号
char nation[30];//民族
char political_status[20];//政治面貌
char marital_status[20];//婚姻状况
char school[200];//毕业院校
char identity[500];//身份证号
char email[20];//邮箱
friend class message;//友元类message
Worker() {
//Null
}
~Worker() {
//Null
}
friend class Staffoperation;//定义友元操作类
};
//操作函数
class Staffoperation :public PersonPosition, public OperationTime {//多重继承
private:
Worker w[101];//100为员工最多数量
int Num;//用于表示记录时员工的序号
int all;//用于表示系统含有多少名员工
public:
Staffoperation() {
Num = 1;
all = 0;
}
virtual void show() {
//Null
//定义虚函数show,供message类调用
}
void add_person();//添加员工具体信息
void searchname();//按姓名查找
void searchnum();//按编号查找
void delname();//按姓名删除
void delnum();//按编号删除
void showall();//显示人事管理系统中所有员工信息
void delall();//清空人事管理系统中所有员工信息
void total();//统计人事管理系统中的员工总数
friend class message;//定义友元类
};
//message类用于重载运算符
class message:public Staffoperation,public Worker {
private:
char name_m[32];
char sex_m[22];
char age_m[22];
char num_m[22];//编号
char address_m[502];//地址
char tel_m[102];//手机号
char nation_m[32];//民族
char political_status_m[22];//政治面貌
char marital_status_m[22];//婚姻状况
char school_m[202];//毕业院校
char identity_m[502];//身份证号
char email_m[22];//邮箱
char position_m[22];//职位
char engage_time_m[102];//聘用时间
char add_time_m[102];//记录时间
public:
message(int i) {
cout << w[i].name << endl;
/*
strcpy_s(name_m, strlen(w[i].name) + 1,w[i].name);
strcpy_s(sex_m, strlen(w[i].sex) + 1, w[i].sex);
strcpy_s(age_m, strlen(w[i].age) + 1, w[i].age);
strcpy_s(num_m, strlen(w[i].num) + 1, w[i].num);
strcpy_s(address_m, strlen(w[i].name) + 1, w[i].name);
strcpy_s(tel_m, strlen(w[i].tel) + 1, w[i].tel);
strcpy_s(nation_m, strlen(w[i].nation) + 1, w[i].nation);
strcpy_s(political_status_m, strlen(w[i].political_status) + 1, w[i].political_status);
strcpy_s(marital_status_m, strlen(w[i].marital_status) + 1, w[i].marital_status);
strcpy_s(school_m, strlen(w[i].school) + 1, w[i].school);
strcpy_s(identity_m, strlen(w[i].identity) + 1, w[i].identity);
strcpy_s(email_m, strlen(w[i].email) + 1, w[i].email);
strcpy_s(position_m, strlen(w[i].position) + 1, w[i].position);
strcpy_s(engage_time_m, strlen(w[i].engage_time) + 1, w[i].engage_time);
strcpy_s(add_time_m, strlen(w[i].add_time) + 1, w[i].add_time);
*/
strcpy(name_m, w[i].name);
strcpy(name, w[i].name);
strcpy(sex_m, w[i].sex);
strcpy(age_m, w[i].age);
strcpy(num_m, w[i].num);
strcpy(address_m, w[i].name);
strcpy(tel_m, w[i].tel);
strcpy(nation_m, w[i].nation);
strcpy(political_status_m, w[i].political_status);
strcpy(marital_status_m, w[i].marital_status);
strcpy(school_m, w[i].school);
strcpy(identity_m, w[i].identity);
strcpy(email_m, w[i].email);
strcpy(position_m, w[i].position);
strcpy(engage_time_m, w[i].engage_time);
strcpy(add_time_m, w[i].add_time);
}
//拷贝构造函数
message(const message& me) {
/*
strcpy_s(name_m, strlen(me.name_m) + 1, me.name_m);
strcpy_s(sex_m, strlen(me.sex_m) + 1, me.sex_m);
strcpy_s(age_m, strlen(me.age_m) + 1, me.age_m);
strcpy_s(num_m, strlen(me.num_m) + 1, me.num_m);
strcpy_s(address_m, strlen(me.name_m) + 1, me.name_m);
strcpy_s(tel_m, strlen(me.tel_m) + 1, me.tel_m);
strcpy_s(nation_m, strlen(me.nation_m) + 1, me.nation_m);
strcpy_s(political_status_m, strlen(me.political_status_m) + 1, me.political_status_m);
strcpy_s(marital_status_m, strlen(me.marital_status_m) + 1, me.marital_status_m);
strcpy_s(school_m, strlen(me.school_m) + 1, me.school_m);
strcpy_s(identity_m, strlen(me.identity_m) + 1, me.identity_m);
strcpy_s(email_m, strlen(me.email_m) + 1, me.email_m);
strcpy_s(position_m, strlen(me.position_m) + 1, me.position_m);
strcpy_s(engage_time_m, strlen(me.engage_time_m) + 1, me.engage_time_m);
strcpy_s(add_time_m, strlen(me.add_time_m) + 1, me.add_time_m);
*/
strcpy(name_m, me.name_m);
strcpy(sex_m, me.sex_m);
strcpy(age_m, me.age_m);
strcpy(num_m, me.num_m);
strcpy(address_m, me.name_m);
strcpy(tel_m, me.tel_m);
strcpy(nation_m, me.nation_m);
strcpy(political_status_m, me.political_status_m);
strcpy(marital_status_m, me.marital_status_m);
strcpy(school_m, me.school_m);
strcpy(identity_m, me.identity_m);
strcpy(email_m, me.email_m);
strcpy(position_m, me.position_m);
strcpy(engage_time_m, me.engage_time_m);
strcpy(add_time_m, me.add_time_m);
}
friend ostream& operator<<(ostream& out, message& m);//重载运算符<<
void show() {
cout << *this;
}
};
//重载运算符<<
ostream& operator<<(ostream& out, message& m) {
out << " 编号:" << m.num_m << endl;
out << " 姓名:" << m.name_m << endl;
out << " 年龄:" << m.age_m << endl;
out << " 性别:" << m.sex_m << endl;
out << " 地址:" << m.address_m << endl;
out << " 手机号:" << m.tel_m << endl;
out << " 国家:" << m.nation_m << endl;
out << " 政治面貌:" << m.political_status_m << endl;
out << " 婚姻状况:" << m.marital_status_m << endl;
out << " 毕业院校:" << m.school_m << endl;
out << " 身份证号:" << m.identity_m << endl;
out << " 邮箱:" << m.email_m << endl;
out << " 聘用时间:" << m.engage_time_m << endl;
out << " 记录时间:" << m.add_time_m << endl;
return out;
}
//密码系统(如需使用管理系统,需要输入正确的密码,若连续三次密码错误,则系统推出)
void password()
{
int password;
int j = 1;
cout << "欲使用本系统,请输入本系统的密码:" << endl;
cin >> password;
while (password != 888 && j < 3)
{
try {//应用异常出来来验证密码
if (password != 888)
throw - 1; //抛出int类型异常
}
catch (int e) {
cout << "您输入的密码有误,请再次输入: " << endl;
j++;
cin >> password;
}
}
if (password != 888 && j >= 3)
{
cout << "您连续三次输入密码有误,系统自动退出" << endl;
exit(0);
}
else {
cout << endl << "欢迎进入人事档案管理系统\n请根据系统功能列表选择相应的功能(请输入选项对应的数字) " << endl;
}
}
//添加员工具体信息
void Staffoperation::add_person() {
string choice = "Y";
char num1[20];
while (choice == "Y" || choice == "y")
{
cout << "-----新建人事档案职员信息----" << endl;
cout << "请输入职员的的编号:(1 - 100) " << endl;
cin >> num1;
for (int x = 0; x <= all; x++)//判断是否有重复的编号
{
while (strcmp(w[x].num, num1) == 0)
{
cout << "此职工编号已存在,请重新输入:" << endl;
cout << "请输入职员的的编号:(1 - 100) " << endl;
cin >> num1;
x = 0;
}
}
//strcpy_s(w[Num].num, num1);
strcpy(w[Num].num, num1);
cout << "请输入职员姓名:" << endl;
cin >> w[Num].name;
//cout << "请输入性别:" << endl;
//cin >> w[Num].sex;
//while (strcmp(w[Num].sex,"男")!=0 && strcmp(w[Num].sex, "女") != 0)
//{
// cout << "您输入的性别有误,请核对后再输入: " << endl;
// cin >> w[Num].sex;
//}
//cout << "请输入年龄:" << endl;
//cin >> w[Num].age;
//cout << "请输入该职员的职位:(经理,管理员,员工) " << endl;
//cin >> w[Num].position;
//while ((string)w[Num].position != "经理" && (string)w[Num].position != "管理员" && (string)w[Num].position != "员工")
//{
// cout << "您输入的职工职位有误,请核对后再输入: " << endl;
// cin >> w[Num].position;
//}
//cout << "请输入该职员的家庭地址: " << endl;
//cin >> w[Num].address;
//cout << "请输入该职员的民族:" << endl;
//cin >> w[Num].nation;
//cout << "请输入职员的政治面貌:(群众,团员,党员)" << endl;
//cin >> w[Num].political_status;
//while ((string)w[Num].political_status != "群众" && (string)w[Num].political_status != "团员" && (string)w[Num].political_status != "党员")
//{
// cout << "您输入的职工政治面貌有误,请核对后再输入: " << endl;
// cin >> w[Num].political_status;
//}
//cout << "请输入职员的婚姻状况(未婚,已婚)" << endl;
//cin >> w[Num].marital_status;
//while ((string)w[Num].marital_status != "未婚" && (string)w[Num].marital_status != "已婚")
//{
// cout << "您输入的职工的婚姻状况有误,请核对后再输入: " << endl;
// cin >> w[Num].marital_status;
//}
//cout << "请输入职员的毕业学校: " << endl;
//cin >> w[Num].school;
//cout << "请输入职员的身份证号:" << endl;
//cin >> w[Num].identity;
//cout << "请输入职员的手机号:" << endl;
//cin >> w[Num].tel;
//cout << "请输入职员的邮箱: " << endl;
//cin >> w[Num].email;
//cout << "请输人职员的聘用时间:" << endl;
//cin >> w[Num].engage_time;
//cout << "请输入此次记录的添加时间:" << endl;
//cin >> w[Num].add_time;
cout << "信息添加成功!" << endl;
cout << "您还想继续添加吗?( y/n) " << endl;
cin >> choice;
while (choice != "Y" && choice != "y" && choice != "N" && choice != "n")
{
cout << "请按要求键入(y/n) " << endl;
cin >> choice;
}
if (choice == "N" || choice == "n")
{
Num++;
all++;
break;
}
Num++;
all++;
}
}
//按姓名查找
void Staffoperation::searchname() {
if (all == 0) {
cout << "目前还没有员工计入系统,即将返回主菜单....." << endl;
menu();
}
else {
char name1[30];
int flag = 0;//查询成功标志
cout << "请输入你想要查询的姓名:" << endl;
cin >> name1;
for (int i = 0; i < 100; i++) {
if (strcmp(name1, w[i].name) == 0) {
cout << "查询成功!该员工的信息如下: " << endl;
int l = i;
message A(l);
//cout << A.name << endl;
cout << w[i].name << endl;
//message B(A);//调用拷贝构造函数
//B.show();
flag = 1;
break;
}
}
if (flag == 0) {
cout << "查询失败!系统中没有此人信息!即将返回主菜单....." << endl;
}
}
}
//按编号查找
void Staffoperation::searchnum() {
if (all == 0) {
cout << "目前还没有员工计入系统,即将返回主菜单....." << endl;
menu();
}
else {
char num1[20];
int flag = 0;//查询成功标志
cout << "请输入你想要查询的编号:" << endl;
cin >> num1;
for (int i = 0; i < 100; i++) {
if (strcmp(w[i].num, num1) == 0) {
cout << "查询成功!该员工的信息如下: " << endl;
message A(i);
//message B(A);//调用拷贝构造函数
/* B.show();*/
flag = 1;
break;
}
}
if (flag == 0) {
cout << "查询失败!系统中没有此人信息!即将返回主菜单....." << endl;
}
}
}
//按姓名删除
void Staffoperation::delname() {
if (all == 0) {
cout << "目前还没有员工计入系统!" << endl;
}
char name2[30];
cout << "请输入你想要删除的员工姓名:" << endl;
cin >> name2;
int flag = 0;//删除标志
for (int i = 0; i < 100; i++) {
if (strcmp(name2, w[i].name) == 0) {
cout << "你想要删除的员工的信息如下: " << endl;
message A(i);
//message B(A);//调用拷贝构造函数
//B.show();
flag = 1;
break;
}
}
if (flag == 0) {
cout << "系统中没有此人信息!" << endl;
}
cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
string p;
int j = 0;
cin >> p;
while (1)
{
if (p == "y" || p == "Y")
{
for (int i = 0; i < 100; i++) {
if (strcmp(name2, w[i].name) == 0) {
j = i;
}
}
for (; j <= 99; j++) {
w[j] = w[j + 1];
}
all--;
cout << "员工信息已删除!" << endl;
break;
}
else if (p == "n" || p == "N")
{
menu();
break;
}
else
{
cout << "输入有误,请重新输入:";
cin >> p;
}
}
}
//按编号删除
void Staffoperation::delnum() {
if (all == 0) {
cout << "目前还没有员工计入系统!." << endl;
}
char num2[20];
cout << "请输入你想要删除的员工编号:" << endl;
cin >> num2;
int flag = 0;//删除标志
for (int i = 0; i < 100; i++) {
if (strcmp(w[i].num, num2) == 0) {
cout << "你想要删除的员工的信息如下: " << endl;
message A(i);
//message B(A);//调用拷贝构造函数
//B.show();
flag = 1;
break;
}
}
if (flag == 0) {
cout << "系统中没有此人信息!" << endl;
}
cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
string p;
int j;
cin >> p;
while (1)
{
if (p == "y" || p == "Y")
{
for (int i = 0; i < 100; i++) {
if (strcmp(w[i].num, num2) == 0) {
j = i;
}
}
for (; j <= 99; j++) {
w[j] = w[j + 1];
}
all--;
cout << "员工信息已删除!" << endl;
break;
}
else if (p == "n" || p == "N")
{
menu();
break;
}
else
{
cout << "输入有误,请重新输入:";
cin >> p;
}
}
}
//显示人事管理系统中所有员工信息
void Staffoperation::showall() {
if (all == 0) {
cout << "信息库为空,请添加职员!" << endl;
menu();
}
else {
cout << "所有员工的信息如下: " << endl;
for (int i = 1; i <= all; i++) {
message A(i);
//message B(A);//调用拷贝构造函数
//B.show();
}
///////////////////////////////////////////
}
}
//清空人事管理系统中所有员工信息
void Staffoperation::delall() {
for (int x = 1; x <= all; x++) {
w[x] = w[0];
}
all = 0;
Num = 1;
cout << "数据已清空!" << endl;
}
//统计人事管理系统中的员工总数
void Staffoperation::total() {
cout << "系统中一共有:" << all << "名职工的信息。" << endl;
}
//定义控制函数
void manage()
{
Staffoperation per;
int choice, k = 1;
menu();
cout << "请根据系统功能列表选择相应的功能(请输入选项对应的数字)" << endl;
//password();
while (k)
{
cin >> choice;
switch (choice)
{
case 1:
per.add_person();//调用增加人事档案中职员信息函数
break;
case 2:
per.searchname();//调用按姓名查找职工信息函数
break;
case 3:
per.searchnum();//调用按编号查找职工信息函数
break;
case 4:
per.delname();//调用按姓名删除职工信息函数
break;
case 5:
per.delnum();//调用按编号删除职工信息函数
break;
case 6:
per.showall();//调用显示人事档案管理系统中所有职员信息的函数
break;
case 7:
per.delall();//调用清空人事档案管理系统中所有数据的函数
break;
case 8:
per.total();//调用输出人事档案管理系统中职员数的函数
break;
case 0:
cout << endl << "即将退出人事档案管理系统,再见!" << endl << endl;
k = 0;
break;
default:
cout << "您输入的选项有错,请重新选择! ";
}
if (k != 0)
{
menu();
cout << "请根据系统功能列表选择相应的功能(请输入选项对应的数字)" << endl;
}
}
}
int main()
{
manage();
return 0;
}