栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

工资管理系统-C++

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

工资管理系统-C++

目录

一、系统内容

1、录入职工信息2、显示职工信息3、职工工资记录4、显示工资信息5、清空当月工资0、退出 二、代码实现

头文件预处理各项类(基类,子类)函数声明主函数入口函数实现1、添加职工信息2、显示职工信息3、职工工资记录4、显示职工工资5、清空职工工资0、退出 三、全部代码

一、系统内容 1、录入职工信息 2、显示职工信息 3、职工工资记录 4、显示工资信息 5、清空当月工资 0、退出 二、代码实现 头文件
#include
#include
#include
#include
#include

using namespace std;
预处理
// 人员信息.txt
#define SECRETARIAL_FILE "secretarial.txt"
#define TECHNICALMANAGER_FILE "technicalManager.txt"
#define TECHNICIAN_FILE "technician.txt"
#define SALESMAN_FILE "salesman.txt"
#define SALESMANAGER_FILE "salesManager.txt"

// 人员工资.txt
#define WAGE_SECRETARIAL_FILE "wage_secretarial.txt"
#define WAGE_TECHNICALMANAGER_FILE "wage_technicalManager.txt"
#define WAGE_TECHNICIAN_FILE "wage_technician.txt"
#define WAGE_SALESMAN_FILE "wage_salesman.txt"
#define WAGE_SALESMANAGER_FILE "wage_salesManager.txt"
各项类(基类,子类)
// 父类
class base {
public:

    // 属性

    // 职工号
    int mNumber;

    // 姓名
    string mName;

    // 月工资
    float mMonthlySalary;

    // 年龄
    int mAge;

    // 性别--男1女2
    int mSex;
};

// 子类1,文秘
class secretarial : public base {
public:
    secretarial() {};

    secretarial(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }


};

// 子类2,技术经理
class technicalManager : public base {
public:
    technicalManager() {};

