1.实现功能
- 用户进入队列排队等待
- 银行窗口办理业务
- VIP客户及公务客户优先办理
- VIP及公务窗口闲置时可以为普通用户办理业务
2.注意
- 为节约空间,仅在博客中提供部分代码
- 本程序采用手动运行方式而非随时间自动运行,不过很容易就可以改成自动运行
3.代码部分
#include<iostream>
#include<windows.h>
#include<conio.h>
using namespace std;
int alltime=0; //程序总运行时间
struct Node{
int data;
Node *next;
};
class Lqueue{
//采用链式队列
private:
Node *front,*rear;
int time;
public:
int len=0;
Lqueue(){
front=rear=NULL;
time=0;
}
bool enqueue(int num);
bool dequeue(int &num);
void clear();
void show();
~Lqueue(){
clear();
}
}; //链式队列函数实现很容易,就不贴出来了
以下为用户类的定义及三种用户的定义
class User{
public:
int type;
int waittime; //等待时间
int sertime=0; //已服务时间
int id=0; //用户编码
};
class Nuser:public User{
//Normal User
public:
Nuser(){
type=1;
waittime=0;
sertime=0;
}
};
class Vuser:public User{
//VIP User
public:
Vuser(){
type=2;
waittime=0;
sertime=0;
}
};
class Ouser:public User{
//公务客户
public:
Ouser(){
type=3;
waittime=0;
sertime=0;
}
};
以下为银行窗口类及三种不同窗口
class Bankwindow{
public:
int full=0;//0为空,1为满
int start=0; //start=0表示未开始服务,=1表示开始服务
int starttime=0;
int servetime(); //返回办理业务所用时间
void serve(); //办理业务
};
void Bankwindow::serve(){
int nowtime=0;
nowtime=alltime;
if(full==1