其他分享
首页 > 其他分享> > 设计公司的人员管理系统要求:(实训3)

设计公司的人员管理系统要求:(实训3)

作者:互联网

**
**设计公司的人员管理系统要求:


(1)employee类:基本信息:编号、姓名、性别、出生日期、职位等出生日期采用自定义的Date类其中:基本信息为private属性,成员函数为public属性employee类有多个构造函数:缺省构造函数、带参数的构造函数;
(2)Date类成员变量:年、月、日成员函数:SetYear(int year)、SetMonth(int month)、SetDay(int day)、GetYear()、GetMonth()、GetDay()
最终基本功能包括:
(1)职工信息的录入
(2)职工信息的显示
(3)用对象数组保存已输入的职工对象
(4)可以修改人员的基本信息,如:姓名、职位等
(5)可以通过编号或姓名进行人员查询,在查询时通过编号或者姓名进行人员查询

测试数据:编号,姓名,性别,出生,年月,职位
01Zhang男1990-01-10Yanfa
02Li男1995-03-28xiaoshou
03Wang女1997-09-17caigou
04Sun女2000-06-11caiwu
05Liu男1998-12-12xingzheng

源代码

#include
#includeusing namespace std;class Data {public: Data(int y = 1900, int m = 1, int d = 1) { year = y; month = m; day = d; }
void SetYear(int y) { year = y; } void SetMonth(int m) { month = m; } void SetDay(int d) { day = d; } int GetYear() { return year; } int GetMonth() { return month; } int GetDay() { return day; }private: int year; int month; int day;};class employee {public: employee();//缺省构造函数 employee(int, string, char, Data&, string);//带参数构造函数。 //employee(int ,string ,char,Data&,string=“worker”);//默认职位worker。 void SetInfo(string nam, string pos) { name = nam; position = pos; } void Show(employee* p, int n); Data& operator = (Data&); friend istream& operator >>(istream&, employee&); friend ostream& operator <<(ostream&, employee&); int GetNum() { return num; } string GetName() { return name; } void SearchNum(int, employee*, int); void SearchName(string, employee*, int);private: int num; string name; char sex; Data birthday; string position;};employee::employee() { num = 1000; name = “xiaoming”; sex = ‘f’; Data birthday(1900, 1, 1); position = “worker”;}employee::employee(int n, string nam, char s, Data& bir, string pos) { num = n; name = nam; sex = s; Data birthay = bir; position = pos;}void employee::Show(employee* p, int n) { cout << “编号、姓名、性别、出生年、月、日、职位为:” << endl; for (int i = 0; i < n; i++) { cout << p[i] << endl; }}Data& employee::operator =(Data& bir) { bir.SetYear(this->birthday.GetYear()); bir.SetMonth(this->birthday.GetMonth()); bir.SetDay(this->birthday.GetDay()); return bir;}istream& operator >>(istream& input, employee& emp) { int year, month, day; input >> emp.num >> emp.name >> emp.sex; input >> year >> month >> day; input >> emp.position;
emp.birthday.SetYear(year); emp.birthday.SetMonth(month); emp.birthday.SetDay(day);
return input;
}ostream& operator <<(ostream& output, employee& emp) { output << emp.num << " " << emp.name << " " << emp.sex << " "; output << emp.birthday.GetYear() << " " << emp.birthday.GetMonth() << " " << emp.birthday.GetDay() << " "; output << emp.position; return output;}void employee::SearchNum(int num, employee* p, int n) { bool flag = 1; for (int i = 0; i < n; i++) { if (num == p[i].GetNum()) { cout << “所找的员工的信息为:” << endl; cout << p[i]; flag = 0; break; } } if (flag)cout << “没有编号为” << num << “的员工,请确认编号输入是否正确!” << endl;}void employee::SearchName(string name, employee* p, int n) { bool flag = 1; for (int i = 0; i < n; i++) { if (namep[i].GetName()) { cout << “所找的员工的信息为:” << endl; cout << p[i]; flag = 0; break; } } if (flag)cout << “没有姓名为” << name << “的员工,请确认姓名输入是否正确!” << endl;}int main() { cout << “请输入你想输入的员工的个数” << endl; int n; cin >> n; cout << endl; //创立员工数组: employee emp[100]; for (int i = 0; i < n; i++) { cout << “请输入第” << i + 1 << “个员工的编号、姓名、性别、出生年、月、日、职位”; cin >> emp[i]; cout << endl; } emp[0].Show(emp, n); //修改信息: cout << “请输入你想修改的上面员工的序号,并输入新的姓名和职位”<<endl; int x; while (cin >> x && x) { string name, position; cin >> name >> position; emp[x - 1].SetInfo(name, position); cout << “若您还想修改信息,请输入上面展示的员工的序号,并输入新的姓名和职位,否则输入0结束” << endl; } cout << “---------------------------------------------------” << endl << endl; emp[0].Show(emp, n); cout << endl; cout << “输入1用编号查询员工信息” << endl; cout << “输入2用姓名查询员工信息” << endl; cout << “输入其他值,结束。” << endl; cin >> x; switch (x) { case 1: { int num; cout << “请输入你要找的员工的编号:”; cin >> num; emp[0].SearchNum(num, emp, n); break; } case 2: { string name; cout << “请输入你要找的员工的姓名:”; cin >> name; emp[0].SearchName(name, emp, n); break; } } return 0;}#include
#includeusing namespace std;class Data {public: Data(int y = 1900, int m = 1, int d = 1) { year = y; month = m; day = d; } void SetYear(int y) { year = y; } void SetMonth(int m) { month = m; } void SetDay(int d) { day = d; } int GetYear() { return year; } int GetMonth() { return month; } int GetDay() { return day; }private: int year; int month; int day;};class employee {public: employee();//缺省构造函数 employee(int, string, char, Data&, string);//带参数构造函数。 //employee(int ,string ,char,Data&,string=“worker”);//默认职位worker。 void SetInfo(string nam, string pos) { name = nam; position = pos; } void Show(employee* p, int n); Data& operator = (Data&); friend istream& operator >>(istream&, employee&); friend ostream& operator <<(ostream&, employee&); int GetNum() { return num; } string GetName() { return name; } void SearchNum(int, employee*, int); void SearchName(string, employee*, int);private: int num; string name; char sex; Data birthday; string position;};employee::employee() { num = 1000; name = “xiaoming”; sex = ‘f’; Data birthday(1900, 1, 1); position = “worker”;}employee::employee(int n, string nam, char s, Data& bir, string pos) { num = n; name = nam; sex = s; Data birthay = bir; position = pos;}void employee::Show(employee* p, int n) { cout << “编号、姓名、性别、出生年、月、日、职位为:” << endl; for (int i = 0; i < n; i++) { cout << p[i] << endl; }}Data& employee::operator =(Data& bir) { bir.SetYear(this->birthday.GetYear()); bir.SetMonth(this->birthday.GetMonth()); bir.SetDay(this->birthday.GetDay()); return bir;}istream& operator >>(istream& input, employee& emp) { int year, month, day; input >> emp.num >> emp.name >> emp.sex; input >> year >> month >> day; input >> emp.position; emp.birthday.SetYear(year); emp.birthday.SetMonth(month); emp.birthday.SetDay(day); return input;}ostream& operator <<(ostream& output, employee& emp) { output << emp.num << " " << emp.name << " " << emp.sex << " "; output << emp.birthday.GetYear() << " " << emp.birthday.GetMonth() << " " << emp.birthday.GetDay() << " "; output << emp.position; return output;}void employee::SearchNum(int num, employee* p, int n) { bool flag = 1; for (int i = 0; i < n; i++) { if (num == p[i].GetNum()) { cout << “所找的员工的信息为:” << endl; cout << p[i]; flag = 0; break; } } if (flag)cout << “没有编号为” << num << “的员工,请确认编号输入是否正确!” << endl;}void employee::SearchName(string name, employee* p, int n) { bool flag = 1; for (int i = 0; i < n; i++) { if (name
p[i].GetName()) { cout << “所找的员工的信息为:” << endl; cout << p[i]; flag = 0; break; } } if (flag)cout << “没有姓名为” << name << “的员工,请确认姓名输入是否正确!” << endl;}int main() { cout << “请输入你想输入的员工的个数” << endl; int n; cin >> n; cout << endl; //创立员工数组: employee emp[100]; for (int i = 0; i < n; i++) { cout << “请输入第” << i + 1 << “个员工的编号、姓名、性别、出生年、月、日、职位”; cin >> emp[i]; cout << endl; } emp[0].Show(emp, n); //修改信息: cout << “请输入你想修改的上面员工的序号,并输入新的姓名和职位”<<endl; int x; while (cin >> x && x) { string name, position; cin >> name >> position; emp[x - 1].SetInfo(name, position); cout << “若您还想修改信息,请输入上面展示的员工的序号,并输入新的姓名和职位,否则输入0结束” << endl; } cout << “---------------------------------------------------” << endl << endl; emp[0].Show(emp, n); cout << endl; cout << “输入1用编号查询员工信息” << endl; cout << “输入2用姓名查询员工信息” << endl; cout << “输入其他值,结束。” << endl; cin >> x; switch (x) { case 1: { int num; cout << “请输入你要找的员工的编号:”; cin >> num; emp[0].SearchNum(num, emp, n); break; } case 2: { string name; cout << “请输入你要找的员工的姓名:”; cin >> name; emp[0].SearchName(name, emp, n); break; } } return 0;}

是不是很长,哈哈哈哈,我也不会。
在这里插入图片描述

标签:name,管理系统,int,month,人员,emp,employee,string,实训
来源: https://blog.csdn.net/m0_65849390/article/details/122170954