目录

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

一、系统内容

1、录入职工信息

2、显示职工信息

3、职工工资记录

4、显示工资信息

5、清空当月工资

0、退出

二、代码实现

头文件

#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include<vector>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女2int 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 << "\t\t-------------------工资管理系统------------------" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 1  录入职工信息               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 2  显示职工信息               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 3  职工工资记录               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 4  显示工资信息               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 5  清空当月工资               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 0  退       出               |" << endl;cout << "\t\t-------------------------------------------------" << 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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> vsm;       //销售经理cout << "请输入要添加的人数:" << endl;cin >> personNumber;// 声明全部变量// 职工号int number;// 姓名string name;//    // 月工资
//    float monthlySalary;// 年龄int age;// 性别--男1女2int 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);}// 循环+1i++;}// 存到人员信息文件之中ofstream ofs;ofs.open(SECRETARIAL_FILE, ios::app);  // 追加for (vector<secretarial>::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<technicalManager>::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<technician>::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<salesman>::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<salesManager>::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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> vsm;       //销售经理// 声明全部变量// 职工号int number;// 姓名string name;//    // 月工资
//    float monthlySalary;// 年龄int age;// 性别--男1女2int 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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> vsm;       //销售经理// 声明全部变量// 职工号int number;// 姓名string name;//    // 月工资
//    float monthlySalary;// 年龄int age;// 性别--男1女2int 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<secretarial> vse;        //文秘容器
//    vector<technicalManager> vtm;   //技术经理
//    vector<technician> vt;          //技术员
//    vector<salesman> vsa;           //销售员
//    vector<salesManager> 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<secretarial>::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<technicalManager>::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<technician>::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<salesman>::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<salesManager>::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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> 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<<"文件已全部清空!"<<endl;system("pause");return;} else if (choice == 'n' || choice == 'N') {return;} else {cout << "输入有误,请重新输入!" << endl;}}
}

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<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include<vector>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女2int 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 << "\t\t-------------------工资管理系统------------------" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 1  录入职工信息               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 2  显示职工信息               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 3  职工工资记录               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 4  显示工资信息               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 5  清空当月工资               |" << endl;cout << "\t\t|                                              |" << endl;cout << "\t\t|                 0  退       出               |" << endl;cout << "\t\t-------------------------------------------------" << 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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> vsm;       //销售经理cout << "请输入要添加的人数:" << endl;cin >> personNumber;// 声明全部变量// 职工号int number;// 姓名string name;//    // 月工资
//    float monthlySalary;// 年龄int age;// 性别--男1女2int 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);}// 循环+1i++;}// 存到人员信息文件之中ofstream ofs;ofs.open(SECRETARIAL_FILE, ios::app);  // 追加for (vector<secretarial>::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<technicalManager>::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<technician>::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<salesman>::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<salesManager>::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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> vsm;       //销售经理// 声明全部变量// 职工号int number;// 姓名string name;//    // 月工资
//    float monthlySalary;// 年龄int age;// 性别--男1女2int 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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> vsm;       //销售经理// 声明全部变量// 职工号int number;// 姓名string name;//    // 月工资
//    float monthlySalary;// 年龄int age;// 性别--男1女2int 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<secretarial> vse;        //文秘容器
//    vector<technicalManager> vtm;   //技术经理
//    vector<technician> vt;          //技术员
//    vector<salesman> vsa;           //销售员
//    vector<salesManager> 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<secretarial>::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<technicalManager>::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<technician>::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<salesman>::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<salesManager>::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<secretarial> vse;        //文秘容器vector<technicalManager> vtm;   //技术经理vector<technician> vt;          //技术员vector<salesman> vsa;           //销售员vector<salesManager> 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<<"文件已全部清空!"<<endl;system("pause");return;} else if (choice == 'n' || choice == 'N') {return;} else {cout << "输入有误,请重新输入!" << endl;}}
}// 退出函数
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;}}}

