之前涨了一个粉,我合理怀疑是因为我连续更的数模才关注的,不过我对它封心锁爱了不会再各更。数模要拿奖实在不是靠学,而是拼命的加页数...
①修改职工
1、在workerManager.h中
//修改职工
void Mod_Emp();
2、在workerManager.cpp中进行具体实现
//修改职工
void WorkerManager::Mod_Emp() {
//先判断文件是否存在
if (!this->m_FileIsEmpty) {
cout << "文件不存在或记录为空" << endl;
}
else {
//查找是否能找到对应id
cout << "请输入修改职工的编号" << endl;
int id = -1;
cin >> id;
int index = this->IsExist(id);
if (index != -1) {//说明职工存在,并且先删除index位置上的职工,再重新赋值
//使用 delete 删除
delete this->m_EmpArray[index];
//chonxgi
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;
Worker* worker = NULL;
switch (dSelect)
{
case 1:
worker = new Employee(newId, newName, dSelect);
break;
case 2:
worker = new Manager(newId, newName, dSelect);
break;
case 3:
worker = new Boss(newId, newName, dSelect);
break;
default:
break;
}
//将新创建的职工职责,保存到数组中
this->m_EmpArray[index] = worker;
cout << "修改成功!" << endl;
//保存到文件中
this->save();
}
else {
cout << "修改失败,未找到该职工" << endl;
}
}
//按任意键清屏
system("pause");
system("cls");
}
这里的操作是先简单的删除,然后新建worker *,在将新建的赋值到原来的index位置
又出了问题
果然是
//先判断文件是否存在
if (this->m_FileIsEmpty) {
cout << "文件不存在或记录为空" << endl;
}
修改后正常,但是目前不能理解if (true)运行的话 m_FileIsEmpty==true 但是输出的是文件不存在
在workermanager.cpp中缺失bool m_FileIsEmpty
②查找职工
有两种查找方式:(1)按编号(2)按姓名
1、在workerManager.h中声明函数
//查找函数
void Find_Emp();
2、在workerManager.cpp中进行具体实现
因为有两种查找方式,所以先写按编号的
//查找函数
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 ret = IsExist(id);
if (ret != -1) {
cout << "查找成功!该职工信息如下:" << endl;
this->m_EmpArray[ret]->showInfo(); //
}
else {
cout << "查找失败,查无此人" << endl;
}
}
else if (select = 2) {
//按照姓名查
}
}
}
3、在职工管理系统.cpp中
case 5:
wm.Find_Emp();
break;
测试:
4、在workermanager.cpp中添加第二种查找方式后:
//查找函数
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 ret = IsExist(id);
if (ret != -1) {
cout << "查找成功!该职工信息如下:" << endl;
this->m_EmpArray[ret]->showInfo(); //
}
else {
cout << "查找失败,查无此人" << endl;
}
}
else if (select = 2) {
//按照姓名
string name;
cout << "请输入查找的姓名:" << endl;
cin >> name;
bool flag = false;
for (int i = 0; i < this->m_EmpNum; i++) {
if (this->m_EmpArray[i]->m_Name == name) {
cout << "查找成功,职工编号为:"
<< this->m_EmpArray[i]->m_ID
<< "号职工信息如下:" << endl;
flag = true;
//调用显示信息接口
this->m_EmpArray[i]->showInfo();
}
}
//如和判断没有找到呢,需要设置变量flag
if (flag == false) {
cout << "查找失败,查无此人!" << endl;
}
}
else {
cout << "输入选项有误" << endl;
}
}
//按任意键清屏
system("pause");
system("cls");
}
测试:
允许出现重名的情况
③排序
1、在WorkerManager.h中:
//按照编号排序
void Sort_Emp();
唉,明日复明日