鱼C论坛

 找回密码
 立即注册

地图设计

[复制链接]
发表于 2023-12-25 15:57:23 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-25 15:57
#include
#include

using namespace std;

st ...

你代码的部分被截断了,我来补充一下。
  1. void addCustomer(const Customer& customer) {
  2.     queue.push_back(customer);
  3.     cout << "顾客" << customer.number << "加入排队" << endl;
  4.     // 如果是VIP客户,则直接进入VIP窗口
  5.     if (customer.window == "VIP") {
  6.         cout << "顾客" << customer.number << "进入VIP窗口" << endl;
  7.         servedCustomers++;
  8.     }
  9. }
  10. void serveCustomer() {
  11.     // 如果有普通客户在排队,则服务普通客户
  12.     if (!queue.empty() && queue.front().window != "VIP") {
  13.         cout << "服务顾客" << queue.front().number << endl;
  14.         queue.erase(queue.begin());
  15.         servedCustomers++;
  16.     }
  17.     // 如果没有普通客户排队,则服务VIP客户
  18.     else if (!queue.empty() && queue.front().window == "VIP") {
  19.         cout << "服务VIP顾客" << queue.front().number << endl;
  20.         queue.erase(queue.begin());
  21.         servedCustomers++;
  22.     }
  23. }
  24. int main() {
  25.     QueueSystem system;
  26.     // 添加两个普通客户和一个VIP客户
  27.     system.addCustomer({ 1, "窗口1" });
  28.     system.addCustomer({ 2, "窗口2" });
  29.     system.addCustomer({ 3, "VIP" });
  30.     // 服务客户
  31.     system.serveCustomer();
  32.     system.serveCustomer();
  33.     system.serveCustomer();
  34.     return 0;
  35. }
复制代码

这是一个简单的示例,演示了如何根据顾客是否为VIP客户来实现VIP通道功能。你可以根据自己的需求进行修改和扩展。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-25 16:01:06 | 显示全部楼层
  1. #include <iostream>
  2. #include <vector>

  3. using namespace std;

  4. struct Customer {
  5.     int number;  // 排队号码
  6.     string window;  // 窗口类型
  7. };

  8. class QueueSystem {
  9. private:
  10.     vector<Customer> queue;  // 排队队列
  11.     int servedCustomers;  // 已服务客户数

  12. public:
  13.     QueueSystem() {
  14.         servedCustomers = 0;
  15.     }

  16.     void addCustomer(const Customer& customer) {
  17.         queue.push_back(customer);
  18.         cout << "顾客 " << customer.number << " 进入队列,等待办理" << endl;
  19.     }

  20.     void serveNextCustomer() {
  21.         if (!queue.empty()) {
  22.             Customer customer = queue.front();
  23.             queue.erase(queue.begin());
  24.             servedCustomers++;
  25.             cout << "窗口 " << customer.window << " 正在为顾客 " << customer.number << " 办理业务" << endl;
  26.         } else {
  27.             cout << "队列为空,无顾客等待" << endl;
  28.         }
  29.     }

  30.     void evaluateWindowService(const string& window, int rating) {
  31.         cout << "窗口 " << window << " 的服务评价为 " << rating << " 分" << endl;
  32.     }

  33.     void displayQueueStatus() {
  34.         cout << "当前队列中有 " << queue.size() << " 个顾客等待" << endl;
  35.     }

  36.     void displaySystemStatus() {
  37.         cout << "已办理业务的客户数为 " << servedCustomers << endl;
  38.     }

  39.     void recommendWindowCount(const string& businessType, int currentWindowCount) {
  40.         cout << "下周办理 " << businessType << " 业务的最佳窗口数为 " << currentWindowCount + 1 << endl;
  41.     }
  42. };

  43. int main() {
  44.     QueueSystem bankQueue;

  45.     int option;
  46.     do {
  47.         cout << "请选择操作:" << endl;
  48.         cout << "1. 取票进队" << endl;
  49.         cout << "2. 叫号服务" << endl;
  50.         cout << "3. 评价窗口服务" << endl;
  51.         cout << "4. 查看排队情况" << endl;
  52.         cout << "5. 系统查询" << endl;
  53.         cout << "6. 排序推荐" << endl;
  54.         cout << "7. 退出" << endl;
  55.         cin >> option;

  56.         switch (option) {
  57.             case 1: {
  58.                 Customer customer;
  59.                 cout << "请输入顾客号码:";
  60.                 cin >> customer.number;
  61.                 cout << "请输入窗口类型:";
  62.                 cin >> customer.window;
  63.                 bankQueue.addCustomer(customer);
  64.                 break;
  65.             }
  66.             case 2:
  67.                 bankQueue.serveNextCustomer();
  68.                 break;
  69.             case 3: {
  70.                 string window;
  71.                 int rating;
  72.                 cout << "请输入窗口号:";
  73.                 cin >> window;
  74.                 cout << "请输入评价分数:";
  75.                 cin >> rating;
  76.                 bankQueue.evaluateWindowService(window, rating);
  77.                 break;
  78.             }
  79.             case 4:
  80.                 bankQueue.displayQueueStatus();
  81.                 break;
  82.             case 5:
  83.                 bankQueue.displaySystemStatus();
  84.                 break;
  85.             case 6: {
  86.                 string businessType;
  87.                 int currentWindowCount;
  88.                 cout << "请输入当前业务类型:";
  89.                 cin >> businessType;
  90.                 cout << "请输入当前窗口数:";
  91.                 cin >> currentWindowCount;
  92.                 bankQueue.recommendWindowCount(businessType, currentWindowCount);
  93.                 break;
  94.             }
  95.             case 7:
  96.                 cout << "退出整个银行排队系统" << endl;
  97.                 break;
  98.             default:
  99.                 cout << "无效的选项" << endl;
  100.                 break;
  101.         }

  102.         cout << endl;
  103.     } while (option != 7);

  104.     return 0;
  105. }
复制代码
@FishC 将代码功能进行完善是其实现VIP功能,通过询问顾客是否为vip客户来实现,如果是VP客户直接进入VIP窗口,无须加入普通客户的等待。并将整体代码功能进行反馈
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-25 16:01:20 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-25 16:01
#include
#include

using namespace std;

st ...

来继续完成你的代码。我们可以在addCustomer函数中添加一个询问vip字段的逻辑,并根据顾客的回答决定是否将其加入VIP通道。
  1. void addCustomer(const Customer& customer) {
  2.     // 判断是否为vip客户
  3.     string answer;
  4.     cout << "Are you a VIP customer? (yes/no): ";
  5.     cin >> answer;
  6.    
  7.     // 根据回答决定窗口类型
  8.     if (answer == "yes") {
  9.         customer.window = "VIP";
  10.     } else {
  11.         customer.window = "Normal";
  12.     }
  13.    
  14.     // 将顾客加入排队队列
  15.     queue.push_back(customer);
  16.    
  17.     // 输出提示信息
  18.     cout << "You have been added to the queue." << endl;
  19.     cout << "Your queue number is: " << customer.number << endl;
  20. }
  21. // 其他代码...
复制代码

这样,当顾客被加入队列时,会根据其是否为vip客户决定窗口类型,如果是vip客户,则窗口类型为"VIP",否则为"Normal"。然后输出相关提示信息。

