工资管理系统

#include<iostream>
#include<cmath>
#include<cstring>
#include<fstream>
#include<algorithm>
#include<vector>
#include <iomanip>

using namespace std;
//阶级基础工资  class Wages
int class1[11] = { 8000,7000,6000,5000,3300,3000,2800,2600,2500,2400,2300 };
int class2[7] = { 3400,3000,2500,2400,2200,2100,2000 };
int class3[6] = { 3400,3000,2600,2400,2200,2100 };
int class4[6] = { 3400,3000,2600,2300,2200,2100 };
//一等岗位基础工资 Position salary
int Posalary1[11] = { 7500,5500,4000,3000,1600,1500,1500,1400,1300,500,400 };
int Posalary2[7] = { 1600,1500,1000,1000,350,300,300 };
int Posalary3[6] = { 1600,1500,1400,1300,1000,700 };
int Posalary4[6] = { 1600,1500,1400,1300,500,400 };
//挡位工资档差 根据工龄计算 最高9级 每年工作一年增加一级 Gear Salary
int Gsalary1[11] = { 2000,2000,1500,1000,700,600,500,450,300,200,150 };
int Gsalary2[7] = { 700,600,300,300,150,150,150 };
int Gsalary3[6] = { 700,600,450,300,200,150 };
int Gsalary4[6] = { 700,600,450,300,200,150 };

//绩效工资 Performance salary
int Prsalary1[11] = { 6000,5000,4000,3000,1000,900,800,700,600,400,300 };
int Prsalary2[7] = { 1000,900,700,600,400,300,200 };
int Prsalary3[6] = { 1000,900,700,600,400,300 };
int Prsalary4[6] = { 1000,900,700,600,400,300 };
//福利待遇 Benefits salary
//交通补助 Transpotation subsidy
int Tsubsidy = 50;//每月
//午餐补贴 Lunch subsidy 
int Lsubsidy = 10;//每天
//缺勤与加班工资(考察工资) Examine wages

class position {
public:
    int JobPositision;
    int stage;
    string Pposition;
    friend ostream& operator<<(ostream& os, const position& P) {
        os << P.Pposition;
        return os;
    }
    friend istream& operator>>(istream& is, position P) {
        is >> P.Pposition;
        return is;
    }
};

class Person {
public:
    string name;
    string phonenumber;
    string gender;
    int age;
public:
    Person() = default;
    Person(string name, string phonenumber, string gender, int age) :name(name), phonenumber(phonenumber), gender(gender), age(age) { }
    void show() {
        cout << name << endl << gender << endl << age << endl << phonenumber << endl;
    }
};
class employee :public Person {
public:
    int worknumber;//工号
    int positionsalary;//职位工资
    int seniority;//工龄
    int Performancesalary;//绩效工资
    int benefitssalary;
    int examinewages;
    string birthday;
    class position p;
    int totalsalary;
    int basesalary;//基础工资 (根据等级和工龄计算)
    string department;
public:
    employee(string name, string phonenumber, string gender, int age, int seniority, string position) :Person(name, phonenumber, gender, age) {

    }
    employee() = default;
    void show() {}
    friend ostream& operator<<(ostream& os, const employee& E) {
        os << std::left << setw(6) << E.name << setw(6) << E.gender << setw(6) << E.age << setw(12) << E.phonenumber << setw(10) << E.birthday << setw(16) << E.p.Pposition << setw(10) << E.worknumber << setw(6) << E.seniority << setw(10) << E.totalsalary << setw(12) << E.department << endl;
        return os;
    }
    friend istream& operator>>(istream& is, employee& E) {
        is >> std::left >> setw(6) >> E.name >> setw(6) >> E.gender >> setw(6) >> E.age >> setw(12) >> E.phonenumber >> setw(8) >> E.birthday >> setw(16) >> E.p.Pposition >> setw(10) >> E.worknumber >> E.seniority;
        return is;
    }
};

