窗口排队系统c++要求:1窗口应有编号,业务类型,排队队列等属性2窗口数量无限制3窗口可以动态增加或删除,但存在排队的窗口不能被删除4窗口业务状态支持暂停,暂停时该窗口不再接受顾客排队5暂停的窗口支持业务恢复
时间: 2023-07-19 17:07:40 浏览: 132
以下是一个简单的窗口排队系统的C++代码,符合您的要求:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 定义业务类型枚举
enum ServiceType {
TYPE1,
TYPE2,
TYPE3
};
// 定义窗口类
class Window {
public:
Window(int id, ServiceType type) {
this->id = id;
this->type = type;
this->isPaused = false;
}
// 获取窗口属性
int getId() {
return id;
}
ServiceType getType() {
return type;
}
bool getPaused() {
return isPaused;
}
// 窗口业务状态控制
void pause() {
isPaused = true;
}
void resume() {
isPaused = false;
}
private:
int id; // 窗口编号
ServiceType type; // 业务类型
bool isPaused; // 窗口是否暂停服务
};
// 定义排队队列类
class Queue {
public:
Queue(ServiceType type) {
this->type = type;
}
// 添加窗口到队列
void addWindow(Window* window) {
windows.push_back(window);
}
// 获取队列属性
ServiceType getType() {
return type;
}
int getSize() {
return windows.size();
}
// 获取队列中等待服务的窗口
Window* getNextWindow() {
for (auto it = windows.begin(); it != windows.end(); it++) {
if (!(*it)->getPaused()) {
return *it;
}
}
return nullptr;
}
// 从队列中删除窗口
void removeWindow(Window* window) {
for (auto it = windows.begin(); it != windows.end(); it++) {
if (*it == window) {
windows.erase(it);
break;
}
}
}
private:
ServiceType type; // 业务类型
vector<Window*> windows; // 窗口队列
};
// 定义窗口管理类
class WindowManager {
public:
// 动态添加窗口
void addWindow(ServiceType type) {
int id = getLastWindowId() + 1;
Window* window = new Window(id, type);
windows.push_back(window);
getQueue(type)->addWindow(window);
}
// 动态删除窗口
void removeWindow(Window* window) {
if (!window->getPaused()) {
getQueue(window->getType())->removeWindow(window);
for (auto it = windows.begin(); it != windows.end(); it++) {
if (*it == window) {
windows.erase(it);
break;
}
}
delete window;
}
}
// 获取所有窗口
vector<Window*> getAllWindows() {
return windows;
}
// 获取所有队列
vector<Queue*> getAllQueues() {
return queues;
}
// 业务暂停
void pause(Window* window) {
if (!window->getPaused()) {
window->pause();
getQueue(window->getType())->removeWindow(window);
}
}
// 业务恢复
void resume(Window* window) {
if (window->getPaused()) {
window->resume();
getQueue(window->getType())->addWindow(window);
}
}
private:
vector<Window*> windows; // 窗口列表
vector<Queue*> queues; // 队列列表
// 获取上一个窗口的编号
int getLastWindowId() {
if (windows.empty()) {
return 0;
}
else {
return windows.back()->getId();
}
}
// 获取业务类型对应的队列
Queue* getQueue(ServiceType type) {
for (auto it = queues.begin(); it != queues.end(); it++) {
if ((*it)->getType() == type) {
return *it;
}
}
Queue* queue = new Queue(type);
queues.push_back(queue);
return queue;
}
};
int main() {
WindowManager wm;
// 添加窗口
wm.addWindow(TYPE1);
wm.addWindow(TYPE2);
wm.addWindow(TYPE3);
// 业务暂停
vector<Window*> windows = wm.getAllWindows();
wm.pause(windows[0]);
wm.pause(windows[1]);
// 业务恢复
wm.resume(windows[1]);
// 删除窗口
wm.removeWindow(windows[0]);
// 输出所有窗口和队列的属性
windows = wm.getAllWindows();
for (auto it = windows.begin(); it != windows.end(); it++) {
cout << "Window " << (*it)->getId() << ": Type " << (*it)->getType() << ", Paused " << (*it)->getPaused() << endl;
}
vector<Queue*> queues = wm.getAllQueues();
for (auto it = queues.begin(); it != queues.end(); it++) {
cout << "Queue Type " << (*it)->getType() << ": Size " << (*it)->getSize() << endl;
}
return 0;
}
```
阅读全文