窗口排队系统c++要求:1窗口应有编号,业务类型,排队队列等属性2窗口数量无限
时间: 2023-11-30 17:02:17 浏览: 37
以下是一个简单的窗口排队系统的C++代码示例:
```cpp
#include <iostream>
#include <queue>
#include <string>
using namespace std;
// 窗口类
class Window {
public:
int id;
string type;
queue<string> queueList;
Window() {
id = 0;
type = "";
}
Window(int id, string type) {
this->id = id;
this->type = type;
}
// 客户加入排队队列
void addCustomer(string customer) {
queueList.push(customer);
}
// 客户离开排队队列
void removeCustomer() {
if (!queueList.empty()) {
queueList.pop();
}
}
// 显示队列状态
void displayQueue() {
cout << "窗口" << id << "(" << type << ")的排队队列:" << endl;
if (queueList.empty()) {
cout << "当前队列为空!" << endl;
} else {
queue<string> temp = queueList;
while (!temp.empty()) {
cout << temp.front() << " ";
temp.pop();
}
cout << endl;
}
}
};
int main() {
// 创建窗口
vector<Window> windows;
for (int i = 1; ; i++) {
string type;
cout << "请输入窗口" << i << "的业务类型(输入q结束):";
cin >> type;
if (type == "q") {
break;
}
Window window(i, type);
windows.push_back(window);
}
// 客户排队
while (true) {
int windowId;
string customer;
cout << "请输入需要排队的窗口编号(输入0结束):";
cin >> windowId;
if (windowId == 0) {
break;
}
cout << "请输入客户姓名:";
cin >> customer;
if (windowId > 0 && windowId <= windows.size()) {
windows[windowId - 1].addCustomer(customer);
cout << "客户已成功加入窗口" << windowId << "的排队队列!" << endl;
} else {
cout << "窗口编号错误,请重新输入!" << endl;
}
}
// 显示各个窗口的队列状态
for (int i = 0; i < windows.size(); i++) {
windows[i].displayQueue();
}
// 客户离开排队队列
while (true) {
int windowId;
cout << "请输入需要处理的窗口编号(输入0结束):";
cin >> windowId;
if (windowId == 0) {
break;
}
if (windowId > 0 && windowId <= windows.size()) {
windows[windowId - 1].removeCustomer();
cout << "客户已成功离开窗口" << windowId << "的排队队列!" << endl;
} else {
cout << "窗口编号错误,请重新输入!" << endl;
}
}
// 显示各个窗口的队列状态
for (int i = 0; i < windows.size(); i++) {
windows[i].displayQueue();
}
return 0;
}
```
在这个示例中,我们定义了一个`Window`类表示窗口,其中包含窗口的编号、业务类型和排队队列等属性。客户可以通过输入窗口编号和姓名来加入排队队列,也可以通过输入窗口编号来离开排队队列。程序会根据窗口的数量动态创建窗口,并可以无限扩展。