C++实现员工工资管理系统

时间:2023-01-27 23:16:44

类的抽象与类间关系

Ø Date类:日期类,表示一个日期

Ø Department类:表示部门类。

Ø Employee类:表示员工的抽象类。

Ø Technician类:表示技术员类。

Ø Saler类:表示销售员类。

Ø Manager类:表示经理类。

Ø SalerManager类:表示销售经理类。

类间关系——组合关系,如下图如下。


C++实现员工工资管理系统

1 主控模块运行界面

C++实现员工工资管理系统C++实现员工工资管理系统

2 添加信息模块运行界面

C++实现员工工资管理系统C++实现员工工资管理系统

3 查询信息模块运行界面


C++实现员工工资管理系统C++实现员工工资管理系统

4.删除信息模块运行界面

C++实现员工工资管理系统

C++实现员工工资管理系统

5 显示信息模块运行界面

C++实现员工工资管理系统C++实现员工工资管理系统

6 部门管理运行界面

C++实现员工工资管理系统C++实现员工工资管理系统

7 部门信息浏览界面

C++实现员工工资管理系统C++实现员工工资管理系统

8 按部门统计信息界面

C++实现员工工资管理系统C++实现员工工资管理系统

9 工资排序运行界面

C++实现员工工资管理系统C++实现员工工资管理系统

10 部门相关操作运行界面

C++实现员工工资管理系统

C++实现员工工资管理系统C++实现员工工资管理系统


C++实现员工工资管理系统

11 退出模块运行界面

C++实现员工工资管理系统C++实现员工工资管理系统

部分代码:

//data.h//类的设计
#ifndef _EMPLOYEE#define _EMPLOYEE#include <map>#include "define.h"#include <string>#include <fstream>#include <iostream>using namespace std;/*日期类*/class Date{protected:int age;int year;int month;int day;public:  void Init(int y, int m, int d);int GetYear();int GetMonth();int GetDay();int GetAge();};/*部门类*/class Department{protected:static int dCount;//部门数目string *str;//储存所有部门int *bianhao;//部门编号 public:Department();//默认构造函数~Department();//清理动态申请的空间void InitDep(string *s, int *b, int length);//加载文件后初始化部门信息string Check(string d);//查找是否有这个部门  <绑定关系>void Add(string NewDep);//添加部门void Delete(string OldDep);//删除部门void Modify(string OldDep, string NewDep);//修改部门的名字   depNa原来部门的名字  dep_Na修改后的名字void Scan();//浏览部门int GetDNumber(string d);//获取部门编号static int GetDCount();//获取部门数目string GetDep(int choice);//获取所需部门};/*员工抽象类*/class Employee//派生类成员函数可以访问直接基类的保护成员,但派生的派生则不可以{protected:static int eCount;//员工数目static int MaxNum;//最大工号int number;//工号 (系统自动赋值  不输入)int age;//年龄float salary;//当月工资string name;//姓名string sex;//性别string department;//员工所属的部门Department dep;//部门  (类的组合)string job;//岗位Date date;//日期类public:Employee();//无参(默认)构造函数void Init();//初始化员工   基本信息virtual void Output();//输出员工信息(虚函数 动态多态性)Employee &operator =(const Employee &obj);//重载=static int GetECount();//获取员工数目int GetNumber();//获取工号     int GetAge();//获取员工年龄float GetSalary();//获取员工当月工资string GetName();//获取员工姓名string GetSex();//获取员工性别string GetJob();//获取员工岗位string GetDepartment() const;//获取员工的部门void SetMaxNum(int m);//加载文件后设置初始化最大工号void SetECount(int size);//修改员工数目void SetName(string tname);//修改姓名void SetSex(string tsex);//修改性别void SetAge(int tage);//修改年龄void SetJob(string tjob);//修改岗位void SetSalary(float tsalary);//修改当月工资void SetDep(string tdepart);//修改员工所属的部门 void InitDep(string *s, int *b, int length);//初始化部门信息string Check(string d);//查找是否有这个部门  <绑定关系>void AddDep(string NewDep);//添加部门void DeleteDep(string OldDep);//删除部门void ModifyDep(string OldDep, string NewDep);//修改部门的名字void BrowseDep();//浏览部门int GetDNumber(string d);//获取部门编号int GetDCount() const;//获取部门数目string GetDep(int choice);//获取所需部门};/*技术员类*/class Technician :virtual public Employee//虚基类继承(至多调用一次虚基类的构造函数){private:float hours;//工作时间public:Technician();//无参(默认)构造函数Technician(const Technician &obj);//拷贝构造函数    ①拷贝构造的概念是用已有对象构造新对象.void Input();//输入技术员信息void Output();//输出技术员信息float GetHours();//获取工时void SetHours(float hour);//修改工时Technician &operator =(const Technician &obj);//重载=  //②赋值运算的概念是=左右操作数均已存在friend ostream & operator << (ostream &out, Technician &tec);//友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性)friend istream & operator >> (istream &in, Technician &tec);//友元函数输入重载运算符">>"  ;};/*销售员类*/class Saler :virtual public Employee{private:float balance;//销售额度public:Saler();//无参(默认)构造函数Saler(const Saler &obj);//拷贝构造函数void Input();//输入销售员信息void Output();//输出销售员信息float GetBalance();//获取员工销售额度void SetBalance(float tbalance);//修改员工销售额度Saler &operator =(const Saler &obj);//重载=friend ostream & operator << (ostream &out, Saler &s);    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性)friend istream & operator >> (istream &in, Saler &s);    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性)};/*经理类*/class Manager :virtual public Employee{public:Manager();//无参(默认)构造函数Manager(const Manager &obj);//拷贝构造函数void Input();//输入经理信息void Output();//输出经理信息//Manager &operator =(const Manager &obj);//重载=friend ostream & operator << (ostream &out, Manager &m);    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性)friend   istream & operator >> (istream &in, Manager &m);};/*销售经理类*/class SalerManager :public Saler, public Manager//继承销售员   经理  先调用构造Saler    在调用 Manager{float totalBalance;//该部门的销售总额度public:SalerManager();//无参(默认)构造函数SalerManager(const SalerManager &obj);//拷贝构造函数void Input();//输入销售经理信息void Output();//输出销售经理信息int GetNumber();int GetAge();float GetTotal();//获取该部门的销售总额度float GetSalary();string GetName();string GetDepartment() const;//获取员工的部门void SetName(string tname);//修改姓名void SetSex(string tsex);//修改性别void SetAge(int tage);//修改年龄void SetJob(string tjob);//修改岗位void SetSalary(float tsalary);//修改当月工资void SetDep(string tdepart);//修改员工所属的部门 void SetTotal(float ttotalBalance);//修改该部门的销售总额度SalerManager &operator =(const SalerManager &obj);//重载=friend ostream & operator << (ostream &out, SalerManager &sm);    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性)friend istream & operator >> (istream &in, SalerManager &sm);    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性)};#endif