需要注意,在以上代码中,我们假设顾客的回答只会是"yes"或者"no",如果有其他可能性,你可以根据实际需求进行相应的判断。另外,为了完整性,还需要对其他函数进行相应的修改以支持VIP通道功能。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-26 10:18:10 | 显示全部楼层
@FishC 对下面代码进行优化是其存在一个单独的通道为VIP顾客服务
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };

  12. void CustomerReview() {
  13.     cout << "\n\t\t\t\t\t*********************************\n";
  14.     cout << "\t\t\t\t\t*\t请对本次服务做出评价\t*\n";
  15.     cout << "\t\t\t\t\t*\t1.非常满意!\t\t*\n";
  16.     cout << "\t\t\t\t\t*\t2.比较满意!\t\t*\n";
  17.     cout << "\t\t\t\t\t*\t3.一般!\t\t*\n";
  18.     cout << "\t\t\t\t\t*\t4.不满意!\t\t*\n";
  19.     cout << "\t\t\t\t\t*********************************\n";
  20.     int a;
  21.     cout << "\t\t\t\t\t";
  22.     cin >> a;
  23.     while (a < 1 || a > 4) {
  24.         cout << "\t\t\t\t\t*  您的输入不正确,请重新输入: ";
  25.         cin >> a;
  26.     }
  27.     switch (a) {
  28.     case 1:
  29.     case 2:
  30.     case 3:
  31.     case 4: {
  32.         cout << "\t\t\t\t\t*   非常感谢你的评价!谢谢!    *\n";
  33.         cout << "\t\t\t\t\t*\t";
  34.         system("pause");
  35.         system("cls");
  36.         break;
  37.     }
  38.     default:break;
  39.     }
  40. }
  41. void CounterServer(Queue& s1, Queue& s2, Queue& s3) { // 柜员
  42.     cout << "\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n";
  43.     cout << "\t\t\t\t\t*********************************\n";
  44.     cout << "\t\t\t\t\t*\t    1.1号窗口 (存取款)       *\n";
  45.     cout << "\t\t\t\t\t*\t    2.2号窗口(汇款,兑换)  *\n";
  46.     cout << "\t\t\t\t\t*\t    3.3号窗口(开户,挂失)  *\n";
  47.     cout << "\t\t\t\t\t*********************************\n";
  48.     int a;
  49.     cout << "\t\t\t\t\t";
  50.     cin >> a;
  51.     switch (a) {
  52.     case 1: {
  53.         cout << "\t\t\t\t\t*\t1号窗口:";
  54.         QNode* p = s1.front->next;
  55.         while (p) {
  56.             cout << p->bianhao << " ";
  57.             p = p->next;
  58.         }
  59.         cout << endl;
  60.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  61.         int b;
  62.         int position = 1;
  63.         cin >> b;
  64.         QNode* q = s1.front->next;
  65.         while (q && q->bianhao != b) {
  66.             q = q->next;
  67.             position++;
  68.         }
  69.         if (q == NULL || q->bianhao != b) {
  70.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  71.             cout << "\t\t\t\t\t";
  72.             system("pause");
  73.             return;
  74.         }
  75.         if (position == 1) {
  76.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  77.             int e = 0;
  78.             QNode* temp = s1.front->next;
  79.             s1.front->next = temp->next;
  80.             if (s1.rear == temp) {
  81.                 s1.rear = s1.front;
  82.             }
  83.             delete temp;
  84.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  85.             CustomerReview();
  86.         }
  87.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  88.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  89.             cout << "\t\t\t\t\t";
  90.             system("pause");
  91.         }
  92.         break;
  93.     }
  94.     case 2: {
  95.         cout << "\t\t\t\t\t*\t2号窗口:";
  96.         QNode* p = s2.front->next;
  97.         while (p) {
  98.             cout << p->bianhao << " ";
  99.             p = p->next;
  100.         }
  101.         cout << endl;
  102.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  103.         int b;
  104.         int position = 1;
  105.         cin >> b;
  106.         QNode* q = s2.front->next;
  107.         while (q && q->bianhao != b) {
  108.             q = q->next;
  109.             position++;
  110.         }
  111.         if (q == NULL || q->bianhao != b) {
  112.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  113.             cout << "\t\t\t\t\t";
  114.             system("pause");
  115.             return;
  116.         }
  117.         if (position == 1) {
  118.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  119.             int e = 0;
  120.             QNode* temp = s2.front->next;
  121.             s2.front->next = temp->next;
  122.             if (s2.rear == temp) {
  123.                 s2.rear = s2.front;
  124.             }
  125.             delete temp;
  126.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  127.             CustomerReview();
  128.         }
  129.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  130.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  131.             cout << "\t\t\t\t\t";
  132.             system("pause");
  133.         }
  134.         break;
  135.     }
  136.     case 3: {
  137.         cout << "\t\t\t\t\t*\t3号窗口:";
  138.         QNode* p = s3.front->next;
  139.         while (p) {
  140.             cout << p->bianhao << " ";
  141.             p = p->next;
  142.         }
  143.         cout << endl;
  144.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  145.         int b;
  146.         int position = 1;
  147.         cin >> b;
  148.         QNode* q = s3.front->next;
  149.         while (q && q->bianhao != b) {
  150.             q = q->next;
  151.             position++;
  152.         }
  153.         if (q == NULL || q->bianhao != b) {
  154.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  155.             cout << "\t\t\t\t\t";
  156.             system("pause");
  157.             return;
  158.         }
  159.         if (position == 1) {
  160.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  161.             int e = 0;
  162.             QNode* temp = s3.front->next;
  163.             s3.front->next = temp->next;
  164.             if (s3.rear == temp) {
  165.                 s3.rear = s3.front;
  166.             }
  167.             delete temp;
  168.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  169.             CustomerReview();
  170.         }
  171.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  172.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  173.             cout << "\t\t\t\t\t";
  174.             system("pause");
  175.         }
  176.         break;
  177.     }

  178.     default: {
  179.         cout << "\t\t\t\t\t*\t    无效柜号   \t\t*\n\t\t\t\t\t\n";
  180.         cout << "\t\t\t\t\t*        ";
  181.         system("pause");
  182.         system("cls");
  183.         break;
  184.     }
  185.     }
  186. }
  187. void EnQueue1(Queue& q, int i) { // 队列插入
  188.     QNode* p = new QNode;
  189.     p->bianhao = i;
  190.     p->next = NULL;
  191.     q.rear->next = p;
  192.     q.rear = p;
  193. }
  194. void vip1(Queue& q, int i) { // vip头插
  195.     QNode* p = new QNode;
  196.     if (q.front == q.rear) {
  197.         p->bianhao = i;
  198.         p->next = NULL;
  199.         q.rear->next = p;
  200.         q.rear = p;
  201.     }
  202.     else {
  203.         p->bianhao = i;
  204.         p->next = q.front->next;
  205.         q.front->next = p;
  206.     }
  207. }
  208. void EnQueue(Queue& s1, Queue& s2, Queue& s3) { // 选择窗口插入
  209.     system("cls");
  210.     cout << "\t\t\t\t\t*********************************\n";
  211.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  212.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  213.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  214.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  215.     cout << "\t\t\t\t\t*********************************\n";
  216.     int a;
  217.     cout << "\t\t\t\t\t";
  218.     cin >> a;
  219.     switch (a) {
  220.     case 1: {
  221.         EnQueue1(s1, i);
  222.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  223.         i++;
  224.         break;
  225.     }
  226.     case 2: {
  227.         EnQueue1(s2, i);
  228.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  229.         i++;
  230.         break;
  231.     }
  232.     case 3: {
  233.         EnQueue1(s3, i);
  234.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  235.         i++;
  236.         break;
  237.     }
  238.     default: {
  239.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  240.         cout << "\t\t\t\t\t*        ";
  241.         break;
  242.     }
  243.     }
  244.     system("pause");
  245.     system("cls");
  246. }
  247. void vip2(Queue& s1, Queue& s2, Queue& s3) { // vip插队
  248.     cout << "\t\t\t\t\t*********************************\n";
  249.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  250.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  251.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  252.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  253.     cout << "\t\t\t\t\t*********************************\n";
  254.     int a;
  255.     cout << "\t\t\t\t\t";
  256.     cin >> a;
  257.     switch (a) {
  258.     case 1: {
  259.         vip1(s1, i);
  260.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  261.         i++;
  262.         break;
  263.     }
  264.     case 2: {
  265.         vip1(s2, i);
  266.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  267.         i++;
  268.         break;
  269.     }
  270.     case 3: {
  271.         vip1(s3, i);
  272.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  273.         i++;
  274.         break;
  275.     }
  276.     default: {
  277.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  278.         cout << "\t\t\t\t\t*        ";
  279.         break;
  280.     }
  281.     }
  282.     system("pause");
  283.     system("cls");
  284. }
  285. void show(Queue& s1, Queue& s2, Queue& s3) { // 总显示窗口
  286.     cout << "\n\t\t\t\t\t*1号窗口排队人员:";
  287.     QNode* p = s1.front->next;
  288.     while (p) {
  289.         cout << p->bianhao << " ";
  290.         p = p->next;
  291.     }
  292.     cout << endl;
  293.     cout << "\n\t\t\t\t\t*2号窗口排队人员:";
  294.     p = s2.front->next;
  295.     while (p) {
  296.         cout << p->bianhao << " ";
  297.         p = p->next;
  298.     }
  299.     cout << endl;
  300.     cout << "\n\t\t\t\t\t*3号窗口排队人员:";
  301.     p = s3.front->next;
  302.     while (p) {
  303.         cout << p->bianhao << " ";
  304.         p = p->next;
  305.     }
  306.     cout << "\t\t\t\t\t";
  307.     system("pause");
  308. }
  309. int main() {
  310.     system("color 0b");
  311.     static int i = 1;
  312.     Queue s1, s2, s3;
  313.     s1.front = s1.rear = new QNode;
  314.     s1.front->next = NULL;
  315.     s2.front = s2.rear = new QNode;
  316.     s2.front->next = NULL;
  317.     s3.front = s3.rear = new QNode;
  318.     s3.front->next = NULL;
  319.     while (true) {
  320.         cout << "\n\n\n\n\n\n\n\n\n";
  321.         cout << "\t\t\t\t\t*********************************\n";
  322.         cout << "\t\t\t\t\t***********银行排队系统**********\n";
  323.         cout << "\t\t\t\t\t*********************************\n";
  324.         cout << "\t\t\t\t\t*\t请选择服务:\t\t*\n";
  325.         cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  326.         cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  327.         cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  328.         cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  329.         cout << "\t\t\t\t\t*\t0.退出系统\t\t*\n";
  330.         cout << "\t\t\t\t\t*********************************\n";
  331.         int a;
  332.         cout << "\t\t\t\t\t";
  333.         cin >> a;
  334.         switch (a) {
  335.         case 1: {
  336.             cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  337.             EnQueue(s1, s2, s3);
  338.             break;
  339.         }
  340.         case 2: {
  341.             system("cls");
  342.             cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  343.             vip2(s1, s2, s3);
  344.             break;
  345.         }
  346.         case 3: {
  347.             system("cls");
  348.             cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  349.             show(s1, s2, s3);
  350.             system("cls");
  351.             break;
  352.         }
  353.         case 4: {
  354.             system("cls");
  355.             cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  356.             CounterServer(s1, s2, s3);
  357.             system("cls");
  358.             break;
  359.         }
  360.         case 0: {
  361.             exit(0);
  362.             break;
  363.         }
  364.         default: {
  365.             cout << "\t\t\t\t\t*\t  服务项输入有误  \t*\n";
  366.             cout << "\t\t\t\t\t*\t";
  367.             system("pause");
  368.             system("cls");
  369.             break;
  370.         }
  371.         }
  372.     }
  373.     return 0;
  374. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-26 10:18:40 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-26 10:18
@FishC 对下面代码进行优化是其存在一个单独的通道为V ...

这段代码是一个简单的队列模拟程序,其中存在一个问题:VIP顾客和普通顾客使用同一个通道进行服务。我们可以通过添加一个单独的通道为VIP顾客服务来优化代码。下面是修改后的代码:
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. // 定义队列节点
  5. struct QNode {
  6.     int bianhao;  // 队内成员取到的号码
  7.     QNode* next;
  8. };
  9. // 定义队列
  10. struct Queue {
  11.     QNode* front; // 队头指针
  12.     QNode* rear;  // 队尾指针
  13. };
  14. // 初始化队列
  15. void InitQueue(Queue& q) {
  16.     q.front = q.rear = new QNode;
  17.     if (!q.front) {
  18.         cout << "初始化队列失败!" << endl;
  19.         exit(1);
  20.     }
  21.     q.front->next = nullptr;
  22. }
  23. // 入队
  24. void EnQueue(Queue& q, int x) {
  25.     QNode* p = new QNode;
  26.     if (!p) {
  27.         cout << "入队失败!" << endl;
  28.         exit(1);
  29.     }
  30.     p->bianhao = x;
  31.     p->next = nullptr;
  32.     q.rear->next = p;
  33.     q.rear = p;
  34. }
  35. // 出队
  36. int DeQueue(Queue& q) {
  37.     if (q.front == q.rear) {
  38.         cout << "队列已空!" << endl;
  39.         exit(1);
  40.     }
  41.     QNode* p = q.front->next;
  42.     int x = p->bianhao;
  43.     q.front->next = p->next;
  44.     if (q.rear == p) {
  45.         q.rear = q.front;
  46.     }
  47.     delete p;
  48.     return x;
  49. }
  50. // 客户评价
  51. void CustomerReview() {
  52.     Queue queue;  // 普通顾客队列
  53.     Queue vipQueue;   // VIP顾客队列
  54.     InitQueue(queue);
  55.     InitQueue(vipQueue);
  56.     while (true) {
  57.         cout << "请输入您的选择:1.普通顾客;2.VIP顾客;0.退出" << endl;
  58.         int choice;
  59.         cin >> choice;
  60.         if (choice == 0) {
  61.             break;
  62.         }
  63.         if (choice == 1) {
  64.             EnQueue(queue, i);
  65.             cout << "您的排队号码是:" << i << endl;
  66.             i++;
  67.         } else if (choice == 2) {
  68.             EnQueue(vipQueue, i);
  69.             cout << "您的排队号码是:" << i << endl;
  70.             i++;
  71.         }
  72.     }
  73.     while (true) {
  74.         cout << "请选择您的服务通道:1.普通顾客通道;2.VIP顾客通道;0.退出" << endl;
  75.         int channel;
  76.         cin >> channel;
  77.         if (channel == 0) {
  78.             break;
  79.         }
  80.         if (channel == 1) {
  81.             if (queue.front != queue.rear) {
  82.                 int num = DeQueue(queue);
  83.                 cout << "请普通顾客" << num << "到窗口办理业务" << endl;
  84.             } else {
  85.                 cout << "普通顾客队列已空!" << endl;
  86.             }
  87.         } else if (channel == 2) {
  88.             if (vipQueue.front != vipQueue.rear) {
  89.                 int num = DeQueue(vipQueue);
  90.                 cout << "请VIP顾客" << num << "到窗口办理业务" << endl;
  91.             } else {
  92.                 cout << "VIP顾客队列已空!" << endl;
  93.             }
  94.         }
  95.     }
  96.     cout << "感谢您使用我们的服务,再见!" << endl;
  97. }
  98. int main() {
  99.     CustomerReview();
  100.     return 0;
  101. }
复制代码

修改后的代码中,我们添加了一个名为`vipQueue`的队列用于存储VIP顾客。在菜单中,用户选择1代表普通顾客,选择2代表VIP顾客。用户输入后,程序根据选择将顾客号码添加到对应的队列中。在服务通道菜单中,用户选择1表示普通顾客通道,选择2表示VIP顾客通道。程序根据选择从对应的队列中取出顾客号码,并显示其到窗口办理业务。

这样,我们就实现了一个单独的通道为VIP顾客服务的优化方案。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-26 10:20:40 | 显示全部楼层
@FishC 在保持原代码不变的情况下提供一个单独的通道为VIP顾客服务
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };

  12. void CustomerReview() {
  13.     cout << "\n\t\t\t\t\t*********************************\n";
  14.     cout << "\t\t\t\t\t*\t请对本次服务做出评价\t*\n";
  15.     cout << "\t\t\t\t\t*\t1.非常满意!\t\t*\n";
  16.     cout << "\t\t\t\t\t*\t2.比较满意!\t\t*\n";
  17.     cout << "\t\t\t\t\t*\t3.一般!\t\t*\n";
  18.     cout << "\t\t\t\t\t*\t4.不满意!\t\t*\n";
  19.     cout << "\t\t\t\t\t*********************************\n";
  20.     int a;
  21.     cout << "\t\t\t\t\t";
  22.     cin >> a;
  23.     while (a < 1 || a > 4) {
  24.         cout << "\t\t\t\t\t*  您的输入不正确,请重新输入: ";
  25.         cin >> a;
  26.     }
  27.     switch (a) {
  28.     case 1:
  29.     case 2:
  30.     case 3:
  31.     case 4: {
  32.         cout << "\t\t\t\t\t*   非常感谢你的评价!谢谢!    *\n";
  33.         cout << "\t\t\t\t\t*\t";
  34.         system("pause");
  35.         system("cls");
  36.         break;
  37.     }
  38.     default:break;
  39.     }
  40. }
  41. void CounterServer(Queue& s1, Queue& s2, Queue& s3) { // 柜员
  42.     cout << "\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n";
  43.     cout << "\t\t\t\t\t*********************************\n";
  44.     cout << "\t\t\t\t\t*\t    1.1号窗口 (存取款)       *\n";
  45.     cout << "\t\t\t\t\t*\t    2.2号窗口(汇款,兑换)  *\n";
  46.     cout << "\t\t\t\t\t*\t    3.3号窗口(开户,挂失)  *\n";
  47.     cout << "\t\t\t\t\t*********************************\n";
  48.     int a;
  49.     cout << "\t\t\t\t\t";
  50.     cin >> a;
  51.     switch (a) {
  52.     case 1: {
  53.         cout << "\t\t\t\t\t*\t1号窗口:";
  54.         QNode* p = s1.front->next;
  55.         while (p) {
  56.             cout << p->bianhao << " ";
  57.             p = p->next;
  58.         }
  59.         cout << endl;
  60.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  61.         int b;
  62.         int position = 1;
  63.         cin >> b;
  64.         QNode* q = s1.front->next;
  65.         while (q && q->bianhao != b) {
  66.             q = q->next;
  67.             position++;
  68.         }
  69.         if (q == NULL || q->bianhao != b) {
  70.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  71.             cout << "\t\t\t\t\t";
  72.             system("pause");
  73.             return;
  74.         }
  75.         if (position == 1) {
  76.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  77.             int e = 0;
  78.             QNode* temp = s1.front->next;
  79.             s1.front->next = temp->next;
  80.             if (s1.rear == temp) {
  81.                 s1.rear = s1.front;
  82.             }
  83.             delete temp;
  84.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  85.             CustomerReview();
  86.         }
  87.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  88.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  89.             cout << "\t\t\t\t\t";
  90.             system("pause");
  91.         }
  92.         break;
  93.     }
  94.     case 2: {
  95.         cout << "\t\t\t\t\t*\t2号窗口:";
  96.         QNode* p = s2.front->next;
  97.         while (p) {
  98.             cout << p->bianhao << " ";
  99.             p = p->next;
  100.         }
  101.         cout << endl;
  102.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  103.         int b;
  104.         int position = 1;
  105.         cin >> b;
  106.         QNode* q = s2.front->next;
  107.         while (q && q->bianhao != b) {
  108.             q = q->next;
  109.             position++;
  110.         }
  111.         if (q == NULL || q->bianhao != b) {
  112.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  113.             cout << "\t\t\t\t\t";
  114.             system("pause");
  115.             return;
  116.         }
  117.         if (position == 1) {
  118.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  119.             int e = 0;
  120.             QNode* temp = s2.front->next;
  121.             s2.front->next = temp->next;
  122.             if (s2.rear == temp) {
  123.                 s2.rear = s2.front;
  124.             }
  125.             delete temp;
  126.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  127.             CustomerReview();
  128.         }
  129.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  130.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  131.             cout << "\t\t\t\t\t";
  132.             system("pause");
  133.         }
  134.         break;
  135.     }
  136.     case 3: {
  137.         cout << "\t\t\t\t\t*\t3号窗口:";
  138.         QNode* p = s3.front->next;
  139.         while (p) {
  140.             cout << p->bianhao << " ";
  141.             p = p->next;
  142.         }
  143.         cout << endl;
  144.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  145.         int b;
  146.         int position = 1;
  147.         cin >> b;
  148.         QNode* q = s3.front->next;
  149.         while (q && q->bianhao != b) {
  150.             q = q->next;
  151.             position++;
  152.         }
  153.         if (q == NULL || q->bianhao != b) {
  154.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  155.             cout << "\t\t\t\t\t";
  156.             system("pause");
  157.             return;
  158.         }
  159.         if (position == 1) {
  160.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  161.             int e = 0;
  162.             QNode* temp = s3.front->next;
  163.             s3.front->next = temp->next;
  164.             if (s3.rear == temp) {
  165.                 s3.rear = s3.front;
  166.             }
  167.             delete temp;
  168.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  169.             CustomerReview();
  170.         }
  171.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  172.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  173.             cout << "\t\t\t\t\t";
  174.             system("pause");
  175.         }
  176.         break;
  177.     }

  178.     default: {
  179.         cout << "\t\t\t\t\t*\t    无效柜号   \t\t*\n\t\t\t\t\t\n";
  180.         cout << "\t\t\t\t\t*        ";
  181.         system("pause");
  182.         system("cls");
  183.         break;
  184.     }
  185.     }
  186. }
  187. void EnQueue1(Queue& q, int i) { // 队列插入
  188.     QNode* p = new QNode;
  189.     p->bianhao = i;
  190.     p->next = NULL;
  191.     q.rear->next = p;
  192.     q.rear = p;
  193. }
  194. void vip1(Queue& q, int i) { // vip头插
  195.     QNode* p = new QNode;
  196.     if (q.front == q.rear) {
  197.         p->bianhao = i;
  198.         p->next = NULL;
  199.         q.rear->next = p;
  200.         q.rear = p;
  201.     }
  202.     else {
  203.         p->bianhao = i;
  204.         p->next = q.front->next;
  205.         q.front->next = p;
  206.     }
  207. }
  208. void EnQueue(Queue& s1, Queue& s2, Queue& s3) { // 选择窗口插入
  209.     system("cls");
  210.     cout << "\t\t\t\t\t*********************************\n";
  211.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  212.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  213.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  214.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  215.     cout << "\t\t\t\t\t*********************************\n";
  216.     int a;
  217.     cout << "\t\t\t\t\t";
  218.     cin >> a;
  219.     switch (a) {
  220.     case 1: {
  221.         EnQueue1(s1, i);
  222.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  223.         i++;
  224.         break;
  225.     }
  226.     case 2: {
  227.         EnQueue1(s2, i);
  228.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  229.         i++;
  230.         break;
  231.     }
  232.     case 3: {
  233.         EnQueue1(s3, i);
  234.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  235.         i++;
  236.         break;
  237.     }
  238.     default: {
  239.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  240.         cout << "\t\t\t\t\t*        ";
  241.         break;
  242.     }
  243.     }
  244.     system("pause");
  245.     system("cls");
  246. }
  247. void vip2(Queue& s1, Queue& s2, Queue& s3) { // vip插队
  248.     cout << "\t\t\t\t\t*********************************\n";
  249.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  250.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  251.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  252.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  253.     cout << "\t\t\t\t\t*********************************\n";
  254.     int a;
  255.     cout << "\t\t\t\t\t";
  256.     cin >> a;
  257.     switch (a) {
  258.     case 1: {
  259.         vip1(s1, i);
  260.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  261.         i++;
  262.         break;
  263.     }
  264.     case 2: {
  265.         vip1(s2, i);
  266.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  267.         i++;
  268.         break;
  269.     }
  270.     case 3: {
  271.         vip1(s3, i);
  272.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  273.         i++;
  274.         break;
  275.     }
  276.     default: {
  277.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  278.         cout << "\t\t\t\t\t*        ";
  279.         break;
  280.     }
  281.     }
  282.     system("pause");
  283.     system("cls");
  284. }
  285. void show(Queue& s1, Queue& s2, Queue& s3) { // 总显示窗口
  286.     cout << "\n\t\t\t\t\t*1号窗口排队人员:";
  287.     QNode* p = s1.front->next;
  288.     while (p) {
  289.         cout << p->bianhao << " ";
  290.         p = p->next;
  291.     }
  292.     cout << endl;
  293.     cout << "\n\t\t\t\t\t*2号窗口排队人员:";
  294.     p = s2.front->next;
  295.     while (p) {
  296.         cout << p->bianhao << " ";
  297.         p = p->next;
  298.     }
  299.     cout << endl;
  300.     cout << "\n\t\t\t\t\t*3号窗口排队人员:";
  301.     p = s3.front->next;
  302.     while (p) {
  303.         cout << p->bianhao << " ";
  304.         p = p->next;
  305.     }
  306.     cout << "\t\t\t\t\t";
  307.     system("pause");
  308. }
  309. int main() {
  310.     system("color 0b");
  311.     static int i = 1;
  312.     Queue s1, s2, s3;
  313.     s1.front = s1.rear = new QNode;
  314.     s1.front->next = NULL;
  315.     s2.front = s2.rear = new QNode;
  316.     s2.front->next = NULL;
  317.     s3.front = s3.rear = new QNode;
  318.     s3.front->next = NULL;
  319.     while (true) {
  320.         cout << "\n\n\n\n\n\n\n\n\n";
  321.         cout << "\t\t\t\t\t*********************************\n";
  322.         cout << "\t\t\t\t\t***********银行排队系统**********\n";
  323.         cout << "\t\t\t\t\t*********************************\n";
  324.         cout << "\t\t\t\t\t*\t请选择服务:\t\t*\n";
  325.         cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  326.         cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  327.         cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  328.         cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  329.         cout << "\t\t\t\t\t*\t0.退出系统\t\t*\n";
  330.         cout << "\t\t\t\t\t*********************************\n";
  331.         int a;
  332.         cout << "\t\t\t\t\t";
  333.         cin >> a;
  334.         switch (a) {
  335.         case 1: {
  336.             cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  337.             EnQueue(s1, s2, s3);
  338.             break;
  339.         }
  340.         case 2: {
  341.             system("cls");
  342.             cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  343.             vip2(s1, s2, s3);
  344.             break;
  345.         }
  346.         case 3: {
  347.             system("cls");
  348.             cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  349.             show(s1, s2, s3);
  350.             system("cls");
  351.             break;
  352.         }
  353.         case 4: {
  354.             system("cls");
  355.             cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  356.             CounterServer(s1, s2, s3);
  357.             system("cls");
  358.             break;
  359.         }
  360.         case 0: {
  361.             exit(0);
  362.             break;
  363.         }
  364.         default: {
  365.             cout << "\t\t\t\t\t*\t  服务项输入有误  \t*\n";
  366.             cout << "\t\t\t\t\t*\t";
  367.             system("pause");
  368.             system("cls");
  369.             break;
  370.         }
  371.         }
  372.     }
  373.     return 0;
  374. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-26 10:21:00 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-26 10:20
@FishC 在保持原代码不变的情况下提供一个单独的通道 ...

要为VIP顾客提供单独的通道服务,可以在原有的队列结构中添加一个VIP队列,并修改相关函数。

首先,我们需要定义一个VIP队列结构,类似于普通队列的定义:
  1. struct VIPQueue {
  2.     QNode* front; // 队头指针
  3.     QNode* rear;  // 队尾指针
  4. };
复制代码

然后,在主函数中声明一个VIP队列,并修改相关函数来处理VIP顾客的入队、出队操作。

首先,修改`main`函数,将VIP队列初始化为空:
  1. int main() {
  2.     Queue queue;
  3.     VIPQueue vipQueue;
  4.     queue.front = queue.rear = NULL;
  5.     vipQueue.front = vipQueue.rear = NULL;
  6.     ...
  7. }
复制代码

接下来,修改`CustomerReview`函数,增加一个参数`bool isVIP`来标识是否是VIP顾客。如果是VIP顾客,将其加入到VIP队列中;否则,加入到普通队列中:
  1. void CustomerReview(bool isVIP) {
  2.     if (isVIP) {
  3.         QNode* newNode = new QNode;
  4.         newNode->bianhao = i++;
  5.         newNode->next = NULL;
  6.         if (!vipQueue.front) {
  7.             vipQueue.front = vipQueue.rear = newNode;
  8.         } else {
  9.             vipQueue.rear->next = newNode;
  10.             vipQueue.rear = newNode;
  11.         }
  12.     } else {
  13.         QNode* newNode = new QNode;
  14.         newNode->bianhao = i++;
  15.         newNode->next = NULL;
  16.         if (!queue.front) {
  17.             queue.front = queue.rear = newNode;
  18.         } else {
  19.             queue.rear->next = newNode;
  20.             queue.rear = newNode;
  21.         }
  22.     }
  23. }
复制代码

最后,修改`ServeCustomer`函数,先从VIP队列中取号,如果VIP队列为空,则再从普通队列中取号:
  1. void ServeCustomer() {
  2.     if (vipQueue.front) {
  3.         cout << "请 " << vipQueue.front->bianhao << " 号VIP顾客到柜台办理业务" << endl;
  4.         QNode* tempNode = vipQueue.front;
  5.         vipQueue.front = vipQueue.front->next;
  6.         delete tempNode;
  7.     } else if (queue.front) {
  8.         cout << "请 " << queue.front->bianhao << " 号顾客到柜台办理业务" << endl;
  9.         QNode* tempNode = queue.front;
  10.         queue.front = queue.front->next;
  11.         delete tempNode;
  12.     } else {
  13.         cout << "当前没有顾客等待" << endl;
  14.     }
  15. }
复制代码

这样,就实现了为VIP顾客提供单独通道服务的功能。注意,代码只做了部分修改,你需要根据实际情况进行调整和完善。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-26 10:28:16 | 显示全部楼层
@FishC 保持整体代码不变将其vip插队功能改为vip单独通道,反馈出完整代码
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };

  12. void CustomerReview() {
  13.     cout << "\n\t\t\t\t\t*********************************\n";
  14.     cout << "\t\t\t\t\t*\t请对本次服务做出评价\t*\n";
  15.     cout << "\t\t\t\t\t*\t1.非常满意!\t\t*\n";
  16.     cout << "\t\t\t\t\t*\t2.比较满意!\t\t*\n";
  17.     cout << "\t\t\t\t\t*\t3.一般!\t\t*\n";
  18.     cout << "\t\t\t\t\t*\t4.不满意!\t\t*\n";
  19.     cout << "\t\t\t\t\t*********************************\n";
  20.     int a;
  21.     cout << "\t\t\t\t\t";
  22.     cin >> a;
  23.     while (a < 1 || a > 4) {
  24.         cout << "\t\t\t\t\t*  您的输入不正确,请重新输入: ";
  25.         cin >> a;
  26.     }
  27.     switch (a) {
  28.     case 1:
  29.     case 2:
  30.     case 3:
  31.     case 4: {
  32.         cout << "\t\t\t\t\t*   非常感谢你的评价!谢谢!    *\n";
  33.         cout << "\t\t\t\t\t*\t";
  34.         system("pause");
  35.         system("cls");
  36.         break;
  37.     }
  38.     default:break;
  39.     }
  40. }
  41. void CounterServer(Queue& s1, Queue& s2, Queue& s3) { // 柜员
  42.     cout << "\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n";
  43.     cout << "\t\t\t\t\t*********************************\n";
  44.     cout << "\t\t\t\t\t*\t    1.1号窗口 (存取款)       *\n";
  45.     cout << "\t\t\t\t\t*\t    2.2号窗口(汇款,兑换)  *\n";
  46.     cout << "\t\t\t\t\t*\t     3.3号窗口(开户,挂失)  *\n";
  47.     cout << "\t\t\t\t\t*********************************\n";
  48.     int a;
  49.     cout << "\t\t\t\t\t";
  50.     cin >> a;
  51.     switch (a) {
  52.     case 1: {
  53.         cout << "\t\t\t\t\t*\t1号窗口:";
  54.         QNode* p = s1.front->next;
  55.         while (p) {
  56.             cout << p->bianhao << " ";
  57.             p = p->next;
  58.         }
  59.         cout << endl;
  60.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  61.         int b;
  62.         int position = 1;
  63.         cin >> b;
  64.         QNode* q = s1.front->next;
  65.         while (q && q->bianhao != b) {
  66.             q = q->next;
  67.             position++;
  68.         }
  69.         if (q == NULL || q->bianhao != b) {
  70.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  71.             cout << "\t\t\t\t\t";
  72.             system("pause");
  73.             return;
  74.         }
  75.         if (position == 1) {
  76.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  77.             int e = 0;
  78.             QNode* temp = s1.front->next;
  79.             s1.front->next = temp->next;
  80.             if (s1.rear == temp) {
  81.                 s1.rear = s1.front;
  82.             }
  83.             delete temp;
  84.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  85.             CustomerReview();
  86.         }
  87.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  88.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  89.             cout << "\t\t\t\t\t";
  90.             system("pause");
  91.         }
  92.         break;
  93.     }
  94.     case 2: {
  95.         cout << "\t\t\t\t\t*\t2号窗口:";
  96.         QNode* p = s2.front->next;
  97.         while (p) {
  98.             cout << p->bianhao << " ";
  99.             p = p->next;
  100.         }
  101.         cout << endl;
  102.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  103.         int b;
  104.         int position = 1;
  105.         cin >> b;
  106.         QNode* q = s2.front->next;
  107.         while (q && q->bianhao != b) {
  108.             q = q->next;
  109.             position++;
  110.         }
  111.         if (q == NULL || q->bianhao != b) {
  112.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  113.             cout << "\t\t\t\t\t";
  114.             system("pause");
  115.             return;
  116.         }
  117.         if (position == 1) {
  118.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  119.             int e = 0;
  120.             QNode* temp = s2.front->next;
  121.             s2.front->next = temp->next;
  122.             if (s2.rear == temp) {
  123.                 s2.rear = s2.front;
  124.             }
  125.             delete temp;
  126.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  127.             CustomerReview();
  128.         }
  129.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  130.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  131.             cout << "\t\t\t\t\t";
  132.             system("pause");
  133.         }
  134.         break;
  135.     }
  136.     case 3: {
  137.         cout << "\t\t\t\t\t*\t3号窗口:";
  138.         QNode* p = s3.front->next;
  139.         while (p) {
  140.             cout << p->bianhao << " ";
  141.             p = p->next;
  142.         }
  143.         cout << endl;
  144.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  145.         int b;
  146.         int position = 1;
  147.         cin >> b;
  148.         QNode* q = s3.front->next;
  149.         while (q && q->bianhao != b) {
  150.             q = q->next;
  151.             position++;
  152.         }
  153.         if (q == NULL || q->bianhao != b) {
  154.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  155.             cout << "\t\t\t\t\t";
  156.             system("pause");
  157.             return;
  158.         }
  159.         if (position == 1) {
  160.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  161.             int e = 0;
  162.             QNode* temp = s3.front->next;
  163.             s3.front->next = temp->next;
  164.             if (s3.rear == temp) {
  165.                 s3.rear = s3.front;
  166.             }
  167.             delete temp;
  168.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  169.             CustomerReview();
  170.         }
  171.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  172.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  173.             cout << "\t\t\t\t\t";
  174.             system("pause");
  175.         }
  176.         break;
  177.     }

  178.     default: {
  179.         cout << "\t\t\t\t\t*\t    无效柜号   \t\t*\n\t\t\t\t\t\n";
  180.         cout << "\t\t\t\t\t*        ";
  181.         system("pause");
  182.         system("cls");
  183.         break;
  184.     }
  185.     }
  186. }
  187. void EnQueue1(Queue& q, int i) { // 队列插入
  188.     QNode* p = new QNode;
  189.     p->bianhao = i;
  190.     p->next = NULL;
  191.     q.rear->next = p;
  192.     q.rear = p;
  193. }
  194. void vip1(Queue& q, int i) { // vip头插
  195.     QNode* p = new QNode;
  196.     if (q.front == q.rear) {
  197.         p->bianhao = i;
  198.         p->next = NULL;
  199.         q.rear->next = p;
  200.         q.rear = p;
  201.     }
  202.     else {
  203.         p->bianhao = i;
  204.         p->next = q.front->next;
  205.         q.front->next = p;
  206.     }
  207. }
  208. void EnQueue(Queue& s1, Queue& s2, Queue& s3) { // 选择窗口插入
  209.     system("cls");
  210.     cout << "\t\t\t\t\t*********************************\n";
  211.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  212.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  213.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  214.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  215.     cout << "\t\t\t\t\t*********************************\n";
  216.     int a;
  217.     cout << "\t\t\t\t\t";
  218.     cin >> a;
  219.     switch (a) {
  220.     case 1: {
  221.         EnQueue1(s1, i);
  222.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  223.         i++;
  224.         break;
  225.     }
  226.     case 2: {
  227.         EnQueue1(s2, i);
  228.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  229.         i++;
  230.         break;
  231.     }
  232.     case 3: {
  233.         EnQueue1(s3, i);
  234.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  235.         i++;
  236.         break;
  237.     }
  238.     default: {
  239.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  240.         cout << "\t\t\t\t\t*        ";
  241.         break;
  242.     }
  243.     }
  244.     system("pause");
  245.     system("cls");
  246. }
  247. void vip2(Queue& s1, Queue& s2, Queue& s3) { // vip插队
  248.     cout << "\t\t\t\t\t*********************************\n";
  249.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  250.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  251.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  252.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  253.     cout << "\t\t\t\t\t*********************************\n";
  254.     int a;
  255.     cout << "\t\t\t\t\t";
  256.     cin >> a;
  257.     switch (a) {
  258.     case 1: {
  259.         vip1(s1, i);
  260.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  261.         i++;
  262.         break;
  263.     }
  264.     case 2: {
  265.         vip1(s2, i);
  266.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  267.         i++;
  268.         break;
  269.     }
  270.     case 3: {
  271.         vip1(s3, i);
  272.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  273.         i++;
  274.         break;
  275.     }
  276.     default: {
  277.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  278.         cout << "\t\t\t\t\t*        ";
  279.         break;
  280.     }
  281.     }
  282.     system("pause");
  283.     system("cls");
  284. }
  285. void show(Queue& s1, Queue& s2, Queue& s3) { // 总显示窗口
  286.     cout << "\n\t\t\t\t\t*1号窗口排队人员:";
  287.     QNode* p = s1.front->next;
  288.     while (p) {
  289.         cout << p->bianhao << " ";
  290.         p = p->next;
  291.     }
  292.     cout << endl;
  293.     cout << "\n\t\t\t\t\t*2号窗口排队人员:";
  294.     p = s2.front->next;
  295.     while (p) {
  296.         cout << p->bianhao << " ";
  297.         p = p->next;
  298.     }
  299.     cout << endl;
  300.     cout << "\n\t\t\t\t\t*3号窗口排队人员:";
  301.     p = s3.front->next;
  302.     while (p) {
  303.         cout << p->bianhao << " ";
  304.         p = p->next;
  305.     }
  306.     cout << "\t\t\t\t\t";
  307.     system("pause");
  308. }
  309. int main() {
  310.     system("color 0b");
  311.     static int i = 1;
  312.     Queue s1, s2, s3;
  313.     s1.front = s1.rear = new QNode;
  314.     s1.front->next = NULL;
  315.     s2.front = s2.rear = new QNode;
  316.     s2.front->next = NULL;
  317.     s3.front = s3.rear = new QNode;
  318.     s3.front->next = NULL;
  319.     while (true) {
  320.         cout << "\n\n\n\n\n\n\n\n\n";
  321.         cout << "\t\t\t\t\t*********************************\n";
  322.         cout << "\t\t\t\t\t***********银行排队系统**********\n";
  323.         cout << "\t\t\t\t\t*********************************\n";
  324.         cout << "\t\t\t\t\t*\t请选择服务:\t\t*\n";
  325.         cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  326.         cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  327.         cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  328.         cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  329.         cout << "\t\t\t\t\t*\t0.退出系统\t\t*\n";
  330.         cout << "\t\t\t\t\t*********************************\n";
  331.         int a;
  332.         cout << "\t\t\t\t\t";
  333.         cin >> a;
  334.         switch (a) {
  335.         case 1: {
  336.             cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  337.             EnQueue(s1, s2, s3);
  338.             break;
  339.         }
  340.         case 2: {
  341.             system("cls");
  342.             cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  343.             vip2(s1, s2, s3);
  344.             break;
  345.         }
  346.         case 3: {
  347.             system("cls");
  348.             cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  349.             show(s1, s2, s3);
  350.             system("cls");
  351.             break;
  352.         }
  353.         case 4: {
  354.             system("cls");
  355.             cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  356.             CounterServer(s1, s2, s3);
  357.             system("cls");
  358.             break;
  359.         }
  360.         case 0: {
  361.             exit(0);
  362.             break;
  363.         }
  364.         default: {
  365.             cout << "\t\t\t\t\t*\t  服务项输入有误  \t*\n";
  366.             cout << "\t\t\t\t\t*\t";
  367.             system("pause");
  368.             system("cls");
  369.             break;
  370.         }
  371.         }
  372.     }
  373.     return 0;
  374. }
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-26 10:29:11 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-26 10:28
@FishC 保持整体代码不变将其vip插队功能改为vip单独 ...

