C++实现公司人事管理系统

这篇文章主要为大家详细介绍了C++实现公司人事管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

C++实现公司人事管理系统

本文实例为大家分享了C++实现公司人事管理系统的具体代码,供大家参考,具体内容如下

一.问题描述

一个小公司包含四类人员:经理,技术人员,销售人员和销售经理,各类人员的工资计算方法如下:经理:固定月薪(8000);技术人员:月薪按技术等级(1~8)(1600+等级*300);销售人员:按提成(4%*销售额);销售经理:底薪+提成(1500+0.2%*总销售额);设计一个管理程序,实现对各类人员的信息输入,修改和显示。

二 .基本要求

(1)使用面向对象编程思想编写开发过程中需要用到的类,比如:设计Person类:编号,姓名,岗位,工资,成员函数可设一个计算月薪的纯虚函数;另外再设计四个针对四类人员的类均继承 Person;添加相应的派生类数据成员和函数,经理和销售经理可以没有新的数据成员,计算月薪即可; 技术人员添加技术等级数据成员,销售人员添加数据成员:销售额。还需设计一个Manage 类来完成各种操作。人员数组 vector,数据类型为基类指针。

(2)需要使用菜单功能显示添加人员(输入),修改信息,浏览信息,按姓名查找,月薪排序。

(3)为了设计简洁,假定经理和销售经理都只能有一个;用文本编辑器编辑一个文本文件(总数 20 人以上)包含各类人员的信息;并且在程序中能修改保存。

基本流程图

C++实现公司人事管理系统

#include<iostream>

#include<vector>

#include<string>

#include<cstdlib>

#include<windows.h>

#include<iomanip>

#include<fstream>

#include <algorithm>

#define filename "student.txt"

using namespace std; 

class Person

{

public:

    Person(string, string, int = 0);

    double virtual pay_salary() = 0;

    void  virtual show();         

    bool operator<(const Person*&) const;    

    static int num;

    int Number;  

    double Salary;

    string Name;

    string Department;

    int c;

};

bool Person::operator<(const Person*& obj) const

{

    return this->Salary > obj->Salary;

}

Person::Person(string name1, string work1, int c1)

{

    c = c1;

    Number = num++;

    Name = name1;

    Department = work1;

}

int Person::num = 1;

void  Person::show() {

    cout<<"-----------------------------------"<<endl;

    cout <<right<<setw(3)<<Number<<setw(10)<<Name<<setw(11)<<Department<<setw(8)<<Salary;

    

}

class Manager :public Person

{

public:

    Manager(string, string, int);

    double pay_salary();

    void show();

};

Manager::Manager(string name1, string post1, int c1) :Person(name1, post1, c1)

{

    pay_salary();

}

double Manager::pay_salary()

 {

    Salary = 8000;

    return Salary;

}

void Manager::show()

{

    cout<<"-----------------------------------"<<endl;

    cout <<right<<setw(3)<<Number<<setw(10)<<Name<<setw(9)<<Department<<setw(10)<<Salary; 

}

class SaleManager :public Person

 {

public:

    SaleManager(string, string, int);

    double pay_salary();

    void show();

};

SaleManager::SaleManager(string name1, string post1, int c1) :Person(name1, post1, c1)

 {

    pay_salary();

}

double SaleManager::pay_salary()

{

    Salary = 1500;

    return Salary;

}

void SaleManager::show()

{

    cout<<"-----------------------------------"<<endl;

    cout <<right<<setw(3)<<Number<<setw(10)<<Name<<setw(11)<<Department<<setw(8)<<Salary; 

}

class Salesman :public Person

 {

public:

    Salesman(string, string, int);

    int salevolume;

    double pay_salary();

    void show();

};

Salesman::Salesman(string name1, string post1, int sv) :Person(name1, post1, sv)

{

    salevolume = sv;

    pay_salary();

}

double Salesman::pay_salary()

 {

    Salary = 0.04 * salevolume;

    return Salary;

}

void Salesman::show()

{

    cout<<"-----------------------------------"<<endl;

    cout <<right<<setw(3)<<Number<<setw(10)<<Name<<setw(11)<<Department<<setw(8)<<Salary; 

}

class Technician :public Person