工资管理系统-C++相关推荐

  1. 计算机会计学ufo报表,计算机会计实践部分工资管理系统.ppt

    <计算机会计实践部分工资管理系统.ppt>由会员分享,可在线阅读,更多相关<计算机会计实践部分工资管理系统.ppt(22页珍藏版)>请在人人文库网上搜索. 1.计算机会计学,主 ...

  2. c语言编程员工信息排序,员工工资管理系统(c语言编程)

    <员工工资管理系统(c语言编程)>由会员分享,可在线阅读,更多相关<员工工资管理系统(c语言编程)(6页珍藏版)>请在人人文库网上搜索. 1.include #include# ...

  3. python工资管理系统课程设计_高校教师绩效工资管理系统设计开发,源码下载

    大家好,我是全微毕设团队的创始人,本团队擅长JAVA(SSM,SSH,SPRINGBOOT).PYTHON.PHP.C#.安卓等多项技术. 今天将为大家分析一个高校教师绩效工资管理系统(高校教师绩效工 ...

  4. C语言编写工资管理系统类似学生管理系统

    C语言编写工资管理系统类似学生管理系统 开始界面和菜单界面B void start() //开始界面 {system("cls");//清屏 system("color ...

  5. java高校职工工资管理论文_毕业设计论文java大学工资管理系统

    毕业设计论文java大学工资管理系统 本 科 生 毕 业 论 文(设 计)题 目:大学工资管理系统 学 号: _________姓 名: ____ ___年 级: ___________学 院: __ ...

  6. 企业员工工资管理系统

    企业工资管理是人力资源管理的一个核心环节,在市场经济和全球一体化的大背景下,随着人力资源管理在战略层面上发挥着越来越重要的作用,传统的薪酬制度已于现代化的要求不匹配,并越来越限制着企业的发展.本系统以 ...

  7. 医院计算机管理工资,医院工资管理系统的设计与开发

    [第五篇]论文题目:  医院工资管理系统的设计与开发 摘要:随着计算机的普及和医院业务的飞速发展,信息化对医院的发展发挥着越来越重要的作用.工资管理是一项琐碎.复杂而又十分细致的工作,一般不允许发生差 ...

  8. python工资管理系统课程设计_Python3实现的简单工资管理系统示例

    本文实例讲述了Python3实现的简单工资管理系统.分享给大家供大家参考,具体如下: 工资管理系统要求: 1. 查询员工工资 2. 修改员工工资 3. 增加新员工记录 4. 退出 执行代码: #!/u ...

  9. Swing企业员工工资管理系统v1.4(java毕业设计)

    企业员工工资管理系统实现功能: 外部功能:工资管理系统具有输入.修改.查询功能. 系统具体可分为:员工信息管理,工资管理,公司部门管理以及系统维护等四个模块 1.部门管理包括部门情况的增加.修改.删除 ...

  10. Java Swing Mysql实现的员工工资管理系统项目源码附带视频指导运行教程

    java swing mysql数据库实现的员工工资管理系统, 该项目功能相对完善,有管理员和普通用户两个角色, 分别实现了一些列功能,数据库采用的是mysql, 这个代码的复杂度非常适合Java初学 ...

最新文章

  1. Windows XP鲜为人知的70招
  2. IETester-IE兼容性测试工具
  3. linux shell 字符串作变量名 间接变量引用
  4. 8.1 mnist_soft,TensorFlow构建回归模型
  5. 吴恩达深度学习笔记10-Course4-Week1【卷积神经网络】
  6. yum groupinstall “Development Tools“查看其软件列表
  7. Python算法(含源代码下载)
  8. @ConfigurationProperties 在IDEA中出现红色波浪线问题
  9. Javascript事件模型系列(一)事件及事件的三种模型
  10. 基于安卓手机的WAPI证书安装使用详解
  11. 随机效应估算与固定效应估算_面板数据分析中固定效应和随机效应的估计结果完全一致,与OLS差别不大...
  12. 《数字孪生》(Yanlz+VR元宇宙+Unity+SteamVR+云技术+5G+AI+虚拟现实+数字映射+仿真+物理模型+传感器更新+运动历史+多学科+多物理量+多尺度+多概率+立钻哥哥++==)
  13. dotnet OpenXML 读取 PPT 主序列进入退出强调动画
  14. 微信小程序利用百度api达成植物识别
  15. 使用jQuery制作图书简介
  16. ML 学海拾贝 07/03/2018
  17. MySQL备份恢复练习
  18. 7-5 梅森数 (10 分)
  19. React 官网为什么那么快?
  20. PHP面试题汇总参考

热门文章

  1. 【解决方案】三星T5移动硬盘连接mac pro提示“已断开连接”
  2. PageHelper 分页的实例
  3. 职业化“实训”网管培训班招生简章
  4. php图片一句话木马使用方法
  5. crosswalk 初步使用
  6. 和阿里P7聊过后,才知道自己是个棒槌...
  7. STM32W芯片的JTAG口用于GPIO
  8. GCC 13 新增 Ampere-1A CPU 支持
  9. 在PHP中创建Google登录页面
  10. python中的StratifiedKFold