Staff management system design ideas

Time:2022-7-7

Requirements overview:

Since the design of this system, we must consider the corresponding needs. The employee management system, as the name suggests, is designed to manage employees. The most basic “add, delete, modify and check” in the system is naturally indispensable.

First, design the header file

First, we define multiple header files (the main purpose of establishing header files is to provide the declaration of global variables, global functions or the definition of common data types, so as to realize separate compilation and code reuse. At the same time, it is also conducive to strengthening security.)
Staff management system design ideas

They are as follows (each of the following header files corresponds to the person of each identity):

boss.h

#pragma once
#include<iostream>
using namespace std;

class boss :public worker
{
public:
    boss(int id, string name, int post);
    virtual void showinfo();
    virtual string getpost();
};

employee.h

#pragma once
class employee :public worker
{
public:
    employee(int id, string name, int post);
    virtual void showinfo();
    virtual string getpost();
};

manager.h

#pragma once
class Manager :public Worker
{
public:

    Manager(int id, string name, int post);
    virtual void ShowInfo();
    virtual string getPost();

};

worker manager.h

#pragma once
#include<iostream>
using namespace std;
#include"boss.h"
#include"manager.h"
#include"worker.h"
#include"employee.h"
#include<fstream>
#define TXT "empfine.txt"
class worker_manager
{
public:
    worker_manager();
    void showmenu();
    int m_EmpNum;
    worker** m_EmpArray;
    void Add_Emp();
    void save();
    bool_m_File;
    int get_EmpNum();
    void In_emp();
    void Show_emp();
    int    Ison_Emp(int id);
    void Del_Emp();
    void Mod_Emp();
    void Find_Emp();
    void Sort_Emp();
    void Clean_File();

    ~worker_manager();

};

worker.h

#pragma once
class worker
{
public:
    virtual void showinfo() = 0;
    virtual string getpost() = 0;
    int m_id;
    string m_name;
    int m_post;
};

The source files are as follows:

boss.cpp

#include "boss.h"

Boss::Boss(int id, string name, int post)
{
    this->m_Id = id;
    this->m_Name = name;
    this->m_Post = post;

}
void Boss::ShowInFo()
{
    Cout < < "employee No.: < < this->m_ Id
        < < "\t employee name:" < < this->m_ Name
        < < "\t employee Department:" < this->getpost()
        < < "\ tposition responsibilities: manage all affairs of the company" < < endl;
}
string Boss::getPost()
{
    Return string ("boss");
}

employee.cpp