{

public:

    Technician(string, string, int);

    double pay_salary();

    void show();

};

Technician::Technician(string name1, string post1, int rank1) :Person(name1, post1, rank1) 

{

    pay_salary();

}

double Technician::pay_salary()

{

    Salary = 1600 + 300 * c;

    return Salary;

}

void Technician::show()

 {

     cout<<"-----------------------------------"<<endl;

    cout <<right<<setw(3)<<Number<<setw(10)<<Name<<setw(11)<<Department<<setw(8)<<Salary; 

}

class Manage

{

public:

    void Menu() { salevolume = 0; }

    int salevolume;

    vector<Person*> Ma;

    void add(Person*);

    void alter(string);

    void addtofile();

    void show();

    void show1();

    Person* find(string&);

};

Person* Manage::find(string& name1) {

    for (vector<Person*>::iterator iter = Ma.begin(); iter != Ma.end(); iter++) {

        if ((*iter)->Name == name1) {

            return *iter;

        }

    }

    return NULL;

}

void Manage::alter(string name1) {

    for (vector<Person*>::iterator iter = Ma.begin(); iter != Ma.end(); iter++) {

        if ((*iter)->Name == name1) {

            Ma.erase(iter);

            return;

        }

    }

    cout << "查无此人" << endl;

}

void Manage::add(Person* people)

{

    if (people->Department == "销售人员") {

        salevolume += ((Salesman*)people)->salevolume;

    }

    Ma.push_back(people);

}

void Manage::addtofile()

 {

    ofstream outfile(filename);

    for (vector<Person*>::iterator iter = Ma.begin(); iter != Ma.end(); iter++) {

        outfile << (*iter)->Department << " " << (*iter)->Name << " ";

        if ((*iter)->c == 0) outfile << endl;

        else outfile << (*iter)->c << endl;

    }

    outfile.close();

}

bool cmp(Person* x, Person* y) {

    return x->Salary > y->Salary;

}

void Manage::show() {

    for (vector<Person*>::iterator iter = Ma.begin(); iter != Ma.end(); iter++) {

        if ((*iter)->Department == "销售经理") {

            (*iter)->Salary = salevolume * 0.002 +1500;

            break;

        }

    }

    sort(Ma.begin(), Ma.end(), cmp);

    for (vector<Person*>::iterator iter = Ma.begin(); iter != Ma.end(); iter++) {

        (*iter)->show();

        cout << endl;

    }

}

void readfile(Manage& obj)

 {

    FILE* fp;

    fp = fopen(filename, "r");

    if (fp == NULL) {

        cout << "未找到人员名单" << endl;

        return;

    }

    while (!feof(fp)) {

        char post[20];

        char Name[20];

        int c;  

        fscanf(fp, "%s%s%d", post, Name,&c);

        if (!strcmp(post, "经理")) {

            Person* peo = new Manager(Name, post, 0);

            obj.add(peo);

        }

        else if (!strcmp(post, "技术人员")) {

            Person* peo = new Technician(Name, post, c);

            obj.add(peo);

        }

        else if (!strcmp(post, "销售人员")) {

            Person* peo = new Salesman(Name, post, c);

            obj.add(peo);

        }

        else if (!strcmp(post, "销售经理")) {

            Person* peo = new SaleManager(Name, post, 0);

            obj.add(peo);

        }

    }

    fclose(fp);

}

void Manage::show1()

{

    for (vector<Person*>::iterator iter = Ma.begin(); iter != Ma.end(); iter++) {

        (*iter)->show();

        cout << endl;

    }

}

