基本信息
源码名称:c++ 企业员工管理系统(增、删、改、查、排序)
源码大小:57.92M
文件格式:.zip
开发语言:C/C++
更新时间:2019-06-12
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
企业员工管理系统


#include"WorkerManager.h"
#include<string>
//#include"worker.h"
//#include"employee.h"
//#include"boss.h"
//#include"manager.h"


//构造函数
WorkerManager::WorkerManager()
{
//文件不存在
ifstream ifs;
ifs.open(FILENAME, ios::in);//读文件
if (!ifs.is_open())
{
cout << "文件不存在" << endl;
//初始化记录人数
this->m_EmpNum = 0;
//初台化数组指针
this->m_EmpArray = NULL;
//初始化文件是否为空
this->m_FileIsEmpty = true;
ifs.close();
return;


//文件存在,数据为空
char ch;
ifs >> ch;
if (ifs.eof())
{
//文件为空
cout << "文件为空"<<endl;
//初始化记录人数
this->m_EmpNum = 0;
//初台化数组指针
this->m_EmpArray = NULL;
//初始化文件是否为空
this->m_FileIsEmpty = true;
ifs.close();
return;
}
//文件存在,并且记录数据
int num = this->get_EmpNum();
cout << "现有职工人数为:" << num << endl;
this->m_EmpNum = num;
//开辟空间
this->m_EmpArray = new Worker * [this->m_EmpNum];
//将文件中的数据,存到数据组
this->init_Emp();

//
////测试代码
//for (int  i = 0; i < this->m_EmpNum; i )
//{
// cout << "职工编号:" << this->m_EmpArray[i]->m_Id
// << "\t职工姓名:" << this->m_EmpArray[i]->m_Name
// << "\t部门编号:" << this->m_EmpArray[i]->m_DeptId
// << endl;

//}
}
//展示菜单
void WorkerManager::Show_Menu()
{

cout << "#########################################" << endl;
cout << "#########################################" << endl;
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;
cout << "#########################################" << endl;
cout << "#########################################" << endl;
}
void WorkerManager::ExisSystem()
{
cout << "欢迎下次使用本系统!" << endl;
system("pause");
exit(0);
}
void WorkerManager::Add_Emp()
{
cout << "请输要入添加职工的数量"<<endl;
int addnum = 0;//保存添加数量
cin >> addnum;
if (addnum > 0)
{
if (addnum > 11)
{
cout << "一次最多添加10个职工。" << endl;

}
//添加开始计算新空间大小
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;//部门选择
while (true)
{
cout << "请输入第" << i 1 << "个新职工编号:" << endl;
cin >> id;
if (this->isExist(id) != -1)
{
cout << "系统已有您输入职工编号,请重新输入!";
}
else
{
break;
}

}


cout << "请输入第" << i 1 << "个新职工姓名:" << endl;
cin >> name;
cout << "请选择该职工岗位:" << endl
<< "1、老板" << endl
<< "2、经理" << endl
<< "3、普通职工" << endl;

cin >>dselect;
Worker* worker =NULL;
switch (dselect)
{
case 1:
worker = new Boss(id, name, 1);
break;
case 2:
worker = new Manager(id, name, 2);
break;
case 3:
worker = new Employee(id, name, 3);
break;
default:
cout << "输入错误,重置为:普通员工" << endl;
worker = new Employee(id, name, 3);
break;
break;
}
newspace[this->m_EmpNum i] = worker;

}
//释放原有空间
delete[] this->m_EmpArray;

//更改新空间指向。
this->m_EmpArray = newspace;

//更新新的职工人数
this->m_EmpNum = newsize;

//更新职工文件是否为空
this->m_FileIsEmpty = false;

//提示添加成功
cout << "成功添加" << addnum << "名职工" << endl;
this->save();

}
else
{
cout << "输入有误!" << endl;
}

}

//保存文件
void WorkerManager::save()
{
ofstream ofs;
ofs.open(FILENAME, 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_DeptId << endl;
}
ofs.close();//关闭文件
}
//统计人数
int WorkerManager::get_EmpNum()
{
ifstream ifs;
ifs.open(FILENAME, ios::in);
int id;
string name;
int dId;
int num = 0;
while ( ifs >> id && ifs >> name && ifs >> dId )
{
//统计人数
num ;
}
return num;
}

//初始化员工
void WorkerManager::init_Emp()
{
ifstream ifs;
ifs.open(FILENAME, ios::in);
int id;
string name;
int dId;
int index=0;
while (ifs >> id && ifs >> name && ifs >> dId)
{
Worker * worker = NULL;
if (dId == 1)//老板
{
worker = new Boss(id, name, dId);
}
else if (dId == 2)//经理
{
worker = new Manager(id, name, dId);
}
else//普通员工
{
worker = new Employee(id, name, dId);
}
this->m_EmpArray[index] = worker;
index ;
}
ifs.close();

}

//显示职工
void WorkerManager::show_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
}
else
{
for (int i = 0; i < m_EmpNum;i )
{
this->m_EmpArray[i]->showInfo();
}
}

}