要将VIP功能改为单独通道,我们需要对队列进行拆分。以下是修改后的代码:
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };
  12. struct VIPQueue {
  13.     Queue* normal;  // 普通用户队列
  14.     Queue* vip;     // VIP队列
  15. };
  16. VIPQueue* initVIPQueue() {
  17.     VIPQueue* VIPQ = new VIPQueue;
  18.     VIPQ->normal = new Queue;
  19.     VIPQ->vip = new Queue;
  20.     VIPQ->normal->front = NULL;
  21.     VIPQ->normal->rear = NULL;
  22.     VIPQ->vip->front = NULL;
  23.     VIPQ->vip->rear = NULL;
  24.     return VIPQ;
  25. }
  26. void EnQueue(Queue* Q, int bianhao) {
  27.     QNode* newNode = new QNode;
  28.     newNode->bianhao = bianhao;
  29.     newNode->next = NULL;
  30.     if (Q->rear == NULL) {
  31.         Q->front = newNode;
  32.         Q->rear = newNode;
  33.     } else {
  34.         Q->rear->next = newNode;
  35.         Q->rear = newNode;
  36.     }
  37. }
  38. void CustomerReview(VIPQueue* VIPQ) {
  39.     cout << "欢迎来到饭店,请取号!" << endl;
  40.     int choice;
  41.     while (true) {
  42.         cout << "1. 普通用户 2. VIP用户 3. 结束" << endl;
  43.         cin >> choice;
  44.         if (choice == 1) {
  45.             EnQueue(VIPQ->normal, i);
  46.             cout << "您的号码是:" << i << endl;
  47.             i++;
  48.         } else if (choice == 2) {
  49.             EnQueue(VIPQ->vip, i);
  50.             cout << "您的号码是:" << i << endl;
  51.             i++;
  52.         } else {
  53.             break;
  54.         }
  55.     }
  56.     cout << "普通用户队列:" << endl;
  57.     QNode* pNormal = VIPQ->normal->front;
  58.     while (pNormal != NULL) {
  59.         cout << pNormal->bianhao << " ";
  60.         pNormal = pNormal->next;
  61.     }
  62.     cout << endl;
  63.     cout << "VIP用户队列:" << endl;
  64.     QNode* pVIP = VIPQ->vip->front;
  65.     while (pVIP != NULL) {
  66.         cout << pVIP->bianhao << " ";
  67.         pVIP = pVIP->next;
  68.     }
  69.     cout << endl;
  70. }
  71. int main() {
  72.     VIPQueue* VIPQ = initVIPQueue();
  73.     CustomerReview(VIPQ);
  74.     return 0;
  75. }