//data.cpp 类的实现
#define _CRT_SECURE_NO_WARNINGS#include "define.h"#include "data.h"#include <iostream>#include <fstream>#include <iomanip>using namespace std;int Department::dCount = 6;//部门数目  默认6个部门(1.财政部  2.人力部  3.营销部 4.研发部 5.信息部 6.服务部 )int Employee::eCount = 0;//员工数目int Employee::MaxNum = 0;string Dep[6] = { "财政部", "人力部", "营销部", "研发部", "信息部", "服务部" };/********************Date类成员函数定义********************/void Date::Init(int y,int m,int d){year = y;month = m;day = d;}int Date::GetYear(){return year;}int Date::GetMonth(){return month;}int Date::GetDay(){return day;}int Date::GetAge(){time_t t=time(NULL); int yNow, mNow, dNow;char y[5];strftime(y,5,"%Y",localtime(&t));//字符串转数字sscanf(y, "%d", &yNow);// 计算年数age = yNow - year;return age;}/*****************Department类成员函数定义*****************/Department::Department()//默认构造函数{str = new string[Department::dCount];for (int i = 0; i < dCount; i++)//初始化部门名str[i] = Dep[i];bianhao = new int[Department::dCount];for (int i = 0; i < dCount; i++)//初始化部门编号bianhao[i] = i + 1;}Department::~Department()//清理动态申请的空间{if (str)delete[]str;str = NULL;if (bianhao)delete[]bianhao;bianhao = NULL;}void Department::InitDep(string *s, int *b, int length)//加载文件后初始化部门信息{str = new string[length];bianhao = new int[length];for (int i = 0; i < length; i++){str[i] = s[i];bianhao[i] = b[i];}}string Department::Check(string d)//查找是否有这个部门  <绑定关系>{for (int i = 0; i < dCount; i++){if (d == str[i])return d;}return "0";}void Department::Add(string NewDep)//添加部门{if (Check(NewDep) != "0")//部门存在 则不添加return;string *temp = new string[Department::dCount];int *itemp = new int[Department::dCount];for (int i = 0; i < dCount; i++)//备份原有的部门temp[i] = str[i];for (int i = 0; i < dCount; i++)//备份原有的部门编号itemp[i] = bianhao[i];if (str)delete[]str;if (bianhao)delete[]bianhao;int i;str = new string[Department::dCount + 1];bianhao = new int[Department::dCount + 1];for (i = 0; i < dCount; i++)//覆盖原有的部门str[i] = temp[i];for (i = 0; i < dCount; i++)//新增加1bianhao[i] = itemp[i];bianhao[dCount] = bianhao[i - 1] + 1;str[dCount] = NewDep;//新增dCount++;cout << "添加部门成功。\n";delete[]temp;}void Department::Delete(string OldDep)//删除部门{if (dCount != 0 && Check(OldDep) != "0"){for (int i = 0; i < dCount; i++){if (str[i] == OldDep)//查找要删除的部门{cout << "删除" << OldDep << "部门成功!\n";for (int j = i; j < dCount - 1; j++){str[j] = str[j + 1];//将要删除的部门覆盖掉bianhao[j] = bianhao[j + 1];}break;}}dCount--;}elsecout << "还没有该部门!\n";}void Department::Modify(string OldDep, string NewDep)//修改部门的名称{if (dCount != 0 && Check(OldDep) != "0"){for (int i = 0; i < dCount; i++){if (str[i] == OldDep)//查找要修改的部门{str[i] = NewDep;cout << "修改部门成功!\n";break;}}}elsecout << "还没有该部门!\n";}void Department::Scan()//浏览部门{cout << endl;SIGN_3;for (int i = 0; i < dCount; i++){cout << "       ┃ 选项:(" << i + 1 << ")   ┃ 编号:" << bianhao[i] << "   ┃ " << str[i] <<" ┃"<< endl;if (i + 1 != dCount)SIGN_4;}SIGN_5;}int  Department::GetDNumber(string d)//获取部门编号 {for (int i = 0; i < dCount; i++){if (str[i] == d)return i;}return -1;}int Department::GetDCount()//获取部门数目{return dCount;}string Department::GetDep(int choice)//获取所需部门{if (choice < 0 || choice >= dCount)return "0";return str[choice];}/*****************Employee类成员函数定义*****************/Employee::Employee()//无参(默认)构造函数{age = 0;//表示还没有这个员工salary = 0;//工资初始化为0job = "---";name = "---";number = 0;sex = "---";SetDep("----");}void Employee::Init()//初始化员工{string depart;cout << "输入姓名:";cin >> name;cout << "输入性别:";cin >> sex;while (sex != "男" && sex != "女"){cout << "输入错误!请重新输入(男或者女):";cin >> sex;}cout << "输入出生日期(格式为 1999-1-1):";char strAge[13];int year, month, day;int i;cin >> strAge;while (strAge[4] != '-' || (strAge[7] != '-'&& strAge[6]!='-')){cout << "格式错误,请重新输入:";AGAIN:cin >> strAge;}char y[5] = {0};for (i = 0; i < strlen(strAge); i++){if (strAge[i] == '-')break;y[i] = strAge[i];}int k = 0;char m[3] = {0};for (i++; i < strlen(strAge); i++){if (strAge[i] == '-')break;m[k++] = strAge[i];}int j = 0;char d[3] = {0};for (i++; i < strlen(strAge); i++){if (strAge[i] == '\0')break;d[j++] = strAge[i];}sscanf(y, "%d", &year);   sscanf(m,"%d", &month);sscanf(d, "%d", &day);if (year >2000 || year < 1900 || month>12 || day>31){cout << "输入的日期不切实际!请重新输入:";goto AGAIN;}date.Init(year, month, day);age = date.GetAge();cout << "输入部门:";cin >> depart;while (Check(depart) == "0"){cout << "还没有" << depart << "这个部门,请重新输入:";cin >> depart;}SetDep(depart);number = MaxNum + 1;//最大员工数加1  备注eCount++;//实际员工数加1MaxNum++;}void Employee::Output()//输出员工信息{}Employee &Employee::operator = (const Employee &obj){this->number = obj.number;//工号this->name = obj.name;//姓名this->sex = obj.sex;//性别this->age = obj.age;//年龄SetDep(department);//部门this->job = obj.job;//岗位this->salary = obj.salary;//当月工资return *this;}int Employee::GetECount()//获取员工数目{return eCount;}int Employee::GetNumber()//获取工号  (函数访问静态成员数据){return number;}int Employee::GetAge()//获取员工年龄{return age;}float Employee::GetSalary()//获取员工当月工资{return salary;}string Employee::GetName()//获取员工姓名{return name;}string Employee::GetSex()//获取员工性别{return sex;}string Employee::GetJob()//获取员工岗位{return job;}string Employee::GetDepartment()  const//获取员工的部门{return department;}void Employee::SetMaxNum(int m)//加载文件后设置初始化最大工号{MaxNum = m;}void Employee::SetECount(int size)//修改员工数目{eCount = size;}void Employee::SetName(string tname)//修改姓名{name = tname;}void Employee::SetSex(string tsex)//修改性别{sex = tsex;}void Employee::SetAge(int tage)//修改年龄{age = tage;}void Employee::SetJob(string tjob)//修改岗位{job = tjob;}void Employee::SetSalary(float tsalary)//修改当月工资{salary = tsalary;}void Employee::SetDep(string tdepart)//修改员工所属的部门 {department = tdepart;}void Employee::InitDep(string *s, int *b, int length)//初始化部门信息{dep.InitDep(s, b, length);}string Employee::Check(string d)//查找是否有这个部门  <绑定关系>{return dep.Check(d);}void Employee::AddDep(string NewDep)//添加部门{dep.Add(NewDep);}void Employee::DeleteDep(string OldDep)//删除部门{dep.Delete(OldDep);}void Employee::ModifyDep(string OldDep, string NewDep)//修改部门的名字{dep.Modify(OldDep, NewDep);}void Employee::BrowseDep()//浏览部门{dep.Scan();}int Employee::GetDNumber(string d)//获取部门数目{return dep.GetDNumber(d);}int Employee::GetDCount()const//获取部门数目{return dep.GetDCount();}string Employee::GetDep(int choice)//获取所需部门{return dep.GetDep(choice);}/**************Technician类成员函数定义*******************/Technician::Technician()//无参(默认)构造函数{hours = 0;job = "技术员";}Technician::Technician(const Technician &obj)//拷贝构造函数{hours = obj.hours;//工时eCount = obj.eCount;//员工数目number = obj.number;//工号 (系统自动赋值  不输入)name = obj.name;//姓名sex = obj.sex;//性别age = obj.age;//年龄SetDep(obj.GetDepartment());//部门  (类的组合)job = obj.job;//岗位salary = obj.salary;//当月工资}void Technician::Input()//输入技术员信息{this->Init();}void Technician::Output()//输出技术员信息{ cout << setw(5) << number << setw(8) << name << setw(6) << sex << setw(7) << age << setw(11) << GetDepartment() << setw(10) << job << setw(6) << hours << "       ----" << setw(12) << salary << endl;}float Technician::GetHours()//获取工时{return hours;}void Technician::SetHours(float hour)//修改工时{this->hours = hour;}Technician &Technician::operator = (const Technician &obj)//重载={Employee::operator = (obj);//调用Employee的重载=this->hours = obj.hours;return *this;}ostream & operator << (ostream &out, Technician &tec)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){out << tec.number << ' ' << tec.name << ' ' << tec.sex << ' ' << tec.age << ' ' << tec.GetDepartment()<< ' ' << tec.job << ' ' << tec.hours << ' ' << tec.salary << endl;return out;}istream & operator >> (istream &in, Technician &tec)    //友元函数重载输出运算符">>"  ( 函数/运算符重载 静态多态性){in >> tec.number >> tec.name >> tec.sex >> tec.age >> tec.department>> tec.job >> tec.hours >> tec.salary;return in;}/****************Saler类成员函数定义********************/Saler::Saler()//无参(默认)构造函数{job = "销售员";balance = 0;}Saler::Saler(const Saler &obj){balance = obj.balance;//销售额度eCount = obj.eCount;//员工数目number = obj.number;//工号 (系统自动赋值  不输入)name = obj.name;//姓名sex = obj.sex;//性别age = obj.age;//年龄SetDep(obj.GetDepartment());//部门  (类的组合)job = obj.job;//岗位salary = obj.salary;//当月工资}void Saler::Input()//输入销售员信息{this->Init();}void Saler::Output()//输出销售员信息{cout << setw(5) << number << setw(8) << name << setw(6) << sex << setw(7) << age << setw(11) << GetDepartment() << setw(10) << job << "    ---" << setw(10) << balance << setw(12) << salary << endl;}float Saler::GetBalance()//获取销售额度{return balance;}void Saler::SetBalance(float tbalance)//修改员工销售额度{balance = tbalance;}Saler &Saler::operator =(const Saler &obj)//重载={Employee::operator = (obj);this->balance = obj.balance;return *this;}ostream & operator << (ostream &out, Saler &s)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){out << s.number << ' ' << s.name << ' ' << s.sex << ' ' << s.age << ' ' << s.department << ' ' << s.job << ' ' << s.balance << ' ' << s.salary << endl;return out;}istream & operator >> (istream &in, Saler &s)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){in >> s.number >> s.name >> s.sex >> s.age >> s.department>> s.job >> s.balance >> s.salary;return in;}/****************Manager类成员函数定义********************/Manager::Manager()//无参(默认)构造函数{salary = REGULAR_SALARY;job = "经理";}Manager::Manager(const Manager &obj)//拷贝构造函数{eCount = obj.eCount;//员工数目number = obj.number;//工号 (系统自动赋值  不输入)name = obj.name;//姓名sex = obj.sex;//性别age = obj.age;//年龄SetDep(obj.GetDepartment());//部门  (类的组合)job = obj.job;//岗位salary = obj.salary;//当月工资}void Manager::Input(){this->Init();//输入经理信息}void Manager::Output(){cout << setw(5) << number << setw(8) << name << setw(6) << sex << setw(7) << age << setw(11) << department << setw(10) << job << "    ---" << "      ----" << setw(12) << salary << endl;}//Manager &Manager::operator = (const Manager &obj)//重载=//{//Employee::operator = (obj);//return *this;//}ostream & operator << (ostream &out, Manager &m)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){out << m.number << ' ' << m.name << ' ' << m.sex << ' ' << m.age << ' ' << m.department << ' ' << m.job << ' ' << m.salary << endl;return out;}istream & operator >> (istream &in, Manager &m)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){in >> m.number >> m.name >> m.sex >> m.age >> m.department>> m.job >> m.salary;return in;}/**************SalerManager类成员函数定义*****************/SalerManager::SalerManager()//无参(默认)构造函数{totalBalance = 0;}SalerManager::SalerManager(const SalerManager &obj){eCount = obj.eCount;//员工数目number = obj.number;//工号 (系统自动赋值  不输入)name = obj.name;//姓名sex = obj.sex;//性别age = obj.age;//年龄SetDep(obj.GetDepartment());//部门  (类的组合)job = obj.job;//岗位salary = obj.salary;//当月工资totalBalance = obj.totalBalance;//该部门的总销售额度}void SalerManager::Input()//输入销售经理信息{Saler::SetJob("销售经理");this->Saler::Init();}void SalerManager::Output()//输出销售经理信息{cout << setw(5) << GetNumber() << setw(8) << GetName() << setw(6) << GetSex() << setw(7) << GetAge() << setw(11) << GetDepartment() << setw(10) << GetJob() << "    ---" << setw(10) << GetTotal() << setw(12) << GetSalary() << endl;}float SalerManager::GetSalary(){return Saler::GetSalary();}float SalerManager::GetTotal()//获取该部门的销售总额度{return totalBalance;}int SalerManager::GetNumber()//获取工号 {return Saler::GetNumber();}int SalerManager::GetAge()//获取年龄{return Saler::GetAge();}string SalerManager::GetName()//获取姓名{return Saler::GetName();}string SalerManager::GetDepartment() const//获取员工的部门{return Saler::GetDepartment();}void SalerManager::SetTotal(float ttotalBalance)//修改该部门的销售总额度{totalBalance = ttotalBalance;}void SalerManager::SetName(string tname)//修改姓名{Saler::SetName(tname);}void SalerManager::SetSex(string tsex)//修改性别{Saler::SetSex(tsex);}void SalerManager::SetAge(int tage)//修改年龄{Saler::SetAge(tage);}void SalerManager::SetJob(string tjob)//修改岗位{Saler::SetJob(tjob);}void SalerManager::SetSalary(float tsalary)//修改当月工资{Saler::SetSalary(tsalary);}void SalerManager::SetDep(string tdepart)//修改员工所属的部门 {Saler::SetDep(tdepart);}SalerManager &SalerManager::operator = (const SalerManager &obj)//重载={Employee::operator = (obj);totalBalance = obj.totalBalance;return *this;}ostream & operator << (ostream &out, SalerManager &sm)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){out << sm.GetNumber() << ' ' << sm.GetName() << ' ' << sm.GetSex() << ' ' << sm.GetAge() << ' ' << sm.department << ' ' << sm.GetJob() << ' ' << sm.GetTotal() << ' ' << sm.GetSalary() << endl;return out;}istream & operator >> (istream &in, SalerManager &sm)    //友元函数重载输出运算符"<<"  ( 函数/运算符重载 静态多态性){in >> sm.number >> sm.name >> sm.sex >> sm.age >> sm.department>> sm.job >> sm.totalBalance >> sm.salary;return in;}

完整的代码:

http://download.csdn.net/detail/zhangxiaoyu_sy/9889872