ifstream infile;
ofstream outfile;
bool statu = true;
bool statu1 = true;
bool statu2 = true;
int a, b;
bool T = true;
employee temple;
int findnumber;//工号查找
string name;//姓名查找
vector<employee>Vcopy;//拷贝储存
vector<employee>basicbackup;//原始数据储存
vector<employee>backbackup;
const int N = 500;
const int M = 500;
vector<vector<employee>>leftbackup(500, vector<employee>(500, temple));
vector<vector<employee>>rightbackup(500, vector<employee>(500, temple));
int availableleftbackupnumber = 0;
int availablerightcountnumber = 0;
int countnumber = 0;
bool s = true;
string departmentfind;
string namefind;
string namefind1;

//展示菜单页面
void showmeau() {
    for (int i = 0; i < 20; i++) cout << "*";
    cout << endl;
    cout << "请选择你要你要进行的操作序号:" << endl;
    cout << "1、添加员工及其信息" << endl;
    cout << "2、删除员工及其信息" << endl;
    cout << "3、显示全部员工及其信息" << endl;
    cout << "4、查找员工信息及其工资信息" << endl;
    cout << "5、添加考勤信息" << endl;
    cout << "6、输出全部员工月度工资" << endl;
    cout << "7、输出全部员工年度工资" << endl;
    cout << "8、按照工号或姓名排序员工信息及其工资信息" << endl;
    cout << "9、恢复成最开始数据" << endl;
    cout << "10、撤销" << endl;
    cout << "11、恢复" << endl;
    cout << "12、按部门查询员工及信息" << endl;
    cout << "13、修改员工信息" << endl;
    cout << "14、退出工资管理系统" << endl;
    for (int i = 0; i < 20; i++) cout << "*";
    cout << endl;
}
//添加员工信息
void addmessage() {
    //string name, string phonenumber, string gender, int age,int seniority,string position
    statu2 = true;
    while (statu2) {
        cout << "请依次输入姓名、性别、年龄、电话、生日、职位、工号、工龄" << endl;
        cin >> temple;
        cout << "输入职位分类" << endl;
        cout << "1、管理部" << endl;
        cout << "2、生产部" << endl;
        cout << "3、技术部" << endl;
        cout << "4、营销部" << endl;
        T = true;
        while (T) {
            cin >> temple.p.JobPositision;
            if (temple.p.JobPositision == 1) temple.department = "管理部", T = false;
            else if (temple.p.JobPositision == 2) temple.department = "生产部", T = false;
            else if (temple.p.JobPositision == 3) temple.department = "技术部", T = false;
            else if (temple.p.JobPositision == 4) temple.department = "营销部", T = false;
            else {
                cout << "输入错误,请重新输入" << endl;
            }
        }
        cout << "输入职位职位等级" << endl;
        cout << "管理部11级" << endl;
        cout << "生产部7级" << endl;
        cout << "技术部6级" << endl;
        cout << "营销部6级" << endl;
        T = true;
        while (T) {
            cin >> temple.p.stage;
            if (temple.p.JobPositision == 1 && (temple.p.stage > 0 || temple.p.stage <= 11)) T = false;
            else if (temple.p.JobPositision == 2 && (temple.p.stage > 0 || temple.p.stage <= 7)) T = false;
            else if (temple.p.JobPositision == 3 && (temple.p.stage > 0 || temple.p.stage <= 6)) T = false;
            else if (temple.p.JobPositision == 4 && (temple.p.stage > 0 || temple.p.stage <= 6)) T = false;
            if (T) cout << "输入职位等级错误,请重新输入!" << endl;
        }
        if (temple.p.JobPositision == 1) {
            temple.basesalary = class1[temple.p.stage - 1];
            temple.positionsalary = Posalary1[temple.p.stage - 1] + Gsalary1[temple.p.stage - 1] * min(8, temple.seniority - 1);
            temple.Performancesalary = Prsalary1[temple.p.stage - 1];
        }
        else if (temple.p.JobPositision == 2) {
            temple.basesalary = class2[temple.p.stage - 1];
            temple.positionsalary = Posalary2[temple.p.stage - 1] + Gsalary2[temple.p.stage - 1] * min(8, temple.seniority - 1);
            temple.Performancesalary = Prsalary2[temple.p.stage - 1];
        }
        else if (temple.p.JobPositision == 3) {
            temple.basesalary = class3[temple.p.stage - 1];
            temple.positionsalary = Posalary3[temple.p.stage - 1] + Gsalary3[temple.p.stage - 1] * min(8, temple.seniority - 1);
            temple.Performancesalary = Prsalary3[temple.p.stage - 1];
        }
        else {
            temple.basesalary = class4[temple.p.stage - 1];
            temple.positionsalary = Posalary4[temple.p.stage - 1] + Gsalary4[temple.p.stage - 1] * min(8, temple.seniority - 1);
            temple.Performancesalary = Prsalary4[temple.p.stage - 1];
        }
        temple.benefitssalary = Tsubsidy + Lsubsidy;
        cout << "依次输入加班和事假天数" << endl;
        cin >> a >> b;
        temple.examinewages = (a - b) * (temple.basesalary + temple.positionsalary) / 30;
        temple.totalsalary = temple.basesalary + temple.Performancesalary + temple.positionsalary + temple.benefitssalary + temple.examinewages;
        statu1 = true;
        while (statu1) {
            cout << "请确定输入是否正确" << endl;
            cout << "姓名  性别  年龄  电话        生日      职位            工号      工龄  工资      部门" << endl;
            cout << temple;

            cout << "正确:输入1   错误:输入2" << endl;
            cin >> a;
            if (a == 1) statu2 = false, statu1 = false;
            else if (a == 2) statu1 = false;
            else
                cout << "序号输入错误,请重新输入" << endl;

        }
    }
    outfile.open("employee.txt", ofstream::app);
    outfile << temple;
    outfile.close();
    cout << "员工信息已经录入" << endl;
}
//删除员工信息 输入姓名 或者工号
void deletemessage() {
    cout << "请输入要删除员工的工号" << endl;
    cin >> findnumber;
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        if (temple.worknumber != findnumber)
        {
            Vcopy.push_back(temple);
        }
        if (temple.worknumber == findnumber) {
            T = false;
            cout << " 已查询到并删除员工" << endl;
        }
    }
    infile.close();
    if (T) {
        cout << "未查询到该员工,请重新输入或者检查输入是否正确" << endl;

    }
    else {
        outfile.open("employee.txt", ofstream::out | ofstream::trunc);
        while (!Vcopy.empty()) {
            temple = Vcopy.front(); Vcopy.erase(Vcopy.begin());
            outfile << temple;
        }
    }
    outfile.close();
}
//展示全部员工信息
void showmessage() {
    //cout << 1;
    infile.open("employee.txt");
    cout << "姓名  性别  年龄  电话        生日      职位            工号      工龄  工资      部门" << endl;
    while (infile >> temple) {
        //cout << 2;
        infile >> temple.totalsalary >> temple.department;
        cout << temple;
    }
    infile.close();
}
void showdepartmentmessage() {
    cout << "请输入你要查询信息的部门" << endl;
    cin >> departmentfind;
    infile.open("employee.txt");
    cout << "姓名  性别  年龄  电话        生日      职位            工号      工龄  工资      部门" << endl;
    T = true;
    while (T)
    {
        while (infile >> temple)
        {
            //cout << 2;
            infile >> temple.totalsalary >> temple.department;
            if (temple.department == departmentfind)
            {
                cout << temple;
                T = false;
            }
        }
        if (T)
        {
            T = false;
            cout << "此部门暂无员工" << endl;
        }
        infile.close();
    }
}
//查找员工信息
void findmessage() {
    statu1 = true;
    while (statu1) {
        cout << "请输入查询信息的种类的序号:" << endl;
        cout << "1、按工号查询" << endl;
        cout << "2、按姓名查询" << endl;
        cin >> a;
        if (a == 1) {
            statu1 = false;
            cout << "输入要查找的员工的工号" << endl;
            cin >> findnumber;
            infile.open("employee.txt");
            while (infile >> temple)
            {
                T = true;
                infile >> temple.totalsalary >> temple.department;
                if (temple.worknumber == findnumber) {
                    cout << "姓名  性别  年龄  电话        生日      职位            工号      工龄  工资      部门" << endl;
                    cout << temple;
                    T = false;
                    
                }
            }
            if (T)
                cout << "未查询到此人,请检查拼写是否正确或重新输入" << endl;
            infile.close();
        }
        else if (a == 2) {
            statu1 = false;
            cout << "输入要查找员工的姓名" << endl;
            cin >> namefind;
            infile.open("employee.txt");
            while (infile >> temple)
            {
                T = true;
                infile >> temple.totalsalary >> temple.department;
                if (temple.name == namefind) {
                    cout << "姓名  性别  年龄  电话        生日      职位            工号      工龄  工资      部门" << endl;
                    cout << temple;
                    T = false;
                    break;
                }
            }
            if (T)
                cout << "未查询到此人,请检查拼写是否正确或重新输入" << endl;
            infile.close();
        }
        else {
            cout << "输入序号错误,请重新输入" << endl;
        }
    }
}
//添加缺勤或者加班信息
void AddExamMessage() {
    T = true;
    cout << "依次输入要添加考勤信息员工的工号和加班以及缺勤天数" << endl;
    Vcopy.clear();
    cin >> findnumber >> a >> b;
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        if (temple.worknumber == findnumber) {
            T = false;
            temple.totalsalary += (a - b) * (temple.basesalary + temple.positionsalary) / 30;
            Vcopy.push_back(temple);
        }
        else
            Vcopy.push_back(temple);
    }
    infile.close();
    if (T) {
        cout << "未查询到此员工,请重新输入" << endl;
    }
    else {
        outfile.open("employee.txt", ofstream::trunc);
        while (!Vcopy.empty()) {
            temple = Vcopy.back();
            Vcopy.pop_back();
            outfile << temple;
        }
        outfile.close();
    }
}
//打印全部员工月度信息
void PrintMonthMoney() {
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        cout << "姓名:" << temple.name << " 月工资: " << temple.totalsalary << " 部门:" << temple.department << endl;
    }
    infile.close();
}
//打印全部员工年度信息
void PrintYearMoney() {
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        cout << "姓名:" << temple.name << "年工资:" << temple.totalsalary * 12 << " 部门:" << temple.department << endl;
    }
    infile.close();
}
//排序
bool cmp(employee t1, employee t2) {
    if (t1.worknumber < t2.worknumber) return true;
    return false;
}
//按工号排序
void sortByworknumber() {
    Vcopy.clear();
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        Vcopy.push_back(temple);
    }
    infile.close();
    sort(Vcopy.begin(), Vcopy.end(), cmp);
    outfile.open("employee.txt", ofstream::out | ofstream::trunc);
    while (!Vcopy.empty()) {
        temple = Vcopy.front(); Vcopy.erase(Vcopy.begin());
        outfile << temple;
    }
    outfile.close();
    cout << "排序成功" << endl;
}
//按部门排序
bool cmp2(employee t1, employee t2) {
    if (t1.department > t2.department) return true;
    return false;
}
void sortbydepartment() {
    Vcopy.clear();
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        Vcopy.push_back(temple);
    }
    infile.close();
    sort(Vcopy.begin(), Vcopy.end(), cmp2);
    outfile.open("employee.txt", ofstream::out | ofstream::trunc);
    while (!Vcopy.empty()) {
        temple = Vcopy.front(); Vcopy.erase(Vcopy.begin());
        outfile << temple;
    }
    outfile.close();
    cout << "排序成功" << endl;
}

