#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#define MAX 2
#define price 3
#define NULL 0
typedef struct time{
int hour;/*时针*/
int min;/*分针*/
}Time;/*时间结点*/
typedef struct node{
char num[10];
Time reach;
Time leave;
}CarNode;/*车辆信息结点*/
typedef struct NODE{
CarNode *stack[MAX+1];
int top;
}SeqStackCar;/*模拟车站*/
typedef struct car{
CarNode *data;
struct car *next;
}QueueNode;
typedef struct Node{
QueueNode *head;
QueueNode *rear;
}LinkQueueCar;/*模拟的通道*/
void InitStack(SeqStackCar *s)
{/*初始化车站*/
int i;
s->top=0;
for(i=0;i<=MAX;i++)
s->stack[s->top]=NULL;
printf("\nInitStack successed");
}
int InitQueue(LinkQueueCar *Q)
{/*初始化通道*/
Q->head=(QueueNode *)malloc(sizeof(QueueNode));
if(Q->head!=NULL)
{Q->head->next=NULL;
Q->rear=Q->head;
printf("\nInitQueue Successed");
return(1);
}
else return(-1);
}
void PRINT(CarNode *p,int room)
{/*打印出站车的信息*/
int A1,A2,B1,B2;
printf("\nPlease enter the now's time:/**:**/");
scanf("%d:%d",&(p->leave.hour),&(p->leave.min));
printf("\nThe leave car's number:");
puts(p->num);
printf("\nThe room's number is: %d",room);
printf("\nThe reach time is: %d:%d",p->reach.hour,p->reach.min);
printf("\nThe leave time is: %d:%d",p->leave.hour,p->leave.min);
A1=p->reach.hour;
A2=p->reach.min;
B1=p->leave.hour;
B2=p->leave.min;
printf("\nThe price is: %d",((B1-A1)*60+(B2-A2))*price);
free(p);
}
int Arrival(SeqStackCar *Enter,LinkQueueCar *W)
{ CarNode *p;
QueueNode *t;
p=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("\nPlease enter the car's number.");
/*scanf("%s",&(p->num));*/
gets(p->num);
if(Enter->top<MAX)
{ Enter->top++;
printf("\nThe car can enter the stack and the room's number is %d.",Enter->top);
printf("\nPlease enter the car's reach time:/**:**/");
scanf("%d:%d",&(p->reach.hour),&(p->reach.min));
Enter->stack[Enter->top]=p;
return(1);}
else
{ printf("\nThe car must wait.");
t=(QueueNode *)malloc(sizeof(QueueNode));
t->data=p;
t->next=NULL;
W->rear->next=t;
W->rear=t;
return(1);
}
}
void Leave(SeqStackCar *Enter,SeqStackCar *Temp,LinkQueueCar *W)
{ int room;
CarNode *p,*t;
QueueNode *q;
if(Enter->top>0)/*判断车站内是否有车*/
{
while(1)
{ printf("\nPlease enter the car's room number./1--%d/",Enter->top);
scanf("%d",&room);
if(room>=1&&room<=Enter->top)break;
}
while(Enter->top>room)
{ Temp->top++;
Temp->stack[Temp->top]=Enter->stack[Enter->top];
Enter->stack[Enter->top]=NULL;
Enter->top--;
}
p=Enter->stack[Enter->top];
Enter->stack[Enter->top]=NULL;
Enter->top--;
while(Temp->top>=1)
{ Enter->top++;
Enter->stack[Enter->top]=Temp->stack[Temp->top];
Temp->stack[Temp->top]=NULL;
Temp->top--;
}
PRINT(p,room);
if((W->head!=W->rear)&&Enter->top<MAX)/*判断通道上是否有车及车站是否已满*/
{ q=W->head->next;
t=q->data;
printf("\n\nThe wait car can enter the bus stop .\n the car's number is:");
puts(t->num);
Enter->top++;
printf("the room's number is: %d",Enter->top);
printf("\nPlease enter the time/**:**/:");
scanf("%d:%d",&(t->reach.hour),&(t->reach.min));
W->head->next=q->next;
if(q==W->rear)W->rear=W->head;
Enter->stack[Enter->top]=t;
free(q);
}
else printf("\nThere is not car at waiting line.\n");
}
else printf("\nThere is not car at bus stop.");
}
void List1(SeqStackCar *S)
{ int i;
if(S->top>0) /*判断车站内是否有车*/
{printf("\nThe bus stop:");
printf("\nThe room Number reach time car number\n");
for(i=1;i<=S->top;i++)
{ printf(" %d ",i);
printf(" %d:%d ",S->stack[i]->reach.hour,S->stack[i]->reach.min);
puts(S->stack[i]->num);
}
}
else printf("\nThere is not car at bus stop.");
}
void List2(LinkQueueCar *W)
{ QueueNode *p;
p=W->head->next;
if(W->head!=W->rear)/*判断通道上是否有车*/
{printf("\nThe Wait car number:\n");
while(p!=NULL)
{ puts(p->data->num);
p=p->next;
}
}
else printf("\nThere is not car at waiting line.");
}
void List(SeqStackCar S,LinkQueueCar W)
{ int flag,tag;
flag=1;
while(flag)
{ printf("\nTo select 1|2|3:");
printf("\n1.Bus stop;\n2.The Waiting line;\n3.return;\n");
while(1)
{ scanf("%d",&tag);
if(tag>=1||tag<=3)break;
else printf("\nTo select 1|2|3:");
}
switch(tag)
{ case 1:List1(&S);break;/*列表打印车站信息*/
case 2:List2(&W);break;/*列表打印通道信息*/
case 3:flag=0;break;
default: break;
}
}}
main()
{
SeqStackCar Enter,Temp;
LinkQueueCar Wait;
int ch;
InitStack(&Enter);
InitStack(&Temp);
InitQueue(&Wait);
while(1)
{ printf("\nTo Select Number;");
printf("\n1. Car arrival;");
printf("\n2. Car leave;");
printf("\n3. List car;");
printf("\n4. Exit;\n");
while(1)
{ scanf("%d",&ch);
if(ch>=1&&ch<=4)break;
else printf("\nPlease enter the number 1|2|3|4.");}
switch(ch)
{ case 1:Arrival(&Enter,&Wait);break; /*车辆到达*/
case 2:Leave(&Enter,&Temp,&Wait);break;/*车辆离开*/
case 3:List(Enter,Wait);break; /*列表打印信息*/
case 4:exit(0);/*退出主程序*/
default: break;
}
}
}
CAR.rar_车辆管理
版权申诉
101 浏览量
2022-09-21
04:30:21
上传
评论
收藏 2KB RAR 举报
周楷雯
- 粉丝: 80
- 资源: 1万+
最新资源
- 源码设计Python+opencv实时的人眼识别+眨眼检测+闭眼检测源代码+详细教程.zip
- 10个数据结构课程设计实例二叉树建立遍历冒泡排序快速排序等.zip
- 课程设计opencv4.5.4人脸识别类FaceRecognizerSF所需onnx文件.zip
- MediaPipe手势识别小案例用MediaPipe+opencv+PySide2+PyGame进行搭建源码+项目说明.zip
- html+css+js网页设计.rar
- c语言文件读写操作代码.rar
- Python有多种开发框架.rar
- 基于FPGA控制28BYJ48型四相八拍电机步进电机实验Verilog逻辑源码Quartus工程文件+文档说明资料.zip
- 机智云-植物宝制作stm32单片机程序源码+ android app源码+文档说明资料.zip
- php-leetcode题解之整数反转.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