    technicalManager(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 子类3,技术员
class technician : public base {
public:
    technician() {};

    technician(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 子类4,销售员
class salesman : public base {
public:
    salesman() {};

    salesman(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 子类5,销售经理
class salesManager : public base {
public:
    salesManager() {};

    salesManager(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

函数声明
// 添加职工函数
void addPerson();

// 显示职工信息函数
void showPerson();

// 记录职工工资函数
void recordsWages();

// 显示工资函数
void showWage();

// 清空当月工资
void clearWage();

// 退出函数
void exitSystem();
主函数入口
int main() {

    // 初始化用户选择
    int select = 0;

    // 开始大循环
    while (true) {
        cout << "tt-------------------工资管理系统------------------" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 1  录入职工信息               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 2  显示职工信息               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 3  职工工资记录               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 4  显示工资信息               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 5  清空当月工资               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 0  退       出               |" << endl;
        cout << "tt-------------------------------------------------" << endl;

        // 录入信息
        cout << "请输入您的选择:" << endl;
        cin >> select;

        // 根据选项不同进入对应的接口
        switch (select) {
            case 1:
                addPerson();
                break;
            case 2:
                showPerson();
                break;
            case 3:
                recordsWages();
                break;
            case 4:
                showWage();
                break;
            case 5:
                clearWage();
                break;
            case 0:
                exitSystem();
                break;


        }

    }

    return 0;
}
函数实现 1、添加职工信息
 // 初始化用户选择
    int personNumber = 0;

    // 初始化容器
    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理


    cout << "请输入要添加的人数:" << endl;
    cin >> personNumber;

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;

//    // 月工资
//    float monthlySalary;

    // 年龄
    int age;

    // 性别--男1女2
    int sex;

    // 初始化循坏
    int i = 1;

    while (i <= personNumber) {
        // 初始化用户选择
        int choice = 0;
        cout << "===============================================" << endl;
        cout << "请输入职工所在岗位:" << endl;
        cout << "1、文秘" << endl;
        cout << "2、技术经理" << endl;
        cout << "3、技术员" << endl;
        cout << "4、销售员" << endl;
        cout << "5、销售经理" << endl;

        cin >> choice;

        if (choice == 1) {                //文秘

            cout << "请输入文秘姓名:" << endl;
            cin >> name;

            cout << "请输入文秘的职工编号(100x):" << endl;
            cin >> number;


            cout << "请输入文秘的年龄:" << endl;
            cin >> age;

            cout << "请输入文秘的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            secretarial se(number, name, age, sex);

            // 装到容器之中
            vse.push_back(se);
        } else if (choice == 2) {           //技术经理
            cout << "请输入技术经理姓名:" << endl;
            cin >> name;

            cout << "请输入技术经理的职工编号(200x):" << endl;
            cin >> number;

            cout << "请输入技术经理的年龄:" << endl;
            cin >> age;

            cout << "请输入技术经理的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            technicalManager tm(number, name, age, sex);

            // 装到容器之中
            vtm.push_back(tm);

        } else if (choice == 3) {           //技术员
            cout << "请输入技术员姓名:" << endl;
            cin >> name;

            cout << "请输入技术员的职工编号(300x):" << endl;
            cin >> number;


            cout << "请输入技术员的年龄:" << endl;
            cin >> age;

            cout << "请输入技术员的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            technician tc(number, name, age, sex);

            // 装到容器之中
            vt.push_back(tc);

        } else if (choice == 4) {           //销售员
            cout << "请输入销售员姓名:" << endl;
            cin >> name;

            cout << "请输入销售员的职工编号(400x):" << endl;
            cin >> number;


            cout << "请输入销售员的年龄:" << endl;
            cin >> age;

            cout << "请输入销售员的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            salesman sa(number, name, age, sex);

            // 装到容器之中
            vsa.push_back(sa);

        } else if (choice == 5) {           //销售经理
            cout << "请输入销售经理姓名:" << endl;
            cin >> name;

            cout << "请输入销售经理的职工编号(500x):" << endl;
            cin >> number;


            cout << "请输入销售经理的年龄:" << endl;
            cin >> age;

            cout << "请输入销售经理的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            salesManager sm(number, name, age, sex);

            // 装到容器之中
            vsm.push_back(sm);

        }

        // 循环+1
        i++;

    }

    // 存到人员信息文件之中
    ofstream ofs;
    ofs.open(SECRETARIAL_FILE, ios::app);  // 追加
    for (vector::iterator it1 = vse.begin(); it1 != vse.end(); it1++) {
        ofs << it1->mNumber << "    "
            << it1->mName << "    "
            << it1->mAge << "    "
            << it1->mSex << endl;
    }
    ofs.close();

    ofs.open(TECHNICALMANAGER_FILE, ios::app);
    for (vector::iterator it2 = vtm.begin(); it2 != vtm.end(); it2++) {
        ofs << it2->mNumber << "    "
            << it2->mName << "    "
            << it2->mAge << "    "
            << it2->mSex << endl;
    }
    ofs.close();

    ofs.open(TECHNICIAN_FILE, ios::app);
    for (vector::iterator it3 = vt.begin(); it3 != vt.end(); it3++) {
        ofs << it3->mNumber << "    "
            << it3->mName << "    "
            << it3->mAge << "    "
            << it3->mSex << endl;
    }
    ofs.close();

    ofs.open(SALESMAN_FILE, ios::app);
    for (vector::iterator it4 = vsa.begin(); it4 != vsa.end(); it4++) {
        ofs << it4->mNumber << "    "
            << it4->mName << "    "
            << it4->mAge << "    "
            << it4->mSex << endl;
    }
    ofs.close();

    ofs.open(SALESMANAGER_FILE, ios::app);
    for (vector::iterator it5 = vsm.begin(); it5 != vsm.end(); it5++) {
        ofs << it5->mNumber << "    "
            << it5->mName << "    "
            << it5->mAge << "    "
            << it5->mSex << endl;
    }
    ofs.close();

    // 人员信息存入完成
    cout << "人员信息存入完成!" << endl;
    return;


}
2、显示职工信息
// 打开文件
    // 读文件

    // 初始化容器
    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;

//    // 月工资
//    float monthlySalary;

    // 年龄
    int age;

    // 性别--男1女2
    int sex;

    ifstream ifs;
    ifs.open(SECRETARIAL_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "文秘信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
            ifs.close();
        }
    } else {
        cout << "文秘文件打开失败" << endl;
    }

    ifs.open(TECHNICALMANAGER_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "技术经理信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();

    } else {
        cout << "技术经理文件打开失败" << endl;
    }


    ifs.open(TECHNICIAN_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "技术员信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();

    } else {
        cout << "技术员文件打开失败" << endl;
    }


    ifs.open(SALESMAN_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "销售员信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();
    } else {
        cout << "销售员文件打开失败" << endl;
    }


    ifs.open(SALESMANAGER_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "销售经理信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();
    } else {
        cout << "销售经理文件打开失败" << endl;
    }



    // 文件展示完毕
    system("pause");
3、职工工资记录
void recordsWages() {
    // 打开文件
    // 读文件




    // 初始化容器
    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;

//    // 月工资
//    float monthlySalary;

    // 年龄
    int age;

    // 性别--男1女2
    int sex;

    ifstream ifs;
    ifs.open(SECRETARIAL_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            secretarial se(number, name, age, sex);
            // 装到容器之中
            vse.push_back(se);


        }
        ifs.close();
    } else {
        cout << "文秘文件打开失败" << endl;
    }

    ifs.open(TECHNICALMANAGER_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            technicalManager tm(number, name, age, sex);

            // 装到容器之中
            vtm.push_back(tm);
        }
        ifs.close();

    } else {
        cout << "技术经理文件打开失败" << endl;
    }


    ifs.open(TECHNICIAN_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            technician tc(number, name, age, sex);

            // 装到容器之中
            vt.push_back(tc);
        }
        ifs.close();

    } else {
        cout << "技术员文件打开失败" << endl;
    }


    ifs.open(SALESMAN_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            salesman sa(number, name, age, sex);

            // 装到容器之中
            vsa.push_back(sa);
        }
        ifs.close();
    } else {
        cout << "销售员文件打开失败" << endl;
    }


    ifs.open(SALESMANAGER_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            salesManager sm(number, name, age, sex);

            // 装到容器之中
            vsm.push_back(sm);
        }
        ifs.close();
    } else {
        cout << "销售经理文件打开失败" << endl;
    }

//    vector vse;        //文秘容器
//    vector vtm;   //技术经理
//    vector vt;          //技术员
//    vector vsa;           //销售员
//    vector vsm;       //销售经理

//#define WAGE_SECRETARIAL_FILE "wage_Secretarial.txt"
//#define WAGE_TECHNICALMANAGER_FILE "wage_technicalManager.txt"
//#define WAGE_TECHNICIAN_FILE "wage_technician.txt"
//#define WAGE_SALESMAN_FILE "wage_salesman.txt"
//#define WAGE_SALESMANAGER_FILE "wage_salesManager.txt"

    ofstream ofs;
    ofs.open(WAGE_SECRETARIAL_FILE, ios::app);
    for (vector::iterator it = vse.begin(); it != vse.end(); it++) {
        double bonus, wage;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "文秘的当月奖金:" << endl;
        cin >> bonus;
        wage = (bonus + 4000);


        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << bonus << "        "
            << wage << endl;

    }
    ofs.close();

    ofs.open(WAGE_TECHNICALMANAGER_FILE, ios::app);
    for (vector::iterator it = vtm.begin(); it != vtm.end(); it++) {
        double wage;
        int level;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "技术经理的业绩等级(1~10):" << endl;

        cin >> level;
        float levels = level * 1000;

        wage = levels + 5000;

        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << level << "        "
            << wage << endl;

    }
    ofs.close();

    ofs.open(WAGE_TECHNICIAN_FILE, ios::app);
    for (vector::iterator it = vt.begin(); it != vt.end(); it++) {

        double time, wage;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "技术员的工作时长(小时):" << endl;
        cin >> time;

        wage = time * 40;

        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << time << "        "
            << wage << endl;
    }
    ofs.close();


    ofs.open(WAGE_SALESMAN_FILE, ios::app);
    for (vector::iterator it = vsa.begin(); it != vsa.end(); it++) {
        double wage, sales;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "销售员的销售额:" << endl;
        cin >> sales;


        wage = sales * 0.05;
        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << sales << "        "
            << wage << endl;

    }
    ofs.close();

    ofs.open(WAGE_SALESMANAGER_FILE, ios::app);
    for (vector::iterator it = vsm.begin(); it != vsm.end(); it++) {
        long wage, salesNum;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "销售经理的总销售金额:" << endl;
        cin >> salesNum;
        wage = salesNum * 0.003;

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << salesNum << "        "
            << wage << endl;
    }
    ofs.close();

    // 记录完毕
    cout << "工资情况记录完毕" << endl;
    system("pause");

}
4、显示职工工资
void showWage() {

    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;


    ifstream ifs;
    ifs.open(WAGE_SECRETARIAL_FILE, ios::in);
    if (ifs.is_open()) {
        float bonus, wage;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "文秘工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> bonus && ifs >> wage) {
            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "奖金:" << bonus << "    "
                 << "工资:" << wage << endl;

        }
    } else {
        cout << "文秘工资文件打开失败" << endl;
    }


