14.13 查找职工
按照编号和姓名两种方式进行查找
1、实现功能
先声明
在这里插入代码片
再实现
先让用户进行选择查找的方式,再进行查找
//查找职工
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 << "请输入职工编号:";
cin >> id;
int index = this->isExit(id);
if (index != -1)
{
cout << "查找成功,该职工信息如下:" << endl;
this->m_EmpArray[index]->showInfo();
}
else
{
cout << "查无此人!" << endl;
}
}
else if (select == 2)
{
string name = "";
cout << "请输入查找的姓名:";
cin >> name;
bool flag = false;
for (int i = 0; i < this->m_EmpNum; i++)
{
if (this->m_EmpArray[i]->m_Name == name)
{
this->m_EmpArray[i]->showInfo();
flag = true;
}
}
if (!flag)
{
cout << "查无此人!";
}
}
else
{
cout << "输入的选项有误!" << endl;
}
}
}
2、在main里添加选择
case 5: //查找职工
wm.find_Emp();
break;
3、测试