c语言窗口排队管理系统
时间: 2023-07-13 14:32:50 浏览: 128
好的,我可以为您提供一些关于C语言窗口排队管理系统的思路。
首先,我们需要定义一个窗口结构体,包括窗口号、窗口名称、窗口状态(是否空闲)、当前服务的顾客等信息。然后,我们可以定义一个顾客结构体,包括顾客号、顾客姓名、到达时间、服务时间等信息。
接下来,我们可以使用链表来存储窗口和顾客信息,便于动态添加和删除。
当有顾客到达时,可以将其加入到顾客链表中,并根据顾客的到达时间排序。然后,遍历窗口链表,找到空闲窗口并将其服务的顾客设置为刚刚到达的顾客,并将窗口状态设置为忙碌。
在服务过程中,可以根据顾客的服务时间模拟窗口服务过程,当顾客服务完成后,将其从窗口中移除,并将窗口状态设置为空闲。
除此之外,我们还可以添加一些功能,比如查询窗口状态、查询顾客状态、强制结束服务等等。
这是一个简单的思路,具体实现可以根据需求进行调整。
相关问题
c语言窗口排队管理系统代码
这是一个简单的C语言窗口排队管理系统的代码,仅供参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME_LEN 20
// 窗口结构体
typedef struct Window {
int win_id; // 窗口号
char win_name[MAX_NAME_LEN]; // 窗口名称
int is_free; // 窗口是否空闲
struct Customer *cur_customer; // 当前服务的顾客
struct Window *next; // 下一个窗口
} Window;
// 顾客结构体
typedef struct Customer {
int cus_id; // 顾客号
char cus_name[MAX_NAME_LEN]; // 顾客姓名
int arrive_time; // 到达时间
int service_time; // 服务时间
struct Customer *next; // 下一个顾客
} Customer;
// 在链表尾部插入窗口
void insert_window(Window **head, int id, char *name) {
Window *new_win = (Window *)malloc(sizeof(Window));
new_win->win_id = id;
strcpy(new_win->win_name, name);
new_win->is_free = 1;
new_win->cur_customer = NULL;
new_win->next = NULL;
if (*head == NULL) {
*head = new_win;
} else {
Window *p = *head;
while (p->next != NULL) {
p = p->next;
}
p->next = new_win;
}
}
// 在链表尾部插入顾客
void insert_customer(Customer **head, int id, char *name, int arrive_time, int service_time) {
Customer *new_cus = (Customer *)malloc(sizeof(Customer));
new_cus->cus_id = id;
strcpy(new_cus->cus_name, name);
new_cus->arrive_time = arrive_time;
new_cus->service_time = service_time;
new_cus->next = NULL;
if (*head == NULL) {
*head = new_cus;
} else {
Customer *p = *head;
while (p->next != NULL) {
p = p->next;
}
p->next = new_cus;
}
}
// 根据到达时间排序顾客链表
void sort_customer(Customer **head) {
if (*head == NULL || (*head)->next == NULL) {
return;
}
Customer *p, *q, *temp;
p = *head;
*head = NULL;
while (p != NULL) {
temp = p;
p = p->next;
if (*head == NULL || (*head)->arrive_time > temp->arrive_time) {
temp->next = *head;
*head = temp;
} else {
q = *head;
while (q->next != NULL && q->next->arrive_time <= temp->arrive_time) {
q = q->next;
}
temp->next = q->next;
q->next = temp;
}
}
}
// 根据窗口号查找窗口
Window *find_window_by_id(Window *head, int id) {
Window *p = head;
while (p != NULL && p->win_id != id) {
p = p->next;
}
return p;
}
// 根据顾客号查找顾客
Customer *find_customer_by_id(Customer *head, int id) {
Customer *p = head;
while (p != NULL && p->cus_id != id) {
p = p->next;
}
return p;
}
// 查找空闲窗口
Window *find_free_window(Window *head) {
Window *p = head;
while (p != NULL && p->is_free == 0) {
p = p->next;
}
return p;
}
// 更新窗口状态
void update_window_status(Window *win, Customer *cus) {
win->is_free = 0;
win->cur_customer = cus;
}
// 从链表中删除顾客
void remove_customer(Customer **head, Customer *cus) {
if (*head == cus) {
*head = (*head)->next;
} else {
Customer *p = *head;
while (p != NULL && p->next != cus) {
p = p->next;
}
if (p != NULL) {
p->next = cus->next;
}
}
free(cus);
}
// 从窗口中移除顾客
void remove_customer_from_window(Window *win) {
win->is_free = 1;
win->cur_customer = NULL;
}
// 打印窗口信息
void print_window_info(Window *head) {
Window *p = head;
while (p != NULL) {
printf("Window %d: %s, %s\n", p->win_id, p->win_name, p->is_free ? "Free" : "Busy");
if (!p->is_free) {
printf("\tServing customer: %d, %s\n", p->cur_customer->cus_id, p->cur_customer->cus_name);
}
p = p->next;
}
}
// 打印顾客信息
void print_customer_info(Customer *head) {
Customer *p = head;
while (p != NULL) {
printf("Customer %d: %s, Arrive time: %d, Service time: %d\n", p->cus_id, p->cus_name, p->arrive_time, p->service_time);
p = p->next;
}
}
int main() {
Window *win_head = NULL;
Customer *cus_head = NULL;
// 初始化窗口
insert_window(&win_head, 1, "Window 1");
insert_window(&win_head, 2, "Window 2");
insert_window(&win_head, 3, "Window 3");
insert_window(&win_head, 4, "Window 4");
int choice;
while (1) {
printf("1. Add customer\n");
printf("2. Serve customer\n");
printf("3. Print window info\n");
printf("4. Print customer info\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1: {
int cus_id, arrive_time, service_time;
char cus_name[MAX_NAME_LEN];
printf("Enter customer ID: ");
scanf("%d", &cus_id);
printf("Enter customer name: ");
scanf("%s", cus_name);
printf("Enter arrive time: ");
scanf("%d", &arrive_time);
printf("Enter service time: ");
scanf("%d", &service_time);
insert_customer(&cus_head, cus_id, cus_name, arrive_time, service_time);
sort_customer(&cus_head);
printf("Customer added successfully.\n");
break;
}
case 2: {
int win_id, cus_id;
printf("Enter window ID: ");
scanf("%d", &win_id);
printf("Enter customer ID: ");
scanf("%d", &cus_id);
Window *win = find_window_by_id(win_head, win_id);
Customer *cus = find_customer_by_id(cus_head, cus_id);
if (win == NULL) {
printf("Invalid window ID.\n");
} else if (cus == NULL) {
printf("Invalid customer ID.\n");
} else if (win->is_free == 0) {
printf("Window is busy.\n");
} else {
update_window_status(win, cus);
remove_customer(&cus_head, cus);
printf("Customer %d is served by window %d.\n", cus_id, win_id);
}
break;
}
case 3: {
print_window_info(win_head);
break;
}
case 4: {
print_customer_info(cus_head);
break;
}
case 5: {
exit(0);
}
default: {
printf("Invalid choice.\n");
break;
}
}
}
return 0;
}
```
注意:这只是一个简单的实现,还有很多可以优化的地方。比如可以使用优先队列来管理顾客,可以添加更多的功能,可以使用更加严谨的输入判断等等。
c语言代码银行窗口排队排队管理系统
好的,以下是一个简单的银行窗口排队管理系统的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 客户信息结构体
struct customer {
char name[20]; // 客户姓名
int type; // 业务类型
int time; // 办理时间
struct customer *next; // 指向下一个客户的指针
};
// 队列结构体
struct queue {
int count; // 队列中客户数量
struct customer *head; // 队列头指针
struct customer *tail; // 队列尾指针
};
// 初始化队列
void init_queue(struct queue *q) {
q->count = 0;
q->head = NULL;
q->tail = NULL;
}
// 入队操作
void enqueue(struct queue *q, char *name, int type) {
struct customer *new_customer = (struct customer*) malloc(sizeof(struct customer));
strcpy(new_customer->name, name);
new_customer->type = type;
new_customer->time = 0;
new_customer->next = NULL;
if (q->count == 0) {
q->head = new_customer;
q->tail = new_customer;
} else {
q->tail->next = new_customer;
q->tail = new_customer;
}
q->count++;
}
// 出队操作
void dequeue(struct queue *q) {
if (q->count > 0) {
struct customer *customer_to_serve = q->head;
q->head = customer_to_serve->next;
free(customer_to_serve);
q->count--;
}
}
// 显示队列中客户信息
void show_queue(struct queue *q) {
printf("当前排队人数:%d\n", q->count);
printf("姓名\t业务类型\t预计等待时间\n");
struct customer *p = q->head;
int wait_time = 0;
while (p != NULL) {
wait_time += 3; // 假设每个客户办理业务需要3分钟
p->time = wait_time;
printf("%s\t%d\t\t%d\n", p->name, p->type, p->time);
p = p->next;
}
}
int main() {
struct queue q;
init_queue(&q);
while (1) {
// 显示菜单
printf("\n银行业务类型:\n");
printf("1. 存款\n");
printf("2. 取款\n");
printf("3. 转账\n");
printf("4. 查询\n");
printf("0. 退出\n");
// 获取用户输入
int choice;
printf("请输入业务类型:");
scanf("%d", &choice);
if (choice == 0) {
break;
}
// 获取客户姓名
char name[20];
printf("请输入您的姓名:");
scanf("%s", name);
// 将客户加入队列
enqueue(&q, name, choice);
// 显示当前队列中的客户信息
show_queue(&q);
}
return 0;
}
```
这个示例代码实现了银行窗口排队管理系统的基本功能,包括入队、出队、显示队列中客户信息等。当用户输入业务类型和姓名后,客户就会被加入队列中,同时系统会显示当前队列中的客户信息和预计等待时间。可以根据实际需求扩展代码,增加更多的功能。
阅读全文
相关推荐
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)