//储存打开程序时的状态
void Basicbackup() {
    basicbackup.clear();
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;
        basicbackup.push_back(temple);
    }
    infile.close();
}
//[状态:总向左撤回步数:线性+1] 储存任何一个改动信息步数发生之前的数据库
void Leftbackup() {
    availableleftbackupnumber++;
    leftbackup[availableleftbackupnumber - 1].clear();
    infile.open("employee.txt");
    while (infile >> temple) {
        infile >> temple.totalsalary >> temple.department;

        leftbackup[availableleftbackupnumber - 1].push_back(temple);
    }
    infile.close();
}
//[状态:总向右撤回步数:线性+1] 储存任何向左撤回操作发生之前的数据库
void Rightbackup()
{
    {
        availablerightcountnumber++;
        rightbackup[availablerightcountnumber - 1].clear();
        infile.open("employee.txt");
        while (infile >> temple)
        {
            infile >> temple.totalsalary >> temple.department;
            rightbackup[availablerightcountnumber - 1].push_back(temple);
        }
        infile.close();
    }


}
//恢复打开程序时的状态
void Recoverbasic()
{

    backbackup = basicbackup;

    outfile.open("employee.txt", ofstream::out | ofstream::trunc);
    while (!basicbackup.empty())
    {
        temple = basicbackup.front(); basicbackup.erase(basicbackup.begin());
        outfile << temple;
    }
    basicbackup = backbackup;
    outfile.close();
    cout << "已恢复初始状态" << endl;
}
//标记相较于执行撤回操作时的数据:-1 总向左撤回步数:-1 向左撤回数据库消除一步数据库
void Recoverleft()
{

    if (availableleftbackupnumber > 0)
    {
        countnumber--;
        if (!leftbackup[availableleftbackupnumber - 1].empty())
            outfile.open("employee.txt", ofstream::out | ofstream::trunc);
        while (!leftbackup[availableleftbackupnumber - 1].empty())
        {
            temple = leftbackup[availableleftbackupnumber - 1].front();
            leftbackup[availableleftbackupnumber - 1].erase(leftbackup[availableleftbackupnumber - 1].begin());
            outfile << temple;
        }
        outfile.close();
        availableleftbackupnumber--;
        cout << "已向左撤回" << endl;
    }
    else
    {
        cout << "无法向左撤回" << endl;
    }
}
//标记相较于执行撤回操作时的数据:+1 总向右撤回步数:-1 向右撤回数据库消除一步数据库
void Recoverright()
{

    if (availablerightcountnumber > 0)
    {
        countnumber++;
        if (!rightbackup[-countnumber].empty())
            outfile.open("employee.txt", ofstream::out | ofstream::trunc);
        while (!rightbackup[-countnumber].empty())
        {
            temple = rightbackup[-countnumber].front();
            rightbackup[-countnumber].erase(rightbackup[-countnumber].begin());
            outfile << temple;
        }
        availablerightcountnumber--;

        outfile.close();
        cout << "已向右撤回" << endl;
    }
    else
    {
        cout << "无法向右撤回" << endl;
    }
}
//当需要执行这步程序时,开始新的基础数据,已经无法向右撤回,向右撤回步数清零,向右撤回数据库清零
void clearrightbackup()
{
    for (int i = 0; i < rightbackup.size(); i++)
    {
        rightbackup[i].clear();
    }
    availablerightcountnumber = 0;
}
//当需要执行这步程序时,开始新的基础数据,减少已执行的相较于原基础数据的向左撤回步数(即向左撤回步数为剩余的没使用过的步数),清除执行过的步数的向左撤回数据库
void clearleftbackup()
{
    for (int i = leftbackup.size() + countnumber; i < leftbackup.size(); i++)
    {
        rightbackup[i].clear();
    }

}
void changedata()
{
    T = true;
    while (T)
    {
        cout << "请输入你修改的方式的序号:" << endl;
        cout << "1、按姓名修改" << endl;
        cout << "2、按工号修改" << endl;
        cin >> a;
        if (a == 1) {
            T = false;
            cout << "请输入要修改员工的姓名" << endl;
            cin >> namefind;
            infile.open("employee.txt");

            Vcopy.clear();
            s = true;
            while (infile >> temple) {
                infile >> temple.totalsalary >> temple.department;
                if (temple.name == namefind && s == true) {
                    s = false;
                    cout << "已查询到该员工,请输入你要修改的内容的序号:";
                    cout << "1、姓名" << endl;
                    cout << "2、性别" << endl;
                    cout << "3、年龄" << endl;
                    cout << "4、电话" << endl;
                    cout << "5、生日" << endl;
                    cout << "6、职位" << endl;
                    cout << "7、工号" << endl;
                    cout << "8、工龄" << endl;
                    cout << "9、部门" << endl;
                    statu1 = true;
                    while (statu1) {
                        cin >> a;
                        if (a == 1) {
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的姓名:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的姓名" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                {
                                    statu2 = false, temple.name = namefind, cout << "修改成功" << endl;
                                }
                                else
                                    cout << "前后修改姓名不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 2) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的性别:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的性别" << endl;
                                //此处为性别
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.gender = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改性别不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 3) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的年龄:" << endl;
                                cin >> a;
                                cout << "请再次输入你要修改为的姓名" << endl;
                                cin >> b;
                                if (a == b)
                                    statu2 = false, temple.age = a, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改年龄不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 4) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的电话:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的电话" << endl;
                                //此处为电话
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.phonenumber = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改电话不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 5) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                //此处为生日
                                cout << "请输入你要修改为的生日:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的生日" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.birthday = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改生日不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 6) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                //此处为职位
                                cout << "请输入你要修改为的职位:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的职位" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.p.Pposition = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改职位不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 7) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的工号:" << endl;
                                cin >> a;
                                cout << "请再次输入你要修改为的工号" << endl;
                                cin >> b;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.worknumber = a, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改工号不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 8) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;

                                cout << "请输入你要修改为的工龄:" << endl;
                                cin >> a;
                                cout << "请再次输入你要修改为的工龄" << endl;
                                cin >> b;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.seniority = a, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改工龄不一致,请重新输入。" << endl;
                            }
                        }

                        else if (a == 9) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                //此处为职位
                                cout << "请输入你要修改为的部门:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的部门" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.department = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改部门不一致,请重新输入。" << endl;
                            }
                        }
                        else
                        {
                            cout << "输入的序号错误,请重新输入" << endl;
                        }
                    }
                }

                Vcopy.push_back(temple);
            }
            if (s)
            {
                T = true; cout << "未查询到此人" << endl;
            }
            infile.close();
            outfile.open("employee.txt", ofstream::trunc);
            while (!Vcopy.empty()) {
                temple = Vcopy.back(); Vcopy.pop_back();
                outfile << temple;
            }
            outfile.close();
        }
        else if (a == 2) {
            T = false;
            cout << "请输入要修改员工的工号" << endl;
            cin >> a;
            infile.open("employee.txt");

            Vcopy.clear();
            s = true;
            while (infile >> temple) {
                infile >> temple.totalsalary >> temple.department;
                if (temple.worknumber == a && s == true) {
                    s = false;
                    cout << "已查询到该员工,请输入你要修改的内容的序号:" << endl;
                    cout << "1、姓名" << endl;
                    cout << "2、性别" << endl;
                    cout << "3、年龄" << endl;
                    cout << "4、电话" << endl;
                    cout << "5、生日" << endl;
                    cout << "6、职位" << endl;
                    cout << "7、工号" << endl;
                    cout << "8、工龄" << endl;
                    cout << "9、部门" << endl;
                    statu1 = true;
                    while (statu1) {
                        cin >> a;
                        if (a == 1) {
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的姓名:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的姓名" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.name = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改姓名不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 2) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的性别:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的性别" << endl;
                                //此处为性别
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.gender = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改性别不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 3) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的年龄:" << endl;
                                cin >> a;
                                cout << "请再次输入你要修改为的姓名" << endl;
                                cin >> b;
                                if (a == b)
                                    statu2 = false, temple.age = a, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改年龄不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 4) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的电话:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的电话" << endl;
                                //此处为电话
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.phonenumber = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改电话不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 5) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                //此处为生日
                                cout << "请输入你要修改为的生日:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的生日" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.birthday = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改生日不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 6) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                //此处为职位
                                cout << "请输入你要修改为的职位:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的职位" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.p.Pposition = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改职位不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 7) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                cout << "请输入你要修改为的工号:" << endl;
                                cin >> a;
                                cout << "请再次输入你要修改为的工号" << endl;
                                cin >> b;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.worknumber = a, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改工号不一致,请重新输入。" << endl;
                            }
                        }
                        else if (a == 8) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;

                                cout << "请输入你要修改为的工龄:" << endl;
                                cin >> a;
                                cout << "请再次输入你要修改为的工龄" << endl;
                                cin >> b;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.seniority = a, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改工龄不一致,请重新输入。" << endl;
                            }
                        }

                        else if (a == 9) {
                            statu1 = false;
                            statu2 = true;
                            while (statu2) {
                                statu1 = false;
                                //此处为职位
                                cout << "请输入你要修改为的部门:" << endl;
                                cin >> namefind;
                                cout << "请再次输入你要修改为的部门" << endl;
                                cin >> namefind1;
                                if (namefind1 == namefind)
                                    statu2 = false, temple.department = namefind, cout << "修改成功" << endl;
                                else
                                    cout << "前后修改部门不一致,请重新输入。" << endl;
                            }
                        }
                        else {
                            cout << "输入的序号错误,请重新输入" << endl;
                        }
                    }
                }
                Vcopy.push_back(temple);
            }
            if (s)
            {
                T = true; cout << "未查询到此人" << endl;
            }
            infile.close();
            outfile.open("employee.txt", ofstream::trunc);
            while (!Vcopy.empty())
            {
                temple = Vcopy.back(); Vcopy.pop_back();
                outfile << temple;
            }
            outfile.close();
        }
        else
        {
            T = true;
            cout << "输出错误,请重新输入" << endl;
        }
    }
}