include "employee.h"
employee::employee(int id, string name, int post)
{
    this->m_Id = id;
    this->m_Name = name;
    this->m_Post = post;

}
void employee::showinfo(
    {
     Cout < < "employee No.: < < this->m_ Id
     < < "\t employee name:" < < this->m_ Name
     < < "\t employee Department:" < this->getpost()
    < < "\ tposition responsibilities: complete the tasks assigned by the manager" < < endl;
    }
    string employee::getpost()
    {
        Return string ("employee");
    }

manager.cpp

#include "manager.h"
Manager::Manager(int id, string name, int post)
{
    this->m_Id = id;
    this->m_Name = name;
    this->m_Post = post;
}
void Manager::ShowInfo()
{
    Cout < < "employee No.: < < this->m_ Id
        < < "\t employee name:" < < this->m_ Name
        < < "\t employee Department:" < this->getpost()
        < < "\ tposition responsibilities: complete the tasks assigned by the boss and distribute the tasks to employees" < < endl;

}
string Manager::getPost()
{
    Return string ("manager");
}

workmanager.h

#include "worker manager.h"
worker_manager::Worker_Manager()
{
ifstream ifs;
ifs.open(TXT, Ios::in);
if (!ifs.is_open())
{
this->m_EmpNum = 0;
this->m_EmpArray = NULL;
this->m_File = true;
ifs.close();
return;
}
char ch;
ifs >> ch;
if (ifs.eof())
{
this->m_EmpNum = 0;
this->m_EmpNum = NULL;
this->m_File = true;
ifs.close();
return;
}
int num = this->get_EmpNum();
this->m_EmpNum = num;
this->m_EmpArray = new ew Worker * [this->m_EmpNum];
this->In_Emp();
}
void Worker_Manager::ShowMenu()
{
cout << "****************************************" << endl;
Cout < < "********* welcome to the employee management system! ********" < < endl;
Cout < < "********** 0. exit the management program **********" < < endl;
Cout < < "*********** 1. add employee information **********" < < endl;
Cout < < "********** 2. display employee information **********" < < endl;
Cout < < "********** 3. delete employee information **********" < < endl;
Cout < < "************ 4. modify employee information ************" < < endl;
Cout < < "************* 5. find employee information *************" < < endl;
Cout < < "************ 6. employee number sorting **********" < < endl;
Cout < < "*********** 7. empty all documents **********" < < endl;
}
void Worker_Manager::Add_Emp()
{
Cout < < "please enter the number of employees to add:" < < endl;
//Save user input quantity
int addNum = 0;
cin >> addNum;
if (addNum > 0)
{
//Calculate the size of the added new space
int newSize = this->m_ EmpNum + addNum;// Number of people in new space = original number of people + newly increased number of people
//Open up new space
Worker** newSpace = new Worker * [newSize];
//Copy the original data to the new space
if (this->m_EmpArray != NULL)
{
for (int i = 0; i < this->m_EmpNum; i++)
{
newSpace[i] = this->m_EmpArray[i];
}
}
//Add new data
for (int i = 0; i < addNum; i++)
{
int id;
string name;
int post;
Cout < < "please enter the number of new employees" < < I + 1 < <: < < endl;
cin >> id;
Cout < < "please enter the first" < < I + 1 < < "name of new employee:" < < endl;
cin >> name;
Cout < < "please select an employee position:" < < endl;
Cout < < 1. Ordinary employees < < endl;
Cout < < 2. Manager < < endl;
Cout < < 3. Boss < < endl;
cin >> post;
Worker* worker = NULL;
switch (post)
{
case 1:
worker = new Employee(id, name, post);
break;
case 2:
worker = new Manager(id, name, post);
break;
case 3:
worker = new Boss(id, name, post);
break;
default:
Cout < < wrong input < < endl;
break;
}
//Save the created employee pointer to the array
newSpace[this->m_EmpNum + i] = worker;
}
//Release the original pointer
delete[] this->m_EmpArray;
//Change the direction of the new space
this->m_EmpArray = newSpace;
//Update the number of employees
this->m_EmpNum = newSize;
Cout < < successfully added < < addnum < < new employees < < endl;
this->m_File = false;
//Save data to file
this->save();
}
else
{
Cout < < "input error" < < endl;
}
system("pause");
system("cls");
}
void Worker_Manager::save()
{
ofstream ofs;
ofs.open(TXT, ios::out);
for (int i = 0; i < this->m_EmpNum; i++)
{
ofs << this->m_EmpArray[i]->m_Id << " "
<< this->m_EmpArray[i]->m_Name << " "
<< this->m_EmpArray[i]->m_Post << " "
<< endl;
}
ofs.close();
}
int Worker_Manager::get_EmpNum()
{
ifstream ifs;
ifs.open(TXT, ios::in);
int id;
string name;
int post;
int num = 0;
while (ifs >> id && ifs >> name && ifs >> post)
{
num++;
}
return num;
}
void Worker_Manager::In_Emp()
{
ifstream ifs;
ifs.open(TXT, ios::in);
int id;
string name;
int post;
int index = 0;
while (ifs >> id && ifs >> name && ifs >> post)
{
Worker* worker = NULL;
if (post == 1)
{
worker = new Employee(id, name, post);// Ordinary staff
}
else if (post == 2)
{
worker = new Manager(id, name, post);// manager
}
else
{
worker = new Boss(id, name, post);// boss
}
this->m_EmpArray[index] = worker;
index++;
}
ifs.close();
}
void Worker_Manager::Show_Emp()
{
if (this->m_File)
{
Cout < < "the file does not exist or is empty" < < endl;
}
else
{
for (int i = 0; i < this->m_EmpNum; i++)
{
//Using polymorphic calls
this->m_EmpArray[i]->ShowInfo();
}
}
//Clear screen
system("pause");
system("cls");
}
int Worker_Manager::Ison_Emp(int id)
{
int index = -1;
for (int i = 0; i < this->m_EmpNum; i++)
{
if (this->m_EmpArray[i]->m_Id == id)
{
index = i;
break;
}
}
return index;
}
void Worker_Manager::Del_Emp()
{
if (this->m_File)
{
Cout < < "the file does not exist or is empty" < < endl;
}
else
{
Cout < < "please enter the number of the employee you want to delete:" < < endl;
int id;
cin >> id;
int ret = this->Ison_Emp(id);
//Employees exist and are in the index position
if (ret != -1)
{
for (int i = ret; i < this->m_EmpNum - 1; i++)
{
//Data forward
this->m_EmpArray[i] = this->m_EmpArray[i + 1];
}
//Number of updates
this->m_EmpNum--;
Cout < < delete successfully < < endl;
//Sync to file
this->save();
}
else
{
Cout < < delete failed < < endl;
}
}
system("pause");
system("cls");
}
void Worker_Manager::Mod_Emp()
{
if (this->m_File)
{
Cout < < "the file does not exist or is empty" < < endl;
}
else
{
int id = 0;
Cout < < "enter the employee number you want to modify:" < < endl;
cin >> id;
int ret = this->Ison_Emp(id);
if (ret != -1)
{
delete this->m_EmpArray[ret];
int Newid = 0;
string name = "";
int post = 0;
Cout < < "found:" < < ID < < "employee number, please enter the new employee number:" < < endl;
cin >> Newid;
Cout < < "found:" < < ID < < "employee number, please enter the new employee name:" < endl;
cin >> name;
Cout < < please enter a new position < < endl;
Cout < < 1. Ordinary employees < < endl;
Cout < < 2. Manager < < endl;
Cout < < 3. Boss < < endl;
cin >> post;
Worker* worker = NULL;
switch (post)
{
case 1:
worker = new Employee(Newid, name, post);
break;
case 2:
worker = new Manager(Newid, name, post);
break;
case 3:
worker = new Boss(Newid, name, post);
break;
default:
break;
}
//Put the modified data back to the original position
this->m_EmpArray[ret] = worker;
Cout < < successfully modified < < endl;
this->save();
}
else
{
Cout < < modify failed < < endl;
}
}
system("pause");
system("cls");
}
void Worker_Manager::Find_Emp()
{
if (this->m_File)
{
Cout < < "the file does not exist or is empty" < < endl;
}
else
{
Cout < < "please choose the way to find" < < endl;
Cout < < 1. Search by number < < endl;
Cout < < 2. Search by name < < endl;
int input = 0;
cin >> input;
if (input == 1)
{
//Find by number
int id = 0;
Cout < < "please enter the number you want to find:" < < endl;
cin >> id;
int ret = this->Ison_Emp(id);
if (ret != -1)
{
Cout < < find this person's information as follows: < < endl;
this->m_EmpArray[ret]->ShowInfo();
}
else
{
Cout < < "no one found" < < endl;
}
}
else if (input == 2)
{
//Find by name
string name;
Cout < < "please enter the name of the person you want to find:" < < endl;
cin >> name;
bool flag = false;
for (int i = 0; i < this->m_EmpNum; i++)
{
if (this->m_EmpArray[i]->m_Name == name)
{
Cout < < "successfully found the employee, the employee number is:" < < this->m_ EmpArray[i]->m_ Id
< < the employee information is as follows < < endl;
this->m_EmpArray[i]->ShowInfo();
flag = true;
}
if (flag == false)
{
Cout < < "no one found" < < endl;
}
}
}
else
{
Cout < < "wrong input option" < < endl;
}
}
system("pause");
system("cls");
}
void Worker_Manager::Sort_Emp()
{
if (this->m_File)
{
Cout < < "the file does not exist or is empty" < < endl;
system("pause");
system("cls");
}
else
{
Cout < < please select sorting method < < endl;
Cout < < 1. Ascending by employee number < < endl;
Cout < < 2. Descending by employee number < < endl;
int input = 0;
cin >> input;
for (int i = 0; i < this->m_EmpNum; i++)
{
int minOrmax = i;
for (int j = i + 1; j < this->m_EmpNum; j++)
{
if (input == 1)
{
if (this->m_EmpArray[minOrmax]->m_Id > this->m_EmpArray[j]->m_Id)
{
minOrmax = j;
}
}
else
{
if (this->m_EmpArray[minOrmax]->m_Id < this->m_EmpArray[j]->m_Id)
{
minOrmax = j;
}
}
}
if (minOrmax != i)
{
Worker* temp = this->m_EmpArray[i];
this->m_EmpArray[i] = this->m_EmpArray[minOrmax];
this->m_EmpArray[minOrmax] = temp;
}
}
Cout < < "sorting succeeded, and the sorting result is:" < < endl;
this->save();
this->Show_Emp();
}
}
void Worker_Manager::Clean_File()
{
Cout < < "are you sure to empty?"<< endl;
Cout < < 1. Confirm < < endl;
Cout < < 2. Cancel < < endl;
int input = 0;
Cout < < "please enter:" < < endl;
cin >> input;
if (input == 1)
{
ofstream ofs;
ofs.open(TXT, ios::trunc);
ofs.close();
if (this->m_EmpArray != NULL)
{
//Delete all employee objects in the heap
for (int i = 0; i < this->m_EmpNum; i++)
{
delete this->m_EmpArray[i];
this->m_EmpArray[i] = NULL;
}
//Delete heap pointer
delete[] this->m_EmpArray;
this->m_EmpArray = NULL;
this->m_File = true;
this->m_EmpNum = 0;
}
Cout < < empty successfully < < endl;
}
system("pause");
system("cls");
}
Worker_Manager::~Worker_Manager()
{
if (this->m_EmpArray != NULL)
{
for (int i = 0; i < this->m_EmpNum; i++)
{
if (this->m_EmpArray[i] != NULL)
{
delete this->m_EmpArray[i];
}
}
delete[]this->m_EmpArray;
this->m_EmpArray = NULL;
}

Staff management cpp

#include <iostream>
using namespace std;
#include <string>
#include"worker manager.h"
#include"worker.h"
#include"employee.h"
#include"boss.h"
#include"manager.h"
int main()
{
//Instantiate an object and abbreviate something for later operation
worker_manager wm;
int input = 0;
do
{
wm.showmenu();
Cout < < "please enter your choice:" < < endl;
cin >> input;
switch (input)
{
case 0:
Cout < < "welcome to use next time" < < endl;
break;
case 1:
wm.Add_Emp();
break;
case 2:
wm.Show_Emp();
break;
Case 3: // delete employee
wm.Del_Emp();
break;
Case 4: // modify employee
wm.Mod_Emp();
break;
Case 5: // find employees
wm.Find_Emp();
break;
Case 6: // sort employees
wm.Sort_Emp();
break;
Case 7: // empty the document
wm.Clean_File();
break;
default:
system("cls"); // Clear screen
break;
}
} while (input);
system("pause");
return 0;
}

Recommended Today

Leetcode PHP题解–D127 455. Assign Cookies

D127 455. Assign Cookies topic link 455. Assign Cookies topic analysis Given two arrays, the first array represents the capacity of each container, and the second array represents the number of each item. The items need to be stuffed into the container, but there are two conditions. Condition 1: Only one item can be stuffed […]