    ifs.close();


    ifs.open(WAGE_TECHNICALMANAGER_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "技术经理工资如下:" << endl;
        double wage;
        int level;
        while (ifs >> name && ifs >> number && ifs >> level && ifs >> wage) {
            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "技术等级:" << level << "    "
                 << "工资:" << wage << endl;
        }


    } else {
        cout << "技术经理文件打开失败" << endl;
    }
    ifs.close();


    ifs.open(WAGE_TECHNICIAN_FILE, ios::in);
    if (ifs.is_open()) {


        double time, wage;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "技术员工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> time && ifs >> wage) {

            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "工作小时:" << time << "    "
                 << "工资:" << wage << endl;


        }

    } else {
        cout << "技术员工资文件打开失败" << endl;
    }


    ifs.close();


    ifs.open(WAGE_SALESMAN_FILE, ios::in);
    if (ifs.is_open()) {

        double wage, sales;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "销售员工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> sales && ifs >> wage) {

            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "销售额:" << sales << "    "
                 << "工资:" << wage << endl;
        }


    } else {
        cout << "销售员工资文件打开失败" << endl;
    }
    ifs.close();


    ifs.open(WAGE_SALESMANAGER_FILE, ios::in);
    if (ifs.is_open()) {

        long wage, salesNum;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "销售经理工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> salesNum && ifs >> wage) {

            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "销售总额:" << salesNum << "    "
                 << "工资:" << wage << endl;

        }
    } else {
        cout << "销售经理工资文件打开失败" << endl;
    }


    ifs.close();

