@FishC 对下面代码进行优化是其存在一个单独的通道为VIP顾客服务#include <iostream>
using namespace std;
static int i = 1;
struct QNode {
int bianhao; // 队内成员取到的号码
QNode* next;
};
struct Queue {
QNode* front; // 队头指针
QNode* rear; // 队尾指针
};
void CustomerReview() {
cout << "\n\t\t\t\t\t*********************************\n";
cout << "\t\t\t\t\t*\t请对本次服务做出评价\t*\n";
cout << "\t\t\t\t\t*\t1.非常满意!\t\t*\n";
cout << "\t\t\t\t\t*\t2.比较满意!\t\t*\n";
cout << "\t\t\t\t\t*\t3.一般!\t\t*\n";
cout << "\t\t\t\t\t*\t4.不满意!\t\t*\n";
cout << "\t\t\t\t\t*********************************\n";
int a;
cout << "\t\t\t\t\t";
cin >> a;
while (a < 1 || a > 4) {
cout << "\t\t\t\t\t* 您的输入不正确,请重新输入: ";
cin >> a;
}
switch (a) {
case 1:
case 2:
case 3:
case 4: {
cout << "\t\t\t\t\t* 非常感谢你的评价!谢谢! *\n";
cout << "\t\t\t\t\t*\t";
system("pause");
system("cls");
break;
}
default:break;
}
}
void CounterServer(Queue& s1, Queue& s2, Queue& s3) { // 柜员
cout << "\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n";
cout << "\t\t\t\t\t*********************************\n";
cout << "\t\t\t\t\t*\t 1.1号窗口 (存取款) *\n";
cout << "\t\t\t\t\t*\t 2.2号窗口(汇款,兑换) *\n";
cout << "\t\t\t\t\t*\t 3.3号窗口(开户,挂失) *\n";
cout << "\t\t\t\t\t*********************************\n";
int a;
cout << "\t\t\t\t\t";
cin >> a;
switch (a) {
case 1: {
cout << "\t\t\t\t\t*\t1号窗口:";
QNode* p = s1.front->next;
while (p) {
cout << p->bianhao << " ";
p = p->next;
}
cout << endl;
cout << "\t\t\t\t\t* 请输入所取的号码:";
int b;
int position = 1;
cin >> b;
QNode* q = s1.front->next;
while (q && q->bianhao != b) {
q = q->next;
position++;
}
if (q == NULL || q->bianhao != b) {
cout << "\t\t\t\t\t* 对不起,您输入的号码不存在! *\n";
cout << "\t\t\t\t\t";
system("pause");
return;
}
if (position == 1) {
cout << "\t\t\t\t\t*\t 你现在是第1位! \t*\n";
int e = 0;
QNode* temp = s1.front->next;
s1.front->next = temp->next;
if (s1.rear == temp) {
s1.rear = s1.front;
}
delete temp;
cout << "\t\t\t\t\t*\t 办理完成! \t*\n";
CustomerReview();
}
if (position != 1 && (q != NULL || q->bianhao == b)) {
cout << "\t\t\t\t\t* 你现在是第" << position << "位,请等候谢谢! *\n";
cout << "\t\t\t\t\t";
system("pause");
}
break;
}
case 2: {
cout << "\t\t\t\t\t*\t2号窗口:";
QNode* p = s2.front->next;
while (p) {
cout << p->bianhao << " ";
p = p->next;
}
cout << endl;
cout << "\t\t\t\t\t* 请输入所取的号码:";
int b;
int position = 1;
cin >> b;
QNode* q = s2.front->next;
while (q && q->bianhao != b) {
q = q->next;
position++;
}
if (q == NULL || q->bianhao != b) {
cout << "\t\t\t\t\t* 对不起,您输入的号码不存在! *\n";
cout << "\t\t\t\t\t";
system("pause");
return;
}
if (position == 1) {
cout << "\t\t\t\t\t*\t 你现在是第1位! \t*\n";
int e = 0;
QNode* temp = s2.front->next;
s2.front->next = temp->next;
if (s2.rear == temp) {
s2.rear = s2.front;
}
delete temp;
cout << "\t\t\t\t\t*\t 办理完成! \t*\n";
CustomerReview();
}
if (position != 1 && (q != NULL || q->bianhao == b)) {
cout << "\t\t\t\t\t* 你现在是第" << position << "位,请等候谢谢! *\n";
cout << "\t\t\t\t\t";
system("pause");
}
break;
}
case 3: {
cout << "\t\t\t\t\t*\t3号窗口:";
QNode* p = s3.front->next;
while (p) {
cout << p->bianhao << " ";
p = p->next;
}
cout << endl;
cout << "\t\t\t\t\t* 请输入所取的号码:";
int b;
int position = 1;
cin >> b;
QNode* q = s3.front->next;
while (q && q->bianhao != b) {
q = q->next;
position++;
}
if (q == NULL || q->bianhao != b) {
cout << "\t\t\t\t\t* 对不起,您输入的号码不存在! *\n";
cout << "\t\t\t\t\t";
system("pause");
return;
}
if (position == 1) {
cout << "\t\t\t\t\t*\t 你现在是第1位! \t*\n";
int e = 0;
QNode* temp = s3.front->next;
s3.front->next = temp->next;
if (s3.rear == temp) {
s3.rear = s3.front;
}
delete temp;
cout << "\t\t\t\t\t*\t 办理完成! \t*\n";
CustomerReview();
}
if (position != 1 && (q != NULL || q->bianhao == b)) {
cout << "\t\t\t\t\t* 你现在是第" << position << "位,请等候谢谢! *\n";
cout << "\t\t\t\t\t";
system("pause");
}
break;
}
default: {
cout << "\t\t\t\t\t*\t 无效柜号 \t\t*\n\t\t\t\t\t\n";
cout << "\t\t\t\t\t* ";
system("pause");
system("cls");
break;
}
}
}
void EnQueue1(Queue& q, int i) { // 队列插入
QNode* p = new QNode;
p->bianhao = i;
p->next = NULL;
q.rear->next = p;
q.rear = p;
}
void vip1(Queue& q, int i) { // vip头插
QNode* p = new QNode;
if (q.front == q.rear) {
p->bianhao = i;
p->next = NULL;
q.rear->next = p;
q.rear = p;
}
else {
p->bianhao = i;
p->next = q.front->next;
q.front->next = p;
}
}
void EnQueue(Queue& s1, Queue& s2, Queue& s3) { // 选择窗口插入
system("cls");
cout << "\t\t\t\t\t*********************************\n";
cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
cout << "\t\t\t\t\t*\t 1.1号窗口 *\n";
cout << "\t\t\t\t\t*\t 2.2号窗口 *\n";
cout << "\t\t\t\t\t*\t 3.3号窗口 *\n";
cout << "\t\t\t\t\t*********************************\n";
int a;
cout << "\t\t\t\t\t";
cin >> a;
switch (a) {
case 1: {
EnQueue1(s1, i);
cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
i++;
break;
}
case 2: {
EnQueue1(s2, i);
cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
i++;
break;
}
case 3: {
EnQueue1(s3, i);
cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
i++;
break;
}
default: {
cout << "\t\t\t\t\t* 无效窗口 *\n\t\t\t\t\t\n";
cout << "\t\t\t\t\t* ";
break;
}
}
system("pause");
system("cls");
}
void vip2(Queue& s1, Queue& s2, Queue& s3) { // vip插队
cout << "\t\t\t\t\t*********************************\n";
cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
cout << "\t\t\t\t\t*\t 1.1号窗口 *\n";
cout << "\t\t\t\t\t*\t 2.2号窗口 *\n";
cout << "\t\t\t\t\t*\t 3.3号窗口 *\n";
cout << "\t\t\t\t\t*********************************\n";
int a;
cout << "\t\t\t\t\t";
cin >> a;
switch (a) {
case 1: {
vip1(s1, i);
cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
i++;
break;
}
case 2: {
vip1(s2, i);
cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
i++;
break;
}
case 3: {
vip1(s3, i);
cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
i++;
break;
}
default: {
cout << "\t\t\t\t\t* 无效窗口 *\n\t\t\t\t\t\n";
cout << "\t\t\t\t\t* ";
break;
}
}
system("pause");
system("cls");
}
void show(Queue& s1, Queue& s2, Queue& s3) { // 总显示窗口
cout << "\n\t\t\t\t\t*1号窗口排队人员:";
QNode* p = s1.front->next;
while (p) {
cout << p->bianhao << " ";
p = p->next;
}
cout << endl;
cout << "\n\t\t\t\t\t*2号窗口排队人员:";
p = s2.front->next;
while (p) {
cout << p->bianhao << " ";
p = p->next;
}
cout << endl;
cout << "\n\t\t\t\t\t*3号窗口排队人员:";
p = s3.front->next;
while (p) {
cout << p->bianhao << " ";
p = p->next;
}
cout << "\t\t\t\t\t";
system("pause");
}
int main() {
system("color 0b");
static int i = 1;
Queue s1, s2, s3;
s1.front = s1.rear = new QNode;
s1.front->next = NULL;
s2.front = s2.rear = new QNode;
s2.front->next = NULL;
s3.front = s3.rear = new QNode;
s3.front->next = NULL;
while (true) {
cout << "\n\n\n\n\n\n\n\n\n";
cout << "\t\t\t\t\t*********************************\n";
cout << "\t\t\t\t\t***********银行排队系统**********\n";
cout << "\t\t\t\t\t*********************************\n";
cout << "\t\t\t\t\t*\t请选择服务:\t\t*\n";
cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
cout << "\t\t\t\t\t*\t0.退出系统\t\t*\n";
cout << "\t\t\t\t\t*********************************\n";
int a;
cout << "\t\t\t\t\t";
cin >> a;
switch (a) {
case 1: {
cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
EnQueue(s1, s2, s3);
break;
}
case 2: {
system("cls");
cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
vip2(s1, s2, s3);
break;
}
case 3: {
system("cls");
cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
show(s1, s2, s3);
system("cls");
break;
}
case 4: {
system("cls");
cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
CounterServer(s1, s2, s3);
system("cls");
break;
}
case 0: {
exit(0);
break;
}
default: {
cout << "\t\t\t\t\t*\t 服务项输入有误 \t*\n";
cout << "\t\t\t\t\t*\t";
system("pause");
system("cls");
break;
}
}
}
return 0;
}
|