//删除职工
void WorkerManager::del_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
}
else
{
//按照职工编号删除
cout << "请输入要删除的职工编号:" << endl;
int id = 0;
cin >> id;
int index=this->isExist(id);
if (index != -1)//说明职工不存在
{
for (int i = index;i < this->m_EmpNum - 1;i )
{
this->m_EmpArray[i] = this->m_EmpArray[i 1];
}
this->m_EmpNum--;//更新数组中记录人员个数
this->save();//保存到文件
cout << "删除成功" << endl;


}
else
{
cout << "删除失败,未找到职工。"<<endl;
}
}

}

//查找职工
void WorkerManager::find_Emp()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或记录为空!" << endl;
}
else
{
cout << "请选择查找方式:" << endl
<<"1、按编号查找:" << endl
<<"2、按姓名查找:" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
//按照职工编号查找
cout << "请输入要查找的职工编号:" << endl;
int id = 0;
cin >> id;
int index = this->isExist(id);
if (index != -1)//说明职工不存在
{
m_EmpArray[index]->showInfo();
}
else
{
cout << "查找失败,未找到职工。" << endl;
}
}
else if(select==2)

//按照职工姓名查找
cout << "请输入要查找的职工姓名:" << endl;
string name = "";
cin >> name;
bool isEmp = false;
for (int i = 0; i < this->m_EmpNum; i )
{
if (this->m_EmpArray[i]->m_Name == name)
{
this->m_EmpArray[i]->showInfo();
isEmp = true;
}
}
if (!isEmp)
{
cout << "没有" << name << "这个员工!" << endl;
}
}
else
{
cout << "输入有识破!" << endl;
}

}

}

//根据编号查询是否存在职工
int WorkerManager::isExist(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 WorkerManager::mod_Emp()
{
if(this->m_FileIsEmpty)
{
cout << "文件或记录不存在!" << endl;
}
else
{
cout << "请输入要修改职工的编号:" << endl;
int id;
cin >> id;
int ret = this->isExist(id);
if (ret != -1)
{
delete this->m_EmpArray[ret];
int newId = 0;
string newName = "";
int dSelect = 0;



while (true)
{
cout << "查到:" << id << "号职工,请输入新职工号:";
cin >> newId;
if (this->isExist(newId) != -1)
{
cout << "系统已有您输入职工编号,请重新输入!";
}
else
{
break;
}

}



cout << "请输入新姓名:" << endl;
cin >> newName;
xx:
cout << "请输入岗位:" << endl;
cout << "1.老板" << endl;
cout << "2.经理" << endl;
cout << "3.普通职工" << endl;
cin >> dSelect;
Worker* worker = NULL;
switch (dSelect)

{
case 1:
worker = new Boss(newId, newName, dSelect);
break;
case 2:
worker = new Manager(newId, newName, dSelect);
break;
case 3:
worker = new Employee(newId, newName, dSelect);
break;
default:
cout << "输入错误,重置为:普通员工" << endl;
worker = new Employee(newId, newName, dSelect);
break;
}
this->m_EmpArray[ret] = worker;
cout << "修改成功!" << endl;
this->save();

}
else
{
cout << "修改失败,查无此人!" << endl;
}
}
}

//排序
void WorkerManager::sort_Emp()
{

if (this->m_FileIsEmpty)
{
cout << "文件或记录不存在!" << endl;
return;
}

cout << "请选择排序方式,默认升序排序:"<<endl
<< "1、升序排序:"<<endl
<< "2、降序排序:"<<endl;
int select;
cin >> select;
Worker* temp = NULL;
if (select>2 ||select<1)
{
select = 1;
}

for (int i = 0; i < this->m_EmpNum-1; i )
{
for (int j = i 1; j < this->m_EmpNum; j )
{

if (select == 1)
{
if (this->m_EmpArray[i]->m_Id > this->m_EmpArray[j]->m_Id)
{
temp = m_EmpArray[i];
m_EmpArray[i] = m_EmpArray[j];
m_EmpArray[j] = temp;
}
}
else
{
if (this->m_EmpArray[i]->m_Id < this->m_EmpArray[j]->m_Id)
{
temp = m_EmpArray[i];
m_EmpArray[i] = m_EmpArray[j];
m_EmpArray[j] = temp;
}
}
}
}
this->save();
this->show_Emp();




}

//清空数据
void WorkerManager::clean_File()
{
cout << "确定要清空么?" << endl;
cout << "1、清空" << endl;
cout << "2.返回" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
//清空文件
ofstream ofs(FILENAME, ios::trunc);//删除文件事重新创建
ofs.close();//关闭文件
if (this->m_EmpArray != NULL)
{
//删除堆区的每个职工对象
for (int i = 0;i < this->m_EmpNum;i )
{
delete this->m_EmpArray[i];
this->m_EmpArray[i] = NULL;

}
delete[] this->m_EmpArray;
this->m_EmpArray = NULL;
this->m_EmpNum = 0;
this->m_FileIsEmpty = true;

}
cout << "清空成功!" << endl;
}

}

//析构函数
WorkerManager::~WorkerManager()
{
if (this->m_EmpArray != NULL)
{
delete[] this->m_EmpArray;
this->m_EmpArray = NULL;
}
}