C语言停车场管理系统源代码
停车场管理C源代码
s->stacksize++;}
car pop(sqstack *s)
{ car e;
if(s->top==s->base)
{printf("停车场内没有该车辆!\n");
exit(0) ;}
e=*--s->top;
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct
{ int number;
int time;}car;
typedef struct
{ car *base;
car *top;
int stacksize;}sqstack;
printf("'A'或者'a'表示车辆到达 'D'或者'd'表示车辆离开 'E'或者'e'表示退出系统\n\n");
Initstack(&In);
Initstack(&Out);
InitQueue(&Q);
printf("请输入停车场的车位总数以及它的收费标准(元/小时):");
p->number=a->number;
p->time=a->time;
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
经典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)
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语言版)停车场管理(完美版)
数据结构(C语言版)停车场管理(完美版)#include#include#include#define OK 1#define OVERFLOW -2#define SIZE 2 //停车场位置数typedef int Status;typedef struct Car1{int number; //车号int ar_time; //到达时间}CarNode;typedef struct{CarNode *base; //堆栈底CarNode *top; //堆栈顶int stacksize;}Park;typedef struct Car2{int number; //车号int ar_time; //到达时间struct Car2 *next;}*CarPtr;typedef struct{ //便道CarPtr front; //便道的队列的对头CarPtr rear; //便道的队列的队尾int length;}Shortcut;Status InitStack(Park &P){ //初始化停车场P.base=(CarNode*)malloc(SIZE*sizeof(Car1));if(!P.base)exit(OVERFLOW);P.top=P.base;P.stacksize=0;return OK;}Status Push(Park &P,CarNode e){ //车进入停车场*P.top++=e;++P.stacksize;return OK;}Status Pop(Park &P,CarNode &e){ //车离开停车场if(P.top==P.base)printf("停车场为空");else{e=*--P.top;--P.stacksize;}return OK;}Status InitQueue(Shortcut &S){ //初始化便道S.front=S.rear=(CarPtr)malloc(sizeof(Car2));if(!S.front||!S.rear)exit(OVERFLOW);S.front->next=NULL;S.length=0;return OK;}Status EnQueue(Shortcut &S,int number,int ar_time){ //车进入便道CarPtr p;p=(CarPtr)malloc(sizeof(Car2));if(!p)exit(OVERFLOW);p->number=number;p->ar_time=ar_time;p->next=NULL;S.rear->next=p;S.rear=p;++S.length;return OK;}Status DeQueue(Shortcut &S,CarPtr &w){ //车离开便道if(S.length==0)printf("通道为空");else{w=S.front->next;S.front->next=w->next;--S.length;}return OK;}//对进栈车辆的处理Status Arrival(Park &P,Shortcut &S){int number,ar_time;printf("请输入车牌号:");scanf("%d",&number);printf("请输入进停车场的时刻:");scanf("%d",&ar_time);if(P.stacksize<size){CarNode c;c.number=number;c.ar_time=ar_time;Push(P,c);printf("该车停在第%d号车道\n",P.stacksize);}else{EnQueue(S,number,ar_time);printf("停车场已满,暂时停在便道的第%d个位置。
模拟停车场——c语言源代码
模拟停车场——c语⾔源代码实验3 栈与队列的实现及应⽤各模块名称以及功能说明:input_car(top)函数:停车函数,当有车辆驶⼊时记录停车场的停车记录,以栈的⽅式,在停车上限之前每次有车来就堆栈,最后返回栈顶指针。
input_line_car(front,counter2)函数:候车函数,当有车来时,但停车场已满,则利⽤此函数记录便车道上的停车记录,以队列的⽅式,先驶⼊的车排前⾯,后驶⼊的车排后⾯,当停车场中有车驶出时,最后返回⾸指针。
output_car(top,front,counter2)函数:以输⼊要驶出的车的车牌为⽐较标准,从栈顶不断向下查找,建⽴辅助栈,在向下查找的过程中,将要驶出的车后⾯的车村如辅助栈,等该车出栈后,在将辅助栈⾥的元素重新记录到停车场的栈中,同时判断便车道中的停车数,若有停车,则将便车道上最先候车的车停⼊最后的位置,该函数返回栈顶指针。
out_line_car(front)函数:便车道⾸指针后移,返回⾸指针。
show(top,front)函数:表⽰停车场以及便车道情况的函数,停车场是通过栈顶不断向下输出停车情况,便车道通过由⾸指针不断向后输出便车道情况,⽆返回值。
主要功能函数的程序流程图:input_car(top):input_line_car(front,counter2)out_line_car(front)函数:show(top,front)函数:源代码:#include#include#include#define FEE 3 /*每⼩时收费标准*/#define MAX 5 /*停车场容量*/struct node /*停车场中每辆车的表⽰*/ {int number,time;struct node *link;};typedef node NODE;struct queue /*便车道中每辆车的表⽰*/ {struct queue *next;};typedef queue QUEUE;NODE *input_car(NODE *top) /*停车函数*/ {NODE *p;p=(NODE *)malloc(sizeof(NODE));if(p==NULL){printf("没有内存了!\n");exit(1);}else{printf("请输⼊车牌号:");scanf("%d",&p->number);printf("输⼊您停车的时刻:");scanf("%d",&p->time);p->link=top;top=p;}return top;}QUEUE *input_line_car(QUEUE *front,int counter2) /*候车函数*/ {QUEUE *rear,*p;int i,n;if(counter2==0){p=(QUEUE *)malloc(sizeof(QUEUE));printf("请输⼊车牌号:");scanf("%d",&p->number);p->next=NULL;front=p;}{rear=front;for(i=0;i{rear=rear->next;}p=(QUEUE *)malloc(sizeof(QUEUE));printf("请输⼊车牌号:");scanf("%d",&p->number);rear->next=p;p->next=NULL;}return front;}NODE *output_car(NODE *top,QUEUE *front,int counter2)/*车辆开出函数*/ { NODE *p,*q,*s,*t,*m,*n;q=(NODE *)malloc(sizeof(NODE));q=NULL;int a,b;if(top==NULL){printf("泊车位⽆停车情况!\n");}else{printf("请输⼊要出停车场的车的车牌号:");scanf("%d",&a);while(top->number!=a)/*寻找应该驶出的车辆*/{p=(NODE *)malloc(sizeof(NODE));p->number=top->number;p->time=top->time;p->link=q;q=p;if(top==NULL){printf("输⼊有误停车场内没有该车\n\n");top=NULL;while(q!=NULL){m=(NODE *)malloc(sizeof(NODE));m->number=q->number;m->time=q->time;m->link=top;top=m;q=q->link;}printf("请再输⼊正确车牌号:");scanf("%d",&a);q=NULL;while(top->number!=a){n=(NODE *)malloc(sizeof(NODE));n->number=top->number;n->time=top->time;n->link=q;q=n;top=top->link;}break;}}printf("请输⼊出停车场的时间:");scanf("%d",&b);printf("\n车牌为%d的车开出停车场,停车时间%d点⾄%d点收费%d元\n",a,top->time,b,FEE*(b-top->time));printf("\n此时便车道上最先候车的车进⼊停车场,进⼊时间:%d\n",b); top=top->link;{s=(NODE *)malloc(sizeof(NODE));s->number=q->number;s->time=q->time;s->link=top;top=s;q=q->link;}if(counter2>0)/*若便车道上有车,则驶⼊停车场*/{t=(NODE *)malloc(sizeof(NODE));t->number=front->number;t->time=b;t->link=top;top=t;}}return top;}QUEUE *out_line_car(QUEUE *front)/*便车道的车开⼊停车场函数*/{QUEUE *p;p=front;front=p->next;free(p);return front;}void show(NODE *top,QUEUE *front)/*停车场以及便车道停车情况函数*/ int x,y;if(top==NULL){printf("⽆泊车记录!\n");}elseprintf("停车位的停车情况为(右边为先停⼊的车):"); while(top!=NULL){x=top->number;printf("%5d",x);top=top->link;}printf("\n");}if(front==NULL){printf("⽆车停于便车道!\n");}else{printf("便车道的停车情况为(左边为先候车的车):"); while(front!=NULL){y=front->number;printf("%5d",y);front=front->next;}printf("\n");}}int main(){int chioce,flag=1;int counter1=0;/*停车场停车数*/int counter2=0;/*便车道停车数*/NODE *top,*p;QUEUE *front,*q;top=NULL;front=NULL;printf("\n");printf("请输⼊您的操作:车辆到达2车辆离开3显⽰停车场内及便道上的停车情况4退出系统\n"); printf("\n"); while(flag){scanf("%d",&chioce);switch(chioce){case 1:{if(counter1{p=input_car(top);counter1++;top=p;}else{printf("停车场已满,此时只能停车于便车道!\n");q=input_line_car(front,counter2);counter2++;front=q;}}break;case 2:{p=output_car(top,front,counter2);top=p;if(counter2>0){q=out_line_car(front);counter2--;front=q;}}break;case 3:show(top,front); break;case 4:flag=0;}printf("\n");printf("请继续操作!\n"); }printf("\n");printf("谢谢使⽤!\n\n"); return 0;}。
c语言实现停车场管理系统
c语言实现停车场管理系统#include#include #include#define Size 2#define price 5typedef struct { char num[20]; int reachtime; int leavetime; }carinfo;typedef struct stack{ carinfo car[5]; int top;}Stack;typedef struct Node{ carinfo data; struct Node*next; }QueueNode;typedef struct { QueueNode *front; QueueNode *rear;}Queue,*linkQueue;int EnterQ(Queue *Q,carinfo x); int inistack(Stack *S) //初始化栈{S->top=-1; return 1;}void Push(Stack *S,carinfo x) //进栈操作{S->top++; S->car[S->top]=x;printf(" 进站成功!"); }void Pop(Stack *S,carinfo x) //出栈操作{ if(S->top=-1) printf(" 空栈,无法出栈!");x=S->car[S->top];S->top--;printf(" 出栈成功!");}IsEmpty(Stack *S) // 判断栈空{ if(S->top==-1) return 1;elsereturn 0;}int iniQueue(Queue *Q) //初始化便道{Q->front=(QueueNode *)malloc(sizeof(QueueNode)); //申请节点if(Q->front!=NULL){Q->rear=Q->front;Q->front->next=NULL;return 1;}else return 0;}int EnterQ(Queue *Q,carinfo x) //进便道{QueueNode *newNode;newNode=(QueueNode *)malloc(sizeof(QueueNode)); if(newNode!=NULL){ newNode->data=x; newNode->next=NULL;Q->rear->next=newNode; Q->rear=newNode; return 1;}else return 0;}int DeleteQ(Queue *Q,carinfo x) // 出便道{QueueNode *p; p=Q->front->next;if(Q->front==Q->rear) //判断便道是否有车return 0;x=p->data;if(p->next==Q->rear)Q->rear=Q->front;Q->front->next=NULL;}Q->front->next=p->next; free(p); return 1;}void Lpush(Stack *S,carinfo x){ Push(S,x); //进临时栈}void LPop(Stack *S,carinfo x){Pop(S,x);}int Arrive(Stack *S,Queue *Q) // 车辆到达{carinfo x;int a;printf(" 输入车牌号:"); scanf("%s",x.num); printf(" 请输入进车场的时间:");scanf("%d",&x.reachtime);if(S->top==Size-1){printf(" 车场已满,不能进入,进便道");//递归调用进便道操作a=EnterQ(Q, x);if(a==1){ printf("OK\n");} else printf("No!\n");}else{ Push(S,x);} return 1;}int Departure(Stack *S) // 车辆离开操作{int money;。
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
#include<stdio.h>#include<stdlib.h>#define stacksize 2 //车站//容量///////////////////////////////////////////////////////typedef struct Snode{int number;float int_time[2];float bian_time[2];}record;typedef struct {record *base;record *top;int size;}Stack;/////////////////////////////////////////////////////typedef struct Qnode{int number;float int_time[2];struct Qnode *next;}Qnode,*Queue;typedef struct {Queue front;Queue rear;}Linkqueue;void xunhuan(Stack L,Linkqueue Q);void jixu(Stack L,Linkqueue Q);//////////////////////////////////////////////////////////////////////////////////////////////////////////void InitStack(Stack &L) //堆栈操作{L.base=(record*)malloc(sizeof(Snode)*stacksize);if(!L.base)exit(0);L.top=L.base;L.size=stacksize;}/////////////////////////////////////////////////////void input(Stack &L,record h){*L.top++=h;}///////////////////////////////////////////////////Snode output(Stack &L,record &e){e=*--L.top;return e;}int Stackman(Stack L){if(L.top-L.base==L.size)return 0;elsereturn 1;}int StackEmpty(Stack L){if(L.base==L.top)return 0;elsereturn 1;}////////////////////////////////////////////////////////////////////////////////////////////////////void Initque(Linkqueue &Q) //队列操作{Q.front=Q.rear=(Queue)malloc(sizeof(Qnode));if(!Q.front)exit(0);Q.front->next=NULL;}//////////////////////////////////////////////////void enqueue(Linkqueue &Q,int number,float time[]){Queue q;printf("停车场已满,请将车辆停入便道!\n");q=(Queue)malloc(sizeof(Qnode));q->int_time[0]=time[0];q->int_time[1]=time[1];q->number=number;q->next=NULL;Q.rear->next=q;Q.rear=q;}///////////////////////////////////////////////////void outqueue(Linkqueue &Q,Queue &e) //此处有点问题??????????????{// Qnode *q;// q=(Queue)malloc(sizeof(Qnode));e=Q.front->next;// Q.front->next=q->next;//delete q;Q.front->next=Q.front->next->next;if(Q.rear==e){Q.front=Q.rear;// Q.front=NULL;}}int QEmpty(Linkqueue Q){if(Q.rear==Q.front)return 0;elsereturn 1;}//////////////////////////////////////////////////// //停车场管理操作////////////////////////////////////////////////////void jixu(Stack L,Linkqueue Q){int n;fflush(stdin);scanf("%d",&n);switch(n){case 1:printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");xunhuan(L,Q);break;case 2:printf("****************************退出管理系统*****************************\n");default:printf("\n输入错误,请重新输入: ");jixu(L,Q);break;}}void jiaofei(float time[],float time1[],float time2[]) //缴费操作{float data1,data2;double money;if(time2[0]!=0&&time2[1]!=0)data2=(time1[0]-time2[0]-1)*60+60-time2[1]+time1[1];elsedata2=0;data1=(time[0]-time1[0]-1)*60+60-time1[1]+time[1];// printf("进入车场时间%f,退出车场时间%f\n",time1[1],time[1]);printf("你的停车时间为%lf小时,在便道停留时间%f小时\n",data1/60,data2/60);money=data1/60*5.0+data2/60*2.0;printf("请交纳%lf元\n",money);/* if(data1<=60.0)printf("请交纳5元。
停车场管理系统代码
// 1、停车场管理.cpp : Defines the entry point for the console application. //^include stdafx.h*'^include vcon 1o.h>^include <malloc・h>^include <stdio.h>^include <stdlib.h>^include <windows. h>//清空当前屏幕#define ClearScreen() system( 'cls M )〃设置背景前景颜色//#define setcolor() system(u color 2f )//显不字符串szPrompt并等待用户按下任意键#define Pause( szPrompt) printf( %s: szPrompt ),getch()typedef struct carinformation // 车辆信息{char szRegistrationMark[64]; // 车牌号char szArrivalTime[16]; // 到达时间char szEntranceT1me[16]; //进入停车场(开始计费)时间char szDepartureTime[16]; // 离开时间} TCARINFORMATION, *LPTCARINFORAAATION;typedef struct carstack{LPTCARINFORMATION IpCarlnformation; // 车辆信息int nTop; //栈顶元素下标int nStackSize; // 栈容量} TCARSTACK, *LPTCARSTACK;//初始化栈IpCarStack,将其容量设置为nSizevoid ln1tStack( LPTCARSTACK ftlpCarStack, int nSize ){IpCarStack = ( LPTCARSTACK ) malloc( sizeof ( TCARSTACK ));lpCarStack->lpCarlnformation = ( LPTCARINFORMATION ) malloc( nSize * sizeof ( TCARINFORAAATION ));lpCarStack->nTop = -1;lpCarStack->nStackSize = n Size;}// 车辆信息carinfo 入栈IpCarStackvoid Push( LPTCARSTACK ftlpCarStack, TCARINFORAAATION carinfo ){IpCarStack-Top++;lpCarStack->lpCarl nformation [lpCarStack->nTop] = carinfo;}//车辆信息从栈IpCarStack中弹出并存入carinfovoid Pop( LPTCARSTACK ftlpCarStack, TCARINFORMATION &carinfo ) {carinfo = lpCarStack->lpCarlnformation[lpCarStack-> nTop];IpCarStack->nTop・・;}//若栈IpCarstack空,返回TRUE;否贝!J,返回FALSEBOOL IsStackEmptyf LPTCARSTACK IpCarStack ){return IpCarStackjnTop == -1;}//若栈IpStackFull满,返回TRUE;否则,返回FALSEBOOL IsStackFulK LPTCARSTACK IpCarStack ) return lpCarStack->nTop == ( lpCarStack->nStackSize • 1 );}// 销毁栈IpCarStack,将指针IpCarStack 置为NULLvoid DestroyStack( LPTCARSTACK &IpCarStack ){free( lpCarStack->lpCarlnformation );free( IpCarStack );IpCarStack = NULL;}typedef struct carnode // 链队结点信息{TCARINFORMATION carinfo; // 车辆信息struct carnode *lpNext; //指向下一个元素的指针} TCARNODE, *LPTCARNODE;typedef struct carqueue // ¥连队{LPTCARNODE IpHead; // 头结点LPTCARNODE IpRear; //指向当前队尾的指针int nEffectivesize; //当前队中元素个数} TCARQUEUE, *LPTCARQUEUE;//初始化链队IpCarQueuevoid lnitQueue( LPTCARQUEUE ftlpCarQueue ){IpCarQueue = ( LPTCARQUEUE ) malloc( sizeof( TCARQUEUE )); lpCarQueue->lpHead = ( LPTCARNODE) malloc( sizeof( TCARNODE ));lpCarQueue->lpHead->lpNext = NULL;lpCarQueue->lpRear = lpCarQueue->lpHead;IpCarQueue-EffectiveSize = 0;}// 车辆信息carinfo 入队IpCarQueuevoid EnQueue( LPTCARQUEUE ftlpCarQueue, TCARINFORMATION carinfo ) {LPTCARNODE IpCarNode = ( LPTCARNODE ) malloc( sizeof( carnode )); lpCarNode->car1nfo = cari nfo;lpCarNode->lpNext = NULL;lpCarQueue->lpRear->lpNext = IpCarNode;lpCarQueue->lpRear = lpCarQueue->lpRear->lpNext;IpCarQueue->n EffectiveSize++;}//队头元素从链队IpCarQueue中出队并存入carinfovoid DeQueue( LPTCARQUEUE ftlpCarQueue, TCARINFORMATION ftcarinfo ) { LPTCARNODE IpTemp = lpCarQueue->lpHead->lpNext;carinfo = IpTemp ・>cari nfo;lpCarQueue->lpHead->lpNext = IpTemp ・> IpNext;free( IpTemp );IpCarQueue->n EffectiveSize-;}//若链队IpCarQueue为空,返回TRUE;否则,返回FALSEBOOL lsQueueEmpty( LPTCARQUEUE IpCarQueue ){return LpCarQueue->nEffect1veSize == 0;}//销毁链队IpCarQueuevoid DestroyQueue( LPTCARQUEUE EtlpCarQueue )LPTCARNODE IpNextCarNode = NULL;for ( LPTCARNODE IpCarNode = lpCarQueue->lpHead; IpCarNode != NULL; IpCarNode = IpNextCarNode ){IpNextCarNode = lpCarNode->lpNext;free( IpCarNode );}free( IpCarQueue );IpCarQueue = NULL;}//将字符串时间格式转换为数字(分钟)格式,例如12:36将被转换为756 (12 * 60 + 36)int ConvertTimeFormat( char *lpTime ){Int nHour = 0;int nMinute = 0;sscanf( IpTime, “%d:%d; 8tnHour, SnMinute );return nHour * 60 + nMinute;}//根据在停车场内的停留时间nContinuanceMinutes (分钟)计算费用double CalculateExpense( int nContinuanceMinutes ){return nContinuanceMinutes * ( 5.0 / 60 );}int main( void ){// setcolor();Int nParkCapability = 0; // 停车场容量putchar( \n*);PHns)jscanf(・•衣d jppnparkcapabujry「LPTCARSTACK -pear-stack"NULL"二®世曲生需更蹦-njrsrack 二pcarsrack 》nparkcmpmbsrty)八LPTCARQUEUE 【Pear-Queue =NULL"、二冊®曲爲兰赫更-njrQueue(-pcarQueue)jcharcCommandTypeHNULLj二劭3淋起 charSzuser-npuru28jH宀NULLY二a l}^> do宀Qearscreenoj二 seccoor(rpurchar(An ・rI .... );I -n -)j1 ->・-W 養区);purs(d ・W S B J F)jI H ・)」1-0・)」pucchar( -\n ・)一purs(=0辽)j P U £・A S§A 3926N 3W 3・・rPUS ・・9SPA3926二 444・・);puts(ni・);puts( © );putchar( \rf );printf(“请输入命令:“);seanf( “%s", szllserlnput);puts(H ................. “);char szCarlnformation[128] = { NULL};sscanff szllserlnput, //将命令类型与车辆信息分开存放”%c,%s“,&cCommandType, //用户输入的前半部分,即命令类型szCarlnformation //用户输入的后半部分,即车辆信息);char *LpCommaLocation = NULL; //车辆信息字符串中的逗号位置for ( IpCommaLocation = szCarlnformation; *lpCommaLocation != *\0'; lpCommaLocation++ ){if (*lpCommaLocation ==){break;}}*lpCommaLocati on = \0';TCARINFORMATION carinfo = { NULL }; //存储本次用户输入的车辆信息strcpy( carinfo.szRegistrationMark, szCarlnformation );if ( cCommandType == A )strcpy( carinfo.szArrivalTime, IpCommaLocation + 1 );if ( FALSE == lsStackFull( IpCarStack )){strcpy( carinfo.szEntranceTime, carinfo.szArrivalTime ); Push( IpCarStack, carinfo );printf(“已进入停车场第%d个车位\n“,lpCarStack->nTop + 1);printf("车牌号:\t\t%s\n", carinfo.szRegistrationMark ); printf("进入时间:\t%s\n", carinfo.szEntranceTime ); puts(“是否收费:\t是“);}else{EnQueue( IpCarQueue, carinfo );printf(“停车场已满,已停放在便道的第%d个车位\n“,lpCarQueue->nEffectiveS1ze);printf("车牌号:\t\t%s\n", carinfo.szRegistrationMark ); printf("停放时间:\t%s\n", carinfo.szArrivalTime );puts( ••是否收费:\t否”);}}else if ( cCommandType == 'D')strcpy( carinfo.szDepartureTime, IpCommaLocation + 1 );LPTCARSTACK IpTempCarStack = NULL;lnitStack( IpTempCarStack, nParkCapability );TCARINFORMATION carinfoOut = { NULL };BOOL blsCarFound = FALSE;while ( FALSE == lsStackEmpty( IpCarStack )){Pop( IpCarStack, carinfoOut);if ( 0 != strcmp( carinfoOut.szRegistrationMark, carinfo.szRegistrationMark )) {Push( IpTempCarStack, carinfoOut);}else{blsCarFound = TRUE;break;}}while ( FALSE == IsStackEmptyf IpTempCarStack )){TCARINFORAAATION tempcarinfo = { NULL };Pop( IpTempCarStack, tempcarinfo );Push( IpCarStack, tempcarinfo );} if ( FALSE == blsCarFound ) printf(1车牌号为%s 的车未进入停车场・\n;carinfo.szRegistrationMark );Pause(M.................... \n按任意键输入下 V信息…\n“);continue;strcpy( carinfoOut.szDepartureTime, carinfo.szDepartureTime );int nEntranceTime = ConvertTimeFormat( carinfoOut.szEntranceTime ); Int nDepartureTIme = ConvertTimeFormat( carinfoOut.szDepartureTime ); int nContinuanceMinutes = nDepartureTime • nEntranceTime;printf("计费时段:\t%s - %s (共%d 分钟)\n",carinfoOut.szE ntran ceTime,carinfoOut.szDepartureTime, nContinu anceMinutes);double rExpense = CalculateExpense( nContinuanceMinutes );printf("应交纳的费用:\t%.1 If 7E\n", rExpense );if ( FALSE == lsQueueEmpty( IpCarQueue )){TCARINFORAAATION tempcarinfo = { NULL };DeQueue( IpCarQueue, tempcarinfo );strcpy( tempcarinfo.szEntranceTim® carinfoOut.szDepartureTime ); Push( IpCarStack, tempcarinfo );puts(" .................... ”);printf(“停放在便道的第1个车位,车牌号为%s的车已进入停车场\n“,tempcarinfo. szRegistrati on Markelse if ( cCommandType == E )puts( "********************"puts(H :吴远彦\n M);puts「学号:\n u);Uts( M********************" )•break;else if ( cCommandType == 0*){ClearScree n();//setcolor();putchar( *\n );puts( “[停车场使用情况]\n“);puts( •[车位]\t[车牌号]\t倒达时间]\t[进入(开始计费)时间]\n“); for (in t i = 0; i <= IpCarStack-Top; i++ ){printf( M%d\t%s\t\t%s\t\t%s\n\i + 1,IpCarStack- > IpCar I nformati on [i]・ szRegistratio nAAark, lpCarStack->lpCarlnformat1 on [i].szArrivalTime,lpCarStack->lpCarlnformation[i].szE ntranceTime);}putchar( \n );putchar( \n );putchar( \n );puts( •■[便道使用情况]\n“);puts( •[车位]\t[车牌号]\t[到达时间]\t[进入(开始计费)时间]\n“); int nNum = 0;for ( LPTCARNODE IpCarNode = lpCarQueue->lpHead->lpNext; IpCarNode != NULL; IpCarNode = lpCarNode->lpNext ){n Num++;printf( ,,%d\t%s\t\t%s\t\t%s\n\n Num,lpCarNode->carinfo.szRegistratio nMark,lpCarNode->carinfo.szArrivalTime,lpCarNode->carinfo.szEntra nceTime);}putchar( \n );}else{puts(“输入信息有误.第f 字符只能为'A'或D或E或0'(区分大宵) }Pause(”.................... \n按任意键输入下一息.\n“);} while ( TRUE );DestroyStack( IpCarStack );DestroyQueue( IpCarQueue );Pause( “\n按任意键退出程序...\n“);return 0;。
停车场管理系统代码(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);
//运行界面及功能选择
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;}}}。
c语言停车场代码
#include <stdio.h>#include <string.h>#include<stdlib.h># define SMAX 2# define QMAX 25typedef struct {char num[20];int reachtime;}carinfo;//车的数据元素类型,num[20]代表车牌号码,reachtime代表车辆到达的时间typedef struct /*栈*/{ carinfo stack[SMAX+1];int top;//栈顶指针}seqstack;typedef struct squeue /*队列*/{carinfo queue[QMAX+1];int front,rear;//front为头指针,rear为尾指针}seqqueue;void initstack(seqstack *s)//栈s的初始化{s->top=-1;//把栈顶置为-1}int stackempty(seqstack *s)//判断栈s是否为空,栈空返回1,否则返回0{if(s->top==-1)//判断栈顶指针top是否为-1return 1;//当栈为空时,返回1,否则,返回0elsereturn 0;}int pushstack(seqstack *s,carinfo x) //将元素x插入栈s中,插入成功返回1,否则返回0 {if(s->top>=SMAX)//在元素进栈前,判断是否栈已满{return 0;}else{s->top++; //修改栈顶指针s->stack[s->top]=x;//元素x进栈return 1;}}int popstack(seqstack *s,carinfo *x) //删除栈s中的队首元素,并将该值赋值给x,删除成功返回1,否则返回0{if(s->top==-1) //元素出栈时,判断栈是否为空{return 0;}else{*x=s->stack[s->top];//将出栈的元素给xs->top--; //将栈顶指针减1,修改栈顶指针,即出栈return 1;}}int getcar(seqstack *s,carinfo x) /*取车*/{int a,b,money,v,h;carinfo m,n;seqstack k; //输入临时栈initstack(&k); //对临时栈进行初始化a=0;while((!stackempty(s)) && a==0){popstack(s,&n);if(strcmp(x.num,n.num)==0) //判断车牌号字符串是否匹配{printf("请输入取车时间");//如果匹配则输入取车时间scanf("%d",&v);/*printf("请输入存车天数");scanf("%d",&h);*/money=((v-n.reachtime)+h*24)*5; //并计算收费printf("车辆已经取出,收费%d\n",money);printf("——————欢迎光临——————\n\n\n");while(!stackempty(&k))//将存放在临时栈中的元神存入原始栈,也就是将车辆存入车库{popstack(&k,&m);pushstack(s,m);}a=1;}else //如果不匹配,则将出栈的车辆放入临时栈{k.top++;k.stack[k.top]=x;}}if(stackempty(s)) //如果车库为空,即没有找到匹配的车辆,则要寻找的车辆不存在{printf("车辆不存在");while(!stackempty(&k)){popstack(&k,&m);pushstack(s,m);}}}void initqueue(seqqueue *q)//队列q初始化{q->front=q->rear=-1; //队头指针和队尾指针分别置为-1}int queueempty(seqqueue *q)//判断队列q是否为空,队空返回1,否则返回0{if(q->front==q->rear)//判断头指针,尾指针是否相等return 1;elsereturn 0;}int enqueue(seqqueue *q,carinfo x)//将元素x插入队列q中,插入成功返回1,否则返回0 {if(q->rear==QMAX) //在元素进队前,判断是否队列已满return 0;q->rear=q->rear+1; //队尾指针向后移动一个位置q->queue[q->rear]=x;//在队尾插入元素xreturn 1;}int delqueue(seqqueue *q,carinfo *x)//删除顺序队列q中的队首元素,并将该值赋值给x,删除成功返回1,否则返回0{if(q->front==q->rear) //在删除元素之前,判断队列是否为空return 0;else{q->front=q->front+1; //将队头指针向后移动一个位置*x=q->queue[q->front];//将要删除的元素赋值给xreturn 1;}}void main(){ int h,n,c,d;int m;carinfo a,b,x;seqqueue i; //输入栈,即车库seqstack l; //输入队列,即便道initstack(&l); //对栈进行初始化initqueue(&i); //对队列进行初始化d=1;while(1){printf("请输入车辆执行状态,1为进场停车,2为取车:"); //输入要执行的操作while (1){scanf("%d",&m);if(m==1 || m==2) break; //判断输入是否正确else printf("\n 输入有误,请重新选择:1或2:");}if(m==1) //如果输入为1,则进行入车库操作{printf("请输入车辆号码:");scanf("%s",&a.num); //输入车牌号printf("请输入进车库时间(请将时间取整):"); //输入进车时间scanf("%d",&a.reachtime);h=pushstack(&l,a); //进栈,即进入车库if(h==0) //判断车库是否已满{printf("车库已满\n");enqueue(&i,a); //如果满,则入队,即进入便道n=i.rear-i.front;printf("车辆已入便道%d位置\n\n\n",n);}elseprintf("车辆%s已存入车库\n\n\n",a.num);}else //如果输入为2,则进行取车操作{printf("请输入要取得车辆号:");scanf("%s",&x.num); //输入车牌号getcar(&l,x); //调用getcar函数,进行取车操作while(!queueempty(&i)&&d==1)//取车之后,判断是否需要将便道中的车入库{if(l.top>=2) //如果车库是满的,则不操作d=3;else{delqueue(&i,&b); //否则,将便道中的车出队,并入栈,进车库pushstack(&l,b);printf("车辆%s已从便道进入车库\n",b.num);}}}}}。
停车场管理系统程序源代码
#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语言版本的数据结构课程设计,规定用栈模拟停车场,用队列模拟便道,实现停车场的收费管理系统停车场停满车后车会停在便道上面下面附上源码,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)。
#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");break;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元。
");if(data1>60.0&&data1<=120.0)printf("请交纳10元。
");if(data1>120.0)printf("请交纳20元。
");*/}void leave(Stack &L,Linkqueue &Q,int number,float time[]) //汽车离开操作{Stack S;InitStack(S);float time1[2],time2[2];record e,e1;Queue q;e1=output(L,e);while(e.number!=number){input(S,e1);e1=output(L,e);}time1[0]=e.int_time[0]; //入车站时间time1[1]=e.int_time[1];time2[0]=e.bian_time[0]; //入便道时间time2[1]=e.bian_time[1];jiaofei(time,time1,time2); //////////////////////////while(StackEmpty(S))input(L,output(S,e1));while(QEmpty(Q)&&Stackman(L)){outqueue(Q,q);//printf("\n\n请输入汽车从便道进入停车场的时间,输入格式为(时空格分):");e.bian_time[0]=q->int_time[0];e.bian_time[1]=q->int_time[1];//scanf("%f %f",&time2[0],&time2[1]);e.int_time[0]=time[0];e.int_time[1]=time[1];e.number=q->number;printf("\n汽车从便道退出进入停车场……");printf("\n请将%d号车停在%d号位置!\n",e.number,L.top-L.base+1);input(L,e);}}/////////////////////////////////////////////////////void xunhuan(Stack L,Linkqueue Q) //选择操作及循环{// Queue q;char ch;int number;float time[2],time2[2];fflush(stdin);printf("\nA:进入停车场D:退出停车场E:退出管理系统\n"); printf("\n请输入:");scanf("%c",&ch);fflush(stdin);switch(ch){case 'A':printf("\n请输入车牌号: ");scanf("%d",&number);printf("请输入入场时间,输入格式为(时空格分):");scanf("%f %f",&time[0],&time[1]);if(Stackman(L)){ record e;e.int_time[0]=time[0];e.int_time[1]=time[1];e.bian_time[0]=0.0;e.bian_time[1]=0.0;e.number=number;printf("请将车停在%d号位置!",L.top-L.base+1);input(L,e);}else{enqueue(Q,number,time);}printf("\n");printf("\n1、继续操作2、退出操作: ");jixu(L,Q);break;case 'D':if(StackEmpty(L)){printf("请输入离开汽车的车牌号:");scanf("%d",&number);printf("输入汽车离开时间:");scanf("%f %f",&time2[0],&time2[1]);leave(L,Q,number,time2);}elseprintf("停车场为空\n");printf("\n1、继续操作2、退出操作: ");jixu(L,Q);break;case 'E':{printf("***************************退出管理系统*****************************\n");break;}default:{printf("输入错误,请重新输入!\n");printf("############################################################\n");xunhuan(L,Q);break;}}}////////////////////////////////////////////////////////////////////////////////////////////////////////void main() //主函数操作{Linkqueue Q;Stack L;InitStack(L);Initque(Q);printf("****************************欢迎进入停车场管理系统******************************\n");printf(" 收费标准\n");printf(" ------------------------------------\n");printf(" | 车场内5.0元/h,便道内2.0元/h | \n");printf(" ------------------------------------\n");printf(" \n---------------------------------请选择操作-------------------------------------\n"); xunhuan(L,Q);}。