int main(){

    int x;

    Manage T;

    readfile(T);

    while(1){

        cout<< "    ———————————————————————————————" << endl

            << "    |       公司人事管理系统        |" << endl

            << "    ———————————————————————————————" << endl

            << "    |         1.添加员工           |" << endl

            << "    |         2.修改信息           |" << endl

            << "    |         3.按姓名查找         |" << endl

            << "    |         4.显示所有信息       |" << endl

            << "    |         5.按月薪降序排序     |" << endl

            << "    |         0.保存并退出程序     |" << endl

            << "    ———————————————————————————————" << endl;        

        cout<< "请选择->";

        cin >> x;

        switch (x) {

        case 1: {

            while (1) {

                int n;

                string Name;

                cout << "请输入姓名:" ;

                cin >> Name;

                cout << "请输入人员岗位(1.经理 2.技术人员 3. 销售人员 4.销售经理):" ; 

                cin >> n;

                if (n == 1) {

                    Person* peo = new Manager(Name, "经理", 0);

                    T.add(peo);

                    cout << "添加成功" << endl << endl << endl;

                    break;

                }

                else if (n == 2) {

                    while (1) {

                        int rank = 0;

                        cout << "请输入技术等级(1~8):" ;

                        cin >> rank;

                        if (rank > 8 || rank < 1) {

                            cout << "输入错误,请在1~8之间输入:" ;

                        }

                        else {

                            Person* peo = new Technician(Name, "技术人员", rank);

                            T.add(peo);

                            break;

                        }

                    }

                    cout << "添加成功" << endl << endl << endl;

                    break;

                }

                else if (n == 3) {

                    int sales = 0;

                    cout << "请输入销售额:" << endl;

                    cin >> sales;

                    Person* peo = new Salesman(Name, "销售人员", sales);

                    T.add(peo);

                    cout << "添加成功" << endl << endl << endl;

                    break;

                }

                else if (n == 4) {

                    Person* peo = new SaleManager(Name, "销售经理", 0);

                    T.add(peo);

                    cout << "添加成功" << endl << endl << endl;

                    break;

                }

                else {

                    cout << "输入错误,请重新输入:" << endl;

                }

            }

         system("pause");}

                break;

        case 2: {

            string Name;

            int n = 0;

            cout << "请输入姓名:" ;

            cin >> Name;

            Person* peo = T.find(Name);

            if (peo == NULL) {

                cout << "        查无此人" << endl << endl << endl;

                break;

            }

            peo->show();

            if (peo->Department == "经理") {

                cout << "    经理无法修改" << endl;

            }

            else if (peo->Department == "技术人员") {

                int rank = 0;

                while (1) {

                    cout <<endl<< "请输入技术等级(1~8):" << endl;

                    cin >> rank;

                    if (rank > 8 || rank < 1) {

                        cout << "等级输入错误,请重新输入" << endl;

                    }

                    else break;

                }

                T.alter(Name);

                peo = new Technician(Name, "技术人员", rank);

                T.add(peo);

                cout << "修改成功!" << endl;

                

            }

            else if (peo->Department == "销售人员") {

                int sales = 0;

                cout <<endl<< "请输入销售额:" << endl;

                cin >> sales;

                T.alter(Name);

                peo = new Salesman(Name, "销售人员", sales);

                T.add(peo);

                cout << "    修改成功!" << endl;

                

            }

            else if (peo->Department == "销售经理") {

                cout << "   销售经理无法修改" << endl;

            }

            else {

                cout << "输入错误" << endl;

            }

        }system("pause");

                break;

        case 3: {

            string Name;

            int n = 0;

            cout << "请输入所查找人的姓名:";

            cin >> Name;

            Person* peo = T.find(Name);

            if (peo == NULL) {

                cout << "查无此人" << endl;

                system("cls");

                break;

            }

            cout<<"-----------------------------------"<<endl;

            cout <<left<<setw(8)<<"序 号"<<setw(9)<<"姓 名"<<setw(10)<<"岗 位"<<setw(10)<<"工 资"<< endl; 

            peo->show();

            cout<<endl<<"-----------------------------------"<<endl;

            cout << endl;

            system("pause");

            

        }

                break;

        case 4: { 

            cout<<"-----------------------------------"<<endl;

            cout <<left<<setw(8)<<"序 号"<<setw(9)<<"姓 名"<<setw(10)<<"岗 位"<<setw(10)<<"工 资"<< endl; 




            T.show1();

            cout<<"-----------------------------------"<<endl;

            system("pause");

            system("cls");

        }

                break;

        case 5: { 

            cout<<"-----------------------------------"<<endl;

            cout <<left<<setw(8)<<"序 号"<<setw(9)<<"姓 名"<<setw(10)<<"岗 位"<<setw(10)<<"工 资"<< endl; 

                T.show();

        }

            system("pause");

                break;

        case 0:

            T.addtofile();

            exit(0);

        default:

            cout << "输入错误请重新输入" << endl;

            break;

        }

    }

    return 0;

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

原创文章,作者:192.168.1.1,如若转载,请注明出处:https://www.224m.com/229981.html

(0)
192.168.1.1192.168.1.1
上一篇 2022年11月7日 10:19
下一篇 2022年11月7日 12:04

相关推荐

  • 天猫商城旗舰店官网 天猫是京东吗?

    天猫商城旗舰店官网 淘宝和官网有什么区别?天猫是京东吗? 1.淘宝网的C2C任何人都可以开店,淘宝商城B2C店铺(即商是商场)是以公司的形式注册的,也就是说没有注册公司是不可能开店的。一个是摊位,

    投稿 2022年7月19日
  • 国内登机箱尺寸要求 2020飞机行李箱尺寸规定?

    国内登机箱尺寸要求登机大小?2020飞机行李箱尺寸规定?1.根据2020年登机箱尺寸的新规定,一般来说,16寸、17寸、18寸8英寸和20英寸的登机箱可以直接携带,必须托运22英寸、24英寸和28英寸

    投稿 2022年7月23日
  • 电脑一启动就蓝屏 电脑启动后蓝屏怎么解决?

    电脑一启动就蓝屏电脑一开就蓝屏?电脑启动后蓝屏怎么解决?显示器,CPU工作中热量很大,所以保持良好的通风非常重要。如果显示器过热,会导致颜色和图像失真,甚至缩短显示器的使用寿命。工作时间过长也会导致电

    投稿 2022年7月16日
  • 高级程序员月薪是多少 如何辨别一个程序员水平的高低?

    高级程序员月薪是多少 C 程序员现在能拿多少工资?如何辨别一个程序员水平的高低? 程序员的工资与语言、开发经验和技术水平有关。总的来说,C 程序员的工资普遍高于同级别其他语言的程序员。一、在一线

    投稿 2022年7月11日
  • mac office365 苹果笔记本能用office吗?

    mac 苹果的microsoft office365和windows能通用吗?office365 苹果笔记本能用office吗? 不能。微软软件或windows平台上的软件,都不支持mac os下

    投稿 2022年7月15日
  • 海尔空调故障代码e7 海尔空调故障最简单的处理方法?

    海尔空调故障代码e7 显示海尔空调故障e7是什么意思?海尔空调故障最简单的处理方法? 海尔空调显示e7故障代码表过流或相序保护外反馈故障。如果出现这个问题,如果不是新空调,一般是过流保护。

    投稿 2022年7月22日
  • 单独给文件夹设置密码 怎样给文档文件设置密码?

    单独给文件夹设置密码如何设置密码保存我的电脑文件?怎样给文档文件设置密码?加密文件夹:1.双击桌面计算机图标,显示您计算机中的所有磁盘,并准备加密锁定文件夹。2.鼠标右键文件夹,弹出快捷菜单,选择启用

    投稿 2022年7月25日
  • 笔记本后盖怎么拆 笔记本电脑的键盘怎么拆卸?

    笔记本后盖怎么拆 笔记本后盖怎么拆?笔记本电脑的键盘怎么拆卸? 1.把笔记本翻过来,先把电池的固定扣推到底。笔记本电池有两个扣:固定扣(推过去不会反弹)和活动扣(不推就会反弹),一边一边。如下图所

    投稿 2022年7月22日
  • wow什么插件最好用 魔兽世界插件推荐?

    wow什么插件最好用 魔兽世界哪个插件好?魔兽世界插件推荐? 1.下载任务,查询绿色版本或安装版本(安装吧~以后升级也方便)2.去官方主页下载魔兽精灵就是大家都说的wowshell3.进入人物界面

    投稿 2022年7月7日
  • 华为手机系列 在华为商城买手机靠谱吗?

    华为手机系列 华为手机有几个系列,特点是什么?在华为商城买手机靠谱吗? 华为的产品系统仍然非常丰富。作为国内手机的兄弟,华为已经为不同的用户群体部署了相应的产品。华为今天的成功与其产品系列的定位和

    投稿 2022年7月12日