经典C源码 之 停车场管理系统
- 格式:doc
- 大小:34.50 KB
- 文档页数:4
停车场管理系统【要求】(1)有一个两层的停车场,每层有6个车位,当第一层车停满后才允许使用第二层(停车场可用一个二维数组实现,每个数组元素存放一个车牌号),每辆车的信息包括车牌号、层号、车位号、停车时间共4项,其中停车时间按分钟计算。
(2)假设停车场初始状态为第一层已经有4辆车,其车位号依次为1~4,停车时间依次为20,15,10,5,即先将这4辆车的信息存入文件car.dat中(数组的对应元素也要进行赋值)。
(3)停车操作:当一辆车进入停车场时,先输入其车牌号,再为它分配一个层号和一个车位号(分配前先查询车位的使用情况,如果第一层有空位则必须停在第一层),停车时间设为5,最后将新停入的汽车的信息添入文件car。
dat中,并将在此之前的所有停车时间加5。
(4)收费管理(取车):当有车离开时,输入其车牌号,先按其停车时间计算费用,每5分钟0.2元(停车费用可设置一个变量进行保存),同时从文件car。
dat 中删除该车的信息,并将该车对应的车位设置为可用状态(即二维数组对应元素清零),按用户的选择来判断是否要输出停车收费的总计。
(5)输出停车场中全部车辆的信息.(6)退出系统。
【提示】(1)需求分析:车辆信息要用文件储存,提供文件的输入输出操作;当车要离开时要删除文件中该车的信息,因而要提供文件的删除操作;另外还要用键盘式菜单实现功能选择.(2)总体设计:整个管理系统可设计为停车模块、取车模块、车辆信息浏览模块.二、总体设计根据上面的需求分析,可以将这个系统的设计分为四大模块(如图2—1):停车、取车、车辆信息浏览、退出。
其中主要功能是停车、取车、车辆信息浏览三个模块。
图2—1系统功能模块图根据模块图可画出总的流程图(图2—2)图2—2 总流程图三、详细设计1、车辆信息车辆信息包括车牌号、层号、车位号、停车时间,将这四类数据组合成结构体car,以便于引用。
【程序】struct car{int carnumber;int floor;int position;int time;}car[12];2、车位信息由于停车场有两层,每层六个车位,故车位信息可由一个二维数组park[2][6]表示,注意停车场中已经停放了4辆车,设这四辆车的车牌号为6840,4167,3548,9201。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<malloc.h>#include<time.h>//获取系统时间#include<conio.h>//包含屏幕操作函数#define NULL 0#define LEN sizeof(struct car)//用于存放时间typedef struct time{int intimeyear;int intimemounth;int intimeday;int intimehour;int intimeminute;int intimesecond;//驶入时间,驶入时系统获取int outtimehour;int outtimeminute;int outtimesecond;//驶出时间}TIME;//用于存放车辆信息typedef struct car{int number;//在头指针中代表空车位,在其它指针中代表其车位号,从1-15按顺序char license[10];//每辆车自己的型号TIME time;//时间struct car *next;}CAR;//用于存放每日费用,并写入文件,便于计算一个月收入struct oneday{int tyear;int tmounth;int tday;int onedayfee;}one;CAR *creat();void inbigcar();//驶入一辆大型客车或货车void inmiddlecar();//驶入一辆中型客车或货车void insmallcar();//驶入一辆轿车int outbigcar();//输出一辆大型客车或货车int outmiddlecar();//开出一辆中型客车或货车int outsmallcar();//开出一辆轿车void lookup1();//分别输出A区,B区,C区当前所停放的汽车的信息void lookup2();//分别输出A区,B区,C区当前空闲的车位号void lookup3();//输入车牌号,输出该车所停放的车位号void lookup4();//输出A区,B区,C区当前所停放的汽车的数量void lookup5();//输入当前时间,分别统计A区,B区,C区到当前时间为止,停车时间超过5小时的汽车数量,并输出这些汽车的信息void lookup6();//输入一个日期(年.月),统计该月停车场的收费金额int onemoufee(int year,int mounth);//计算一个月的收入CAR *Ahead,*Bhead,*Chead;void main(){printf("\n\n\n\n================================================================== ==============\n\n\n\n");printf("\t\t********欢迎使用Light停车场管理系统!********\n\n\n\n\n");printf("========================================================================= =======\n\n\n\n");printf("\t\t\t 请按任意键进入\n");getchar();FILE *fp,*fp1;int year,mounth,day,hour,m,n=1,i=0;int Amoney=0,Bmoney=0,Cmoney=0,summoney=0;if((fp=fopen("table.txt","a"))==NULL){printf("Cannot open file!\n");exit(0);}//end if创立一个文件,以便记录Ahead=creat();Bhead=creat();Chead=creat();time_t nowtime;struct tm *timeinfo;time( &nowtime );timeinfo = localtime( &nowtime );one.tyear =year= timeinfo->tm_year + 1900;one.tmounth =mounth=timeinfo->tm_mon + 1;one.tday =day= timeinfo->tm_mday;hour = timeinfo->tm_hour;printf("%d\n",hour);if(hour<6||hour>=22){system("cls");printf("\n\n\n=================================================================== =============\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * Light停车场管理系统close *\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * 营业时间:6:00-22:00 *\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * 请您营业时间再来!*\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("========================================================================= =======\n");printf("\n\t\t\t\t请按任意键结束\n");getchar();exit(0);}//end iffprintf(fp,"%d年%d月%d日",year,mounth,day);while(n==1){system("cls");printf("\n");printf("========================================================================= =======\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * Light停车场管理系统*\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * 欢迎使用!*\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("\t\t * *\n");printf("========================================================================= =======\n\n");printf("\t 1. 停车 3. 查询\n");printf("\t 2. 取车0. 退出\n\n");printf("\t 请选择: ");scanf("%d",&m);switch(m){case 1:while(n==1){system("cls");printf("\t\t欢迎您停车!\n\n\t\t请选择您的停车区域\n");printf("--------------------------------------------------------------------------------\n\n");printf("\t 1. A区停放轿车 3. C区停放大型客车或货车\n");printf("\t 2. B区停放中型客车或货车0. 退出\n\n");printf("\t 请选择您需要的服务(0-3):");printf("\n\t 请选择: ");scanf("%d", &m);getchar();//驶入状况下选择车型switch(m){case 1:insmallcar();break;case 2:inmiddlecar();break;case 3:inbigcar();break;case 0:break;default:printf("You input the wrong number.\n");}//end switchprintf("\n\t如果您想继续停车,请输入1;如果想进入主菜单或退出,请输入任意数字:");printf("\n\t 请选择: ");scanf("%d",&n);}break;case 2: while(n==1){system("cls");printf("\t\t欢迎您取车!\n\n\t\t请选择您的取车的区域!\n");printf("--------------------------------------------------------------------------------\n\n");printf("\t 1. 从A区取轿车 3. 从C区取大型客车或货车\n");printf("\t 2. 从B区取中型客车或货车0. 退出\n\n");printf("--------------------------------------------------------------------------------\n");printf("\t 请选择您需要的服务(0-3):");scanf("%d", &m);getchar();//驶出状况下选择车型switch(m){case 1:Amoney=outsmallcar();break;case 2:Bmoney=outmiddlecar();break;case 3:Cmoney=outbigcar();break;case 0:break;default:printf("You input the wrong number.\n");}printf("\n\t如果您想继续开车,请输入1;如果想进入主菜单或退出,请输入0:");printf("\n\t 请选择: ");scanf("%d",&n);}one.onedayfee =summoney=Amoney+Bmoney+Cmoney;break;case 3: while(n==1){system("cls");printf("--------------------------------------------------------------------------------\n");printf("\t欢迎进入管理系统\t\n");printf("--------------------------------------------------------------------------------\n");printf("What do you want to look up?\n");printf("1、分别输出A区,B区,C区当前所停放的汽车的信息;\n");printf("2、分别输出A区,B区,C区当前空闲的车位号;\n");printf("3、输入车牌号,输出该车所停放的车位号;\n");printf("4、输出A区,B区,C区当前所停放的汽车的数量;\n");printf("5、输入当前时间,分别统计A区,B区,C区到当前时间为止,停车时间超过5小时的汽车数量,并输出这些汽车的信息;\n");printf("6、输入一个日期(年.月),统计该月停车场的收费金额。
//停车场管理系统#include〈stdio.h〉#include<stdlib。
h〉#define OVERFLOW 0#define ERROR 0#define OK 1#define STACKSIZE 2 //车库容量//时间节点typedef struct time{int hour;int min;}Time;//车辆信息typedef struct{char CarNum;float time;int pos_a; //车在停车场中的位置int pos_b;//车在便道上的位置int flag;}Car,Car2;//车库信息(顺序栈)typedef struct{Car *top;Car *base;int stacksize;}SqStack;//初始化int InitStack(SqStack &S){S。
base=new Car[STACKSIZE];if(!S.base)exit(OVERFLOW);S。
top=S.base;S.stacksize=STACKSIZE;return OK;}//判空int StackEmpty(SqStack S){if(S。
top==S.base)return OK;elsereturn ERROR;}//判满int StackFull(SqStack S){if(S。
top—S.base〉=S。
stacksize)return OK; elsereturn ERROR;}//入栈int Push(SqStack &S,Car e){if(S.top-S.base==S.stacksize) return ERROR;*S.top++=e;return OK;}//出栈int Pop(SqStack &S,Car &e){if(S。
top==S.base)return ERROR;e=*--S.top;return OK;}//遍历栈int StackTraverse(SqStack S){Car *p=S.top;Car *q=S.base;int l=1;if(StackEmpty(S)){for(int j=1;j<=STACKSIZE;j++){printf(”\t车牌:");printf("\t\t到达时间:");printf("\t位置%d:空空”,j);printf(”\n");}return OK;}while(p!=q){Car car=*(q);printf(”\t车牌:%d”,car。
c语言实现停车场管理系统#include#include #include#define Size 2#define price 5typedef struct { char num[20]; int reachtime; int leavetime; }carinfo;typedef struct stack{ carinfo car[5]; int top;}Stack;typedef struct Node{ carinfo data; struct Node*next; }QueueNode;typedef struct { QueueNode *front; QueueNode *rear;}Queue,*linkQueue;int EnterQ(Queue *Q,carinfo x); int inistack(Stack *S) //初始化栈{S->top=-1; return 1;}void Push(Stack *S,carinfo x) //进栈操作{S->top++; S->car[S->top]=x;printf(" 进站成功!"); }void Pop(Stack *S,carinfo x) //出栈操作{ if(S->top=-1) printf(" 空栈,无法出栈!");x=S->car[S->top];S->top--;printf(" 出栈成功!");}IsEmpty(Stack *S) // 判断栈空{ if(S->top==-1) return 1;elsereturn 0;}int iniQueue(Queue *Q) //初始化便道{Q->front=(QueueNode *)malloc(sizeof(QueueNode)); //申请节点if(Q->front!=NULL){Q->rear=Q->front;Q->front->next=NULL;return 1;}else return 0;}int EnterQ(Queue *Q,carinfo x) //进便道{QueueNode *newNode;newNode=(QueueNode *)malloc(sizeof(QueueNode)); if(newNode!=NULL){ newNode->data=x; newNode->next=NULL;Q->rear->next=newNode; Q->rear=newNode; return 1;}else return 0;}int DeleteQ(Queue *Q,carinfo x) // 出便道{QueueNode *p; p=Q->front->next;if(Q->front==Q->rear) //判断便道是否有车return 0;x=p->data;if(p->next==Q->rear)Q->rear=Q->front;Q->front->next=NULL;}Q->front->next=p->next; free(p); return 1;}void Lpush(Stack *S,carinfo x){ Push(S,x); //进临时栈}void LPop(Stack *S,carinfo x){Pop(S,x);}int Arrive(Stack *S,Queue *Q) // 车辆到达{carinfo x;int a;printf(" 输入车牌号:"); scanf("%s",x.num); printf(" 请输入进车场的时间:");scanf("%d",&x.reachtime);if(S->top==Size-1){printf(" 车场已满,不能进入,进便道");//递归调用进便道操作a=EnterQ(Q, x);if(a==1){ printf("OK\n");} else printf("No!\n");}else{ Push(S,x);} return 1;}int Departure(Stack *S) // 车辆离开操作{int money;。
#include<stdio.h>#include<malloc.h>#define N 30 /*停车场类最多的停车数*/ #define M 20 /*便道内最多的停车数*/ #define price 2 /*每单位时间的停车费用*/ typedef struct{int carNo[N]; /*车牌号*/int carTime[N]; /*进场时间*/int top; /*栈指针*/}seqstack; /*定义顺栈占类型*/ typedef struct Node{int carNo[M]; /*车牌号*/struct Node *next;}linkQueue Node;typedef struct{LinkQueue Node *front; /*队首指针*/LinkQueue Node *rear; /*队尾指针*/}LinkQueue; /*定义链队类型*//*以下是顺序栈的基本运算算法*/void Initstack(seqstack *s){s=(seqstack*)malloc(sizeof(seqstack));s->top=-1;}int IsEmpt(seqstack *s){return(s->top==-1);}int IsFull(seqstack *s){return(s->top==N-1);}int Push(seqstack *s,int e1,int e2){if(s->top==N-1) return 0;s->top++;s->carNo[s->top]=e1;s->carTime[s->top]=e2;return 1;}int Pop(seqstack *s,int &e1,int &e2)if(s->top==-1)return 0;e1=s->carNo[s->top];e2=s->carTime[s->top];s->top--;return 1;}void Disqstack(seqstack *s){int i;for(i=s->top;i>=0;i--)printf("%d",s->carNo[i]);printf("\n");}/*以下是链队的基本运算算法*/int InitQueue(LinkQueue *q){q->front=(LinkQueue Node *)malloc(sizeof(LinkQueue Node)); if(q->front!=NULL){q->rear=q->front;q->front->next=NULL;return(true);}else return(false);}int Empt(LinkQueue *q) /*判队满*/{return(q->front==q->rear);}int Lull(LinkQueue *q){return((q-a.rear+1)%M==q->front);}int EnterQueue(LinkQueue *&q,int e) /*进队*/{if((q->rear+1)%M==q->front) /*队满*/return 0;q->rear=(q->rear+1)%M;q->carNo[q->rear]=e;return 1;}int DeleteQueue(LinkQueue *&q,int &e) /*出队*/if(q->front==q->rear) /*对空情况*/return 0;q->front=(q->front+1)%M;e=q->carNo[q->front];return 1;}void DispQueue(LinkQueue *q) /*输出队中元素*/{int i;i=(q->front+1)%M;printf("%d",q->carNo[i];while((q->rear-i+M)%M>0){i=(i+1)%M;printf("%d",q->carNo[i]);}printf("\n");}void main(){int comm;int No,e1,Time,e2;int i,j;seqstack *st1,*st2;LinkQueue *qu;Initstack(st)Initstack(st1);InitQueue(Qu);do{printf("input a number(1:到达2:离开3:停车场4:便道0退出):"); scanf("%d%d%d",&comm,&no,&time);switch(comm){case 1; /*汽车到达*/if(!stackFull(st)) /*便道不满*/{Push(st,no,time);printf(">>停车场位置:%d\n",st->top+1);}else /*停车场满*/{if(!QueueFull(Qu)) /*便道不满*/{EnterQueue(Qu,no);printf(">>候车场位置:%d\n",qu->rear);}elseprintf(">>候车场已满,不能停车\n");}break;case 2: /*汽车离开*/for(i=0;i<=st->top&&st->carNo[i]!=no;i++);if(i>st->top)printf(">>未找到该编号汽车\n";else{ for(j=i;i<=st->top;j++){Pop(st,e1,e2);Push(st1,e1,e2); /*倒车到临时栈st1中*/}Pop(st,e1,e2); /*该汽车离开*/printf(">>%d汽车停车费用:%d\n",no,(time-e2)*price); while(!stackEmpty(st1)) /*将临时栈St1重新回到St中*/ { Pop(st1,e1,e2);Push(st,e1,e2);}if(!QueueEmpty(Qu)) /*队不空时,将队头进栈St*/{DeleteQueue(Qu,e1);Push(st,e1,time); /*以当前时间开始记费*/}}break;case 3: /*显示停车场情况*/if(!stackEmpty(Qu)){ printf(">>停车场中车辆:"); /*输出停车场中的车辆*/ Dispstack(st);}elseprintf(">>停车场中无车辆:");break;case 4: /*显示便道情况*/if(!QueueEmpty(Qu)){printf(">>便道中的车辆:"); /*输出便道中的车辆*/ DispQueue(Qu);}elseprintf(">>便道中无车辆\n");break;case 0: /*结束*/if(!stackEmpty(st)){printf(">>停车场中的车辆:"); /*输出停车场中的车辆*/ Dispstack(st);}if(!QueueEmpty(Qu)){printf(">>便道中车辆:"); /*输出便道中的车辆*/DispQueue(Qu);}break;defaut: /*其他情况*/printf("error\n");break;}}while(comm!=0);}。
#include<stdio.h>#include<stdlib.h>#define stacksize 2 //车站//容量///////////////////////////////////////////////////////typedef struct Snode{int number;float int_time[2];float bian_time[2];}record;typedef struct {record *base;record *top;int size;}Stack;/////////////////////////////////////////////////////typedef struct Qnode{int number;float int_time[2];struct Qnode *next;}Qnode,*Queue;typedef struct {Queue front;Queue rear;}Linkqueue;void xunhuan(Stack L,Linkqueue Q);void jixu(Stack L,Linkqueue Q);//////////////////////////////////////////////////////////////////////////////////////////////////////////void InitStack(Stack &L) //堆栈操作{L.base=(record*)malloc(sizeof(Snode)*stacksize);if(!L.base)exit(0);L.top=L.base;L.size=stacksize;}/////////////////////////////////////////////////////void input(Stack &L,record h){*L.top++=h;}///////////////////////////////////////////////////Snode output(Stack &L,record &e){e=*--L.top;return e;}int Stackman(Stack L){if(L.top-L.base==L.size)return 0;elsereturn 1;}int StackEmpty(Stack L){if(L.base==L.top)return 0;elsereturn 1;}////////////////////////////////////////////////////////////////////////////////////////////////////void Initque(Linkqueue &Q) //队列操作{Q.front=Q.rear=(Queue)malloc(sizeof(Qnode));if(!Q.front)exit(0);Q.front->next=NULL;}//////////////////////////////////////////////////void enqueue(Linkqueue &Q,int number,float time[]){Queue q;printf("停车场已满,请将车辆停入便道!\n");q=(Queue)malloc(sizeof(Qnode));q->int_time[0]=time[0];q->int_time[1]=time[1];q->number=number;q->next=NULL;Q.rear->next=q;Q.rear=q;}///////////////////////////////////////////////////void outqueue(Linkqueue &Q,Queue &e) //此处有点问题??????????????{// Qnode *q;// q=(Queue)malloc(sizeof(Qnode));e=Q.front->next;// Q.front->next=q->next;//delete q;Q.front->next=Q.front->next->next;if(Q.rear==e){Q.front=Q.rear;// Q.front=NULL;}}int QEmpty(Linkqueue Q){if(Q.rear==Q.front)return 0;elsereturn 1;}//////////////////////////////////////////////////// //停车场管理操作////////////////////////////////////////////////////void jixu(Stack L,Linkqueue Q){int n;fflush(stdin);scanf("%d",&n);switch(n){case 1:printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");xunhuan(L,Q);break;case 2:printf("****************************退出管理系统*****************************\n");default:printf("\n输入错误,请重新输入: ");jixu(L,Q);break;}}void jiaofei(float time[],float time1[],float time2[]) //缴费操作{float data1,data2;double money;if(time2[0]!=0&&time2[1]!=0)data2=(time1[0]-time2[0]-1)*60+60-time2[1]+time1[1];elsedata2=0;data1=(time[0]-time1[0]-1)*60+60-time1[1]+time[1];// printf("进入车场时间%f,退出车场时间%f\n",time1[1],time[1]);printf("你的停车时间为%lf小时,在便道停留时间%f小时\n",data1/60,data2/60);money=data1/60*5.0+data2/60*2.0;printf("请交纳%lf元\n",money);/* if(data1<=60.0)printf("请交纳5元。
// 1、停车场管理.cpp : Defines the entry point for the console application. //^include stdafx.h*'^include vcon 1o.h>^include <malloc・h>^include <stdio.h>^include <stdlib.h>^include <windows. h>//清空当前屏幕#define ClearScreen() system( 'cls M )〃设置背景前景颜色//#define setcolor() system(u color 2f )//显不字符串szPrompt并等待用户按下任意键#define Pause( szPrompt) printf( %s: szPrompt ),getch()typedef struct carinformation // 车辆信息{char szRegistrationMark[64]; // 车牌号char szArrivalTime[16]; // 到达时间char szEntranceT1me[16]; //进入停车场(开始计费)时间char szDepartureTime[16]; // 离开时间} TCARINFORMATION, *LPTCARINFORAAATION;typedef struct carstack{LPTCARINFORMATION IpCarlnformation; // 车辆信息int nTop; //栈顶元素下标int nStackSize; // 栈容量} TCARSTACK, *LPTCARSTACK;//初始化栈IpCarStack,将其容量设置为nSizevoid ln1tStack( LPTCARSTACK ftlpCarStack, int nSize ){IpCarStack = ( LPTCARSTACK ) malloc( sizeof ( TCARSTACK ));lpCarStack->lpCarlnformation = ( LPTCARINFORMATION ) malloc( nSize * sizeof ( TCARINFORAAATION ));lpCarStack->nTop = -1;lpCarStack->nStackSize = n Size;}// 车辆信息carinfo 入栈IpCarStackvoid Push( LPTCARSTACK ftlpCarStack, TCARINFORAAATION carinfo ){IpCarStack-Top++;lpCarStack->lpCarl nformation [lpCarStack->nTop] = carinfo;}//车辆信息从栈IpCarStack中弹出并存入carinfovoid Pop( LPTCARSTACK ftlpCarStack, TCARINFORMATION &carinfo ) {carinfo = lpCarStack->lpCarlnformation[lpCarStack-> nTop];IpCarStack->nTop・・;}//若栈IpCarstack空,返回TRUE;否贝!J,返回FALSEBOOL IsStackEmptyf LPTCARSTACK IpCarStack ){return IpCarStackjnTop == -1;}//若栈IpStackFull满,返回TRUE;否则,返回FALSEBOOL IsStackFulK LPTCARSTACK IpCarStack ) return lpCarStack->nTop == ( lpCarStack->nStackSize • 1 );}// 销毁栈IpCarStack,将指针IpCarStack 置为NULLvoid DestroyStack( LPTCARSTACK &IpCarStack ){free( lpCarStack->lpCarlnformation );free( IpCarStack );IpCarStack = NULL;}typedef struct carnode // 链队结点信息{TCARINFORMATION carinfo; // 车辆信息struct carnode *lpNext; //指向下一个元素的指针} TCARNODE, *LPTCARNODE;typedef struct carqueue // ¥连队{LPTCARNODE IpHead; // 头结点LPTCARNODE IpRear; //指向当前队尾的指针int nEffectivesize; //当前队中元素个数} TCARQUEUE, *LPTCARQUEUE;//初始化链队IpCarQueuevoid lnitQueue( LPTCARQUEUE ftlpCarQueue ){IpCarQueue = ( LPTCARQUEUE ) malloc( sizeof( TCARQUEUE )); lpCarQueue->lpHead = ( LPTCARNODE) malloc( sizeof( TCARNODE ));lpCarQueue->lpHead->lpNext = NULL;lpCarQueue->lpRear = lpCarQueue->lpHead;IpCarQueue-EffectiveSize = 0;}// 车辆信息carinfo 入队IpCarQueuevoid EnQueue( LPTCARQUEUE ftlpCarQueue, TCARINFORMATION carinfo ) {LPTCARNODE IpCarNode = ( LPTCARNODE ) malloc( sizeof( carnode )); lpCarNode->car1nfo = cari nfo;lpCarNode->lpNext = NULL;lpCarQueue->lpRear->lpNext = IpCarNode;lpCarQueue->lpRear = lpCarQueue->lpRear->lpNext;IpCarQueue->n EffectiveSize++;}//队头元素从链队IpCarQueue中出队并存入carinfovoid DeQueue( LPTCARQUEUE ftlpCarQueue, TCARINFORMATION ftcarinfo ) { LPTCARNODE IpTemp = lpCarQueue->lpHead->lpNext;carinfo = IpTemp ・>cari nfo;lpCarQueue->lpHead->lpNext = IpTemp ・> IpNext;free( IpTemp );IpCarQueue->n EffectiveSize-;}//若链队IpCarQueue为空,返回TRUE;否则,返回FALSEBOOL lsQueueEmpty( LPTCARQUEUE IpCarQueue ){return LpCarQueue->nEffect1veSize == 0;}//销毁链队IpCarQueuevoid DestroyQueue( LPTCARQUEUE EtlpCarQueue )LPTCARNODE IpNextCarNode = NULL;for ( LPTCARNODE IpCarNode = lpCarQueue->lpHead; IpCarNode != NULL; IpCarNode = IpNextCarNode ){IpNextCarNode = lpCarNode->lpNext;free( IpCarNode );}free( IpCarQueue );IpCarQueue = NULL;}//将字符串时间格式转换为数字(分钟)格式,例如12:36将被转换为756 (12 * 60 + 36)int ConvertTimeFormat( char *lpTime ){Int nHour = 0;int nMinute = 0;sscanf( IpTime, “%d:%d; 8tnHour, SnMinute );return nHour * 60 + nMinute;}//根据在停车场内的停留时间nContinuanceMinutes (分钟)计算费用double CalculateExpense( int nContinuanceMinutes ){return nContinuanceMinutes * ( 5.0 / 60 );}int main( void ){// setcolor();Int nParkCapability = 0; // 停车场容量putchar( \n*);PHns)jscanf(・•衣d jppnparkcapabujry「LPTCARSTACK -pear-stack"NULL"二®世曲生需更蹦-njrsrack 二pcarsrack 》nparkcmpmbsrty)八LPTCARQUEUE 【Pear-Queue =NULL"、二冊®曲爲兰赫更-njrQueue(-pcarQueue)jcharcCommandTypeHNULLj二劭3淋起 charSzuser-npuru28jH宀NULLY二a l}^> do宀Qearscreenoj二 seccoor(rpurchar(An ・rI .... );I -n -)j1 ->・-W 養区);purs(d ・W S B J F)jI H ・)」1-0・)」pucchar( -\n ・)一purs(=0辽)j P U £・A S§A 3926N 3W 3・・rPUS ・・9SPA3926二 444・・);puts(ni・);puts( © );putchar( \rf );printf(“请输入命令:“);seanf( “%s", szllserlnput);puts(H ................. “);char szCarlnformation[128] = { NULL};sscanff szllserlnput, //将命令类型与车辆信息分开存放”%c,%s“,&cCommandType, //用户输入的前半部分,即命令类型szCarlnformation //用户输入的后半部分,即车辆信息);char *LpCommaLocation = NULL; //车辆信息字符串中的逗号位置for ( IpCommaLocation = szCarlnformation; *lpCommaLocation != *\0'; lpCommaLocation++ ){if (*lpCommaLocation ==){break;}}*lpCommaLocati on = \0';TCARINFORMATION carinfo = { NULL }; //存储本次用户输入的车辆信息strcpy( carinfo.szRegistrationMark, szCarlnformation );if ( cCommandType == A )strcpy( carinfo.szArrivalTime, IpCommaLocation + 1 );if ( FALSE == lsStackFull( IpCarStack )){strcpy( carinfo.szEntranceTime, carinfo.szArrivalTime ); Push( IpCarStack, carinfo );printf(“已进入停车场第%d个车位\n“,lpCarStack->nTop + 1);printf("车牌号:\t\t%s\n", carinfo.szRegistrationMark ); printf("进入时间:\t%s\n", carinfo.szEntranceTime ); puts(“是否收费:\t是“);}else{EnQueue( IpCarQueue, carinfo );printf(“停车场已满,已停放在便道的第%d个车位\n“,lpCarQueue->nEffectiveS1ze);printf("车牌号:\t\t%s\n", carinfo.szRegistrationMark ); printf("停放时间:\t%s\n", carinfo.szArrivalTime );puts( ••是否收费:\t否”);}}else if ( cCommandType == 'D')strcpy( carinfo.szDepartureTime, IpCommaLocation + 1 );LPTCARSTACK IpTempCarStack = NULL;lnitStack( IpTempCarStack, nParkCapability );TCARINFORMATION carinfoOut = { NULL };BOOL blsCarFound = FALSE;while ( FALSE == lsStackEmpty( IpCarStack )){Pop( IpCarStack, carinfoOut);if ( 0 != strcmp( carinfoOut.szRegistrationMark, carinfo.szRegistrationMark )) {Push( IpTempCarStack, carinfoOut);}else{blsCarFound = TRUE;break;}}while ( FALSE == IsStackEmptyf IpTempCarStack )){TCARINFORAAATION tempcarinfo = { NULL };Pop( IpTempCarStack, tempcarinfo );Push( IpCarStack, tempcarinfo );} if ( FALSE == blsCarFound ) printf(1车牌号为%s 的车未进入停车场・\n;carinfo.szRegistrationMark );Pause(M.................... \n按任意键输入下 V信息…\n“);continue;strcpy( carinfoOut.szDepartureTime, carinfo.szDepartureTime );int nEntranceTime = ConvertTimeFormat( carinfoOut.szEntranceTime ); Int nDepartureTIme = ConvertTimeFormat( carinfoOut.szDepartureTime ); int nContinuanceMinutes = nDepartureTime • nEntranceTime;printf("计费时段:\t%s - %s (共%d 分钟)\n",carinfoOut.szE ntran ceTime,carinfoOut.szDepartureTime, nContinu anceMinutes);double rExpense = CalculateExpense( nContinuanceMinutes );printf("应交纳的费用:\t%.1 If 7E\n", rExpense );if ( FALSE == lsQueueEmpty( IpCarQueue )){TCARINFORAAATION tempcarinfo = { NULL };DeQueue( IpCarQueue, tempcarinfo );strcpy( tempcarinfo.szEntranceTim® carinfoOut.szDepartureTime ); Push( IpCarStack, tempcarinfo );puts(" .................... ”);printf(“停放在便道的第1个车位,车牌号为%s的车已进入停车场\n“,tempcarinfo. szRegistrati on Markelse if ( cCommandType == E )puts( "********************"puts(H :吴远彦\n M);puts「学号:\n u);Uts( M********************" )•break;else if ( cCommandType == 0*){ClearScree n();//setcolor();putchar( *\n );puts( “[停车场使用情况]\n“);puts( •[车位]\t[车牌号]\t倒达时间]\t[进入(开始计费)时间]\n“); for (in t i = 0; i <= IpCarStack-Top; i++ ){printf( M%d\t%s\t\t%s\t\t%s\n\i + 1,IpCarStack- > IpCar I nformati on [i]・ szRegistratio nAAark, lpCarStack->lpCarlnformat1 on [i].szArrivalTime,lpCarStack->lpCarlnformation[i].szE ntranceTime);}putchar( \n );putchar( \n );putchar( \n );puts( •■[便道使用情况]\n“);puts( •[车位]\t[车牌号]\t[到达时间]\t[进入(开始计费)时间]\n“); int nNum = 0;for ( LPTCARNODE IpCarNode = lpCarQueue->lpHead->lpNext; IpCarNode != NULL; IpCarNode = lpCarNode->lpNext ){n Num++;printf( ,,%d\t%s\t\t%s\t\t%s\n\n Num,lpCarNode->carinfo.szRegistratio nMark,lpCarNode->carinfo.szArrivalTime,lpCarNode->carinfo.szEntra nceTime);}putchar( \n );}else{puts(“输入信息有误.第f 字符只能为'A'或D或E或0'(区分大宵) }Pause(”.................... \n按任意键输入下一息.\n“);} while ( TRUE );DestroyStack( IpCarStack );DestroyQueue( IpCarQueue );Pause( “\n按任意键退出程序...\n“);return 0;。