c语言 银行排队系统 VIP和普通用户分别窗口
时间: 2024-04-28 09:20:19 浏览: 7
好的,C语言银行排队系统中,一般情况下会将VIP用户和普通用户分别安排到不同的窗口进行服务。这样可以提高VIP用户的优先服务体验,也能更好地管理人员和服务资源。
一种实现方式是在程序中设置两个队列,分别存放VIP用户和普通用户。当用户进入银行时,会根据其身份进行判断,如果是VIP用户则优先进入VIP队列,否则进入普通队列。然后根据队列的先进先出原则,依次安排用户到相应的窗口进行服务。同时,可以设置不同的服务时限和服务质量要求,进一步提高VIP用户的服务体验。
当然,这只是一种简单的实现方式,具体的实现方法还需要根据具体的需求和业务流程来确定。
相关问题
c语言 银行排队系统 VIP和普通用户分别窗口 代码
以下是一个简单的C语言银行排队系统的代码示例,其中包括了VIP和普通用户分别窗口的实现:
```c
#include <stdio.h>
#include <stdlib.h>
// 定义队列
#define MAXSIZE 100
typedef struct {
int data[MAXSIZE];
int front; // 队头指针
int rear; // 队尾指针
} Queue;
// 初始化队列
void initQueue(Queue *q) {
q->front = 0;
q->rear = 0;
}
// 入队
void enQueue(Queue *q, int x) {
if ((q->rear + 1) % MAXSIZE == q->front) {
printf("Queue is full.\n");
exit(0);
}
q->data[q->rear] = x;
q->rear = (q->rear + 1) % MAXSIZE;
}
// 出队
int deQueue(Queue *q) {
if (q->front == q->rear) {
printf("Queue is empty.\n");
exit(0);
}
int x = q->data[q->front];
q->front = (q->front + 1) % MAXSIZE;
return x;
}
// 判断队列是否为空
int isEmpty(Queue q) {
return q.front == q.rear;
}
// 主函数
int main() {
Queue vipQueue, normalQueue;
initQueue(&vipQueue);
initQueue(&normalQueue);
int n, m;
printf("Please input the number of VIP users: ");
scanf("%d", &n);
printf("Please input the number of normal users: ");
scanf("%d", &m);
// VIP用户进入队列
for (int i = 0; i < n; i++) {
printf("Please input the arrival time and service time of VIP user %d: ", i+1);
int arrivalTime, serviceTime;
scanf("%d %d", &arrivalTime, &serviceTime);
if (isEmpty(vipQueue)) {
enQueue(&vipQueue, arrivalTime);
} else {
// 按照到达时间插入队列
int j = vipQueue.rear-1;
while (j >= vipQueue.front && vipQueue.data[j] > arrivalTime) {
vipQueue.data[j+1] = vipQueue.data[j];
j--;
}
vipQueue.data[j+1] = arrivalTime;
}
}
// 普通用户进入队列
for (int i = 0; i < m; i++) {
printf("Please input the arrival time and service time of normal user %d: ", i+1);
int arrivalTime, serviceTime;
scanf("%d %d", &arrivalTime, &serviceTime);
if (isEmpty(normalQueue)) {
enQueue(&normalQueue, arrivalTime);
} else {
// 按照到达时间插入队列
int j = normalQueue.rear-1;
while (j >= normalQueue.front && normalQueue.data[j] > arrivalTime) {
normalQueue.data[j+1] = normalQueue.data[j];
j--;
}
normalQueue.data[j+1] = arrivalTime;
}
}
// 开始服务
int currentTime = 0; // 当前时间
int vipIndex = 0; // VIP队列中等待服务的用户的下标
int normalIndex = 0; // 普通队列中等待服务的用户的下标
while (!isEmpty(vipQueue) || !isEmpty(normalQueue)) {
int vipArrivalTime = MAXSIZE, normalArrivalTime = MAXSIZE;
if (!isEmpty(vipQueue)) vipArrivalTime = vipQueue.data[vipQueue.front];
if (!isEmpty(normalQueue)) normalArrivalTime = normalQueue.data[normalQueue.front];
// 选择最早到达的用户
int arrivalTime = vipArrivalTime < normalArrivalTime ? vipArrivalTime : normalArrivalTime;
currentTime = arrivalTime;
// VIP用户优先服务
if (!isEmpty(vipQueue) && vipArrivalTime <= normalArrivalTime && vipQueue.data[vipIndex] <= currentTime) {
printf("VIP user %d is being serviced at VIP window.\n", vipIndex+1);
vipIndex++;
} else if (!isEmpty(normalQueue) && normalQueue.data[normalIndex] <= currentTime) {
printf("Normal user %d is being serviced at normal window.\n", normalIndex+1);
normalIndex++;
}
// 处理完服务时间最短的用户
if (!isEmpty(vipQueue) && vipArrivalTime <= normalArrivalTime && vipQueue.data[vipIndex-1] <= currentTime) {
deQueue(&vipQueue);
} else if (!isEmpty(normalQueue) && normalQueue.data[normalIndex-1] <= currentTime) {
deQueue(&normalQueue);
}
}
return 0;
}
```
以上代码仅供参考,具体实现方式和细节还需要根据实际需求进行调整和完善。
C语言银行排队系统实现
银行排队系统可以采用链队列作为数据结构实现,下面是一个简单的C语言实现:
```c
#include <stdio.h>
#include <stdlib.h>
// 定义链表节点
typedef struct node {
int data;
struct node* next;
} Node;
// 定义链队列
typedef struct queue {
Node* front; // 队头指针
Node* rear; // 队尾指针
} Queue;
// 初始化队列
void initQueue(Queue* q) {
q->front = q->rear = NULL;
}
// 判断队列是否为空
int isEmpty(Queue* q) {
return q->front == NULL;
}
// 入队操作
void enqueue(Queue* q, int data) {
Node* newNode = (Node*)malloc(sizeof(Node));
newNode->data = data;
newNode->next = NULL;
if (isEmpty(q)) {
q->front = q->rear = newNode;
} else {
q->rear->next = newNode;
q->rear = newNode;
}
}
// 出队操作
int dequeue(Queue* q) {
if (isEmpty(q)) {
printf("Queue is empty\n");
return -1;
}
Node* temp = q->front;
int data = temp->data;
q->front = q->front->next;
if (q->front == NULL) {
q->rear = NULL;
}
free(temp);
return data;
}
// 输出队列
void printQueue(Queue* q) {
printf("Queue: ");
Node* p = q->front;
while (p != NULL) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
// 银行排队系统
int main() {
Queue queue;
initQueue(&queue);
int choice, id;
do {
printf("1.办理业务\t2.下一位\n");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("请输入您的身份证号:");
scanf("%d", &id);
enqueue(&queue, id);
printf("请您稍等,当前排队人数为:%d\n", queueLength(&queue));
break;
case 2:
if (isEmpty(&queue)) {
printf("当前没有排队的客户\n");
} else {
int nextId = dequeue(&queue);
printf("请%d号客户前往窗口办理业务\n", nextId);
printf("当前排队人数为:%d\n", queueLength(&queue));
}
break;
default:
printf("无效的选项,请重新输入\n");
break;
}
} while (choice != 0);
return 0;
}
```
上述代码实现了银行排队系统,通过不断调用入队和出队操作来模拟客户排队和服务的过程。每个客户的身份证号作为数据项存储在队列中,当客户办理完业务后,出队列并输出下一个需要办理业务的客户的身份证号。