停车场管理系统源代码

合集下载

停车场管理系统源代码

停车场管理系统源代码
//主函数
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);
}
time=car_D.time-car_I.time;
if(time<0.0) {
printf("输入时间有错!请重新输入!");
}
if(time>0.0&&time<=3.0){
money=time*4;
}
else money=time*6;
printf("你的车牌为%d的车,应收费%5.2f元。",car_D.CarNum,money);
printf("\t\t位置:%d",l++);
printf("\n");
q++;
}
return OK;
}
//备用车道(顺序栈)
typedef struct {
Car2 *top2;
Car2 *base2; //
int stacksize2;
}SqStack2;
//初始化
int InitStack2(SqStack2 &S2){
if(!StackFull(S)){
DeQueue(Q,car_M); //便道上的车离开后进入停车场,那么后面的车的位置都得变。

经典C源码 之 停车场管理系统

经典C源码 之 停车场管理系统
}
break;
case 'o':
if(!StackEmpty(S))
{
Pop(&S,&carout);
printf("The %dth car comes out\n",bel);
if(!QueueEmpty(Q))
{
QueueDelete(&Q,&carout);
Push(&S,carout);
{
stackcar->BottomStack=(struct Car *)malloc(STACKSIZE*sizeof(struct Car));
if(!(stackcar->BottomStack))
return 0;
stackcar->Top=stackcar->BottomStack;
stackcar->Size=STACKSIZE;
}
}
else
printf("There is on car!");
break;
case 'q':
printf("\nThere is %d cars in the garage\n",S.Top-S.BottomStack);
printf("There is %d cars in the queue waiting\n",Q.rear-Q.front);
if(!(Q->front))
return 0;
Q->front->next=0;
return 1;
}
int QueueEnter(struct LinkQueue *Queue,struct Car car)

停车场管理系统程序源代码

停车场管理系统程序源代码

#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);}。

C语言版停车位管理系统

C语言版停车位管理系统

C语⾔版停车位管理系统本⽂实例为⼤家分享了C语⾔实现停车位管理系统的具体代码,供⼤家参考,具体内容如下简单功能介绍1、录⼊车辆信息2、查找车辆信息3、删除车辆信息4、修改车辆信息5、查找区域车辆信息6、排序(按照车主姓名排序)7、展⽰所有车辆信息8、将录⼊的数据保存在⽂件中9、将⽂件中的数据读出算法构造链表的增删改查结构体的定义typedef struct Parking{char name[20]; //车主姓名char carname[10]; //车牌号long information; //车主联系⽅式char region; //车位区域编号int num; //车位编号struct Parking *next; //指针}Parking;录⼊车辆信息利⽤尾插法插⼊新添加的数据Parking *Addcar(Parking *head) //录⼊车辆信息{int x;system("cls"); //清屏操作system("color B"); //改变字体颜⾊Parking *p = head;while(p->next!=NULL) //利⽤尾插法插⼊新⽤户信息{p = p->next;}printf("输⼊需要添加的车辆个数:");scanf("%d", &x);while(x--) //输⼊⽤户信息{system("cls");Parking *Node = (Parking *)malloc(sizeof(Parking));printf("\n输⼊⽤户姓名:");scanf("%s",Node->name);printf("\n输⼊车牌号:");scanf("%s",Node->carname);printf("\n输⼊车主联系⽅式:");scanf("%ld",&Node->information);printf("\n输⼊车位区域编号:");getchar();scanf("%c",&Node->region);printf("\n输⼊车位编号:");scanf("%d",&Node->num);Node->next=NULL;p->next = Node;p = p->next;}printf("\n输⼊完成!");F(head); //打印添加后的⽤户信息printf("\n按任意键返回主页\n");getch(); //⽤来显⽰结果return head;}删除⽤户信息根据⽤户名匹配查找⽤户信息进⾏删除Parking *Delete(Parking *head) //删除⽤户信息{char name[20];system("cls");system("color B");printf("\n\t\t输⼊你要删除的⽤户姓名:");scanf("%s", name);Parking *p = head;Parking *q = p->next;while(q) //找到需要删除数据的前结点{if(strcmp(q->name,name)==0) //判断字符串是否相等函数{p->next = q->next;free(q); //释放内存空间break;}p = q;q = p->next;}if(p->next==NULL){printf("\n\t\t未找到该⽤户信息!");}else{printf("\n\t\t删除成功!!");F(head);}printf("\n\t\t按任意键返回主菜单");getch();return head;}查找⽤户信息根据字符串匹配查找⽤户信息void Find(Parking *head) //查找⽤户信息{system("cls");system("color B");char name[20];printf("\n\t\t输⼊你要查找的⽤户姓名:");scanf("%s", name);Parking *p = head;while(p->next){if(strcmp(p->next->name,name)==0){printf("找到了!\n");printf("该⽤户的信息如下:");printf("\n\t\t---⽤户姓名 %s",p->next->name);printf("\n\t\t---车牌号 %s",p->next->carname);printf("\n\t\t---车主联系⽅式 %ld",p->next->information); printf("\n\t\t---车位区域编号 %c",p->next->region);printf("\n\t\t---车位编号 %d",p->next->num);break;}p = p->next;}if(p->next==NULL)printf("\n\t\t没有找到该⽤户信息");printf("\n\t\t按任意键返回主菜单");getch();}修改⽤户信息查找⽤户找到后显⽰该⽤户的信息,根据⽤户选择修改信息Parking *Change(Parking *head) //修改⽤户信息{char name[20];system("cls");system("color B");printf("输⼊需要修改的⽤户姓名:");scanf("%s", name);Parking *p = head->next;while(p){if(strcmp(p->name,name)==0){system("cls");system("color B");int x;printf("\n\t\t --该⽤户信息-- \n\n");printf("\t---------------------------------------------------------------------\n");printf("\t车主姓名--------车牌号-------车主联系⽅式---车位区域编号-----车位编号----\n");printf("\t%-17s%-16s%-15ld%-16c%-17d\n", p->name, p->carname, p->information, p->region, p->num); printf("\n输⼊你要修改的信息编号:\n");printf(" 1-车主姓名 \n");printf(" 2-车牌号 \n");printf(" 3-车主联系⽅式 \n");printf(" 4-车位区域编号 \n");printf(" 5-车位编号 \n");scanf("%d", &x);switch(x){case 1:printf("\n\t输⼊修改后的信息");scanf("%s", p->name);break;case 2:printf("\n\t输⼊修改后的信息");scanf("%s", p->carname);break;case 3:printf("\n\t输⼊修改后的信息");scanf("%ld", &p->information);break;case 4:printf("\n\t输⼊修改后的信息");scanf("%c", &p->region);break;case 5:printf("\n\t输⼊修改后的信息");scanf("%d", &p->num);break;}printf("\n\t\t修改后的⽤户信息为");printf("\t车主姓名--------车牌号-------车主联系⽅式---车位区域编号-----车位编号----\n");printf("\t%-17s%-16s%-15ld%-16c%-17d\n", p->name, p->carname, p->information, p->region, p->num); break;}p = p->next;}if(p==NULL){printf("\n未找到相应⽤户");printf("\n按任意键返回主页\n");getch();return head;}printf("\n修改完成!");F(head); //显⽰修改后的全部信息printf("\n按任意键返回主页\n");getch();return head;}其他链表操作排序(根据⽤户姓名排序)void *Sort(Parking *head) //排序{Parking *p=head;Parking *q,*p1=NULL,*p2=NULL;while(p->next != NULL){q = p->next;while(q->next != NULL){if(strcmp(p->next->name,q->next->name)>0) //字符串⽐较{p1 = p->next; //记录p与q的下⼀结点p2 = q->next;q->next = q->next->next;p->next = p2;p2->next = p1;}elseq = q->next;}p = p->next;}F(head);printf("\n\t\t按任意键返回主菜单");getch();}查找区域车辆信息void RegionalVehicles(Parking *head) //寻找指定区域内车辆信息{system("cls");system("color B");char c;printf("\n\t\t输⼊你想要查看的区域");getchar();scanf("%c", &c);Parking *p = head->next;printf("\n\t\t --%c区域内车辆⽤户信息-- \n\n",c);printf("\t---------------------------------------------------------------------\n");printf("\t车主姓名--------车牌号-------车主联系⽅式---车位区域编号-----车位编号----\n");while(p){if(p->region==c) //判断区域字符与输⼊字符是否相等,相等则输出{printf("\t%-17s%-16s%-15ld%-16c%-17d\n", p->name, p->carname, p->information, p->region, p->num);}p = p->next;}printf("\n\t\t按任意键返回主菜单");getch();}⽂件的读取与输⼊将数据保存在⽂件中之所以⽤w形式打开⽂件是因为我在程序运⾏前已将⽂件内数据读出,最后进⾏保存数据时覆盖原数据不会导致原数据丢失void Preservation(Parking *head) //保存数据在⽂件中{const char* filename1 = "C:/Users/judicious/Desktop/car.text"; //⽂件路径FILE *fp = fopen(filename1, "w"); //以写的⽅式打开⽂件,若⽂件不存在,则建⽴新的⽂件。

C语言停车场管理系统源代码.doc

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停车场管理系统简单代码实现

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;。

数据结构-停车场管理程序代码

数据结构-停车场管理程序代码

源程序代码:#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语⾔源码实现停车场管理系统本⽂实例为⼤家分享了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;}}}。

停车场管理系统设计源代码

停车场管理系统设计源代码

附录源代码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 ;}。

停车场管理系统代码

停车场管理系统代码
else
{ L.rear->next=new QNode;
cout<<"停车场已满,请进入通道等待。"<<endl;
cout<<"请输入进入车辆的信息"<<endl;
cout<<"车牌号:";cin>>mingz;
strcpy(L.rear->next->car,mingz);
biandaochushihua(L);
for(int i=0,j=1;i<j;++i,++j)
{ jiemian(S,q,L);
cout<<"是否继续操作(y/n)";
char biandao1,biandao2;
cin>>biandao1;
biandao2='n';
int stacksize;
}SqStack;
typedef struct QNode{
char car[10];
struct QNode *next;
}QNode,*QueuePtr;
typedef struct{
QueuePtr front;
QueuePtr rear;
cout<<"2.出车;"<<endl;
cout<<"请选择操作:"<<endl;
cin>>a;
switch(a){
case 1:tingche(S,L);break;

停车场管理系统代码

停车场管理系统代码
num=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语言版课程设计停车场管理系统

课程设计:停车场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("欢迎来到停车场!我是管理员小王。

停车场管理源程序

停车场管理源程序

#include<stdio.h>#include<stdlib.h>#include<string.h>#define N 10 //预设停车场有10个车位#define M 10 //预设便道有10个出位#define D 1.2 //预设车辆停车费为1.2元每小时#define NUMBER 10void menu();void chushi();void jinru();void likai();struct car{int carnum;int cararr;int carlef;int carstay;}car[NUMBER];struct park{int neikong;}chn[N-1];struct changwai{int waikong;}chw[M-1];void main(){menu();}void menu(){int n,w;do{printf("欢迎您进入车辆管理系统:\n");printf("\n");printf("--------------------------------------------\n");printf("| ☆~☆~☆~ 1.进行初始化~☆~☆~☆|\n");printf("| ☆~☆~☆~ 2.有车辆进入~☆~☆~☆|\n");printf("| ☆~☆~☆~ 3.有车辆离开~☆~☆~☆|\n");printf("| ☆~☆~☆~ 4.退出该系统~☆~☆~☆|\n");printf("--------------------------------------------\n");printf("\n");printf("请选择您需要的服务:");scanf("%d",&n);if(n<1||n>4){w=1;getchar();}else w=0;}while(w==1);switch(n){case 1:chushi();break; //停车函数case 2:jinru();break; //开车函数case 3:likai();break; //退出case 4:exit(0);break; //初始化}}void chushi() //初始化{int i,j;for(i=0;i<N;i++)chn[i].neikong=0; //停车场设置为空for(j=0;j<M;j++)chw[i].waikong=0;printf("已进行初始化\n");menu();}void jinru() //车辆进入函数{int i,a;int h=0;printf("请输入该车系序号(从1开始):"); scanf("%d",&a);for(i=1;i<N;i++){if(chn[i].neikong==0) //无车标记if(chn[i].neikong==1) //有车标记h=h+1;}if(h==N)printf("停车场内已满!");else{car[a].carstay=h;chn[h].neikong=1;printf("该车应该停在停车场内\n");}menu();}void likai() //车辆离开函数{int i,k,choi,time;double fee;printf("请输入离开车辆次序号: ",&i);scanf("%d",&i);printf("请输入该车在停车场内已经停留的时间:");scanf("%d",&car[i].carlef);fee=D*(car[i].carlef-car[i].cararr);time=car[i].carlef-car[i].cararr;printf("要离开的车辆信息:\n");printf("次序号为%d的车停时间%d小时,应收费%6.2f元\n",i,time,fee); printf("便道上现在有车么?(请选择1或2)\n 1.有。

停车场管理系统源程序

停车场管理系统源程序

#include <stdio.h>/*包含了与标准I/O库有关的变量定义和宏定义*/#include <stdlib.h>/*文件包含所用的文件*/#include<conio.h>#include<io.h>#include <stdlib.h>int cars[12][4]={{1234,1,1,20},{2345,1,2,15},{3456,1,3,10},{4567,1,4,5},{0,1,5,0},{0,1,6,0},{0,2,1,0},{0,2,2,0},{0,2,3,0},{0,2,4,0},{0,2,5,0},{0,2,6,0}};/*二维数组代表停车信息*/void save(){FILE *fp;int i,j;if((fp=fopen("car.dat","w"))==NULL){printf("cannot open file\n");return;}for(i=0;i<12;i++)for(j=0;j<4;j++)if(fwrite(cars,2,1,fp)!=1)printf("file write error\n");fclose(fp);getchar();}void car_park(void)/*停车操作*/{int x,i,j;printf("\n ^-^ 欢迎您的光临! ^-^\n ");printf(" \n\n 请输入车牌号:\n\n");printf("\n 注意:车牌号要在1000至9999之间\n 输入错误的车牌号将返回菜单\n\n"); scanf("%d",&x);/*输入要停车的车牌号*/for (i=0;i<12;i++)if(cars[i][0]==x||x<1000||x>9999)break;if(i!=12){printf("\n错误的号码或已经停过了!!!\n");getchar();}/*如果此车号以在,打印此车已停*/else if(i==12&&x>=1000&&x<=9999){for (i=0;i<12;i++)if(cars[i][0]==0) {cars[i][0]=x;save();printf("\n\n成功\n\n");printf("层=%d,车位=%d\n",cars[i][1],cars[i][2]);printf("\n\n\nTwo times 'Enter' to end...");break;}/*如果此车号不在,则进行停车操作*/for (i=0;i<12;i++)if(cars[i][0]!=0) cars[i][3]+=5;/*所有停车时间+5*/save();/*保存以上信息到文件*/}}void car_get(void)/*取车操作*/{int i,y;float paid;int a;printf("\n 取车\n\n\n 输入车牌号:\n\n\n\n");printf("\n 车牌号在1000至9999之间\n 错误的号码\n\n"); scanf("%d",&y);/*输入要取车的车牌号*/for(i=0;i<12;i++){for(i=0;i<12;i++)if(cars[i][0]==y){cars[i][0]=0;/*取车后车牌号清零*/paid=0.2*cars[i][3]/5;/*计算停车费用*/printf("\n 计费(1--是2或任意键--否)\n\n\n");scanf("%d",&a);{switch(a){case 1:printf("\n\n\n价格是%8.2fyuan\n",paid);/*打印停车费用*/ cars[i][3]=0;/*时间清零*/save();break;case 2:printf("欢迎您下次光临");cars[i][3]=0;/*时间清零*/save();break;default: break;}}}else;break;}if(i==12)printf("\n此车不在停车场!!!\n");/*如果此车不在,打印号码不在*/}void printfdata()/*停车信息*/{int i,j;FILE *fp;fp=fopen("car.dat","r");/*打开文件"car.dat"*/printf(" \n Number Floor Position Time\n");for(i=0;i<12;i++){for(j=0;j<4;j++){fread(cars,2,1,fp);/*读文件*/printf(" %6d",cars[i][j]);}printf("\n");}fclose(fp);/*关闭文件"car.dat"*/}void save();void car_park(void);void car_get(void);void printfdata();char readcommand();void initialization();int main(){char c;printf("*******************************停车场管理操作程序*******************************\n");printf("设计者:秦民凯专业:岩土工程学号:20081002763 日期: 2010/9/2\n");;printf("--------------------------------------------------------------------------------\n");printf("按'enter'开始\n");while(1){initialization(); /*初始化界面*/c=readcommand(); /*读取停车场状况*/system("cls");switch(c){case 'p': car_park(); break;/*停车操作*/case 'P': car_park(); break;/*停车操作*/case 'g': car_get(); break;/*取车操作*/case 'G': car_get(); break;/*取车操作*/case 'd': printfdata();printf("\n\n please press 'Enter' to continue....\n");scanf("%c",&c); break;/*停车信息*/case 'D': printfdata(); /*停车信息*/printf("\n\n rreupklfdkplease press 'Enter' to continue....\n");scanf("%c",&c); break;case 'e': printf("\n\n\n\n Press 'Enter' to continue...");exit(0); break;case 'E': printf("\n\n\n\n Press 'Enter' to continue...");exit(0); break;default : printf("ERROR! Press 'Enter' to continue..."); getchar(); break;}}}/****************************************************************************** **/void initialization() /*初始函数*/{int i;getchar();printf("\n*********************************************************************** *********\n");printf(" 1. 停车--p 2. 取车--g 3. 停车时间--d 4.退出--E");printf("\n\n********************************************************************** **********\n");}char readcommand() /*选择函数*/{char c;while((c!='p')&&(c!='P')&&(c!='g')&&(c!='G')&&(c!='d')&&(c!='D')&&(c!='e')&&(c!='E')) {printf("输入p,g,d,e 选择!!\n");c=getchar();printf("\n");break;}return c;}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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){
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){
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车牌: ");
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);
while(1){
printf("\t\t\t欢迎来到XXX停车场!\n");
printf("*****************************************************************\n");
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;
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;
//主函数
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;
停车场管理系统源代码
//停车场管理系统
#include<stdio.h>
#include<stdlib.h>
#define OVERFLOW 0
#define ERROR 0
#define OK 1
#define STACKSIZE 2 //车库容量
//时间节点
typedef struct time{
printf("\t\t位置:%d",l++);
printf("\n");
q++;
}
return OK;
}
//备用车道 (顺序栈)
typedef struct {
Car2 *top2;
Car2 *base2; //
int stacksize2;
}SqStack2;
//初始化
int InitStack2(SqStack2 &S2){
if(S2.top2==S2.base2) return ERROR;
e2=*--S2.top2;
return OK;
}
//车道信息(链队)
typedef struct QNode{
Car data;
struct QNode *next;
}QNode,Leabharlann QueuePtr;typedef struct{
}
//出队
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;
}
int hour;
int min;
}Time;
//车辆信息
typedef struct{
char CarNum;
float time;
int pos_a; //车在停车场中的位置
int pos_b;//车在便道上的位置
int flag;
}Car,Car2;
//车库信息 (顺序栈)
typedef struct{
相关文档
最新文档