您好,欢迎访问三七文档
#includestdio.h#includestdlib.h#includestring.h#definetcs2//停车场内最多停车数#defineprice0.02//停车内停车的单价(每分钟)typedefstructts{inttx;//停车的时刻小时inttf;//停车的时刻分钟}ts1;typedefstructcj{charnum[10];//车牌照ts1d;ts1l;}cn;typedefstructCj{cn*stack[tcs+1];inttop;}Car;typedefstructcar{cn*data;structcar*next;}QueueNode;typedefstructNode{QueueNode*head;QueueNode*rear;}LCar;voidTc(Car*);voidBd(LCar*);voidD(Car*,LCar*);voidL(Car*,Car*,LCar*);voidLb(Car,LCar);voidSc(cn*c,intcw){//输出信息intd1,d2,l1,l2;printf(\n车辆离开的时间:);scanf(%d:%d,&(c-l.tx),&(c-l.tf));printf(\n离开车辆的车牌号为:);puts(c-num);printf(\n其到达时间为:%d:%d,c-d.tx,c-d.tf);printf(离开时间为:%d:%d,c-l.tx,c-l.tf);d1=c-d.tx;d2=c-d.tf;l1=c-l.tx;l2=c-l.tf;printf(\n应交费用为:%2.1f元,((l1-d1)*60+(l2-d2))*price);free(c);}voidD(Car*Enter,LCar*W){cn*p;QueueNode*t;p=(cn*)malloc(sizeof(cn));flushall();printf(\n请输入车牌号(例:辽A1234):\n);gets(p-num);if(Enter-toptcs){Enter-top++;printf(\n车辆在车场第%d位置.,Enter-top);printf(\n车辆到达时间:整时=24,分钟60\n);scanf(%d:%d,&(p-d.tx),&(p-d.tf));Enter-stack[Enter-top]=p;}else{printf(\n该车须在便道等待!有车位时进入车场\n);t=(QueueNode*)malloc(sizeof(QueueNode));t-data=p;t-next=NULL;W-rear-next=t;W-rear=t;}}voidL(Car*Enter,Car*Temp,LCar*W){intcw;cn*p,*t;QueueNode*q;if(Enter-top0){while(1){printf(\n请输入车在车场的位置/1--%d/:,Enter-top);scanf(%d,&cw);if(cw=1&&cw=Enter-top)break;}while(Enter-topcw){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--;}Sc(p,cw);if((W-head!=W-rear)&&Enter-toptcs){q=W-head-next;t=q-data;Enter-top++;printf(\n便道的%s号车进入车场第%d位置.,t-num,Enter-top);printf(\n请输入%s号车进入车场的时间:);scanf(%d:%d,&(t-d.tx),&(t-d.tf));W-head-next=q-next;if(q==W-rear)W-rear=W-head;Enter-stack[Enter-top]=t;free(q);}elseprintf(\n便道里没有车.\n);}elseprintf(\n车场里没有车.);}voidLb1(Car*S){inti;if(S-top0){printf(\n车场:);printf(\n位置到达时间车牌号\n);for(i=1;i=S-top;i++){printf(%d,i);printf(%d:%d,S-stack[i]-d.tx,S-stack[i]-d.tf);puts(S-stack[i]-num);}}elseprintf(\n车场里没有车);}voidLb2(LCar*W){QueueNode*p;p=W-head-next;if(W-head!=W-rear){printf(\n等待车辆的号码为:);while(p!=NULL){puts(p-data-num);p=p-next;}}elseprintf(\n便道里没有车.);}voidLb(CarS,LCarW){intflag,tag;flag=1;while(flag){printf(\n请选择1|2|3:\n);printf(\n1.车场列表\n2.便道列表\n3.返回主菜单\n);while(1){scanf(%d,&tag);if(tag=1||tag=3)break;elseprintf(\n请选择1~3:\n);}switch(tag){case1:Lb1(&S);break;case2:Lb2(&W);break;case3:flag=0;break;default:break;}}}voidmain(){CarEnter,Temp;LCarWait;intch;Tc(&Enter);Tc(&Temp);Bd(&Wait);while(1){printf(*************主菜单*************\n);printf(|【1】车辆到达登记|\n);printf(|【2】车辆离开登记|\n);printf(|【3】车辆列表显示|\n);printf(|【4】退出系统|\n);printf(********************************\n);while(1){scanf(%d,&ch);if(ch=1&&ch=4)break;elseprintf(\n请选择:1~4.);}switch(ch){case1:D(&Enter,&Wait);break;case2:L(&Enter,&Temp,&Wait);break;case3:Lb(Enter,Wait);break;case4:exit(0);default:break;}}}voidTc(Car*s){inti;s-top=0;for(i=0;i=tcs;i++)s-stack[s-top]=NULL;}voidBd(LCar*Q){Q-head=(QueueNode*)malloc(sizeof(QueueNode));if(Q-head!=NULL){Q-head-next=NULL;Q-rear=Q-head;}}
本文标题:汽车管理
链接地址:https://www.777doc.com/doc-302811 .html