int main() {
    Basicbackup();
    while (statu) {
        showmeau();
        cout << "请输入你的选择" << endl;
        int c; cin >> c;
        switch (c)
        {
            //对于用户更改后新的数据,用户未执行过向左撤回操作,和向右撤回操作,countnumber=0,已向左撤回的操作无法复原,向左撤回数据库剩余未执行的步数,增加一步执行该新操作之前的数据
        case 1:
            clearrightbackup();
            clearleftbackup();
            Leftbackup();
            addmessage();
            countnumber = 0;
            break;
        case 2:
            clearrightbackup();
            clearleftbackup();
            Leftbackup();
            deletemessage();
            countnumber = 0;
            break;
        case 3:
            showmessage();
            break;
        case 4:
            findmessage();
            break;
        case 5:
            clearrightbackup();
            clearleftbackup();
            Leftbackup();
            AddExamMessage();
            countnumber = 0;
            break;
        case 6:
            PrintMonthMoney();
            break;
        case 7:
            PrintYearMoney();
            break;
        case 14:
            statu = false;
            break;
        case 8:
            T = true;
            clearrightbackup();
            clearleftbackup();
            Leftbackup();
            countnumber = 0;
            while (T) {
                cout << "请输入排序的类型的序号" << endl;
                cout << "1、按工号排序" << endl;
                cout << "2、按部门排序" << endl;
                cin >> a;
                if (a == 1)
                    sortByworknumber(), T = false;
                else if (a == 2)
                    sortbydepartment(), T = false;
                else
                    cout << "输入序号错误,请重新输入" << endl;
            }
            //cout << "姓名  性别  年龄  电话        生日      职位            工号      工龄  工资      部门" << endl;
            showmessage();
            break;
        case 9:
            clearrightbackup();
            clearleftbackup();
            Leftbackup();
            countnumber = 0;
            Recoverbasic();
            break;
        case 10:
            if (availableleftbackupnumber == 0) {
                cout << "无法撤回" << endl;
            }
            else {
                Rightbackup();
                Recoverleft();
            }
            break;
        case 11:
            if (availablerightcountnumber == 0) {
                cout << "无法撤回" << endl;
            }
            else {
                Leftbackup();
                Recoverright();
            }
            break;
        case 12:
            showdepartmentmessage();
            break;
        case 13:
            clearrightbackup();
            clearleftbackup();
            Leftbackup();
            countnumber = 0;
            changedata();
            break;
        default:
            cout << "输入错误,请重新输入" << endl;
        }
        system("pause");
        system("cls");
    }
    infile.close();
    outfile.close();
    return 0;
}

该工资管理系统修改员工职位并未修改工资,并且其他地方也有许多错误,大一课设,仅供参考。

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值