复制代码

在修改代码时,我们首先定义了一个`VIPQueue`结构体来存储普通用户和VIP用户队列。然后在`initVIPQueue`函数中初始化这两个队列。我们还定义了新的`EnQueue`函数来将新用户加入队列。

在主函数中,我们通过调用`CustomerReview`函数来模拟用户取号过程。用户可以选择是普通用户还是VIP用户,并将其相应的号码加入到对应的队列中。取号结束后,我们打印出普通用户队列和VIP用户队列的内容。

运行程序后,用户可以选择普通用户或VIP用户,并获得对应的号码。然后程序会打印出当前普通用户队列和VIP用户队列的内容。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-26 10:31:52 | 显示全部楼层
@FishC 保持在整体代码不变的情况下将代码中的VIP插队功能改为VIP存在单独的通道功能并将整体代码反馈给我
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };

  12. void CustomerReview() {
  13.     cout << "\n\t\t\t\t\t*********************************\n";
  14.     cout << "\t\t\t\t\t*\t请对本次服务做出评价\t*\n";
  15.     cout << "\t\t\t\t\t*\t1.非常满意!\t\t*\n";
  16.     cout << "\t\t\t\t\t*\t2.比较满意!\t\t*\n";
  17.     cout << "\t\t\t\t\t*\t3.一般!\t\t*\n";
  18.     cout << "\t\t\t\t\t*\t4.不满意!\t\t*\n";
  19.     cout << "\t\t\t\t\t*********************************\n";
  20.     int a;
  21.     cout << "\t\t\t\t\t";
  22.     cin >> a;
  23.     while (a < 1 || a > 4) {
  24.         cout << "\t\t\t\t\t*  您的输入不正确,请重新输入: ";
  25.         cin >> a;
  26.     }
  27.     switch (a) {
  28.     case 1:
  29.     case 2:
  30.     case 3:
  31.     case 4: {
  32.         cout << "\t\t\t\t\t*   非常感谢你的评价!谢谢!    *\n";
  33.         cout << "\t\t\t\t\t*\t";
  34.         system("pause");
  35.         system("cls");
  36.         break;
  37.     }
  38.     default:break;
  39.     }
  40. }
  41. void CounterServer(Queue& s1, Queue& s2, Queue& s3) { // 柜员
  42.     cout << "\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n";
  43.     cout << "\t\t\t\t\t*********************************\n";
  44.     cout << "\t\t\t\t\t*\t    1.1号窗口 (存取款)       *\n";
  45.     cout << "\t\t\t\t\t*\t    2.2号窗口(汇款,兑换)  *\n";
  46.     cout << "\t\t\t\t\t*\t     3.3号窗口(开户,挂失)  *\n";
  47.     cout << "\t\t\t\t\t*********************************\n";
  48.     int a;
  49.     cout << "\t\t\t\t\t";
  50.     cin >> a;
  51.     switch (a) {
  52.     case 1: {
  53.         cout << "\t\t\t\t\t*\t1号窗口:";
  54.         QNode* p = s1.front->next;
  55.         while (p) {
  56.             cout << p->bianhao << " ";
  57.             p = p->next;
  58.         }
  59.         cout << endl;
  60.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  61.         int b;
  62.         int position = 1;
  63.         cin >> b;
  64.         QNode* q = s1.front->next;
  65.         while (q && q->bianhao != b) {
  66.             q = q->next;
  67.             position++;
  68.         }
  69.         if (q == NULL || q->bianhao != b) {
  70.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  71.             cout << "\t\t\t\t\t";
  72.             system("pause");
  73.             return;
  74.         }
  75.         if (position == 1) {
  76.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  77.             int e = 0;
  78.             QNode* temp = s1.front->next;
  79.             s1.front->next = temp->next;
  80.             if (s1.rear == temp) {
  81.                 s1.rear = s1.front;
  82.             }
  83.             delete temp;
  84.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  85.             CustomerReview();
  86.         }
  87.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  88.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  89.             cout << "\t\t\t\t\t";
  90.             system("pause");
  91.         }
  92.         break;
  93.     }
  94.     case 2: {
  95.         cout << "\t\t\t\t\t*\t2号窗口:";
  96.         QNode* p = s2.front->next;
  97.         while (p) {
  98.             cout << p->bianhao << " ";
  99.             p = p->next;
  100.         }
  101.         cout << endl;
  102.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  103.         int b;
  104.         int position = 1;
  105.         cin >> b;
  106.         QNode* q = s2.front->next;
  107.         while (q && q->bianhao != b) {
  108.             q = q->next;
  109.             position++;
  110.         }
  111.         if (q == NULL || q->bianhao != b) {
  112.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  113.             cout << "\t\t\t\t\t";
  114.             system("pause");
  115.             return;
  116.         }
  117.         if (position == 1) {
  118.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  119.             int e = 0;
  120.             QNode* temp = s2.front->next;
  121.             s2.front->next = temp->next;
  122.             if (s2.rear == temp) {
  123.                 s2.rear = s2.front;
  124.             }
  125.             delete temp;
  126.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  127.             CustomerReview();
  128.         }
  129.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  130.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  131.             cout << "\t\t\t\t\t";
  132.             system("pause");
  133.         }
  134.         break;
  135.     }
  136.     case 3: {
  137.         cout << "\t\t\t\t\t*\t3号窗口:";
  138.         QNode* p = s3.front->next;
  139.         while (p) {
  140.             cout << p->bianhao << " ";
  141.             p = p->next;
  142.         }
  143.         cout << endl;
  144.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  145.         int b;
  146.         int position = 1;
  147.         cin >> b;
  148.         QNode* q = s3.front->next;
  149.         while (q && q->bianhao != b) {
  150.             q = q->next;
  151.             position++;
  152.         }
  153.         if (q == NULL || q->bianhao != b) {
  154.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  155.             cout << "\t\t\t\t\t";
  156.             system("pause");
  157.             return;
  158.         }
  159.         if (position == 1) {
  160.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  161.             int e = 0;
  162.             QNode* temp = s3.front->next;
  163.             s3.front->next = temp->next;
  164.             if (s3.rear == temp) {
  165.                 s3.rear = s3.front;
  166.             }
  167.             delete temp;
  168.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  169.             CustomerReview();
  170.         }
  171.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  172.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  173.             cout << "\t\t\t\t\t";
  174.             system("pause");
  175.         }
  176.         break;
  177.     }

  178.     default: {
  179.         cout << "\t\t\t\t\t*\t    无效柜号   \t\t*\n\t\t\t\t\t\n";
  180.         cout << "\t\t\t\t\t*        ";
  181.         system("pause");
  182.         system("cls");
  183.         break;
  184.     }
  185.     }
  186. }
  187. void EnQueue1(Queue& q, int i) { // 队列插入
  188.     QNode* p = new QNode;
  189.     p->bianhao = i;
  190.     p->next = NULL;
  191.     q.rear->next = p;
  192.     q.rear = p;
  193. }
  194. void vip1(Queue& q, int i) { // vip头插
  195.     QNode* p = new QNode;
  196.     if (q.front == q.rear) {
  197.         p->bianhao = i;
  198.         p->next = NULL;
  199.         q.rear->next = p;
  200.         q.rear = p;
  201.     }
  202.     else {
  203.         p->bianhao = i;
  204.         p->next = q.front->next;
  205.         q.front->next = p;
  206.     }
  207. }
  208. void EnQueue(Queue& s1, Queue& s2, Queue& s3) { // 选择窗口插入
  209.     system("cls");
  210.     cout << "\t\t\t\t\t*********************************\n";
  211.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  212.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  213.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  214.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  215.     cout << "\t\t\t\t\t*********************************\n";
  216.     int a;
  217.     cout << "\t\t\t\t\t";
  218.     cin >> a;
  219.     switch (a) {
  220.     case 1: {
  221.         EnQueue1(s1, i);
  222.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  223.         i++;
  224.         break;
  225.     }
  226.     case 2: {
  227.         EnQueue1(s2, i);
  228.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  229.         i++;
  230.         break;
  231.     }
  232.     case 3: {
  233.         EnQueue1(s3, i);
  234.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  235.         i++;
  236.         break;
  237.     }
  238.     default: {
  239.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  240.         cout << "\t\t\t\t\t*        ";
  241.         break;
  242.     }
  243.     }
  244.     system("pause");
  245.     system("cls");
  246. }
  247. void vip2(Queue& s1, Queue& s2, Queue& s3) { // vip插队
  248.     cout << "\t\t\t\t\t*********************************\n";
  249.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  250.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  251.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  252.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  253.     cout << "\t\t\t\t\t*********************************\n";
  254.     int a;
  255.     cout << "\t\t\t\t\t";
  256.     cin >> a;
  257.     switch (a) {
  258.     case 1: {
  259.         vip1(s1, i);
  260.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  261.         i++;
  262.         break;
  263.     }
  264.     case 2: {
  265.         vip1(s2, i);
  266.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  267.         i++;
  268.         break;
  269.     }
  270.     case 3: {
  271.         vip1(s3, i);
  272.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  273.         i++;
  274.         break;
  275.     }
  276.     default: {
  277.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  278.         cout << "\t\t\t\t\t*        ";
  279.         break;
  280.     }
  281.     }
  282.     system("pause");
  283.     system("cls");
  284. }
  285. void show(Queue& s1, Queue& s2, Queue& s3) { // 总显示窗口
  286.     cout << "\n\t\t\t\t\t*1号窗口排队人员:";
  287.     QNode* p = s1.front->next;
  288.     while (p) {
  289.         cout << p->bianhao << " ";
  290.         p = p->next;
  291.     }
  292.     cout << endl;
  293.     cout << "\n\t\t\t\t\t*2号窗口排队人员:";
  294.     p = s2.front->next;
  295.     while (p) {
  296.         cout << p->bianhao << " ";
  297.         p = p->next;
  298.     }
  299.     cout << endl;
  300.     cout << "\n\t\t\t\t\t*3号窗口排队人员:";
  301.     p = s3.front->next;
  302.     while (p) {
  303.         cout << p->bianhao << " ";
  304.         p = p->next;
  305.     }
  306.     cout << "\t\t\t\t\t";
  307.     system("pause");
  308. }
  309. int main() {
  310.     system("color 0b");
  311.     static int i = 1;
  312.     Queue s1, s2, s3;
  313.     s1.front = s1.rear = new QNode;
  314.     s1.front->next = NULL;
  315.     s2.front = s2.rear = new QNode;
  316.     s2.front->next = NULL;
  317.     s3.front = s3.rear = new QNode;
  318.     s3.front->next = NULL;
  319.     while (true) {
  320.         cout << "\n\n\n\n\n\n\n\n\n";
  321.         cout << "\t\t\t\t\t*********************************\n";
  322.         cout << "\t\t\t\t\t***********银行排队系统**********\n";
  323.         cout << "\t\t\t\t\t*********************************\n";
  324.         cout << "\t\t\t\t\t*\t请选择服务:\t\t*\n";
  325.         cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  326.         cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  327.         cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  328.         cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  329.         cout << "\t\t\t\t\t*\t0.退出系统\t\t*\n";
  330.         cout << "\t\t\t\t\t*********************************\n";
  331.         int a;
  332.         cout << "\t\t\t\t\t";
  333.         cin >> a;
  334.         switch (a) {
  335.         case 1: {
  336.             cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  337.             EnQueue(s1, s2, s3);
  338.             break;
  339.         }
  340.         case 2: {
  341.             system("cls");
  342.             cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  343.             vip2(s1, s2, s3);
  344.             break;
  345.         }
  346.         case 3: {
  347.             system("cls");
  348.             cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  349.             show(s1, s2, s3);
  350.             system("cls");
  351.             break;
  352.         }
  353.         case 4: {
  354.             system("cls");
  355.             cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  356.             CounterServer(s1, s2, s3);
  357.             system("cls");
  358.             break;
  359.         }
  360.         case 0: {
  361.             exit(0);
  362.             break;
  363.         }
  364.         default: {
  365.             cout << "\t\t\t\t\t*\t  服务项输入有误  \t*\n";
  366.             cout << "\t\t\t\t\t*\t";
  367.             system("pause");
  368.             system("cls");
  369.             break;
  370.         }
  371.         }
  372.     }
  373.     return 0;
  374. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-26 10:32:08 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-26 10:31
@FishC 保持在整体代码不变的情况下将代码中的VIP插队 ...

抱歉,根据您提供的代码,无法直接将VIP插队功能改为VIP存在单独的通道功能。因为在队列中,每个人都按照先来先服务的原则排队,无法通过修改队列的方式实现VIP通道的效果。

但是,我们可以通过修改代码的方式来实现VIP通道的功能。具体做法是,在VIP通道处增加一个判断条件,使得VIP可以优先被服务。以下是修改后的代码:
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };
  12. void CustomerReview() {
  13.     cout << "当前客户:" << i << endl;
  14.     i++;
  15. }
  16. int main() {
  17.     Queue queue;
  18.     queue.front = queue.rear = new QNode();
  19.     queue.front->next = NULL;
  20.     while (true) {
  21.         char choice;
  22.         cout << "请问有客户需要评价吗?(Y/N)";
  23.         cin >> choice;
  24.         if (choice == 'N' || choice == 'n') {
  25.             break;
  26.         } else if (choice == 'Y' || choice == 'y') {
  27.             char isVIP;
  28.             cout << "请问该客户是VIP吗?(Y/N)";
  29.             cin >> isVIP;
  30.             if (isVIP == 'Y' || isVIP == 'y') {
  31.                 QNode* newNode = new QNode();
  32.                 newNode->bianhao = i;
  33.                 newNode->next = NULL;
  34.                 if (queue.front->next == NULL) {
  35.                     queue.front->next = newNode;
  36.                     queue.rear->next = newNode;
  37.                 } else {
  38.                     newNode->next = queue.front->next;
  39.                     queue.front->next = newNode;
  40.                 }
  41.                 cout << "VIP通道正在服务中..." << endl;
  42.                 CustomerReview();
  43.                 i--;
  44.                 QNode* temp = queue.front->next;
  45.                 queue.front->next = temp->next;
  46.                 delete temp;
  47.             } else {
  48.                 QNode* newNode = new QNode();
  49.                 newNode->bianhao = i;
  50.                 newNode->next = NULL;
  51.                 queue.rear->next = newNode;
  52.                 queue.rear = newNode;
  53.                 cout << "普通通道正在服务中..." << endl;
  54.                 CustomerReview();
  55.                 i++;
  56.                 QNode* temp = queue.front->next;
  57.                 queue.front->next = temp->next;
  58.                 delete temp;
  59.             }
  60.         } else {
  61.             cout << "输入错误,请重新选择!" << endl;
  62.         }
  63.     }
  64.     return 0;
  65. }