// 记录完毕
    cout << "工资显示完毕" <<
         endl;
    system("pause");


}
5、清空职工工资
void clearWage(){


    cout << "确认是否清空当月工资?(y/n)" << endl;

    // 初始化用户选择
    char choice;

    while (true) {
        // 录入用户选择
        cin >> choice;

        if (choice == 'y' || choice == 'Y') {
            //#define WAGE_SECRETARIAL_FILE "wage_Secretarial.txt"
            //#define WAGE_TECHNICALMANAGER_FILE "wage_technicalManager.txt"
            //#define WAGE_TECHNICIAN_FILE "wage_technician.txt"
            //#define WAGE_SALESMAN_FILE "wage_salesman.txt"
            //#define WAGE_SALESMANAGER_FILE "wage_salesManager.txt"

            //清空
            ofstream ofs1(WAGE_SECRETARIAL_FILE, ios_base::out);
            ofstream ofs2(WAGE_TECHNICALMANAGER_FILE, ios_base::out);
            ofstream ofs3(WAGE_TECHNICIAN_FILE, ios_base::out);
            ofstream ofs4(WAGE_SALESMAN_FILE, ios_base::out);
            ofstream ofs5(WAGE_SALESMANAGER_FILE, ios_base::out);

            cout<<"文件已全部清空!"< 
0、退出 
void exitSystem() {


    cout << "是否退出程序?(y/n)" << endl;

    // 初始化用户选择
    char choice;

    while (true) {
        // 录入用户选择
        cin >> choice;

        if (choice == 'y' || choice == 'Y') {
            cout << "欢迎您的使用!再见" << endl;


            exit(0);
        } else if (choice == 'n' || choice == 'N') {
            return;
        } else {
            cout << "输入有误,请重新输入!" << endl;
        }
    }

}
三、全部代码
#include
#include
#include
#include
#include

using namespace std;

// 人员信息.txt
#define SECRETARIAL_FILE "secretarial.txt"
#define TECHNICALMANAGER_FILE "technicalManager.txt"
#define TECHNICIAN_FILE "technician.txt"
#define SALESMAN_FILE "salesman.txt"
#define SALESMANAGER_FILE "salesManager.txt"

// 人员工资.txt
#define WAGE_SECRETARIAL_FILE "wage_secretarial.txt"
#define WAGE_TECHNICALMANAGER_FILE "wage_technicalManager.txt"
#define WAGE_TECHNICIAN_FILE "wage_technician.txt"
#define WAGE_SALESMAN_FILE "wage_salesman.txt"
#define WAGE_SALESMANAGER_FILE "wage_salesManager.txt"

// 父类
class base {
public:

    // 属性

    // 职工号
    int mNumber;

    // 姓名
    string mName;

    // 月工资
    float mMonthlySalary;

    // 年龄
    int mAge;

    // 性别--男1女2
    int mSex;
};

// 子类1,文秘
class secretarial : public base {
public:
    secretarial() {};

    secretarial(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }


};

// 子类2,技术经理
class technicalManager : public base {
public:
    technicalManager() {};

    technicalManager(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 子类3,技术员
class technician : public base {
public:
    technician() {};

    technician(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 子类4,销售员
class salesman : public base {
public:
    salesman() {};

    salesman(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 子类5,销售经理
class salesManager : public base {
public:
    salesManager() {};

    salesManager(int number, string name, int age, int sex) {
        this->mNumber = number;
        this->mAge = age;
        this->mName = name;
        this->mSex = sex;
    }
};

// 添加职工函数
void addPerson();

// 显示职工信息函数
void showPerson();

// 记录职工工资函数
void recordsWages();

// 显示工资函数
void showWage();

// 清空当月工资
void clearWage();

// 退出函数
void exitSystem();


int main() {

    // 初始化用户选择
    int select = 0;

    // 开始大循环
    while (true) {
        cout << "tt-------------------工资管理系统------------------" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 1  录入职工信息               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 2  显示职工信息               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 3  职工工资记录               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 4  显示工资信息               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 5  清空当月工资               |" << endl;
        cout << "tt|                                              |" << endl;
        cout << "tt|                 0  退       出               |" << endl;
        cout << "tt-------------------------------------------------" << endl;

        // 录入信息
        cout << "请输入您的选择:" << endl;
        cin >> select;

        // 根据选项不同进入对应的接口
        switch (select) {
            case 1:
                addPerson();
                break;
            case 2:
                showPerson();
                break;
            case 3:
                recordsWages();
                break;
            case 4:
                showWage();
                break;
            case 5:
                clearWage();
                break;
            case 0:
                exitSystem();
                break;


        }

    }

    return 0;
}

// 添加职工函数
void addPerson() {

    // 初始化用户选择
    int personNumber = 0;

    // 初始化容器
    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理


    cout << "请输入要添加的人数:" << endl;
    cin >> personNumber;

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;

//    // 月工资
//    float monthlySalary;

    // 年龄
    int age;

    // 性别--男1女2
    int sex;

    // 初始化循坏
    int i = 1;

    while (i <= personNumber) {
        // 初始化用户选择
        int choice = 0;
        cout << "===============================================" << endl;
        cout << "请输入职工所在岗位:" << endl;
        cout << "1、文秘" << endl;
        cout << "2、技术经理" << endl;
        cout << "3、技术员" << endl;
        cout << "4、销售员" << endl;
        cout << "5、销售经理" << endl;

        cin >> choice;

        if (choice == 1) {                //文秘

            cout << "请输入文秘姓名:" << endl;
            cin >> name;

            cout << "请输入文秘的职工编号(100x):" << endl;
            cin >> number;


            cout << "请输入文秘的年龄:" << endl;
            cin >> age;

            cout << "请输入文秘的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            secretarial se(number, name, age, sex);

            // 装到容器之中
            vse.push_back(se);
        } else if (choice == 2) {           //技术经理
            cout << "请输入技术经理姓名:" << endl;
            cin >> name;

            cout << "请输入技术经理的职工编号(200x):" << endl;
            cin >> number;

            cout << "请输入技术经理的年龄:" << endl;
            cin >> age;

            cout << "请输入技术经理的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            technicalManager tm(number, name, age, sex);

            // 装到容器之中
            vtm.push_back(tm);

        } else if (choice == 3) {           //技术员
            cout << "请输入技术员姓名:" << endl;
            cin >> name;

            cout << "请输入技术员的职工编号(300x):" << endl;
            cin >> number;


            cout << "请输入技术员的年龄:" << endl;
            cin >> age;

            cout << "请输入技术员的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            technician tc(number, name, age, sex);

            // 装到容器之中
            vt.push_back(tc);

        } else if (choice == 4) {           //销售员
            cout << "请输入销售员姓名:" << endl;
            cin >> name;

            cout << "请输入销售员的职工编号(400x):" << endl;
            cin >> number;


            cout << "请输入销售员的年龄:" << endl;
            cin >> age;

            cout << "请输入销售员的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            salesman sa(number, name, age, sex);

            // 装到容器之中
            vsa.push_back(sa);

        } else if (choice == 5) {           //销售经理
            cout << "请输入销售经理姓名:" << endl;
            cin >> name;

            cout << "请输入销售经理的职工编号(500x):" << endl;
            cin >> number;


            cout << "请输入销售经理的年龄:" << endl;
            cin >> age;

            cout << "请输入销售经理的性别(1男,2女)" << endl;
            cin >> sex;

            // 调用有参构造函数
            salesManager sm(number, name, age, sex);

            // 装到容器之中
            vsm.push_back(sm);

        }

        // 循环+1
        i++;

    }

    // 存到人员信息文件之中
    ofstream ofs;
    ofs.open(SECRETARIAL_FILE, ios::app);  // 追加
    for (vector::iterator it1 = vse.begin(); it1 != vse.end(); it1++) {
        ofs << it1->mNumber << "    "
            << it1->mName << "    "
            << it1->mAge << "    "
            << it1->mSex << endl;
    }
    ofs.close();

    ofs.open(TECHNICALMANAGER_FILE, ios::app);
    for (vector::iterator it2 = vtm.begin(); it2 != vtm.end(); it2++) {
        ofs << it2->mNumber << "    "
            << it2->mName << "    "
            << it2->mAge << "    "
            << it2->mSex << endl;
    }
    ofs.close();

    ofs.open(TECHNICIAN_FILE, ios::app);
    for (vector::iterator it3 = vt.begin(); it3 != vt.end(); it3++) {
        ofs << it3->mNumber << "    "
            << it3->mName << "    "
            << it3->mAge << "    "
            << it3->mSex << endl;
    }
    ofs.close();

    ofs.open(SALESMAN_FILE, ios::app);
    for (vector::iterator it4 = vsa.begin(); it4 != vsa.end(); it4++) {
        ofs << it4->mNumber << "    "
            << it4->mName << "    "
            << it4->mAge << "    "
            << it4->mSex << endl;
    }
    ofs.close();

    ofs.open(SALESMANAGER_FILE, ios::app);
    for (vector::iterator it5 = vsm.begin(); it5 != vsm.end(); it5++) {
        ofs << it5->mNumber << "    "
            << it5->mName << "    "
            << it5->mAge << "    "
            << it5->mSex << endl;
    }
    ofs.close();

    // 人员信息存入完成
    cout << "人员信息存入完成!" << endl;
    return;


}

// 显示职工信息函数
void showPerson() {
    // 打开文件
    // 读文件

    // 初始化容器
    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;

//    // 月工资
//    float monthlySalary;

    // 年龄
    int age;

    // 性别--男1女2
    int sex;

    ifstream ifs;
    ifs.open(SECRETARIAL_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "文秘信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
            ifs.close();
        }
    } else {
        cout << "文秘文件打开失败" << endl;
    }

    ifs.open(TECHNICALMANAGER_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "技术经理信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();

    } else {
        cout << "技术经理文件打开失败" << endl;
    }


    ifs.open(TECHNICIAN_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "技术员信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();

    } else {
        cout << "技术员文件打开失败" << endl;
    }


    ifs.open(SALESMAN_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "销售员信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();
    } else {
        cout << "销售员文件打开失败" << endl;
    }


    ifs.open(SALESMANAGER_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "-----------------------------------------------" << endl;
        cout << "销售经理信息如下:" << endl;
        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 三目运算符判断男女
            string sexName;
            sex == 1 ? sexName = "男" : sexName = "女";
            cout << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "年龄:" << age << "    "
                 << "性别:" << sexName << endl;
        }
        ifs.close();
    } else {
        cout << "销售经理文件打开失败" << endl;
    }



    // 文件展示完毕
    system("pause");

}

// 记录职工工资函数
void recordsWages() {
    // 打开文件
    // 读文件




    // 初始化容器
    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;

//    // 月工资
//    float monthlySalary;

    // 年龄
    int age;

    // 性别--男1女2
    int sex;

    ifstream ifs;
    ifs.open(SECRETARIAL_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            secretarial se(number, name, age, sex);
            // 装到容器之中
            vse.push_back(se);


        }
        ifs.close();
    } else {
        cout << "文秘文件打开失败" << endl;
    }

    ifs.open(TECHNICALMANAGER_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            technicalManager tm(number, name, age, sex);

            // 装到容器之中
            vtm.push_back(tm);
        }
        ifs.close();

    } else {
        cout << "技术经理文件打开失败" << endl;
    }


    ifs.open(TECHNICIAN_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            technician tc(number, name, age, sex);

            // 装到容器之中
            vt.push_back(tc);
        }
        ifs.close();

    } else {
        cout << "技术员文件打开失败" << endl;
    }


    ifs.open(SALESMAN_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            salesman sa(number, name, age, sex);

            // 装到容器之中
            vsa.push_back(sa);
        }
        ifs.close();
    } else {
        cout << "销售员文件打开失败" << endl;
    }


    ifs.open(SALESMANAGER_FILE, ios::in);
    if (ifs.is_open()) {

        while (ifs >> number && ifs >> name && ifs >> age && ifs >> sex) {
            // 类
            salesManager sm(number, name, age, sex);

            // 装到容器之中
            vsm.push_back(sm);
        }
        ifs.close();
    } else {
        cout << "销售经理文件打开失败" << endl;
    }

//    vector vse;        //文秘容器
//    vector vtm;   //技术经理
//    vector vt;          //技术员
//    vector vsa;           //销售员
//    vector vsm;       //销售经理

//#define WAGE_SECRETARIAL_FILE "wage_Secretarial.txt"
//#define WAGE_TECHNICALMANAGER_FILE "wage_technicalManager.txt"
//#define WAGE_TECHNICIAN_FILE "wage_technician.txt"
//#define WAGE_SALESMAN_FILE "wage_salesman.txt"
//#define WAGE_SALESMANAGER_FILE "wage_salesManager.txt"

    ofstream ofs;
    ofs.open(WAGE_SECRETARIAL_FILE, ios::app);
    for (vector::iterator it = vse.begin(); it != vse.end(); it++) {
        double bonus, wage;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "文秘的当月奖金:" << endl;
        cin >> bonus;
        wage = (bonus + 4000);


        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << bonus << "        "
            << wage << endl;

    }
    ofs.close();

    ofs.open(WAGE_TECHNICALMANAGER_FILE, ios::app);
    for (vector::iterator it = vtm.begin(); it != vtm.end(); it++) {
        double wage;
        int level;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "技术经理的业绩等级(1~10):" << endl;

        cin >> level;
        float levels = level * 1000;

        wage = levels + 5000;

        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << level << "        "
            << wage << endl;

    }
    ofs.close();

    ofs.open(WAGE_TECHNICIAN_FILE, ios::app);
    for (vector::iterator it = vt.begin(); it != vt.end(); it++) {

        double time, wage;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "技术员的工作时长(小时):" << endl;
        cin >> time;

        wage = time * 40;

        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << time << "        "
            << wage << endl;
    }
    ofs.close();


    ofs.open(WAGE_SALESMAN_FILE, ios::app);
    for (vector::iterator it = vsa.begin(); it != vsa.end(); it++) {
        double wage, sales;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "销售员的销售额:" << endl;
        cin >> sales;


        wage = sales * 0.05;
        // 装到文件之中

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << sales << "        "
            << wage << endl;

    }
    ofs.close();

    ofs.open(WAGE_SALESMANAGER_FILE, ios::app);
    for (vector::iterator it = vsm.begin(); it != vsm.end(); it++) {
        long wage, salesNum;
        cout << "请输入编号为" << it->mNumber << ",姓名为" << it->mName << "销售经理的总销售金额:" << endl;
        cin >> salesNum;
        wage = salesNum * 0.003;

        ofs << it->mName << "        "
            << it->mNumber << "        "
            << salesNum << "        "
            << wage << endl;
    }
    ofs.close();

    // 记录完毕
    cout << "工资情况记录完毕" << endl;
    system("pause");

}

// 显示工资函数
void showWage() {

    vector vse;        //文秘容器
    vector vtm;   //技术经理
    vector vt;          //技术员
    vector vsa;           //销售员
    vector vsm;       //销售经理

    // 声明全部变量
    // 职工号
    int number;

    // 姓名
    string name;


    ifstream ifs;
    ifs.open(WAGE_SECRETARIAL_FILE, ios::in);
    if (ifs.is_open()) {
        float bonus, wage;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "文秘工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> bonus && ifs >> wage) {
            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "奖金:" << bonus << "    "
                 << "工资:" << wage << endl;

        }
    } else {
        cout << "文秘工资文件打开失败" << endl;
    }


    ifs.close();


    ifs.open(WAGE_TECHNICALMANAGER_FILE, ios::in);
    if (ifs.is_open()) {
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "技术经理工资如下:" << endl;
        double wage;
        int level;
        while (ifs >> name && ifs >> number && ifs >> level && ifs >> wage) {
            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "技术等级:" << level << "    "
                 << "工资:" << wage << endl;
        }


    } else {
        cout << "技术经理文件打开失败" << endl;
    }
    ifs.close();


    ifs.open(WAGE_TECHNICIAN_FILE, ios::in);
    if (ifs.is_open()) {


        double time, wage;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "技术员工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> time && ifs >> wage) {

            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "工作小时:" << time << "    "
                 << "工资:" << wage << endl;


        }

    } else {
        cout << "技术员工资文件打开失败" << endl;
    }


    ifs.close();


    ifs.open(WAGE_SALESMAN_FILE, ios::in);
    if (ifs.is_open()) {

        double wage, sales;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "销售员工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> sales && ifs >> wage) {

            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "销售额:" << sales << "    "
                 << "工资:" << wage << endl;
        }


    } else {
        cout << "销售员工资文件打开失败" << endl;
    }
    ifs.close();


    ifs.open(WAGE_SALESMANAGER_FILE, ios::in);
    if (ifs.is_open()) {

        long wage, salesNum;
        cout << "---------------------------------------------------------------------------" << endl;
        cout << "销售经理工资如下:" << endl;
        while (ifs >> name && ifs >> number && ifs >> salesNum && ifs >> wage) {

            cout << "t" << "编号:" << number << "    "
                 << "姓名:" << name << "    "
                 << "销售总额:" << salesNum << "    "
                 << "工资:" << wage << endl;

        }
    } else {
        cout << "销售经理工资文件打开失败" << endl;
    }


    ifs.close();

// 记录完毕
    cout << "工资显示完毕" <<
         endl;
    system("pause");


}




