停车场管理系统源代码
C语言:停车场管理系统
#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语言
t->next=NULL;
q->rear->next=t;
q->rear=t;//q->rear=q->rear->next;
printf("%d号车进入便道等待\n",q->rear->data);
q->geshu++;
}
}
int D_cars(SqStack *s,LinkQueue *q,struct car d)
{QNODE *front,*rear;
int geshu;
}LinkQueue;
QNODE *head;
struct Dcar dd[MAXSIZE];
A_cars(SqStack *s,LinkQueue *q,struct car a)
{QNODE *t, *p;
printf(" ** 停车场管理系统 ** \n");
printf(" ** ** \n");
a=s->top;
printf("停车场内车辆数: %d\n",(s->top)+1);
printf("停车场内剩余空位:%d\n",3-s->top);
printf("详细信息:\n");
while(s->top>=0)
{printf("%d号车,%d时停车\n",(s->G[s->top]).num,(s->G[s->top]).time);
{int i,j,l;
C语言停车场管理系统源代码.doc
#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元。
停车场管理系统的代码
设停车场是一个可停放n 辆车的狭长通道,且只有一个大门可供汽车进出。
在停 车场内,汽车按到达的先后次序,由北向南依次排列(假设大门在最南端)。
若 车场内已停满n 辆车,则后来的汽车要在门外的便道上等候, 当有车开走时,便 道上的第一辆车即可开入。
当停车场内某辆车要离开时,在它之后进去的车辆必 须先推出车场为它让路,待该辆车开出大门以后,其他车辆再按原次序返回车场。
每辆车离开停车场时,应按其停留时间的长短交费(在便道上停留的时间不收 费)。
试编写程序,模拟上述管理过程。
要求以顺序栈模拟停车场,以链队列模 拟便道。
从终端读入汽车到达或离去的数据,每组数据包括三项:(1)是“到达” 还是“离去” (2)汽车牌照号码;(3) “到达”或“离去”的时刻。
与每组输入信 息相应的输出信息为:如果是到达的车辆,则输出其在停车场中或便道上的位置; 如果是离去的车辆,则输出其在停车场中停留的时间和应缴的费用。
(需另设一个栈,临时停放为让路而从车场退出的车。
)#include<iostream> #define M 5using namespace std;typedef int Datatype;typedef struct {Datatype bianhao[M];int top;int h[M]; // int m[M]; //int s[M]; // }Seqstack; // typedef struct Node // { Datatype bianhao; struct Node *next; }node;typedef struct{node *front;node *rear;int count;}biandao; // 便道//停车场顺序栈初始化void lnitSeqstack(Seqstack *t)时分秒停车场栈的定义{t->top=-1;}//进栈,即进入停车场int Push(Seqstack *t,int x,int h,int m,int s){if(t->top==M-1)return 0; // 停车场栈已满t->top++;t->bianhao[t->top]=x;t->h[t->top]=h;t->m[t->top]=m;t->s[t->top]=s;return 1;}//出栈,即离开停车场int Pop(Seqstack *t,int *x,int *h,int *m,int *s) {if(t->top==-1)return 0;else{*x=t->bianhao[t->top]; *h=t->h[t->top]; *m=t->m[t->top];*s=t->s[t->top]; t->top--;return 1;}}//查找某牌照的车在停车场中的位置,若找到则返回其位置,否则返回-1int Find(Seqstack t,int x){int i;for(i=0;iv=t.top;i++){ if(t.bianhao[i]!=x) continue;elsebreak;}if(i>t.top)return(-1);elsereturn(i);}//判断停车场内是否已满int lsSeqstackFull(Seqstack t){if(t.top==M-1)return 1;elsereturn 0;}//判断停车场内是否已没有车辆int lsSeqstackEmpty(Seqstack t) {if(t.top==-1)return 1;elsereturn 0;}//依次显示停车场内停放的所有车辆void ShowSeqstack(Seqstack t) {int i;if(t.top==-1)coutvv"停车场内没有停放车辆"vvendl;elsefor(i=0;i<=t.top;i++)coutvv"牌照:"vvt.bianhao[i]vvendl;}//队列初始化int Initbiandao(biandao *Q){Q->front=new node;if(Q-> front!=NULL){Q->rear=Q->fr ont;Q->front->next=NULL;Q->count=0;return(true);}else return(false);}//入队操作,即当停车场满了的时候,再到达的车辆进去便道队列int Enterbiandao(biandao *Q,int x) {node *NewNode; NewNode=new node; if(NewNode!=NULL) {NewNode->bianhao=x; NewNode->next=NULL;Q->rear->next=NewNode; Q->rear=NewNode;Q->co un t++;return(true);}else return(false);}//出队操作,即便道上的车辆从便道开出来int Deletebiandao(biandao *Q,int *x){node *p;if(Q->fro nt==Q->rear)return(false);p=Q->front->next;Q->front->next=p->next; if(Q->rear==p) Q->rear=Q->fr ont;*x=p->bianhao;free(p);Q->count--;return(true);}//判断便道队列是否为空int lsbiandaoEmpty(biandao Q){if(Q.front==Q.rear) return(true);elsereturn(false);// 当count=0时,就空了}//依次显示便道上停放的所有车辆void Showbiandao(biandao Q)node *p;p=Q.front->next;if(p==NULL)coutvv"便道上没有停放车辆!"vvendl;elsewhile(p!=NULL){coutvv" 牌照:"vvp->bianhaovvendl; p=p->n ext;}}36//计算停留时间差double Time(int h1,int m1,int s1,int h2,int m2,int s2) {double p,q;p=h1*3600+m1*60+s1 -(h2*3600+m2*60+s2); q=(double)p/3600;return(q);}//计算停车费用double Cost(double t,int u){return(t*u);}//主函数void main(){double time,cost;int ch;int x,*y, z;int i,flag=1,h,m,s,unit_price,hh,mm,ss;y=new int; Seqstack *t;// 定义停车栈t=new Seqstack;InitSeqstack(t);biandao *Q;// 定义便道队列Q=new biandao;Initbiandao(Q); Seqstack *r; //定义让路 栈r=new Seqstack;InitSeqstack(r);coutvv"请设置停车费用单价:(_元/小时)"vvendl; cin>>unit_price;while(flag){ 束"vvendl;cin>>ch;switch(ch) {case 1:coutvv" 请输入到达的汽车牌照号码:"vvendl; cin>>x;if(lsSeqstackFull(*t)){coutvv" 停车场已满,请在便道等候 !"vvendl; "vvendlvv"2: 离开"vvendlvv"3:依次显示停车场内停放车H***************************" coutvv" 请选 择命令:"vvendlvv"1:辆"vvendlvv"4:依次显示便道上停放车辆 "<<endlvv"5: 结 coutvv vvendl;coutvv H***************************" vvendl;Enterbiandao(Q,x);coutvv" 将此车停放在便道的"vvQ->countvv" 号位置!"vvendl;}else{while(1){coutvv" 请输入到达的时间(例如,21 08 23) : "vvendl;cin>>h>>m>>s;if (hv0 || h>23) continue; //输入数据不合法,回去重新输入if (mv0 || m>59) continue;if (s>-1 && sv61)break;//输入时间全部合法,退出循环}Push(t,x,h,m,s);coutvv" 将此车停放在停车场的"vvt->top+1vv" 号停车位置"vvendl;}break;case 2:if(lsSeqstackEmpty(*t))coutvv" 停车场内已没有车辆"vvendl;else{coutvv" 请输入要离开的汽车的车牌照号码:"vvendl;cin>>x;if(Find(*t,x)==-1)coutvv" 停车场内没有该汽车!"vvendl;else//有该号码的汽车{while⑴{coutvv" 请输入离开的时间(例如,2358 03) : "vvendl;cin>>h>>m>>s;if (h<0 || h>23) continue;//输入数据不合法,回去重新输入if (m<0 || m>59) continue;if (s>-1 && s<61)break; // 输入时间全部合法,退出循环}if(Find(*t,x)==t->top){Pop(t,y,&hh,&mm,& ss);//要离开的车辆正好是最后一辆进入停车场的车time=Time(h,m,s,hh,mm,ss);coutvv" 停留时间为:"vvtimevv"小时"vvendl; // 结账cost=Cost(time,unit_price);coutvv"应缴费用为:"vvcostvv" 元"vvendl;}else{for(i=(Find(*t,x)+1);iv=t->top;)〃该车不是最后一辆进入停车场的车,其它车要让路{Pop(t,y,&hh,&mm,& ss);Push(r,*y,hh,mm,ss); //进入让路栈rPop(t,y,&hh,&mm, &ss);//要离开的车辆离开了time=Time(h,m,s,hh,mm,ss);coutvv" 停留时间为:时"vvendl; // 结账cost=Cost(time,unit_price);coutvv"应缴费用为: "vvendl;for(i=0;iv=r->top;) // 让路的车辆重新回到停车场{Pop(r,y,&hh,&mm, &ss); Push(t,*y,hh,mm,ss); }}if(!lsbiandaoEmpty(*Q)){Deletebiandao(Q, &z);//便道上的第一辆车出队Push(t, z, h,m,s);//进入停车场,默认进入的时刻就是刚才的车离开的时刻}elsecoutvv"便道上没有车辆等候!"vvendl;}}break;"vvtimevv"小 "vvcostvv"元case 3:ShowSeqstack(*t); break;case 4:Showbiandao(*Q); break;case 5:flag=O;break;default:cout<<"错误命令!"vvendl;}}}。
C停车场管理系统简单代码实现
C停车场管理系统简单代码实现#include<iostream.h>#include<stdio.h>#include<stdlib.h>#include<string.h>#define MAX 30 /*车库容量*/#define price 30 /*每车每小时费用*/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 *); /*初始化栈*/int InitQueue(LinkQueueCar *); /*初始化便道*/int Arrival(SeqStackCar *,LinkQueueCar *); /*车辆到达*/void Leave(SeqStackCar *,SeqStackCar *,LinkQueueCar *); /*车辆离开*/ void List(SeqStackCar,LinkQueueCar); /*显示存车信息*/void main(){system("color 00f");SeqStackCar Enter,Temp;LinkQueueCar Wait;int ch;InitStack(&Enter); /*初始化车站*/InitStack(&Temp); /*初始化让路的临时栈*/InitQueue(&Wait); /*初始化通道*/while(1){cout<<" 欢迎光临"<<endl;cout<<"**************************"<<endl;cout<<" 1. 车辆到达"<<endl;cout<<" 2. 车辆离开"<<endl;cout<<" 3. 列表显示"<<endl;cout<<" 4. 退出系统"<<endl;cout<<"**************************"<<endl;cout<<"请选择所需要的服务!"<<endl;cout<<"请注意正确输入时间,不要为非数字!"<<endl;while(1){cin>>ch;if(ch>=1&&ch<=4)break;else cout<<"请选择:1|2|3|4."<<endl;}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;}}}void InitStack(SeqStackCar *s) /*初始化栈*/{int i;s->top=0;for(i=0;i<=MAX;i++)s->stack[s->top]=NULL;}int InitQueue(LinkQueueCar *Q) /*初始化便道*/{Q->head=(QueueNode *)malloc(sizeof(QueueNode));if(Q->head!=NULL){Q->head->next=NULL;Q->rear=Q->head;return(1);}else return(-1);}void PRINT(CarNode *p,int room) /*打印出站车的信息*/ {int A1,A2,B1,B2;cout<<"请输入离开的时间:/**:**/"<<endl;cin>>p->leave.hour;while(p->leave.hour<p->reach.hour||p->leave.hour>23) {cout<<"error!"<<endl;cout<<"请输入离开的时间的时("<<p->reach.hour<<"-23)"<<endl;cin>>p->leave.hour;B1=p->leave.hour;}cout<<":"<<endl;cin>>p->leave.min;cout<<endl<<"离开车辆的车牌号为:"<<endl;puts(p->num);cout<<"其到达时间为:"<<p->reach.hour<<":"<<p->reach.min<<endl;cout<<"离开时间为: "<<p->leave.hour<<":"<<p->leave.min<<endl;A1=p->reach.hour;A2=p->reach.min;B1=p->leave.hour;B2=p->leave.min;cout<<"应交费用为: "<<((B1-A1)*60+(B2-A2))*price<<"元!"<<endl;free(p);}int Arrival(SeqStackCar *Enter,LinkQueueCar *W) /*车辆到达*/{CarNode *p;QueueNode *t;p=(CarNode *)malloc(sizeof(CarNode));flushall();cout<<"请输入车牌号(例:A1234):"<<endl;gets(p->num);if(Enter->top<MAX) /*车场未满,车进车场*/{Enter->top++;cout<<"车辆在车场第"<<Enter->top <<"位置!"<<endl;cout<<"请输入到达时间:/**:**/"<<endl;cin>>p->reach.hour;while(p->reach.hour<0||p->reach.hour>23){cout<<"error!"<<endl;cout<<"请输入到达时间的时(0-23)!"<<endl;cin>>p->reach.hour;}cout<<":"<<endl;cin>>p->reach.min;while(p->reach.min<0||p->reach.min>59){cout<<"error!"<<endl;cout<<"请输入到达时间的分(0-59)!"<<endl;cin>>p->reach.min;}Enter->stack[Enter->top]=p;return(1);}else /*车场已满,车进便道*/{cout<<"该车须在便道等待!"<<endl;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) /*输入离开车辆的信息*/{cout<<"请输入车在车场的位置1--"<<Enter->top<<":";cin>>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;Enter->top++;cout<<"便道的"<<t->num<<"号车进入车场第"<<Enter->top<<"位置!"<<endl;cout<<"请输入现在的时间如/*:*/:"<<endl;if(p->reach.hour<0||p->reach.hour>23){cout<<"error!"<<endl;cout<<"请输入到达时间的时(0-23)!"<<endl;cin>>p->reach.hour;}cout<<":"<<endl;cin>>p->reach.min;if(p->reach.min<0||p->reach.min>59){cout<<"error!"<<endl;cout<<"请输入到达时间的分(0-59)!"<<endl;cin>>p->reach.min;}W->head->next=q->next;if(q==W->rear) W->rear=W->head;Enter->stack[Enter->top]=t;free(q);}else cout<<"便道里没有车!"<<endl;}else cout<<"车场里没有车!"<<endl; /*没车*/}void List1(SeqStackCar *S) /*列表显示车场信息*/{int i;if(S->top>0) /*判断车站内是否有车*/{cout<<"车场:"<<endl;cout<<" 位置到达时间车牌号"<<endl;for(i=1;i<=S->top;i++){cout<<" "<<i<<""<<S->stack[i]->reach.hour<<":"<<S->stack[i]->reach.min<<" "<<S->stack[i]->num<<endl;}}else cout<<"车场里没有车!"<<endl;}void List2(LinkQueueCar *W) /*列表显示便道信息*/ {QueueNode *p;p=W->head->next;if(W->head!=W->rear) /*判断通道上是否有车*/ {cout<<"等待车辆的号码为:"<<endl;while(p!=NULL){puts(p->data->num);p=p->next;}}else cout<<"便道里没有车!";}void List(SeqStackCar S,LinkQueueCar W){int flag,tag;flag=1;while(flag){cout<<"请选择1|2|3:"<<endl;cout<<"1.车场"<<endl<<"2.便道"<<endl<<"3.返回"<<endl;while(1){cin>>tag;if(tag>=1||tag<=3) break;else cout<<"请选择1|2|3:"<<endl;}switch(tag){case 1:List1(&S);break; /*列表显示车场信息*/case 2:List2(&W);break; /*列表显示便道信息*/case 3:flag=0;break;default: break;}}}。
停车场管理系统代码
// 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;。
停车场管理系统代码(C )
char license_plate[MAX_PLATE];//汽车牌照号码,定义为一个字符指针类型 char state; //汽车当前状态,字符 p 表示停放在停车位上,字符 s 表示停放在便道上, 每辆车的初始状态用字符 i 来进行表示 }CAR;
//定义模拟停车场的栈结构 typedef struct {
StackTop(tmpparking, license_plate);
StackPush(parking, license_plate); cout<<"牌照为"<<license_plate<<"的车进入停车场"<<parking.top+1<<"号 位"<<endl; license_plate[0]='\0'; StackPop(tmpparking); if(parking.top+1==MAX_STOP-1)//判断车离开前停车场是否停满
InitList(sidewalk);
//运行界面及功能选择
停车场管理系统设计源代码
附录源代码1.头文件Car.h#ifndef CAR#define CAR#include <iostream>using namespace std;typedef struct Node{void *data;struct Node *link;}nodeS;typedef struct Sta{nodeS *top;int count;}Stack;typedef struct NodeQ{void *dataptr;struct NodeQ *next;}nodeQ;typedef struct Queues{int count;nodeQ *front;nodeQ *rear;}Que;Stack *Createstack();void* pop(Stack *stack);void push(Stack *stack,void *data);void DestroyStack(Stack *stack);Que *CreateQueue();void Enqueue(Que *queue);void *Dequeue(Que *queue);void Destroyqueue(Que *queue);#endif2.实现文件Car.cpp#include "Car.h"Stack *Createstack(){Stack *stack;stack = new Stack;if(stack == NULL)return NULL;stack->count = 0;stack->top = NULL;return stack;}void push(Stack *stack,void *data){nodeS *node;node = new nodeS;if(node == NULL || stack == NULL)return ;node->data = data;node->link = stack->top;stack->top = node;stack->count++;}void* pop(Stack *stack){void *data;nodeS *node;node = new nodeS;if(stack->count == 0)return NULL;data = stack->top->data;node = stack->top;stack->top = node->link;stack->count--;return data;}void DestroyStack(Stack *stack){nodeS *node;if(stack->count == 0)return ;while(stack->count == 0){delete stack->top->data;node = stack->top;stack->top = node->link;stack->count--;}delete stack;}Que *CreateQueue(){Que *queue;queue = new Que;if(queue == NULL)return NULL;queue->count = 0;queue->front = NULL;queue->rear = NULL;return queue;}void Enqueue(Que *queue){nodeQ *node;node = new nodeQ;if(node == NULL || queue == NULL) return ;node->next = NULL;if(queue->count == 0){queue->front = node;}else{queue->rear->next = node;}queue->rear = node;queue->count++;}void *Dequeue(Que *queue){void *dataptr;if(queue->count == 0)return NULL;dataptr = queue->front->dataptr;if(queue->count == 1)queue->front = queue->rear = NULL;elsequeue->front = queue->front->next;queue->count--;return dataptr;}void Destroyqueue(Que *queue){nodeQ *node;if(queue->count == 0)return ;while(queue->count == 0){delete queue->front->dataptr;node = queue->front;queue->front = node->next;queue->count--;}delete queue;}3.主文件ThePort.cpp#include "Car.h"#include <CTime>#include <fstream>#include <string>typedef struct InFor{string num;int hour;int min;int sec;int year;int mon;int day;}Infor;int face();int Face();bool Book(Stack *stack,Que *queue,int max);void bookface();time_t compare(Infor *infor);void Display(Infor *infor);time_t arrival(Stack *stack,Infor *infor,Que *queue,int max); void leave(Stack *stack,Que *queue,time_t inform);void Getmoney(Infor *infor,int Bianhao,time_t inform); void checknum(string num);void InforBook(Stack *stack,Que *queue,int max);int Inforface();void Inforstack();void Inforleave();void Inforqueue(Que *queue);int main(){ofstream fout("estdout.txt",ios::trunc);ofstream fout2("leaveout.txt",ios::trunc);bookface();fout.close();fout2.close();return 0;}void bookface(){Stack *stack;Que *queue;stack = Createstack();queue = CreateQueue();int max;bool flag = false;while(max = face()){if(max > 20 || max <= 0){cout<<"\t\t\t输入错误,请重新输入!"<<endl;system("pause");system("cls");}else{flag = Book(stack,queue,max);}if(flag == true){break;system("pause");}}}int face(){cout<<endl<<endl;cout<<"请输入停车场的最大容量(1-20):";int max;cin>>max;return max;}int Face(){system("cls");cout<<endl;cout<<"\t\t\t*************************************"<<endl;cout<<"\t\t\t* *"<<endl;cout<<"\t\t\t* 1、停车登记2、离开结算*"<<endl;cout<<"\t\t\t* *"<<endl;cout<<"\t\t\t* 3、登记记录4、退出系统*"<<endl;cout<<"\t\t\t* *"<<endl;cout<<"\t\t\t*************************************"<<endl;cout<<"\t\t请输入你的业务:";int choose;cin>>choose;return choose;}bool Book(Stack *stack,Que *queue,int max){int choose;bool flag = false;time_t inform;while(choose = Face()){Infor *infor;infor = new Infor;if(choose > 4 || choose <= 0){cout<<"\t\t\t输入错误,请重新输入!"<<endl;system("pause");system("cls");}else{switch(choose){case 1:inform = arrival(stack,infor,queue,max);max--;break;case 2:leave(stack,queue,inform);break;case 3:InforBook(stack,queue,max);break;case 4:cout<<endl;cout<<"\t\t\t谢谢使用,欢迎下次再来"<<endl;flag = true;break;}if(flag == true)break;system("pause");}}return flag;}time_t arrival(Stack *stack,Infor *infor,Que *queue,int max){time_t inform;if(max > 0){inform = compare(infor);push(stack,infor);Display(infor);return inform;}else{cout<<endl<<"\t\t\t对不起停车场已满,请停靠在便道上"<<endl;Enqueue(queue);}}time_t compare(Infor *infor){time_t now;struct tm *inform;time(&now);inform = localtime(&now);infor->hour = inform->tm_hour;infor->min = inform->tm_min;infor->sec = inform->tm_sec;infor->year = inform->tm_year;infor->mon = inform->tm_mon;infor->day = inform->tm_mday;cout<<endl;cout<<"请输入你的车牌号<B23548>:";cin>>infor->num;checknum(infor->num);return now;}void Display(Infor *infor){ofstream fout("estdout.txt",ios::app);cout<<endl;cout<<"\t\t\t车牌号:"<<infor->num<<endl;cout<<"\t\t\t当前年月:"<<infor->year+1900<<"/"<<infor->mon+1<<"/"<<infor->day<<endl;cout<<"\t\t\t当前时刻: "<<infor->hour<<":"<<infor->min<<":"<<infor->sec<<endl;fout<<infor->num<<" "<<infor->year+1900<<" "<<infor->mon+1<<" "<<infor->day<<" "<<infor->hour<<" "<<infor->min<<""<<infor->sec<<endl;fout.close();}void leave(Stack *stack,Que *queue,time_t inform){Stack *stacktemp;stacktemp = Createstack();Infor *temp,*a;temp = new Infor;a = new Infor;string num;int m;bool flag;m = stack->count;if(m <= 0){cout<<endl;cout<<"\t\t\t停车场没有车!"<<endl;return ;}else{cout<<endl;cout<<"请输入将要离开的车的车牌号:";cin>>num;while(1){checknum(num);for(int i=0;i<m;i++){temp = (Infor *)pop(stack);push(stacktemp,temp);for(int k=0;k<6;k++){if(temp->num[k] != num[k]){flag = false;break;}elseflag = true;}if(flag == true){if(m == 1){Getmoney(temp,m,inform);}else{a = (Infor *)pop(stacktemp);Getmoney(a,i,inform);for(int j=0;j<i;j++){a = (Infor *)pop(stacktemp);push(stack,a);}if(queue->count > 0){a = (Infor *)Dequeue(queue);compare(a);push(stack,a);}}}}if(flag == false){cout<<endl;cout<<"没有此车的车牌号或车牌号错误,请重新输入:";cin>>num;for(int n=0;n<m;n++){temp = (Infor *)pop(stacktemp);push(stack,temp);}}else break;}}return ;}void checknum(string num){while(1){bool flag = true;if(num.length() != 6 || num[0] > 'Z' || num[0] < 'A'){flag = false;}for(int i=1;i<num.length();i++){if(num[i] > '9' || num[i] < '0'){flag = false;break;}}if(flag == false){cout<<endl;cout<<"你输入的车牌类型,请重新输入你的车牌号<B23548>:";cin>>num;continue;}elsebreak;}}void Getmoney(Infor *infor,int Bianhao,time_t inform){time_t now;struct tm *inform2;time(&now);inform2 = localtime(&now);double pay;ofstream fout("leaveout.txt",ios::app);pay = (difftime(now,inform)*1)/10;cout<<endl;cout<<"\t\t编号:"<<Bianhao<<endl;cout<<"\t\t车牌号:"<<infor->num<<endl;cout<<"\t\t起始年月:"<<infor->year+1900<<"/"<<infor->mon+1<<"/"<<infor->day<<endl;cout<<"\t\t起始时刻:"<<infor->hour<<":"<<infor->min<<":"<<infor->sec<<endl;cout<<"\t\t当前年月:"<<inform2->tm_year+1900<<"/"<<inform2->tm_mon+1<<"/"<<inform2->tm_mday<<endl;cout<<"\t\t当前时刻:"<<inform2->tm_hour<<":"<<inform2->tm_min<<":"<<inform2->tm_sec<<endl;cout<<"\t\t你的需要缴纳的费用:"<<pay<<"元"<<endl;fout<<Bianhao<<" "<<infor->num<<" "<<inform2->tm_year+1900<<""<<inform2->tm_mon+1<<" "<<inform2->tm_mday<<" "<<inform2->tm_hour<<" "<<inform2->tm_min<<" "<<inform2->tm_sec<<" "<<pay<<endl;fout.close();}void InforBook(Stack *stack,Que *queue,int max){int choose;while(choose = Inforface()){if(choose > 4 || choose <= 0){cout<<"\t\t\t输入错误,请重新输入!"<<endl;system("pause");system("cls");}else{switch(choose){case 1:Inforstack();break;case 2:Inforleave();break;case 3:Inforqueue(queue);break;case 4:Book(stack,queue,max);break;}}}}int Inforface(){system("cls");cout<<endl;cout<<"\t\t\t*************************************"<<endl;cout<<"\t\t\t* *"<<endl;cout<<"\t\t\t* 1、今天登记情况2、离开车辆记录*"<<endl;cout<<"\t\t\t* *"<<endl;cout<<"\t\t\t* 3、便道信息查询4、返回主页面*"<<endl;cout<<"\t\t\t* *"<<endl;cout<<"\t\t\t*************************************"<<endl;cout<<"\t\t请输入你的业务:";int choose;cin>>choose;return choose;}void Inforstack(){ifstream fin("estdout.txt");if(fin.eof() == NULL){cout<<endl;cout<<"\t\t\t当前没有停车记录!"<<endl;system("pause");return ;}while(fin.eof() != NULL){Infor *infor;infor = new Infor;fin>>infor->num>>infor->year>>infor->mon>>infor->day>>infor->hour>>infor->min>>infor->sec;cout<<endl;cout<<"\t\t\t车牌号:"<<infor->num<<endl;cout<<"\t\t\t当前年月:"<<infor->year+1900<<"/"<<infor->mon+1<<"/"<<infor->day<<endl;cout<<"\t\t\t当前时刻:"<<infor->hour<<":"<<infor->min<<":"<<infor->sec<<endl;}system("pause");fin.close();}void Inforleave(){ifstream fin("leaveout.txt");if(fin.eof() == NULL){cout<<endl;cout<<"\t\t\t当前没有离开记录!"<<endl;system("pause");return ;}while(fin.eof() != NULL){Infor *infor;int Bianhao;int money;infor = new Infor;fin>>Bianhao>>infor->num>>infor->year>>infor->mon>>infor->day>>infor->hour>>infor->min>>infor->sec>>money;cout<<endl;cout<<"\t\t编号:"<<Bianhao<<endl;cout<<"\t\t车牌号:"<<infor->num<<endl;cout<<"\t\t当前年月:"<<infor->year+1900<<"/"<<infor->mon+1<<"/"<<infor->day<<endl;cout<<"\t\t当前时刻:"<<infor->hour<<":"<<infor->min<<":"<<infor->sec<<endl;cout<<"\t\t缴纳的费用:"<<money<<"元"<<endl;}system("pause");fin.close();}void Inforqueue(Que *queue){if(queue->count == 0){cout<<endl;cout<<"\t\t\t便道里面没有车!"<<endl;system("pause");return ;}cout<<"\t\t\t便道里面停有"<<queue->count<<"辆车!"<<endl;system("pause");return ;}。
数据结构-停车场管理程序代码
源程序代码:#include <stdio.h>#include <stdlib.h>#include <iostream.h>#include <time.h>#define MaxSize 5#define fee 2#define L 10000#define M 20000typedef int ElemType;ElemType tmpnum=0;ElemType tmptime=0;typedef struct {ElemType car_num[MaxSize];ElemType car_time[MaxSize];int top;}STACK;typedef struct qnode {ElemType car_num;ElemType car_time;struct qnode *next;}QTYPT;typedef struct qptr {QTYPT *front;QTYPT *rear;}SQUEUE;SQUEUE LQ;void InitStack(STACK *S){S->top = -1;}int Full(STACK *S){if(S->top==MaxSize-1){printf("\n Stack is full! Push");return 0;}return 1;}int Push(STACK *S,ElemType num,ElemType time){ if(S->top==MaxSize-1){printf("\n Stack is full! Push");return 0;}S->top++;S->car_num[S->top]=num;S->car_time[S->top]=time;return 1;}int Empty(STACK *S){return (S->top==-1 ? 1:0);}int Pop(STACK *S,ElemType *num,ElemType *time){if(Empty(S)){puts("Stack is free Pop");return 0;}*num=S->car_num[S->top];*time=S->car_time[S->top];S->top--;return 1;}int GetTop(STACK *S,ElemType *num,ElemType *time){ if(Empty(S)){puts("Stack is free Gettop");}*num=S->car_num[S->top];*time=S->car_time[S->top];return 1;}void InitQueue(SQUEUE *LQ){QTYPT *p=NULL;p=(QTYPT *)malloc(sizeof(QTYPT));p->next=NULL;LQ->front=LQ->rear=p;}int EnQueue(SQUEUE *LQ,ElemType num,ElemType time){ QTYPT *s;s=(QTYPT *)malloc(sizeof(QTYPT));s->car_num=num;s->car_time=time;s->next=LQ->rear->next;LQ->rear->next=s;LQ->rear=s;return 1;}int CountQueue(SQUEUE *LQ){int i=1;QTYPT *mfront=NULL;QTYPT *mrear=NULL;mfront=LQ->front;mrear=LQ->rear;while(!(LQ->front==LQ->rear)){i++;LQ->front=LQ->front->next;}LQ->front=mfront;return i;}int Empty_Q(SQUEUE *LQ){return (LQ->front==LQ->rear?1:0);}int OutQueue(SQUEUE *LQ,ElemType *num,ElemType *time){ QTYPT *p;if(Empty_Q(LQ)){puts("Quenue is free OutQuenue");return 0;}p=LQ->front->next;*num=p->car_num;*time=p->car_time;LQ->front->next=p->next;if(LQ->front->next==NULL)LQ->rear=LQ->front;free(p);return 1;}int GetHead(SQUEUE *LQ,ElemType *num,ElemType *time){ if(Empty_Q(LQ)){puts("Quenue is free GetHead");return 0;}*num=LQ->front->next->car_num;*time=LQ->front->next->car_time;return 1;}void sleep(int time){clock_t goal;goal=time*(CLOCKS_PER_SEC)+clock();while(goal > clock()){;}}int chackinput(STACK *S,int pnum){int i=0;int num;num = pnum;i=S->top;for(;!(i==-1);i--)if(S->car_num[i]==num)return 1;return 0;}int chacktime(STACK *S,int ptime){return S->car_time[S->top] <= ptime ? 1 : 0;}int displaystats(STACK *S,int pinput){void displayhead(void);int i = 0;i = S->top;switch(pinput){case 10000:{if(!Empty(S))for(;!(i==-1);i--)printf("<===%d时%d号车停与%d车位===>\n",S->car_time[i],S->car_time[i],i+1);elsecout<<"停车场为空";printf("还有车%d个位\n",MaxSize-S->top-1);break;}case 20000:{displayhead();break;}default:{return 1;}}return 0;}void displayhead(void){cout<<'\n'<<"<===============CT停车场管理系统===================>"<<endl;cout<<"<==操作说明: ******* ==>"<<endl;cout<<"<==A:停车命令 ******* ==>"<<endl;cout<<"<==D:出车命令 *** ==>"<<endl;cout<<"<==E:退出程序 *** ==>"<<endl;cout<<"<==L: 显示停车场内状况 "<<endl;cout<<"<==============================================>"<<endl;}void displayChange(STACK *S,ElemType pnum,int ptime){printf(" (单价 %d元/小时 )\n",fee);printf("<======================电子收据===================>\n");printf("<==停车时间:--------------------------%d小时==>\n",ptime-tmptime);printf("<==车牌号码:--------------------------%d==>\n",tmpnum);printf("<==应收费用:--------------------------%d 元==>\n",(ptime-tmptime)*fee);printf("<====================谢谢=欢迎下次再来=============>\n");printf("正在打印收据请稍等\n");for(int count=1; count < 1;count++){printf("=");fflush(stdout);sleep(1);}printf(">\n");sleep(1);}void wait(char *string){printf("%s\n",string);for(int count=1; count < 1;count++){printf("-");fflush(stdout);sleep(1);}printf(">\n");}int outparkstation(STACK *S1,STACK *TS,ElemType pnum){int t_num=0;int t_time=0;while(1){Pop(S1,&t_num,&t_time);if(t_num == pnum){tmpnum=t_num;tmptime=t_time;while(!Empty(TS)){Pop(TS,&t_num,&t_time);Push(S1,t_num,t_time);}return 1;}Push(TS,t_num,t_time);}return 0;}int inparkstation(STACK *S){int parknum;int parktime;printf("还有车%d个位\n",MaxSize-S->top-1);printf("请输入车牌号码:");cin>>parknum;while(chackinput(S,parknum)){ printf("车牌号码重复,请输入%d1或者其他",parknum);cin>>parknum;}printf("请输入停车时间:");cin>>parktime;printf("%d号车于%d时停靠在%d位\n",parknum,parktime,S->top+2);Push(S,parknum,parktime);return 1;}int inbiandao(SQUEUE *SQ,STACK *S){int parknum ;printf("对不起,停车场已满,请您到便道等待.您将第");printf("%d进入停车场\n",CountQueue(SQ));printf("请输入车牌号码:");cin>>parknum;while(chackinput(S,parknum)) { printf("车牌号码重复,请输入%d1或者其他",parknum);cin>>parknum;} EnQueue(SQ,parknum,0);return 1;}int OutParkingStation(SQUEUE *biandao,STACK *car,STACK *tmp){int parknum = 0;int parktime = 0;int buf=0;if(!Empty(car)){displaystats(car,10000);printf("请输入您要调出的车牌号码:");cin>>parknum;while(!chackinput(car,parknum)) { printf("没有您要的%d的车牌号码,请输入正确的车牌号码:",parknum);cin>>parknum;} outparkstation(car,tmp,parknum); printf("%d时%d号车进入停车场\n",tmptime,tmpnum);printf("请输入现在的时间:");cin>>parktime;while(!chacktime(car,parktime)) { cout<<"输入时间小于停车时间,请重新输入:";cin>>parktime; }displayChange(car,parknum,parktime); if(biandao->front==biandao->rear) { }else{ printf("%d号车位空开\n",car->top+2);printf("%d时便道上的%d号汽车驶入%d号车位",parktime,biandao->front->next->car_num,car->top+2);OutQueue(biandao,&parknum,&buf); Push(car,parknum,parktime); }return 2;}printf("停车场为空\n"); return 1; };int main(int argc,char* agv[]){char chance='A';STACK car;InitStack(&car);STACK tmp;InitStack(&tmp);SQUEUE biandao;InitQueue(&biandao);loop:while(1){displayhead();cout<<"=>:";cin>>chance;switch(chance) {case 'A':{wait("正在查询车位,请稍等:");if(Full(&car))inparkstation(&car);elseinbiandao(&biandao,&car);break;}case 'D':{OutParkingStation(&biandao,&car,&tmp);break;}case 'L':{displaystats(&car,10000);break;}case 'M':{displaystats(&car,20000);break;}case 'E':{wait("正在保存数据程序即将退出\n命令执行中:"); exit(0);}default:{cout<<"输入错误"<<endl;goto loop;}}}system("PAUSE");return 0;}。
C语言源码实现停车场管理系统
C语⾔源码实现停车场管理系统本⽂实例为⼤家分享了C语⾔停车场管理系统的具体代码,供⼤家参考,具体内容如下题⽬要求:刚开始在Codeblocks下⽤C语⾔写的,但是⽤指针传递参数的时候总是出问题。
后来就⽤C++,但是调⽤了C的输⼊输出和⽂件操作的头⽂件,所以代码都是C的main.cpp#include <iostream>#include <cstdio>#include <cstdlib>#include <windows.h>#include <ctime>#include <cstring>#include <conio.h>#define N 100using namespace std;typedef struct{char num[8];//车牌号long int time_in;int pos;//车辆的状态,0表⽰停在便道中,1表⽰停在停车场} vehicle; //定义车辆类型typedef struct{vehicle veh[N];int top;} SqStack; //⽤栈表⽰停车场typedef struct LNode{vehicle veh;struct LNode *next;} LinkList; //⽤单链表表⽰便道void Load(FILE *,SqStack *,LinkList *);void ShowMenu(int );int MakeChoice(int ,int );void Parking(SqStack *,LinkList *);void Back(SqStack *);void EnterPkl(SqStack *,LinkList *);void LeavePath(LinkList *);void View(SqStack *,LinkList *);void Write_and_Quit(FILE *,SqStack *,LinkList *);int main(){SqStack *pkl;LinkList *path;FILE *fp;pkl=(SqStack *)malloc(sizeof(SqStack));path=(LinkList *)malloc(sizeof(LinkList));fp=fopen("Parking_lot.txt","r+");if(fp==NULL){printf("数据加载失败!按任意键退出程序");getch();return 0;}Load(fp,pkl,path);while(1){system("cls");ShowMenu(pkl->top);switch(MakeChoice(1,6)){case 1:system("cls");Parking(pkl,path);break;case 2:system("cls");Back(pkl);break;case 3:system("cls");EnterPkl(pkl,path);break;case 4:system("cls");LeavePath(path);break;case 5:system("cls");View(pkl,path);break;default:system("cls");Write_and_Quit(fp,pkl,path);return 0;}}return 0;}function.cpp#include <iostream>#include <cstdio>#include <cstdlib>#include <windows.h>#include <ctime>#include <cstring>#include <conio.h>#define N 100using namespace std;typedef struct{char num[8];//车牌号long int time_in;int pos;//车辆的状态,0表⽰停在便道中,1表⽰停在停车场} vehicle; //定义车辆类型typedef struct{vehicle veh[N];int top;} SqStack; //⽤栈表⽰停车场typedef struct LNode{vehicle veh;struct LNode *next;} LinkList; //⽤单链表表⽰便道void Load(FILE * fp,SqStack * pkl,LinkList * path){pkl->top=-1;path->next=NULL;LinkList *p;char num[8];long int time_in;int pos;while(fscanf(fp,"%s %ld %d\n",num,&time_in,&pos)!=EOF){if(pos==0)//该车辆在便道中{//尾插法建⽴单链表p=(LinkList *)malloc(sizeof(LinkList));strcpy(p->veh.num,num);p->veh.time_in=time_in;p->veh.pos=pos;path->next=p;path=p;}else//该车辆在停车场中{++pkl->top;strcpy(pkl->veh[pkl->top].num,num);pkl->veh[pkl->top].time_in=time_in;pkl->veh[pkl->top].pos=pos;}}path->next=NULL;}void ShowMenu(int n){printf("********⼀个简单的停车场管理系统********\n");if(n+1==N)printf("***************停车场已满***************\n");elseprintf("**********当前停车场共有%03d辆车**********\n",n+1);printf("********说明:停车场每⼩时收费5元********\n");printf("****************1.停车******************\n");printf("****************2.取车******************\n");printf("*********3.便道车辆进⼊停车场***********\n");printf("**************4.离开便道****************\n");printf("**************5.查看车辆****************\n");printf("****************6.退出******************\n");}int MakeChoice(int m,int n){int judge;printf("请输⼊%d~%d\n",m,n);scanf("%d",&judge);while(judge<m||judge>n)//确保输⼊的是1~n{printf("输⼊不合法,请输⼊%d~%d\n",m,n);fflush(stdin);//如果不加这句,输⼊⼀些字母会导致函数⽆限循环 scanf("%d",&judge);}return judge;}void Parking(SqStack *pkl,LinkList *path){LinkList *r;printf("请输⼊车牌号:");if(pkl->top<N-1){fflush(stdin);scanf("%8s",pkl->veh[++pkl->top].num);time(&(pkl->veh[pkl->top].time_in));pkl->veh[pkl->top].pos=1;printf("您的车辆已停⾄%2d号车位\n",pkl->top);}else{fflush(stdin);r=(LinkList *)malloc(sizeof(LinkList));scanf("%8s",r->veh.num);printf("停车场已满,您要暂时停放在便道中吗?\n");printf("1.确定 2.取消\n");if(MakeChoice(1,2)==1){while(path->next!=NULL)path=path->next;r->veh.time_in=0;r->veh.pos=0;path->next=r;r->next=NULL;printf("您的车辆已停放到便道中\n");}elsefree(r);}printf("按任意键返回主菜单");getch();return;}void Back(SqStack *pkl){int n,i=0;long int time_out;double hours;vehicle t_pkl[N];printf("请输⼊您的车辆所在的车位(⽬前还有个⼩问题,前⾯的车⾛了之后当前车位会-1):"); n=MakeChoice(0,pkl->top);printf("%2d上的车辆车牌号为%s,您确定要取⾛该车辆吗?\n",n,pkl->veh[n].num);printf("1.确定 2.取消\n");if(MakeChoice(1,2)==1){time(&time_out);hours=(time_out-pkl->veh[n].time_in)/3600.0;printf("本次停车共计%lf⼩时,收费%lf元,请按任意键确认⽀付\n",hours,hours*5);getch();for(i=0; pkl->top>=n; --pkl->top,++i) //把第n辆到第pkl->top辆车移到t_pklt_pkl[i]=pkl->veh[pkl->top];//此时pkl->top指向第n-1辆车for(i-=2; i>=0; --i) //把第n+1辆到第pkl->top辆车移回pklpkl->veh[++pkl->top]=t_pkl[i];printf("⽀付成功!\n");printf("取车成功,按任意键返回主菜单");getch();return;}else{printf("按任意键返回主菜单");getch();return;}}void EnterPkl(SqStack *pkl,LinkList *path){if(pkl->top==N-1)printf("停车场已满!");else{printf("您确定将便道中第⼀辆车(车牌号:%8s)停⼊停车场吗?\n",path->next->veh.num); printf("1.确定 2.取消\n");if(MakeChoice(1,2)==1){pkl->veh[++pkl->top]=path->next->veh;time(&pkl->veh[pkl->top].time_in);path->next=path->next->next;printf("已停⼊停车场\n");}}printf("按任意键返回主菜单");getch();return;}void LeavePath(LinkList *path){int i=0,n;LinkList *q;printf("请输⼊要离开便道的车辆的位序:");scanf("%d",&n);while(i<n&&path!=NULL){++i;q=path;//保存当前节点的前⼀个节点,如果找到的位置在链表最后,需要将前⼀个节点的指针域置为NULL path=path->next;}if(path!=NULL){printf("您确定便道中第%03d辆车(车牌号:%8s)离开便道吗?\n",n,path->veh.num);printf("1.确定 2.取消\n");if(MakeChoice(1,2)==1){if(path->next!=NULL)//确定离开并且不是便道中最后⼀辆车{q=path->next;path->next=q->next;free(q);printf("第%03d辆车已离开便道\n",n);}else//确定离开并且是便道中最后⼀辆车{printf("第%03d辆车已离开便道\n",n);q->next=NULL;free(path);}}}elseprintf("没有找到第%03d辆车\n",n);printf("按任意键返回主菜单");getch();return;}void View(SqStack *pkl,LinkList *path){int i;long int time_out;double hours;time(&time_out);printf("停车场共有%03d辆车:\n",pkl->top+1);for(i=0; i<=pkl->top; ++i){hours=(time_out-pkl->veh[i].time_in)/3600.0;printf("车位:%2d 车牌号:%8s 停车时长:%lf 应缴费⽤:%lf\n",i,pkl->veh[i].num,hours,hours*5);}printf("便道车辆:\n");if(path->next==NULL)printf("⽆\n");while(path->next!=NULL){path=path->next;printf("车牌号:%s\n",path->veh.num);}printf("按任意键返回主菜单");getch();return;}void Write_and_Quit(FILE *fp,SqStack *pkl,LinkList *path){rewind(fp);LinkList *pre=path,*p=path->next;for(; pkl->top>-1; --pkl->top)fprintf(fp,"%s %ld %d\n",pkl->veh[pkl->top].num,pkl->veh[pkl->top].time_in,pkl->veh[pkl->top].pos);while(p!=NULL){free(pre);fprintf(fp,"%s %ld %d\n",p->veh.num,p->veh.time_in,p->veh.pos);pre=p;p=pre->next;}free(pre);free(pkl);fclose(fp);}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
停车场管理系统源代码
/*停车场管理系统*/#include<stdio.h>#include<stdlib.h>#include<string.h>/*------------------------------------------------------------------------------*/#define MAX 2 /*车库容量*/#define price 0.05 /*每车每分钟费用*/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 *); /*初始化栈*/int InitQueue(LinkQueueCar *); /*初始化便道*/int Arrival(SeqStackCar *,LinkQueueCar *); /*车辆到达*/void Leave(SeqStackCar *,SeqStackCar *,LinkQueueCar *); /*车辆离开*/ void List(SeqStackCar,LinkQueueCar); /*显示存车信息*//*------------------------------------------------------------------------------*/void main(){SeqStackCar Enter,Temp;LinkQueueCar Wait;int ch;InitStack(&Enter); /*初始化停车场*/InitStack(&Temp); /*初始化让路的临时栈*/InitQueue(&Wait); /*初始化便道*/while(1){printf("\n\t************欢迎使用停车场系统************\n"); printf("\n\t\t制作小组:软件12-6组\n");printf("\n1. 车辆到达");printf(" 2. 车辆离开");printf(" 3. 列表显示");printf(" 4. 退出系统\n");while(1){scanf("%d",&ch);if(ch>=1&&ch<=4)break;else printf("\n请选择: 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;}}}/*------------------------------------------------------------------------------*/ void InitStack(SeqStackCar *s) /*初始化栈*/{int i;s->top=0;for(i=0;i<=MAX;i++)s->stack[s->top]=NULL;}int InitQueue(LinkQueueCar *Q) /*初始化便道*/{Q->head=(QueueNode *)malloc(sizeof(QueueNode));if(Q->head!=NULL){Q->head->next=NULL;Q->rear=Q->head;return(1);}else return(-1);}void PRINT(CarNode *p,int room) /*打印出栈车的信息*/{int A1,A2,B1,B2;printf("\n请输入离开的时间:/**:**/");scanf("%d:%d",&(p->leave.hour),&(p->leave.min));printf("\n离开车辆的车牌号为:");puts(p->num);printf("\n其到达时间为: %d:%d",p->reach.hour,p->reach.min);printf("离开时间为: %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("\n应交费用为: %2.1f元",((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("\n请输入车牌号(例:辽P1234):");gets(p->num);if(Enter->top<MAX) /*车场未满,车进车场*/{Enter->top++;printf("\n车辆在车场第%d位置.",Enter->top);printf("\n请输入到达时间:/**:**/");scanf("%d:%d",&(p->reach.hour),&(p->reach.min));Enter->stack[Enter->top]=p;return(1);}else /*车场已满,车进便道*/{printf("\n该车须在便道等待!");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 i, room;CarNode *p,*t;QueueNode *q;/*判断停车场内是否有车*/if(Enter->top>0) /*有车*/{while(1) /*输入离开车辆的信息*/{printf("\n请输入车在车场的位置/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;Enter->top++;printf("\n便道的%s号车进入车场第%d位置.",t->num,Enter->top); printf("\n请输入现在的时间/**:**/:");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("\n便道里没有车.\n");}else printf("\n停车场里没有车."); /*停车场没车*/}void List1(SeqStackCar *S) /*列表显示停车场信息*/{int i;if(S->top>0) /*判断停车场内是否有车*/{printf("\n车场:");printf("\n 位置到达时间车牌号\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("\n车场里没有车");}void List2(LinkQueueCar *W) /*列表显示便道信息*/{QueueNode *p;p=W->head->next;if(W->head!=W->rear) /*判断通道上是否有车*/{printf("\n等待车辆的号码为:");while(p!=NULL){puts(p->data->num);p=p->next;}}else printf("\n便道里没有车.");}void List(SeqStackCar S,LinkQueueCar W){int flag,tag;flag=1;while(flag){printf("\n请选择1|2|3:");printf("\n1.车场\n2.便道\n3.返回\n");while(1){scanf("%d",&tag);if(tag>=1||tag<=3) break;else printf("\n请选择1|2|3:");}switch(tag){case 1:List1(&S);break; /*列表显示车场信息*/ case 2:List2(&W);break; /*列表显示便道信息*/ case 3:flag=0;break;default: break;}}}。
停车场管理系统源代码功能完整版
停车场管理系统源代码功能完整版#include#includeMax);return n;}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 *,int n); /*声明栈*/int InitQueue(LinkQueueCar *); /*声明便道*/int Arrival(SeqStackCar *,LinkQueueCar *,int n); /*车辆进站*/void Leave(SeqStackCar *,SeqStackCar *,LinkQueueCar *,int n); /*车辆出站*/void List(SeqStackCar,LinkQueueCar); /*显示存车信息*/void InitStack(SeqStackCar *s,int n) /*初始化栈*/{int i;s->top=0;for(i=0;ileave.hour reach.hour || (p->leave.hour==p->reach.hourscanf("%d:%d",fflush(stdin);}if(p->leave.hourleave.hour reach.hour ||(p->leave.hour==p->reach.hourprintf("出站的车的车牌号为:");puts(p->num);printf("\n");A1=p->reach.hour;A2=p->reach.min;B1=p->leave.hour;B2=p->leave.min;a=(B1-A1)*60+B2-A2;if(a>=60){b=a/60;c=a-60*b;}else{b=0;c=a;}printf(" 祝您一路顺风,欢迎您下次光临.");printf("\n 收据\n");printf("================================== 车牌号: ");puts(p->num);printf("\n");printf("=================================== ================\n");printf("|进车场时刻| 出车场时刻| 停留时间| 应付(元)|\n");printf("=================================== =================\n");printf("| %d:%d",p->reach.hour,p->reach.min);printf(" | %d:%d",p->leave.hour,p->leave.min);printf(" | %d:%d",b,c);printf(" | %2.1f",0.1*a);printf(" |\n");printf("-----------------------------------------------------\n");free(p);}int Arrival(SeqStackCar *Enter,LinkQueueCar *W,int n) /*车辆到达*/{QueueNode *t;int a,b;CarNode *p,*t1;QueueNode *q;void List2(LinkQueueCar *W);void List1(SeqStackCar *S);p=(CarNode *)malloc(sizeof(CarNode));flushall();printf("请严格按照要求输入车牌号,否则系统会出错!\n"); printf("\n请输入车牌号(%d位):\n",l_che);do{a=l_che;b=strlen(gets(p->num));fflush(stdin);if(a!=b){printf("输入车牌号格式错误,请重新输入(%d位):",l_che); }else break;}while(a!=b);if(Enter->topreach.hourreach.hour>=24 ||p->reach.minreach.min>=60);Enter->stack[Enter->top]=p;List1(Enter);}else {//便道有车则进入便道printf("----------------------------------------------------------------\n");printf("\n请该车在便道稍作等待!\n");printf("----------------------------------------------------------------\n");t=(QueueNode *)malloc(sizeof(QueueNode));t->data=p;t->next=NULL;W->rear->next=t;W->rear=t;List2(W);printf("便道上的第一辆车是否进入车场?\n");printf("“是”请按1 ;不进车场并要离开便道请按0\n");while(1){scanf("%d",if(panduan==1){if((W->head!=W->rear)t1=q->data;Enter->top++;printf("\n现在请便道上的车进入车场.该车的车牌号为:");puts(t1->num);printf("\n该车进入车场第%d位置.",Enter->top);printf("\n请输入现在的时间(即该车进站的时间)/**:**/:");scanf("%d:%d",fflush(stdin);do{if(t1->reach.hourreach.hour>=24 || t1->reach.minreach.min>=60){printf("输入的时间格式有错,请重新输入:");scanf("%d:%d",fflush(stdin);}}while(t1->reach.hourreach.hour>=24 || t1->reach.minreach.min>=60);W->head->next=q->next;if(q==W->rear) W->rear=W->head; Enter->stack[Enter->top]=t1;free(q);List1(Enter);break;}}elseif(panduan==0){q=W->head->next;W->head->next=q->next;printf("便道上第一辆车离开,车牌号为:"); puts(q->data->num);List2(W);break;}}}}else /*车场已满,车进便道*/{printf("----------------------------------------------------------------\n");printf("\n请该车在便道稍作等待!\n");printf("----------------------------------------------------------------\n");t=(QueueNode *)malloc(sizeof(QueueNode));t->data=p;t->next=NULL;W->rear->next=t;W->rear=t;List2(W);return(1);}return(1);}void Leave(SeqStackCar *Enter,SeqStackCar *Temp,LinkQueueCar *W,int n)/*车辆离开*/ {int room;void List2(LinkQueueCar *W);void List1(SeqStackCar *Enter);CarNode *p,*t;QueueNode *q;/*判断车场内是否有车*/if(Enter->top>0) /*有车*/{while(1) /*输入离开车辆的信息*/{printf("\n请输入要离开的车在车场的位置/1--%d/:",Enter->top);scanf("%d",fflush(stdin);if(room>=1}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);/*判断通道上是否有车及车站是否已满*/last:if(W->head!=W->rear)//判断便道上车辆是否进入停车场{printf("便道上的第一辆车是否进入车场?\n");printf("“是”请按1 ;不进车场并要离开便道请按0\n");while(1){scanf("%d",if(panduan==1)/*便道的车辆进入车场*/{if((W->head!=W->rear)t=q->data;Enter->top++;printf("\n现在请便道上的车进入车场.该车的车牌号为:");puts(t->num);printf("\n该车进入车场第%d位置.",Enter->top);printf("\n请输入现在的时间(即该车进站的时间)/**:**/:");scanf("%d:%d",fflush(stdin);do{if(t->reach.hourhead->next;W->head->next=q->next;if(W->rear==q)W->rear=W->head;printf("便道上第一辆车离开,车牌号为:");puts(q->data->num);List2(W);if(W->head!=W->rear)goto last;//跳转break;}}}else {printf("\n----------------------------------------------------------------\n目前便道没有车\n");}}elseprintf("\n----------------------------------------------------------------\n目前车场里没有车!");/*没车,提示便道内车辆是否进入停车场*/}void List1(SeqStackCar *S) /*列表显示车场存车信息*/{int i;if(S->top>0) /*判断车站内是否有车*/{printf("----------------------------------------------------------------\n");printf("\n车场:");printf("\n 位置到达时间车牌号\n");for(i=1;itop;i++){printf(" %d ",i);printf(" %d:%d",S->stack[i]->reach.hour,S->stack[i]->reach.min);puts(S->stack[i]->num);}}elseprintf("\n----------------------------------------------------------------\n目前车场里没有车"); }void List2(LinkQueueCar *W) /*列表显示便道信息*/{QueueNode *p;p=W->head->next;if(W->head!=W->rear) /*判断通道上是否有车*/{printf("----------------------------------------------------------------\n");printf("\n目前正在等待车辆的车牌号");printf("从队头到队尾的顺序依次为:\n");while(p!=NULL){puts(p->data->num);p=p->next;}}elseprintf("\n----------------------------------------------------------------\n目前便道里没有车."); }void List(SeqStackCar S,LinkQueueCar W){int flag,tag;flag=1;while(flag){printf("\n1.车场\n2.便道\n3.返回\n");while(1){printf("\n请选择1|2|3:");scanf("%d",fflush(stdin);do{if(tag3break;}{case 1:List1(break; /*列表显示车场信息*/case 2:List2(break; /*列表显示便道信息*/case 3:flag=0;break;/*返回*/default: break;}}}void L(LinkQueueCarint i=1,j=1;LinkQueueCar QueueTemp;InitQueue(//初始化临时便道,重要行在于可能存在指针没有释放掉int locate;if(W.head==W.rear){printf("----------------------------------------------------------------\n");printf("便道没有车\n");}else{printf("请输入便道上车辆在便道上的位置序号:"); scanf("%d",while(1){if(i!=locateW.head->next=q->next;if(W.rear==q)W.rear=W.head;i+=1;QueueTemp.rear->next=q; QueueTemp.rear=q;}if(i==locate){printf("便道上第%d辆车离开便道车牌号为:",i); if(i==1){ q=W.head->next;W.head->next=q->next;puts(q->data->num);}if(i!=1){q=W.head->next;W.head->next=q->next;puts(q->data->num);}i++;}if(W.head->next==NULL||i==100)//临时队列中的车辆依次进入便道{q=QueueTemp.head->next;i=100;j=0;//j为标志QueueTemp.head->next=q->next;if(QueueTemp.rear==q)QueueTemp.rear=QueueTemp.head;W.rear->next=q;W.rear=q;if(QueueTemp.head==QueueTemp.rear){QueueTemp.rear->ne xt=NULL;break;}}}}}void main(){SeqStackCar Enter,Temp;QueueNode *p;LinkQueueCar Wait;int ch;int n;printf("======================================= ===================== \n"); printf(" 停车场管理系统:\n");printf("\n");printf("\n");printf(" 组员:卢上游何前胡万里\n");printf("======================================= =====================\n"); n=getn();InitStack( /*初始化车场*/InitStack( /*初始化让路的临时栈*/InitQueue( /*初始化便道*/while(1){printf("\n1. 车辆进站");printf(" 2. 车辆出站");printf(" 3. 存车信息");printf(" 4. 便道车辆离开");printf(" 5. 退出系统\n");printf("----------------------------------------------------------------\n");while(1){printf("请选择:1 2 3 4 5.\n");scanf("%d",fflush(stdin);do{if(ch>5 || ch5 || ch<1);break;}switch(ch){case 1:Arrival(break; /*车辆进站*/case 2:Leave(break; /*车辆出站*/case 3:List(Enter,Wait);break; /*存车信息*/case 4:L(Wait);break;// 便道车辆离开/* /*退出系统*/ default:break;}}}21。
停车场管理系统程序源代码
#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);}。
停车场管理系统代码
for(i=0;i<chewei_num;i++)
{
pos[i]=-1;
}
for(i=0;i<biandao_num+car_range;i++)
{
wait[i]=-1;
}
cout<<"第0小时"<<endl;
out<<"第0小时"<<endl;
int pos;
int wait;
int arrive_time;
int leave_time;
int park_time;
int fee;
}cars[24*Range];
int pos[2000];
int wait[2000];
int sum_time=0;
int sum_fee=0;
int sum_arrive=0;
int sum_leave=0;
int sum_away=0;
int pos_num=0;
int wait_num=0;
int come_num;
int l_num;
int front=0;
int now_time;
int num;
int chewei_num=M;
out<<"车号:"<<car<<" 到达时间:"<<cars[car].arrive_time<<" 离开时间:"<<cars[car].leave_time<<" 车位:"<<cars[car].pos<<" 停留时间:"<<cars[car].park_time<<" 费用:"<<cars[car].fee<<endl;
数据结构c语言版课程设计停车场管理系统
课程设计:停车场c语言版本的数据结构课程设计,规定用栈模拟停车场,用队列模拟便道,实现停车场的收费管理系统停车场停满车后车会停在便道上面下面附上源码,vc:(下编译#include <stdio.h>//#include <stdlib.h> //malloc#include <time.h> //获取系统时间所用函数#include <conio.h> //getch()#include <windows.h> //设立光标信息mallco#define MaxSize 5 /*定义停车场栈长度*/#define PRICE 0.05 /*每车每分钟收费值*/#define BASEPRICE 0.5 //基础停车费#define Esc 27 //退出系统#define Exit 3 //结束对话#define Stop 1 //停车#define Drive 2 //取车int jx=0,jy=32; //全局变量日记打印位置typedef struct{int hour;int minute;}Time,*PTime; /*时间结点*/typedef struct /*定义栈元素的类型即车辆信息结点*/ {int num ; /*车牌号*/Time arrtime; /*到达时刻或离区时刻*/}CarNode;typedef struct /*定义栈,模拟停车场*/{CarNode stack[MaxSize];int top;}SqStackCar;typedef struct node /*定义队列结点的类型*/{int num; /*车牌号*/struct node *next;}QueueNode;typedef struct /*定义队列,模拟便道*/{QueueNode *front,*rear;}LinkQueueCar;/*函数声明*/PTime get_time();CarNode getcarInfo();void qingping(int a);void gotoxy(int x,int y);void printlog(Time t,int n,int io,char ab,int po,double f);void printstop(int a,int num,int x0,int y0);void printleave(int a,int po,int num);/*初始化栈*/void InitSeqStack(SqStackCar *s){s->top=-1;}/* push入站函数*/int push(SqStackCar *s,CarNode x) //数据元素x入指针s所指的栈{if(s->top==MaxSize-1)return(0); //假如栈满,返回0 else{s->stack[++s->top]=x; //栈不满,到达车辆入栈return(1);}}/*栈顶元素出栈*/CarNode pop(SqStackCar *s){CarNode x;if(s->top<0){x.num=0;x.arrtime.hour=0;x.arrtime.minute=0;return(x); //假如栈空,返回空值}else{s->top--;return(s->stack[s->top+1]); //栈不空,返回栈顶元素}}/*初始化队列*/void InitLinkQueue(LinkQueueCar *q){q->front=(QueueNode*)malloc(sizeof(QueueNode)); //产生一个新结点,作头结点if(q->front!=NULL){q->rear=q->front;q->front->next=NULL;q->front->num=0; //头结点的num保存队列中数据元素的个数}}/*数据入队列*/void EnLinkQueue(LinkQueueCar *q,int x){QueueNode *p;p=(QueueNode*)malloc(sizeof(QueueNode)); //产生一个新结点p->num=x;p->next=NULL;q->rear->next=p; //新结点入队列q->rear=p;q->front->num++; //队列元素个数加1}/*数据出队列*/int DeLinkQueue(LinkQueueCar *q){QueueNode *p;int n;if(q->front==q->rear) //队空返回0return(0);else{p=q->front->next;q->front->next=p->next;if(p->next==NULL)q->rear=q->front;n=p->num;free(p);q->front->num--;return(n); //返回出队的数据信息}}/********************* 车辆到达***************************/ //参数:停车栈停车队列车辆信息//返回值:空//功能:对传入的车辆进行入栈栈满则入队列void Arrive(SqStackCar *stop,LinkQueueCar *lq,CarNode x){int f;f=push(stop,x); //入栈if (f==0) //栈满{EnLinkQueue(lq,x.num); //入队printstop(1,lq->front->num,0,23);printlog(x.arrtime,x.num,1,'B',lq->front->num,0);qingping(0); printf("您的车停在便道%d号车位上\n",lq->front->num); //更新对话}else{printstop(0,stop->top+1,0,23);printlog(x.arrtime,x.num,1,'P',stop->top+1,0);qingping(0); printf("您的车停在停车场%d号车位上\n",stop->top+1); //更新对话}qingping(1); printf("按任意键继续");getch();}/************************** 车辆离开*************************************///参数:停车栈指针s1,暂存栈指针s2,停车队列指针p,车辆信息x//返回值:空//功能:查找栈中s1的x并出栈,栈中没有则查找队p中并出队,打印离开收费信息void Leave(SqStackCar *s1,SqStackCar *s2,LinkQueueCar *p,CarNode x){double fee=0;int position=s1->top+1; //车辆所在车位int n,f=0;CarNode y;QueueNode *q;while((s1->top > -1)&&(f!=1)) //当栈不空且未找到x{y=pop(s1);if(y.num!=x.num){n=push(s2,y);position--;}elsef=1;}if(y.num==x.num) //找到x{gotoxy(33,17);printf("%d:%-2d",(x.arrtime.hour-y.arrtime.hour),(x.arrtime.minute-y.arrtime.minute) );fee=((x.arrtime.hour-y.arrtime.hour)*60+(x.arrtime.minute-y.arrtime.minute))*PRICE+BASEP RICE;gotoxy(48,17); printf("%2.1f元\n",fee);qingping(0); printf("确认您的车辆信息");qingping(1); printf("按任意键继续");getch();while(s2->top>-1){ y=pop(s2);f=push(s1,y);}n=DeLinkQueue(p);if(n!=0){y.num=n;y.arrtime=x.arrtime;f=push(s1,y);printleave(p->front->num+1,position,s1->top+1); //出栈动画ji队列成员入栈printlog(x.arrtime,x.num,0,'P',position,fee);printlog(y.arrtime,y.num,1,'P',s1->top+1,0);}else{printleave(0,position,s1->top+2);printlog(x.arrtime,x.num,0,'P',position,fee);}}else //若栈中无x{while(s2->top > -1) //还原栈{y=pop(s2);f=push(s1,y);}q=p->front;f=0;position=1;while(f==0&&q->next!=NULL) //当队不空且未找到xif(q->next->num!=x.num){q=q->next;position++;}else //找到x{q->next=q->next->next;p->front->num--;if(q->next==NULL)p->rear=p->front;gotoxy(33,17); printf("0:0");gotoxy(48,17); printf("0元");qingping(0); printf("您的车将离便道");qingping(1); printf("按任意键继续");getch();printleave(-1,position,p->front->num+1); //出队动画printlog(x.arrtime,x.num,0,'B',position,0);f=1;}if(f==0) //未找到x{qingping(0); printf("停车场和便道上均无您的车");qingping(1); printf("按任意键继续");getch();}}}/*获取系统时间*///返回PTime类型PTime get_time(){Time *t;t=new Time;time_t timer;struct tm *tblock;timer=time(NULL);tblock=localtime(&timer);t->minute=tblock->tm_min;t->hour=tblock->tm_hour;return t;}/*移动光标*///蒋光标移动到(x,y)点void gotoxy(int x,int y){COORD coord;coord.X=x;coord.Y=y+3;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); }/*画图*///画出系统界面void panitPL(){gotoxy(20,4);printf("****************对话框****************");int x=18,y=6; //起始点int a[2][4]={2,0,0,1,-2,0,0,-1}; //方向for(int i=0;i<2 ;i++){for(int j=0; j<20; j++){x+=a[i][0]; y+=a[i][1];gotoxy(x,y);printf("═");}x+=a[i][0]; y+=a[i][1];gotoxy(x,y);if(i==0)printf("╗");elseprintf("╚");for(j=0; j<12; j++){x+=a[i][2]; y+=a[i][3];gotoxy(x,y);printf("║");}x+=a[i][2]; y+=a[i][3];gotoxy(x,y);if(i==0)printf("╝");elseprintf("╔");}gotoxy(22,8);printf("小王:");gotoxy(22,11);printf("顾客:");gotoxy(22,14); printf("*********** 停车信息***********");gotoxy(23,15); printf("车牌号:");gotoxy(42,15); printf("时间:");gotoxy(23,17); printf("停车时长:");gotoxy(42,17); printf("收费:");}/*清屏函数*///更新对话框前将原对话晴空void qingping(int a){if(a==0) //清空小王的对话{gotoxy(28,8); printf(" ");gotoxy(28,9); printf(" ");gotoxy(28,8);}else if(a==1) //清空顾客的对话{gotoxy(28,11); printf(" ");gotoxy(28,12); printf(" ");gotoxy(28,13); printf(" ");gotoxy(28,11);}else //清空车辆信息{gotoxy(31,15); printf(" ");gotoxy(48,15); printf(" ");gotoxy(33,17); printf(" ");gotoxy(48,17); printf(" ");gotoxy(31,15);}}//用上下键移动选择int getkey(){char c;int x=28,y=11;while(1){gotoxy(x,11); printf(" ");gotoxy(x,12); printf(" ");gotoxy(x,13); printf(" ");gotoxy(x,y); printf(">>");c=getch();if(c==13) return y-10; //enter键返回当前选项if(c!=-32)continue; //不是方向键进行下次循环c=getch();if(c==72) if(y>11) y--; //上if(c==80) if(y<13) y++; //下}}//输入车辆信息CarNode getcarInfo(){PTime T;CarNode x;qingping(0); printf("请输入您的车牌号\n");qingping(1); printf("在下面输入车辆信息");qingping(2);scanf("%d",&(x.num));T=get_time();x.arrtime=*T;gotoxy(48,15); printf("%d:%d",x.arrtime.hour,x.arrtime.minute);getch();return x;}//打印停车场void printcar(){gotoxy(0,20); //╔ ╗╝╚═║printf("═══════════════════════════════════════╗");printf(" 出场暂放区║ 1 2 3 4 5 ║");printf("---------------------------------------------------------------------- ║");printf(" 主车道║");printf("---------------------------------------------------------------------- ║");printf(" 12 11 10 9 8 7 6 5 4 3 2 1 ║");printf("═══════════════════════════════════╗ ║");printf(" ↑ ╔══════════════╝ ║");printf(" 便道停车区→ ║ 1 2 3 4 5 ║");printf(" ╚══════════════════╝");printf(" 停车场管理日记\n\n");printf(" 时间车牌号进(1)/出(0) 车位(B便道P停车场) 收费(元) "); }//打印日记记录void printlog(Time t,int n,int io,char ab,int po,double f){jy++;gotoxy(jx,jy);// printf(" 时间车牌号进(1)/出(0) 车位(B便道P停车场) 收费(元) ");if(io==0)printf("/ %2.1f",f);gotoxy(jx,jy);printf(" / %d / %c:%d",io,ab,po);gotoxy(jx,jy);printf(" %d:%d / %d",t.hour,t.minute,n);}void printstop(int a,int num,int x0,int y0){static char *car="【█】";// int x0=0,y0=23;int x=0,y=28;if(a==0){x=(num+6)*6;for(;x0<72;x0++){gotoxy(x0,y0); printf("%s",car); Sleep(30);gotoxy(x0,y0); printf(" ");}for(;y0<y;y0++){gotoxy(x0,y0); printf("%s",car); Sleep(100);gotoxy(x0,y0); printf(" ");}for(;x0>x;x0--){gotoxy(x0,y0); printf("%s",car); Sleep(50);gotoxy(x0,y0); printf(" ");}gotoxy(x,y);printf("%s",car);}else{x=(12-num)*6;y=y-3;for(;x0<x;x0++){gotoxy(x0,y0); printf("%s",car); Sleep(30);gotoxy(x0,y0); printf(" ");}gotoxy(x,y);printf("%s",car);}}void printleave(int a,int po,int num){static char *car="【█】";int x0=0,y0=23;int x=0,y=28;int i;if(a==-1){x=(12-po)*6;y=y-3;gotoxy(x,y); printf(" ");gotoxy(x,y-2); printf("%s",car);Sleep(100);if(12>num){gotoxy((12-num)*6,y);printf(" ");}gotoxy(x,y); printf("%s",car);for(;x>x0;x--){gotoxy(x,y-2); printf("%s",car); Sleep(30);gotoxy(x,y-2); printf(" ");}}else{i=num+1;for(;num>po;num--){x=(num+6)*6; y=28;for(;x<72;x++){gotoxy(x,y); printf("%s",car); Sleep(30);gotoxy(x,y); printf(" ");}for(;y>21;y--){gotoxy(x,y); printf("%s",car); Sleep(50);gotoxy(x,y); printf(" ");}for(;x>(i-num+6)*6;x--){gotoxy(x,y); printf("%s",car); Sleep(30);gotoxy(x,y); printf(" ");}gotoxy(x,y); printf("%s",car);}x=(po+6)*6; y=28;for(;x<72;x++){gotoxy(x,y); printf("%s",car); Sleep(30);gotoxy(x,y); printf(" ");}for(;y>23;y--){gotoxy(x,y); printf("%s",car); Sleep(50);gotoxy(x,y); printf(" ");}for(;x>0;x--){gotoxy(x,y); printf("%s",car); Sleep(30);gotoxy(x,y); printf(" ");}num++;for(;i-num>0;num++){x=(i-num+6)*6; y=21;for(;x<72;x++){gotoxy(x,y); printf("%s",car); Sleep(30);gotoxy(x,y); printf(" ");}for(;y<28;y++){gotoxy(x,y); printf("%s",car); Sleep(50);gotoxy(x,y); printf(" ");}for(;x>(num-1+6)*6;x--){gotoxy(x,y); printf("%s",car); Sleep(30);gotoxy(x,y); printf(" ");}gotoxy(x,y); printf("%s",car);}if(a>0){x=66;y=25;gotoxy(x,y); printf(" ");gotoxy(x,y-2); printf("%s",car); Sleep(100);if(12>a){gotoxy((12-a)*6,y);printf(" ");}if(a>1){gotoxy(x,y); printf("%s",car);}printstop(0,i-1,x,y-2);}}}/************************************************************ main ********************************************************/int main(void){SqStackCar s1,s2; //停车栈和暂存栈LinkQueueCar p; //队列InitSeqStack(&s1);InitSeqStack(&s2);InitLinkQueue(&p);printf(" 停车场管理系统\n\n");printf("************************* 欢(=^_^=)迎***************************\n");printf(" 收费标准:基础费0.5元,每分钟收取0.05元,收费精确到0.1元\n");printf(" PS:车牌号由阿拉伯数字组成");panitPL();printcar(); gotoxy(0,-3);char c=0; //接受按键while(1) //按ESC退出系统{for(int i=2;i>-1 ;i--) //初始化对话框qingping(i);printf("按ESC退出系统,其它键开始对话");c=getch();if(c==Esc){qingping(0);break;}while(1){qingping(2);gotoxy(28,8); printf("欢迎来到停车场!我是管理员小王。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
int stacksize;
}SqStack;
//初始化
int InitStack(SqStack &S){
S.base=new Car[STACKSIZE];
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.stacksize=STACKSIZE;
QueuePtr front;
QueuePtr rear;
}LinkQueue;
//初始化
int InitQueue(LinkQueue &Q){
Q.front=Q.rear=new QNode;
Q.front->next=NULL;
return OK;
}
//进队
int EnQueue(LinkQueue &Q,Car e){
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车牌:");
//停车场管理系统
#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;
}
//出队
int DeQueue(LinkQueue &Q,Car &e){
QueuePtr p;
if(Q.front==Q.rear) return ERROR;
p=Q.front->next;
e=p->data;
Q.front->next=p->next;
delete p;
return OK;
}
if(S2.top2==S2.base2) return ERROR;
e2=*--S2.top2;
return OK;
}
//车道信息(链队)
typedef struct QNode{
Car data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct{
while(1){
printf("\t\t\t欢迎来到XXX停车场!\n");
printf("***********************************\n");
//主函数
int main(){
int i=1;
int j=1;
int status;
float time,money;
LinkQueue Q;
Car car_I,car_D,car_M;
SqStack S;
SqStack2 S2;
InitStack(S);
InitStack2(S2);
InitQueue(Q);
QueuePtr p;
p=new QNode;
p->data=e;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return OK;
}
//判空
int QueueEmpty(LinkQueue Q){
if(Q.front==Q.rear) return OK;
else return ERROR;
printf("\t\t位置:%d",l++);
printf("\n");
q++;
}
return OK;
}
//备用车道(顺序栈)
typedef struct {
Car2 *top2;
Car2 *base2; //
int stacksize2;
}SqStack2;
//初始化
int InitStack2(SqStack2 &S2){
else return ERROR;
}
//进栈
int Push2(SqStack2 &S2,Car2 e2){
if(S2.top2-S2.base2==STACKSIZE) return ERROR;
*S2.top2++=e2;
return OK;
}
//出栈
int Pop2(SqStack2 &S2,Car2 &e2){
S2.base2=new Car2[STACKSIZE];
if(!S2.top2) exit(OVERFLOW); //
S2.top2=S2.base2;
S2.stacksize2=STACKSIZE;
return OK;
}
//判空
int StackEmpty2(SqStack2 S2){
if(S2.top2==S2.base2) return OK;
printf("\t\t到达时间:");
printf("\t位置%d:空空",j);
printf("\n");
}
return OK;
}
while(p!=q){
Car car=*(q);
printf("\t车牌: %d",car.CarNum);
printf("\t\t到达时间:%5.2f",car.time);
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;
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;