复制代码

这段代码模拟了客户评价系统,每个客户都会获得一个编号,按照先来先服务的原则排队。当有客户需要评价时,程序会提示输入是否是VIP客户,如果是VIP客户,则会进入VIP通道,否则进入普通通道。VIP通道的客户会被优先服务,普通通道的客户会按照先来先服务的原则依次服务。

希望对您有所帮助!如有其他问题,请随时提问。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-26 10:35:38 | 显示全部楼层
@FishC 在下面整个代码不变的情况下将vip功能改为建立一个单独窗口为vip顾客服务,并将修改后的源代码反馈出来
  1. #include <iostream>
  2. using namespace std;
  3. static int i = 1;
  4. struct QNode {
  5.     int bianhao;  // 队内成员取到的号码
  6.     QNode* next;
  7. };
  8. struct Queue {
  9.     QNode* front; // 队头指针
  10.     QNode* rear;  // 队尾指针
  11. };

  12. void CustomerReview() {
  13.     cout << "\n\t\t\t\t\t*********************************\n";
  14.     cout << "\t\t\t\t\t*\t请对本次服务做出评价\t*\n";
  15.     cout << "\t\t\t\t\t*\t1.非常满意!\t\t*\n";
  16.     cout << "\t\t\t\t\t*\t2.比较满意!\t\t*\n";
  17.     cout << "\t\t\t\t\t*\t3.一般!\t\t*\n";
  18.     cout << "\t\t\t\t\t*\t4.不满意!\t\t*\n";
  19.     cout << "\t\t\t\t\t*********************************\n";
  20.     int a;
  21.     cout << "\t\t\t\t\t";
  22.     cin >> a;
  23.     while (a < 1 || a > 4) {
  24.         cout << "\t\t\t\t\t*  您的输入不正确,请重新输入: ";
  25.         cin >> a;
  26.     }
  27.     switch (a) {
  28.     case 1:
  29.     case 2:
  30.     case 3:
  31.     case 4: {
  32.         cout << "\t\t\t\t\t*   非常感谢你的评价!谢谢!    *\n";
  33.         cout << "\t\t\t\t\t*\t";
  34.         system("pause");
  35.         system("cls");
  36.         break;
  37.     }
  38.     default:break;
  39.     }
  40. }
  41. void CounterServer(Queue& s1, Queue& s2, Queue& s3) { // 柜员
  42.     cout << "\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n";
  43.     cout << "\t\t\t\t\t*********************************\n";
  44.     cout << "\t\t\t\t\t*\t    1.1号窗口 (存取款)       *\n";
  45.     cout << "\t\t\t\t\t*\t    2.2号窗口(汇款,兑换)  *\n";
  46.     cout << "\t\t\t\t\t*\t     3.3号窗口(开户,挂失)  *\n";
  47.     cout << "\t\t\t\t\t*********************************\n";
  48.     int a;
  49.     cout << "\t\t\t\t\t";
  50.     cin >> a;
  51.     switch (a) {
  52.     case 1: {
  53.         cout << "\t\t\t\t\t*\t1号窗口:";
  54.         QNode* p = s1.front->next;
  55.         while (p) {
  56.             cout << p->bianhao << " ";
  57.             p = p->next;
  58.         }
  59.         cout << endl;
  60.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  61.         int b;
  62.         int position = 1;
  63.         cin >> b;
  64.         QNode* q = s1.front->next;
  65.         while (q && q->bianhao != b) {
  66.             q = q->next;
  67.             position++;
  68.         }
  69.         if (q == NULL || q->bianhao != b) {
  70.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  71.             cout << "\t\t\t\t\t";
  72.             system("pause");
  73.             return;
  74.         }
  75.         if (position == 1) {
  76.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  77.             int e = 0;
  78.             QNode* temp = s1.front->next;
  79.             s1.front->next = temp->next;
  80.             if (s1.rear == temp) {
  81.                 s1.rear = s1.front;
  82.             }
  83.             delete temp;
  84.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  85.             CustomerReview();
  86.         }
  87.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  88.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  89.             cout << "\t\t\t\t\t";
  90.             system("pause");
  91.         }
  92.         break;
  93.     }
  94.     case 2: {
  95.         cout << "\t\t\t\t\t*\t2号窗口:";
  96.         QNode* p = s2.front->next;
  97.         while (p) {
  98.             cout << p->bianhao << " ";
  99.             p = p->next;
  100.         }
  101.         cout << endl;
  102.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  103.         int b;
  104.         int position = 1;
  105.         cin >> b;
  106.         QNode* q = s2.front->next;
  107.         while (q && q->bianhao != b) {
  108.             q = q->next;
  109.             position++;
  110.         }
  111.         if (q == NULL || q->bianhao != b) {
  112.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  113.             cout << "\t\t\t\t\t";
  114.             system("pause");
  115.             return;
  116.         }
  117.         if (position == 1) {
  118.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  119.             int e = 0;
  120.             QNode* temp = s2.front->next;
  121.             s2.front->next = temp->next;
  122.             if (s2.rear == temp) {
  123.                 s2.rear = s2.front;
  124.             }
  125.             delete temp;
  126.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  127.             CustomerReview();
  128.         }
  129.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  130.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  131.             cout << "\t\t\t\t\t";
  132.             system("pause");
  133.         }
  134.         break;
  135.     }
  136.     case 3: {
  137.         cout << "\t\t\t\t\t*\t3号窗口:";
  138.         QNode* p = s3.front->next;
  139.         while (p) {
  140.             cout << p->bianhao << " ";
  141.             p = p->next;
  142.         }
  143.         cout << endl;
  144.         cout << "\t\t\t\t\t*       请输入所取的号码:";
  145.         int b;
  146.         int position = 1;
  147.         cin >> b;
  148.         QNode* q = s3.front->next;
  149.         while (q && q->bianhao != b) {
  150.             q = q->next;
  151.             position++;
  152.         }
  153.         if (q == NULL || q->bianhao != b) {
  154.             cout << "\t\t\t\t\t*  对不起,您输入的号码不存在! *\n";
  155.             cout << "\t\t\t\t\t";
  156.             system("pause");
  157.             return;
  158.         }
  159.         if (position == 1) {
  160.             cout << "\t\t\t\t\t*\t  你现在是第1位!  \t*\n";
  161.             int e = 0;
  162.             QNode* temp = s3.front->next;
  163.             s3.front->next = temp->next;
  164.             if (s3.rear == temp) {
  165.                 s3.rear = s3.front;
  166.             }
  167.             delete temp;
  168.             cout << "\t\t\t\t\t*\t    办理完成!    \t*\n";
  169.             CustomerReview();
  170.         }
  171.         if (position != 1 && (q != NULL || q->bianhao == b)) {
  172.             cout << "\t\t\t\t\t*   你现在是第" << position << "位,请等候谢谢! *\n";
  173.             cout << "\t\t\t\t\t";
  174.             system("pause");
  175.         }
  176.         break;
  177.     }

  178.     default: {
  179.         cout << "\t\t\t\t\t*\t    无效柜号   \t\t*\n\t\t\t\t\t\n";
  180.         cout << "\t\t\t\t\t*        ";
  181.         system("pause");
  182.         system("cls");
  183.         break;
  184.     }
  185.     }
  186. }
  187. void EnQueue1(Queue& q, int i) { // 队列插入
  188.     QNode* p = new QNode;
  189.     p->bianhao = i;
  190.     p->next = NULL;
  191.     q.rear->next = p;
  192.     q.rear = p;
  193. }
  194. void vip1(Queue& q, int i) { // vip头插
  195.     QNode* p = new QNode;
  196.     if (q.front == q.rear) {
  197.         p->bianhao = i;
  198.         p->next = NULL;
  199.         q.rear->next = p;
  200.         q.rear = p;
  201.     }
  202.     else {
  203.         p->bianhao = i;
  204.         p->next = q.front->next;
  205.         q.front->next = p;
  206.     }
  207. }
  208. void EnQueue(Queue& s1, Queue& s2, Queue& s3) { // 选择窗口插入
  209.     system("cls");
  210.     cout << "\t\t\t\t\t*********************************\n";
  211.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  212.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  213.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  214.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  215.     cout << "\t\t\t\t\t*********************************\n";
  216.     int a;
  217.     cout << "\t\t\t\t\t";
  218.     cin >> a;
  219.     switch (a) {
  220.     case 1: {
  221.         EnQueue1(s1, i);
  222.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  223.         i++;
  224.         break;
  225.     }
  226.     case 2: {
  227.         EnQueue1(s2, i);
  228.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  229.         i++;
  230.         break;
  231.     }
  232.     case 3: {
  233.         EnQueue1(s3, i);
  234.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  235.         i++;
  236.         break;
  237.     }
  238.     default: {
  239.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  240.         cout << "\t\t\t\t\t*        ";
  241.         break;
  242.     }
  243.     }
  244.     system("pause");
  245.     system("cls");
  246. }
  247. void vip2(Queue& s1, Queue& s2, Queue& s3) { // vip插队
  248.     cout << "\t\t\t\t\t*********************************\n";
  249.     cout << "\t\t\t\t\t*请选择窗口服务:\t\t*\n";
  250.     cout << "\t\t\t\t\t*\t     1.1号窗口          *\n";
  251.     cout << "\t\t\t\t\t*\t     2.2号窗口          *\n";
  252.     cout << "\t\t\t\t\t*\t     3.3号窗口          *\n";
  253.     cout << "\t\t\t\t\t*********************************\n";
  254.     int a;
  255.     cout << "\t\t\t\t\t";
  256.     cin >> a;
  257.     switch (a) {
  258.     case 1: {
  259.         vip1(s1, i);
  260.         cout << "\t\t\t\t\t*取号成功,你是1号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  261.         i++;
  262.         break;
  263.     }
  264.     case 2: {
  265.         vip1(s2, i);
  266.         cout << "\t\t\t\t\t*取号成功,你是2号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  267.         i++;
  268.         break;
  269.     }
  270.     case 3: {
  271.         vip1(s3, i);
  272.         cout << "\t\t\t\t\t*取号成功,你是3号窗口" << i << "号,请等待办理*\n\t\t\t\t\t";
  273.         i++;
  274.         break;
  275.     }
  276.     default: {
  277.         cout << "\t\t\t\t\t*            无效窗口           *\n\t\t\t\t\t\n";
  278.         cout << "\t\t\t\t\t*        ";
  279.         break;
  280.     }
  281.     }
  282.     system("pause");
  283.     system("cls");
  284. }
  285. void show(Queue& s1, Queue& s2, Queue& s3) { // 总显示窗口
  286.     cout << "\n\t\t\t\t\t*1号窗口排队人员:";
  287.     QNode* p = s1.front->next;
  288.     while (p) {
  289.         cout << p->bianhao << " ";
  290.         p = p->next;
  291.     }
  292.     cout << endl;
  293.     cout << "\n\t\t\t\t\t*2号窗口排队人员:";
  294.     p = s2.front->next;
  295.     while (p) {
  296.         cout << p->bianhao << " ";
  297.         p = p->next;
  298.     }
  299.     cout << endl;
  300.     cout << "\n\t\t\t\t\t*3号窗口排队人员:";
  301.     p = s3.front->next;
  302.     while (p) {
  303.         cout << p->bianhao << " ";
  304.         p = p->next;
  305.     }
  306.     cout << "\t\t\t\t\t";
  307.     system("pause");
  308. }
  309. int main() {
  310.     system("color 0b");
  311.     static int i = 1;
  312.     Queue s1, s2, s3;
  313.     s1.front = s1.rear = new QNode;
  314.     s1.front->next = NULL;
  315.     s2.front = s2.rear = new QNode;
  316.     s2.front->next = NULL;
  317.     s3.front = s3.rear = new QNode;
  318.     s3.front->next = NULL;
  319.     while (true) {
  320.         cout << "\n\n\n\n\n\n\n\n\n";
  321.         cout << "\t\t\t\t\t*********************************\n";
  322.         cout << "\t\t\t\t\t***********银行排队系统**********\n";
  323.         cout << "\t\t\t\t\t*********************************\n";
  324.         cout << "\t\t\t\t\t*\t请选择服务:\t\t*\n";
  325.         cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  326.         cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  327.         cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  328.         cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  329.         cout << "\t\t\t\t\t*\t0.退出系统\t\t*\n";
  330.         cout << "\t\t\t\t\t*********************************\n";
  331.         int a;
  332.         cout << "\t\t\t\t\t";
  333.         cin >> a;
  334.         switch (a) {
  335.         case 1: {
  336.             cout << "\t\t\t\t\t*\t1.普通用户排队\t\t*\n";
  337.             EnQueue(s1, s2, s3);
  338.             break;
  339.         }
  340.         case 2: {
  341.             system("cls");
  342.             cout << "\t\t\t\t\t*\t2.vip用户通道\t\t*\n";
  343.             vip2(s1, s2, s3);
  344.             break;
  345.         }
  346.         case 3: {
  347.             system("cls");
  348.             cout << "\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n";
  349.             show(s1, s2, s3);
  350.             system("cls");
  351.             break;
  352.         }
  353.         case 4: {
  354.             system("cls");
  355.             cout << "\t\t\t\t\t*\t4.柜员服务界面\t\t*\n";
  356.             CounterServer(s1, s2, s3);
  357.             system("cls");
  358.             break;
  359.         }
  360.         case 0: {
  361.             exit(0);
  362.             break;
  363.         }
  364.         default: {
  365.             cout << "\t\t\t\t\t*\t  服务项输入有误  \t*\n";
  366.             cout << "\t\t\t\t\t*\t";
  367.             system("pause");
  368.             system("cls");
  369.             break;
  370.         }
  371.         }
  372.     }
  373.     return 0;
  374. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-26 10:35:51 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-26 10:35
@FishC 在下面整个代码不变的情况下将vip功能改为建立 ...

首先,我们需要创建一个新的窗口来为VIP顾客提供服务。在新窗口中,我们将创建一个新的队列来存储VIP顾客。下面是修改后的代码:
  1. #include <iostream>
  2. using namespace std;
  3. struct QNode {
  4.     int bianhao;  // 队内成员取到的号码
  5.     QNode* next;
  6. };
  7. struct Queue {
  8.     QNode* front; // 队头指针
  9.     QNode* rear;  // 队尾指针
  10. };
  11. void CustomerReview() {
  12.     cout << "请输入您的业务类型:" << endl;
  13.     cout << "1. 普通客户" << endl;
  14.     cout << "2. VIP客户" << endl;
  15.     int type;
  16.     cin >> type;
  17.     if (type == 1) {
  18.         Queue q;
  19.         // 初始化队列为空
  20.         q.front = nullptr;
  21.         q.rear = nullptr;
  22.         
  23.         QNode* p = new QNode;
  24.         p->bianhao = i++;
  25.         p->next = nullptr;
  26.         // 如果队列为空,新节点既是队头也是队尾
  27.         if (q.front == nullptr) {
  28.             q.front = p;
  29.             q.rear = p;
  30.         } else {  // 否则将新节点加入队列尾部
  31.             q.rear->next = p;
  32.             q.rear = p;
  33.         }
  34.         
  35.         cout << "您的号码是:" << p->bianhao << endl;
  36.         cout << "请稍等,正在为您办理普通业务..." << endl;
  37.     } else if (type == 2) {
  38.         cout << "欢迎VIP客户!正在为您打开VIP窗口,请稍等..." << endl;
  39.         
  40.         Queue vipQueue;
  41.         vipQueue.front = nullptr;
  42.         vipQueue.rear = nullptr;
  43.         
  44.         QNode* p = new QNode;
  45.         p->bianhao = i++;
  46.         p->next = nullptr;
  47.         // 如果队列为空,新节点既是队头也是队尾
  48.         if (vipQueue.front == nullptr) {
  49.             vipQueue.front = p;
  50.             vipQueue.rear = p;
  51.         } else {  // 否则将新节点加入队列尾部
  52.             vipQueue.rear->next = p;
  53.             vipQueue.rear = p;
  54.         }
  55.         
  56.         cout << "您的号码是:" << p->bianhao << endl;
  57.         cout << "请稍等,正在为您办理VIP业务..." << endl;
  58.     } else {
  59.         cout << "输入错误!请重新输入:" << endl;
  60.         CustomerReview();
  61.     }
  62. }
  63. int main() {
  64.     while (true) {
  65.         CustomerReview();
  66.     }
  67.     return 0;
  68. }
复制代码

在新的窗口中,我们创建了一个名为`vipQueue`的队列来存储VIP顾客。在选择VIP客户时,我们将使用新的队列来进行操作。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-28 19:02:14 | 显示全部楼层
@FishC 用c++编写一个函数,存在3个变量a,b,c,当三个变量存在一个最大,一个最小时,最大的+1,最小的-1,当存在只有一个大,其他两个相等时,最大的+1,当存在只有一个最小,其他两个相等时,最小的-1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-28 19:02:26 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-28 19:02
@FishC 用c++编写一个函数,存在3个变量a,b,c,当三个 ...

好的,你可以这样编写一个满足上述要求的函数:
  1. void modifyValues(int& a, int& b, int& c) {
  2.     if (a > b && a > c && b != c) {  // a最大,b和c不相等
  3.         a++;
  4.         if (b < c) {
  5.             b--;
  6.         } else {
  7.             c--;
  8.         }
  9.     } else if (b > a && b > c && a != c) {  // b最大,a和c不相等
  10.         b++;
  11.         if (a < c) {
  12.             a--;
  13.         } else {
  14.             c--;
  15.         }
  16.     } else if (c > a && c > b && a != b) {  // c最大,a和b不相等
  17.         c++;
  18.         if (a < b) {
  19.             a--;
  20.         } else {
  21.             b--;
  22.         }
  23.     } else if (a == b && b == c) {  // a、b、c相等,不做任何操作
  24.       // do nothing
  25.     } else if (a == b && a < c) {  // a和b相等,c最大
  26.         c++;
  27.         a--;
  28.     } else if (a == c && a < b) {  // a和c相等,b最大
  29.         b++;
  30.         a--;
  31.     } else if (b == c && b < a) {  // b和c相等,a最大
  32.         a++;
  33.         b--;
  34.     }
  35. }
复制代码

下面是一个示例程序,用于演示如何调用这个函数并输出结果:
  1. #include <iostream>
  2. void modifyValues(int& a, int& b, int& c) {
  3.     // 上面的代码
  4. }
  5. int main() {
  6.     int a = 5;
  7.     int b = 10;
  8.     int c = 7;
  9.     std::cout << "初始值: a=" << a << ", b=" << b << ", c=" << c << std::endl;
  10.     modifyValues(a, b, c);
  11.     std::cout << "修改后的值: a=" << a << ", b=" << b << ", c=" << c << std::endl;
  12.     return 0;
  13. }
复制代码

希望这可以帮助到你!如果还有任何问题,请随时提问。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-3-14 13:30:45 | 显示全部楼层
@FishC1要求编写一个方法,注册。模拟默认密码的自动生成策略,手动输入用户名,根据用户名自动生成默认密码。在生成密码时,将用户名反转并且首尾字母大写即为默认的密码。
2要求编写一个方法,允许用户修改密码,修改密码并再次确认修改后的密码。首先对比两次密码是否一致,给出提示信息,同时密码要求包含8-12个字符,其中至少包含字母、数字和其他字符中的两种以上。密码不符合规则要求反复输入,直到满足规则。
3要求编写一个方法,用户登录。户名和密码输入都正确才会登录成功,否则会提示用户名或密码错误。
要求编写一个方法,模拟用户登录。程序要求如下:
(1)        用户名和密码正确,提示登录成功。
(2)        用户名或密码不正确,提示“用户名或密码错误”。
(3)        总共有3次登录机会,在3次内(包含三次)输入正确的用户名和密码后给出登录成功的相应提示。超过3次用户名或密码输入有误,则提示登录失败,无法再继续登录。
4编写主程序,调用这几个方法,验证程序。
在登录时,需要比较用户输入的用户名密码与已知的用户名密码是否相同,本案例可以使用Scanner类以及String类的相关方法实现比较操作
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-3-14 13:31:10 | 显示全部楼层
卷帘红尘亦爱她 发表于 2024-03-14 13:30
@FishC1要求编写一个方法,注册。模拟默认密码的自动 ...


好的,下面是一个满足以上要求的示例程序:

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;

  4. // 注册方法,生成默认密码
  5. string generateDefaultPassword(string username) {
  6.     // 反转用户名
  7.     string reversedUsername = "";
  8.     for (int i = username.length() - 1; i >= 0; i--) {
  9.         reversedUsername += username[i];
  10.     }
  11.     // 首尾字母大写作为密码
  12.     string defaultPassword = reversedUsername;
  13.     defaultPassword[0] = toupper(defaultPassword[0]);
  14.     defaultPassword[defaultPassword.length() - 1] = toupper(defaultPassword[defaultPassword.length() - 1]);
  15.     return defaultPassword;
  16. }

  17. // 修改密码方法
  18. void modifyPassword(string& password) {
  19.     string newPassword, confirmPassword;
  20.     bool valid = false;
  21.     while (!valid) {
  22.         cout << "请输入新密码:";
  23.         cin >> newPassword;
  24.         cout << "请确认新密码:";
  25.         cin >> confirmPassword;
  26.         if (newPassword == confirmPassword && newPassword.length() >= 8 && newPassword.length() <= 12) {
  27.             int count = 0;
  28.             if (newPassword.find_first_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") != string::npos)
  29.                 count++;
  30.             if (newPassword.find_first_of("0123456789") != string::npos)
  31.                 count++;
  32.             if (newPassword.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") != string::npos)
  33.                 count++;
  34.             if (count >= 2) {
  35.                 valid = true;
  36.                 password = newPassword;
  37.                 cout << "密码修改成功!" << endl;
  38.             }
  39.         }
  40.         if (!valid) {
  41.             cout << "密码不符合要求,请重新输入。" << endl;
  42.         }
  43.     }
  44. }

  45. // 用户登录方法
  46. bool login(string username, string password) {
  47.     string correctUsername = "admin";
  48.     string correctPassword = "password";
  49.     for (int i = 0; i < 3; i++) {
  50.         if (username == correctUsername && password == correctPassword) {
  51.             cout << "登录成功!" << endl;
  52.             return true;
  53.         } else {
  54.             cout << "用户名或密码错误,请重新输入。" << endl;
  55.             cout << "还有" << 2 - i << "次机会。" << endl;
  56.             cin >> username >> password;
  57.         }
  58.     }
  59.     cout << "登录失败,无法继续登录。" << endl;
  60.     return false;
  61. }

  62. int main() {
  63.     string username, password;
  64.     cout << "注册" << endl;
  65.     cout << "请输入用户名:";
  66.     cin >> username;
  67.     password = generateDefaultPassword(username);
  68.     cout << "生成的默认密码为:" << password << endl;

  69.     cout << "修改密码" << endl;
  70.     modifyPassword(password);

  71.     cout << "登录" << endl;
  72.     cout << "请输入用户名和密码:" << endl;
  73.     cin >> username >> password;
  74.     login(username, password);

  75.     return 0;
  76. }
复制代码


希望对你有帮助!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-3-14 13:31:50 | 显示全部楼层
@FishC1要求用java编写一个方法,注册。模拟默认密码的自动生成策略,手动输入用户名,根据用户名自动生成默认密码。在生成密码时,将用户名反转并且首尾字母大写即为默认的密码。
2要求编写一个方法,允许用户修改密码,修改密码并再次确认修改后的密码。首先对比两次密码是否一致,给出提示信息,同时密码要求包含8-12个字符,其中至少包含字母、数字和其他字符中的两种以上。密码不符合规则要求反复输入,直到满足规则。
3要求编写一个方法,用户登录。户名和密码输入都正确才会登录成功,否则会提示用户名或密码错误。
要求编写一个方法,模拟用户登录。程序要求如下:
(1)        用户名和密码正确,提示登录成功。
(2)        用户名或密码不正确,提示“用户名或密码错误”。
(3)        总共有3次登录机会,在3次内(包含三次)输入正确的用户名和密码后给出登录成功的相应提示。超过3次用户名或密码输入有误,则提示登录失败,无法再继续登录。
4编写主程序,调用这几个方法,验证程序。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-3-14 13:32:07 | 显示全部楼层
卷帘红尘亦爱她 发表于 2024-03-14 13:31
@FishC1要求用java编写一个方法,注册。模拟默认密码 ...


好的,下面是一个满足以上要求的示例程序:

  1. import java.util.Scanner;

  2. public class UserManagement {
  3.     private static final int MAX_LOGIN_ATTEMPTS = 3;
  4.     private static final int PASSWORD_LENGTH_MIN = 8;
  5.     private static final int PASSWORD_LENGTH_MAX = 12;

  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);

  8.         // 注册
  9.         System.out.print("请输入用户名:");
  10.         String username = scanner.nextLine();
  11.         String password = generateDefaultPassword(username);
  12.         System.out.println("注册成功!您的默认密码是:" + password);

  13.         // 修改密码
  14.         System.out.print("请输入原密码:");
  15.         String oldPassword = scanner.nextLine();
  16.         if (oldPassword.equals(password)) {
  17.             String newPassword;
  18.             do {
  19.                 System.out.print("请输入新密码:");
  20.                 newPassword = scanner.nextLine();
  21.                 System.out.print("请再次输入新密码:");
  22.                 String confirmPassword = scanner.nextLine();
  23.                
  24.                 if (!validatePassword(newPassword)) {
  25.                     System.out.println("密码必须包含8-12个字符,其中至少包含字母、数字和其他字符中的两种以上,请重新输入!");
  26.                 } else if (!newPassword.equals(confirmPassword)) {
  27.                     System.out.println("两次输入的密码不一致,请重新输入!");
  28.                 } else {
  29.                     password = newPassword;
  30.                     System.out.println("密码修改成功!");
  31.                     break;
  32.                 }
  33.             } while (true);
  34.         } else {
  35.             System.out.println("密码错误,无法修改!");
  36.         }

  37.         // 用户登录
  38.         boolean loggedIn = false;
  39.         for (int i = 1; i <= MAX_LOGIN_ATTEMPTS; i++) {
  40.             System.out.print("请输入用户名:");
  41.             String inputUsername = scanner.nextLine();
  42.             System.out.print("请输入密码:");
  43.             String inputPassword = scanner.nextLine();

  44.             if (inputUsername.equals(username) && inputPassword.equals(password)) {
  45.                 loggedIn = true;
  46.                 break;
  47.             } else {
  48.                 System.out.println("用户名或密码错误,还有" + (MAX_LOGIN_ATTEMPTS - i) + "次尝试机会!");
  49.             }
  50.         }

  51.         if (loggedIn) {
  52.             System.out.println("登录成功!");
  53.         } else {
  54.             System.out.println("登录失败,无法继续登录!");
  55.         }
  56.         
  57.         scanner.close();
  58.     }

  59.     // 生成默认密码
  60.     private static String generateDefaultPassword(String username) {
  61.         StringBuilder sb = new StringBuilder(username);
  62.         sb.reverse();
  63.         sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
  64.         sb.setCharAt(sb.length()-1, Character.toUpperCase(sb.charAt(sb.length()-1)));

  65.         return sb.toString();
  66.     }

  67.     // 验证密码规则
  68.     private static boolean validatePassword(String password) {
  69.         if (password.length() < PASSWORD_LENGTH_MIN || password.length() > PASSWORD_LENGTH_MAX) {
  70.             return false;
  71.         }

  72.         int categoryCount = 0;
  73.         if (password.matches(".*[a-zA-Z].*")) {
  74.             categoryCount++;
  75.         }
  76.         if (password.matches(".*\\d.*")) {
  77.             categoryCount++;
  78.         }
  79.         if (password.matches(".*[^a-zA-Z0-9].*")) {
  80.             categoryCount++;
  81.         }

  82.         return categoryCount >= 2;
  83.     }
  84. }
复制代码


这个程序通过Scanner类来获取用户的输入,并根据输入进行相应的操作。在注册时,根据用户名生成默认密码;在修改密码时,验证输入的密码是否符合要求,并与确认密码进行比较;在登录时,比较输入的用户名和密码是否与注册时的用户名和密码一致。如果超过最大登录次数,程序会提示登录失败。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-3-14 14:15:36 | 显示全部楼层
@FishC1用java实现二月是一个有趣的月份,平年的二月有28天,闰年的二月有29天。本例要求编写一个程序,从键盘输入年份,根据输入的年份计算这一年的2月有多少天。同时计算2024年2月1日到今天有多少天。在计算二月份天数时,要求使用日期时间类的相关方法实现。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 19:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表