根据要求设计 需要源代码 数据结构要用C语言 数据结构数据结构C语言
程序使用队列数据结构实现排队叫号系统的各种功能,通过调用不同的函数来实现不同的操作。
具体而言,程序通过定义客户和队列的结构体来实现数据的存储和管理,通过定义入队和出队的函数来实现数据的添加和提取,通过定义取号、叫号、办理、过号和显示队列信息的函数来实现排队叫号系统的各种功能。
在主函数中,程序通过循环接受用户输入,并根据用户的选择调用不同的函数来执行相应的操作,直到用户选择退出系统为止。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_QUEUE_SIZE 100 // 队列的最大长度
// 定义客户结构体
typedef struct {
char type; // 客户类型('N'表示普通客户,'V'表示VIP客户)
int number; // 客户号码
} Customer;
// 定义队列结构体
typedef struct {
Customer data[MAX_QUEUE_SIZE]; // 队列元素
int front; // 队头指针
int rear; // 队尾指针
} Queue;
// 初始化队列
void initQueue(Queue* q) {
q->front = q->rear = 0;
}
// 判断队列是否为空
int isQueueEmpty(const Queue* q) {
return q->front == q->rear;
}
// 判断队列是否已满
int isQueueFull(const Queue* q) {
return (q->rear + 1) % MAX_QUEUE_SIZE == q->front;
}
// 入队
int enqueue(Queue* q, const Customer* customer) {
if (isQueueFull(q)) {
return 0; // 队列已满,入队失败
}
q->data[q->rear] = *customer;
q->rear = (q->rear + 1) % MAX_QUEUE_SIZE;
return 1; // 入队成功
}
// 出队
int dequeue(Queue* q, Customer* customer) {
if (isQueueEmpty(q)) {
return 0; // 队列已空,出队失败
}
*customer = q->data[q->front];
q->front = (q->front + 1) % MAX_QUEUE_SIZE;
return 1; // 出队成功
}
// 取号
void takeNumber(Queue* q, char type) {
static int number = 0; // 号码计数器,初始值为0,静态变量保证每次调用该函数时该值不会被重置
Customer customer = {type, ++number}; // 生成新的客户号码
enqueue(q, &customer); // 入队
printf("取号成功,您的号码是%c%03d,请耐心等待!\n", type, number);
}
// 叫号
void callNumber(Queue* q) {
if (isQueueEmpty(q)) {
printf("队列已空,暂无客户等待!\n");
return;
}
Customer customer;
dequeue(q, &customer); // 出队
printf("请%c%03d号客户前往办理业务!\n", customer.type, customer.number);
}
// 办理
void handleNumber(Queue* q) {
if (isQueueEmpty(q)) {
printf("队列已空,暂无客户等待!\n");
return;
}
Customer customer;
dequeue(q, &customer); // 出队
printf("%c%03d号客户已完成业务,谢谢光临!\n", customer.type, customer.number);
}
// 过号
void passNumber(Queue* q) {
if (isQueueEmpty(q)) {
printf("队列已空,暂无客户等待!\n");
return;
}
Customer customer;
dequeue(q, &customer); // 出队
printf("%c%03d号客户已过号,请注意办理时间!\n", customer.type, customer.number);
}
// 显示队列信息
void displayQueue(const Queue* q) {
printf("当前排队情况:\n");
if (isQueueEmpty(q)) {
printf(" 暂无客户等待!\n");
} else {
printf(" 排队号码:");
for (int i = q->front; i != q->rear; i = (i + 1) % MAX_QUEUE_SIZE) {
printf("%c%03d ", q->data[i].type, q->data[i].number);
}
printf("\n");
}
}
int main() {
Queue q;
initQueue(&q); // 初始化队列
int option;
while (1) {
printf("\n欢迎使用排队叫号系统!请选择您要进行的操作:\n");
printf("1. 普通客户取号\n");
printf("2. VIP客户取号\n");
printf("3. 叫号\n");
printf("4. 办理\n");
printf("5. 过号\n");
printf("6. 显示队列信息\n");
printf("0. 退出系统\n");
scanf("%d", &option);
switch (option) {
case 0:
printf("谢谢使用排队叫号系统!\n");
return 0;
case 1:
takeNumber(&q, 'N');
break;
case 2:
takeNumber(&q, 'V');
break;
case 3:
callNumber(&q);
break;
case 4:
handleNumber(&q);
break;
case 5:
passNumber(&q);
break;
case 6:
displayQueue(&q);
break;
default:
printf("无效的选项,请重新输入!\n");
break;
}
}
return 0;
}
需求就这?看我博客,参照示例
/*
* @Descripttion:
* @version:
* @Author: Yueyang
* @email: 1700695611@qq.com
* @Date: 2020-10-26 19:35:49
* @LastEditors: Yueyang
* @LastEditTime: 2020-11-12 11:13:48
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include "bmp.h"
#include "cv.h"
#include "li_image.h"
#include "li_painter.h"
#include "li_image_proc.h"
#include "math.h"
#define MINDIS 0.0 //最小刻度值对应数值
#define MINTHE 50.0 //最小的刻度对应角度
#define MAXDIS 0.6 //最大刻度值对应数值
#define MAXTHE MINTHE+265 //最大的刻度对应角度
int main()
{
LiLine l;
LiCircle c;
Li_Image* out,*bmp,*gray,*smooth,*canny,*roi ;
char* picname="./picture/panal (";
char outfile[20];
char infile[20];
for(int i=0;i<11;i++){
sprintf(infile,"%s%d%s",picname,i+1,").jpg");
sprintf(outfile,"%s%d%s","out",i+1,".bmp");
LILOG("NEXT PICTURE");
out=Li_Load_Image(infile,LI_JPEG);
bmp=Li_Convert_Image(out,LI_JPEG_2_BMP);
gray=Li_Convert_Image(bmp,LI_BMP_888_2_LI_BMP_8);
smooth=Li_Smooth(gray,Li_GAUSS);
canny= Li_Canny(smooth,LI_CANNY_SOBEL,50,128);
LONG range[]={170,180,100,120};
Li_Hough_Circle(canny,&c,120,130,range);
c.r=c.r- c.r%8;
LONG startx=c.x-c.r ;
LONG starty=c.y-c.r;
LONG endx=c.x+c.r ,endy=c.y+c.r;
roi=Li_Get_Roi(canny,(startx)>0?(startx):0,(starty)>0?(starty):0,(endx)<canny->width?(endx):canny->width,(endy)<canny->height?(endy):canny->height);
Li_Hough_Line(roi,&l,130,250);
Li_Image* res=Li_Get_Roi(bmp,(startx)>0?(startx):0,(starty)>0?(starty):0,(endx)<bmp->width?(endx):bmp->width,(endy)<bmp->height?(endy):bmp->height);
Li_Line_P(res,0xFF0000,l.thera,l.r);
Li_Circle(res,0x00FF00,(res->width-2)/2,(res->height-2)/2,c.r);
double read;
char text[30];
if(l.thera<=90)
read=(180-l.thera-MINTHE)*((MAXDIS-MINDIS)/(MAXTHE-MINTHE));
else
read=(360-l.thera-MINTHE)*((MAXDIS-MINDIS)/(MAXTHE-MINTHE));
printf("%d",l.thera);
sprintf(text,"read num: %lf",read);
Li_String(res,0x0000FF,40,40,150,30,text,12);
Li_Save_Image("./smooth.bmp",smooth);
Li_Save_Image("./canny_sobel.bmp",canny);
Li_Save_Image("./roi.bmp",roi);
Li_Save_Image(outfile,res);
}
LILOG("over");
return 0;
}
代码如下,有用请采纳:
#include <stdio.h>
#include <stdlib.h>
// 定义客户结构体
typedef struct {
int number;
int isVIP;
} Customer;
// 队列结构体
typedef struct {
Customer* customers;
int front;
int rear;
int capacity;
} Queue;
// 创建队列
Queue* createQueue(int capacity) {
Queue* queue = (Queue*)malloc(sizeof(Queue));
queue->customers = (Customer*)malloc(capacity * sizeof(Customer));
queue->front = -1;
queue->rear = -1;
queue->capacity = capacity;
return queue;
}
// 判断队列是否为空
int isEmpty(Queue* queue) {
return queue->front == -1;
}
// 判断队列是否已满
int isFull(Queue* queue) {
return (queue->rear + 1) % queue->capacity == queue->front;
}
// 入队操作
void enqueue(Queue* queue, Customer customer) {
if (isFull(queue)) {
printf("队列已满,无法加入新的客户。\n");
return;
}
if (isEmpty(queue)) {
queue->front = 0;
}
queue->rear = (queue->rear + 1) % queue->capacity;
queue->customers[queue->rear] = customer;
}
// 出队操作
Customer dequeue(Queue* queue) {
if (isEmpty(queue)) {
printf("队列为空,无法出队。\n");
Customer emptyCustomer = {-1, -1};
return emptyCustomer;
}
Customer customer = queue->customers[queue->front];
if (queue->front == queue->rear) {
queue->front = -1;
queue->rear = -1;
} else {
queue->front = (queue->front + 1) % queue->capacity;
}
return customer;
}
// 获取队首客户
Customer getFront(Queue* queue) {
if (isEmpty(queue)) {
printf("队列为空。\n");
Customer emptyCustomer = {-1, -1};
return emptyCustomer;
}
return queue->customers[queue->front];
}
// 显示队列中的客户
void displayQueue(Queue* queue) {
if (isEmpty(queue)) {
printf("队列为空。\n");
return;
}
int i = queue->front;
printf("当前队列中的客户:\n");
while (i != queue->rear) {
printf("客户号码:%d,是否为VIP:%s\n", queue->customers[i].number, queue->customers[i].isVIP ? "是" : "否");
i = (i + 1) % queue->capacity;
}
printf("客户号码:%d,是否为VIP:%s\n", queue->customers[i].number, queue->customers[i].isVIP ? "是" : "否");
}
int main() {
int capacity = 10;
Queue* queue = createQueue(capacity);
// 普通客户取号
Customer customer1 = {1, 0};
enqueue(queue, customer1);
Customer customer2 = {2, 0};
enqueue(queue, customer2);
Customer customer3 = {3, 0};
enqueue(queue, customer3);
// VIP客户取号
Customer customer4 = {4, 1};
enqueue(queue, customer4);
Customer customer5 = {5, 1};
enqueue(queue, customer5);
// 叫号
Customer frontCustomer = getFront(queue);
printf("当前叫号客户:%d\n", frontCustomer.number);
dequeue(queue);
// 办理
printf("正在办理业务的客户:%d\n", frontCustomer.number);
// 过号
printf("过号的客户:%d\n", frontCustomer.number);
dequeue(queue);
// 显示队列
displayQueue(queue);
return 0;
}