////////////////////////////////////////////////////////////////
//银行排号系统设计
//By WeiLele 2014.06.10
//
//
//
//
//
//
//
//
////////////////////////////////////////////////////////////////
#include <iostream>
#include <string.h>
#include <string.h>
#include <cstring>
#include <string>
#include <queue>
#include <memory>
using namespace std;
typedef struct
{
int num;
int isVIP;
}User;
int count_num; //计数值
queue <User> q_nor;
queue <User>q_vip;
typedef struct
{
int cmd_num; //命令符
int cmd5_NUM; //N的值
}Cmd;
Cmd cmd1;
Cmd Get_Cmd(string a);
void Client_Display(void);
void Queue_Display();
void Get();
void Get_VIP();
void Call();
void Delete();
void Count();
void CountN();
void Reset();
void Quit(bool &start_flag);
int main()
{
Client_Display();
string str;
bool start_flag = true;
while (start_flag)
{
cout << "请输入命令:\n";
getline(cin, str); //获取命令
cmd1 = Get_Cmd(str);
cout << "cmd is: " << cmd1.cmd_num << endl;
switch (cmd1.cmd_num)
{
case 1:
{
Get();
}break;
case 2:
{
Get_VIP();
}break;
case 3:
{
Call();
}break;
case 4:
{
Delete();
}break;
case 5:
{
Count();
}break;
case 6:
{
CountN();
}break;
case 7:
{
Reset();
}break;
case 8:
{
Quit(start_flag);
}break;
default:
{
}
}
if (!start_flag)
{
break;
}
Queue_Display();
}
return 0;
}
void Client_Display(void)
{
cout << " ////////////////////////////////////////////////////////////////////////////// " << endl;
cout << "1: get 取号" << endl;
cout << "2: get vip" << endl;
cout << "3: Call 叫号 " << endl;
cout << "4: delete 删除号码 " << endl;
cout << "5: count 获取当前排队总人数" << endl;
cout << "6: countN 获取号码N以前的排队人数 " << endl;
cout << "7: reset 重置排号机" << endl;
cout << "8: quit 退出排号机" << endl;
cout << " ////////////////////////////////////////////////////////////////////////////// " << endl;
}
void Queue_Display()
{
queue <User> q1 = q_nor;
queue <User> q2 = q_vip;
cout << endl << "排队结果如下所示:" << endl;
while (!q2.empty())
{
cout << "vip " << q2.front().num << endl;
q2.pop();
}
while (!q1.empty())
{
cout << q1.front().num << endl;
q1.pop();
}
}
Cmd Get_Cmd(string str)
{
Cmd cmd1;
if (strcmp(str.c_str(), "get") == 0)
{
cmd1.cmd_num = 1;
}
else if (strcmp(str.c_str(), "get vip") == 0)
{
cmd1.cmd_num = 2;
}
else if (strcmp(str.c_str(), "call") == 0)
{
cmd1.cmd_num = 3;
}
else if (strcmp(str.c_str(), "count") == 0)
{
cmd1.cmd_num = 5;
}
else if (str.length() >= 7)
{
string str1, str2;
str1 = str.substr(0, 7); //返回 0-n 字符串
str2 = str.substr(7, str.length());
cout << endl << "子串1" << str1;
cout << endl << "子串2" << str2;
if (strcmp(str1.c_str(), "countN ") == 0)
{
cmd1.cmd_num = 6;
cmd1.cmd5_NUM = atoi(str2.c_str());
cout << "cmd5_NUM" << cmd1.cmd5_NUM;
}
else if (strcmp(str1.c_str(), "delete ") == 0)
{
cmd1.cmd_num = 4;
cmd1.cmd5_NUM = atoi(str2.c_str());
}
else
{
cmd1.cmd_num = 100;
}
}
else if (strcmp(str.c_str(), "reset") == 0)
{
cmd1.cmd_num = 7;
}
else if (strcmp(str.c_str(), "quit") == 0)
{
cmd1.cmd_num = 8;
}
else
{
cmd1.cmd_num = 100; //错误命令,返回100
}
return cmd1;
}
void Get()
{
count_num++;
User user1;
user1.isVIP = false;
user1.num = count_num;
q_nor.push(user1);
}
void Get_VIP()
{
count_num++;
User user1;
user1.isVIP = true;
user1.num = count_num;
q_vip.push(user1);
}
void Call(void)
{
if (!q_vip.empty())
{
q_vip.front();
q_vip.pop();
}
else if (!q_nor.empty())
{
q_nor.front();
q_nor.pop();
}
else
{
cout << "\n目前没有排队客户\n";
}
}
void Delete()
{
bool vip_flag = false;
bool nor_flag = false;
queue <User> q1; //
queue <User> q2;
while (!q_vip.empty())
{
if (q_vip.front().num == cmd1.cmd5_NUM)
{
vip_flag = true;
q_vip.pop(); //直接丢掉
}
else
{
q2.push(q_vip.front());
q_vip.pop();
}
}
q_vip = q2;
while (vip_flag == 0 && !q_nor.empty())
{
if (q_nor.front().num == cmd1.cmd5_NUM)
{
nor_flag = true;
q_nor.pop();
}
else
{
q1.push(q_nor.front());
q_nor.pop();
}
}
q_nor = q1;
if (vip_flag)
{
cout << "\n删除成功: vip " << cmd1.cmd5_NUM << "\n";
}
else if (nor_flag)
{
cout << "\n删除成功: " << cmd1.cmd5_NUM << "\n";
}
else
{
cout << "\n删除失败,不在排队中\n";
}
}
void Count()
{
int N;
N = (q_nor.size()+q_vip.size());
cout << "\n排队总数: \n" << N << endl;
}
void CountN()
{
int N = 0;
queue <User> q1; //
queue <User> q2;
q1 = q_nor;
q2 = q_vip;
bool nor_flag = false;
bool vip_flag = false;
while (!q2.empty())
{
if (q2.front().num == cmd1.cmd5_NUM)
{
vip_flag = true;
break;
}
else
{
q2.pop();
N++;
}
}
while (!vip_flag && !q1.empty())
{
if (q1.front().num == cmd1.cmd5_NUM)
{
nor_flag = true;
break;
}
else
{
q1.pop();
N++;
}
}
if (vip_flag || nor_flag)
{
cout << "\n查找成功: " << N <<"\n";
}
else
{
cout << "\n查找失败\n";
}
}
void Reset()
{
while (!q_nor.empty())
{
q_nor.pop();
}
while (!q_vip.empty())
{
q_vip.pop();
}
count_num = 0;
}
void Quit(bool &start_flag)
{
start_flag = false;
}
Prog_Life
- 粉丝: 30
- 资源: 13
最新资源
- 基于Kotlin与Java跨平台实现的arc进度条设计源码
- 源代码-仿MOP对开式论坛程序.zip
- 基于Python实现的BGP路由协议本科毕业设计源码
- 基于C语言的GEMM矩阵乘法优化设计源码学习与应用
- 基于Java的电影票出售系统设计源码
- 基于Python和Web技术栈的公文传输系统设计源码
- 基于Kolmogorov-Arnold网络(KAN)的激光选区熔化(LPBF)孔隙缺陷声学监测算法设计与实现源码
- 基于C/C/Python的多功能.hcxtools:.cab转.hc22000格式转换工具源码
- 源代码-仿Google网站AJAX拖曳实例ASP保存数据.zip
- 基于Java语言,支持Python和HTML的Flask框架设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