// 清空当月工资
void clearWage(){


    cout << "确认是否清空当月工资?(y/n)" << endl;

    // 初始化用户选择
    char choice;

    while (true) {
        // 录入用户选择
        cin >> choice;

        if (choice == 'y' || choice == 'Y') {
            //#define WAGE_SECRETARIAL_FILE "wage_Secretarial.txt"
            //#define WAGE_TECHNICALMANAGER_FILE "wage_technicalManager.txt"
            //#define WAGE_TECHNICIAN_FILE "wage_technician.txt"
            //#define WAGE_SALESMAN_FILE "wage_salesman.txt"
            //#define WAGE_SALESMANAGER_FILE "wage_salesManager.txt"

            //清空
            ofstream ofs1(WAGE_SECRETARIAL_FILE, ios_base::out);
            ofstream ofs2(WAGE_TECHNICALMANAGER_FILE, ios_base::out);
            ofstream ofs3(WAGE_TECHNICIAN_FILE, ios_base::out);
            ofstream ofs4(WAGE_SALESMAN_FILE, ios_base::out);
            ofstream ofs5(WAGE_SALESMANAGER_FILE, ios_base::out);

            cout<<"文件已全部清空!"<> choice;

        if (choice == 'y' || choice == 'Y') {
            cout << "欢迎您的使用!再见" << endl;


            exit(0);
        } else if (choice == 'n' || choice == 'N') {
            return;
        } else {
            cout << "输入有误,请重新输入!" << endl;
        }
    }

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/779198.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号