14.13 查找职工

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、测试

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值