职工管理系统
1、管理系统需求
职工管理系统可以用来管理公司内所有员工的信息
本程序主要利用C++来实现一个基于多态的职工管理系统
公司中职工分为三类:普通员工、经理、老板,显示信息时,需要显示职工编号、职工姓名、职工岗位、以及职责
普通员工职责:完成经理交给的任务
经理职责:完成老板交给的任务,并下发任务给员工
老板职责:管理公司所有事务
管理系统中需要实现的功能如下:
- 退出管理系统:退出当前管理系统
- 增加职工信息:实现批量添加职工功能,将信息录入到文件中,职工信息为:职工编号、姓名、部门编号
- 显示职工信息:显示公司内所有职工的信息
- 删除离职职工:按照编号删除指定的职工
- 修改职工信息:按照编号修改职工个人信息
- 查找职工信息:按照职工的编号或者职工的姓名进行查找相关的人员信息
- 按照编号排序:按照职工编号,进行排序,排序规则由用户指定
- 清空所有文档:清空文件中记录的所有职工信息(清空前需要再次确认,防止误删)
2、实现
1、菜单
void WorkerManager::showMenu()
{
cout << "*************************************************" << endl;
cout << "**************** 0、退出管理系统 ****************" << endl;
cout << "**************** 1、增加职工信息 ****************" << endl;
cout << "**************** 2、显示职工信息 ****************" << endl;
cout << "**************** 3、删除离职职工 ****************" << endl;
cout << "**************** 4、修改职工信息 ****************" << endl;
cout << "**************** 5、查找职工信息 ****************" << endl;
cout << "**************** 6、按照编号排序 ****************" << endl;
cout << "**************** 7、清空所有文档 ****************" << endl;
cout << "*************************************************" << endl;
}
2、退出功能
void WorkerManager::exitSystem()
{
cout << "欢迎下次使用" << endl;
save();
system("pause");
exit(0);
}
3、增加职工
void WorkerManager::Add_Emp()
{
cout << "请输入增加职工数量:" << endl;
int addNum = 0;
cin >> addNum;
if (addNum > 0)
{
int newSize = this->m_EmpNum + addNum;
//开辟新空间
Worker ** newSpace = new Worker*[newSize];
//将原空间下内容存放到新空间下
if (this->m_EmpArray != NULL)
{
for (int i = 0; i < this->m_EmpNum; i++)
{
newSpace[i] = this->m_EmpArray[i];
}
}
//输出新数据
for (int i = 0; i < addNum; i++)
{
int id;
string name;
int dSelect;
cout << "请输入第" << i + 1 << "个职工编号" << endl;
cin >> id;
cout << "请输入第" << i + 1 << "个新职工姓名:" << endl;
cin >> name;
cout << "请选择该职工的岗位:" << endl;
cout << "1、普通职工" << endl;
cout << "2、经理" << endl;
cout << "3、老板" << endl;
cin >> dSelect;
Worker * worker = NULL;
switch (dSelect)
{
case 1://普通员工
worker = new Employee(id, name, 1);
break;
case 2://经理
worker = new Manager(id, name, 2);
break;
case 3://Boss
worker = new Manager(id, name, 3);
break;
default:break;
}
newSpace[this->m_EmpNum + i] = worker;
}
//释放原有空间
delete[] this->m_EmpArray;
//更改新空间指向
this->m_EmpArray = newSpace;
//更新新的个数
this->m_EmpNum = newSize;
//提示信息
cout << "成功添加" << addNum << "名新职工!" << endl;
}
else {
cout << "输入有误" << endl;
}
system("pause");
system("cls");
}
4、显示职工信息
void WorkerManager::Show_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或者记录为空!" << endl;
}
else
{
for (int i = 0; i < this->m_EmpNum; i++)
{
this->m_EmpArray[i]->showInfo();
}
}
system("pause");
system("cls");
}
5、删除职工信息
void WorkerManager::Del_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
}
else
{
//按照职工编号删除
cout << "请输入想要删除职工编号:" << endl;
int id = 0;
cin >> id;
int result = this->IsExist(id);
if (result == -1)
{
cout << "删除失败,未找到该职工" << endl;
}
else
{
//数据前移
for (int i = result; i < this->m_EmpNum - 1; i++)
{
this->m_EmpArray[i] = this->m_EmpArray[i + 1];
}
this->m_EmpNum--;
cout << "删除成功!" << endl;
}
}
system("pause");
system("cls");
}
6、修改职工信息
void WorkerManager::Mod_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
}
else
{
cout << "请输入修改职工的编号:" << endl;
int id;
cin >> id;
int result = this->IsExist(id);
if (result != -1)
{
int newId = 0;
string newName = "";
int dSelect = 0;
cout << "查到:" << id << "号职工,请出入新职工号:" << endl;
cin >> newId;
cout << "请输入新姓名:" << endl;
cin >> newName;
cout << "请选择该职工的岗位:" << endl;
cout << "1、普通职工" << endl;
cout << "2、经理" << endl;
cout << "3、老板" << endl;
cin >> dSelect;
this->m_EmpArray[result]->m_Id = newId;
this->m_EmpArray[result]->m_Name = newName;
this->m_EmpArray[result]->m_DeptId = dSelect;
cout << "修改成功!" << endl;
}
}
system("pause");
system("cls");
}
7、查找职工信息
void WorkerManager::Find_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
}
else
{
cout << "请输入查找的方式:" << endl;
cout << "1、按照职工编号查找" << endl;
cout << "2、按照姓名查找" << endl;
int select = 0;
cin >> select;
if (select == 1) //按照职工号查找
{
int id;
cout << "请输入查找的职工编号:" << endl;
cin >> id;
int result = this->IsExist(id);
if (result != -1)
{
cout << "查找成功!该职工信息如下:" << endl;
this->m_EmpArray[result]->showInfo();
}
else
{
cout << "查找失败,查无此人" << endl;
}
}
else if (select == 2)
{
string name;
cout << "请输入查找的姓名:" << endl;
cin >> name;
bool flag = false; //查找到的标志
for (int i = 0; i < m_EmpNum; i++)
{
if (m_EmpArray[i]->m_Name == name)
{
cout << "查找成功,职工编号为:"
<< m_EmpArray[i]->m_Id
<< "号的信息如下:" << endl;
flag = true;
this->m_EmpArray[i]->showInfo();
}
}
if (flag == false)
{
//查无此人
cout << "查找失败,查无此人" << endl;
}
}
else
{
cout << "输入选项有误" << endl;
}
}
system("pause");
system("cls");
}
8、按照编号排序
void WorkerManager::Sort_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
system("pause");
system("cls");
}
else
{
cout << "请选择排序方式:" << endl;
cout << "1、按职工号进行升序" << endl;
cout << "2、按职工号进行降序" << endl;
int select = 0;
cin >> select;
for (int i = 0; i < this->m_EmpNum; i++)
{
int minOrMax = i;
for (int j = i+1; j < this->m_EmpNum; j++)
{
if (select == 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 (i != minOrMax)
{
Worker * temp = this->m_EmpArray[i];
this->m_EmpArray[i] = this->m_EmpArray[minOrMax];
this->m_EmpArray[minOrMax] = temp;
}
}
cout << "排序成功,排序后的结果为:" << endl;
this->Show_Emp();
}
}
9、清空所有文档
void WorkerManager::Clean_File()
{
cout << "确认清空?" << endl;
cout << "1、确认" << endl;
cout << "2、返回" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
//打开模式 ios::trunc 如果存在删除文件并重新创建
ofstream ofs;
ofs.open(FILENAME, ios::trunc);
ofs.close();
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];
}
}
this->m_EmpNum = 0;
delete[] this->m_EmpArray;
}
cout << "清空成功!" << endl;
}
system("pause");
system("cls");
}
运行截图



那么整体的项目到这里就算完成了。
需要代码的或者 需要帮忙协助开发的 请加QQ:1170932205 ,
网友评论