停车场管理系统.txt其实全世界最幸福的童话,不过是一起度过柴米油盐的岁月。一个人愿意等待,另一个人才愿意出现。感情有时候只是一个人的事,和任何人无关。爱,或者不爱,只能自行了断。姓名:蒋鹏;学号:20081004340  班序号:19308127
#define NUL 0
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
struct time
{int year;
int mon;
int day;
int hour;
int min;
};
struct parking /*已停车函数*/
{ char code_num[20]; /*车牌号*/
int floor;  /*层号*/
int place;  /*车位号*/
struct time parkingtime1;  /*起始时间*/
struct time parkingtime2;  /*终止时间*/
time_t start;
time_t end;
double  fee;
}parking_message[12]
={{"A0001",1,1,0},{"A0002",1,2,0},/*所停车辆*/
{"A0003",1,3,0},{"A0004",1,4,0},
{"",1,5,0},{"",1,6,0},
{"",2,1,0},{"",2,2,0},
{"",2,3,0},{"",2,4,0},
{"",2,5,0},{"",2,6,0}};
struct tm *local;void back();void save();
void save()            /*保存*/
{int i;char c;
FILE *fp;
fp=fopen("car_dat","w");
for(i=0;i<12;i++)
fwrite(&parking_message[i],sizeof(struct parking),1,fp);
fclose(fp);printf("\n");
printf("按任意键返回主菜单.....\n");
scanf("%c",&c);
if((c=getchar())!='\0') back();}
void park()      /*停车函数*/
{ int i;int j;char code_num[20];
for(i=0;;i++)
{if((strcmp(parking_message[i].code_num,"")==0)&&(i<=11))
{printf("请输入车牌号(五位):");
scanf("%s",code_num);
while(strlen(code_num)!=5)
{printf("输入有误,请重新输入车牌号(五位):");
scanf("%s",code_num);}
for(j=0;j<12;j++)
{if(strcmp(parking_message[j].code_num,code_num)==0){printf("该车已停入,请重新输入车牌号(五位):");scanf("%s",code_num);}
}
strcpy(parking_message[i].code_num, code_num);
printf("成功停车");
printf函数是如何实现的
printf("停车位置:%d层%d车位\n",(i+1)<7?1:2,(i+1)<7?(i+1):(i-5));
parking_message[i].start=time(NUL);
local=localtime(&parking_message[i].start);
parking_message[i].parkingtime1.hour=local->tm_hour;
parking_message[i].parkingtime1.min=local->tm_min;
break;
}
if(i>=12) {printf("所有车位已满!\n");break;printf("\n");}
}
save();
}
void charge()
{void chargeplace();void fee(int j);char code_num[6];void shuchuxinxi();
int i,a;char d; char c;
printf("请输入车牌号(五位):"); 
scanf("%s",code_num);
while(strlen(code_num)!=5)
{printf("输入有误,请重新输入车牌号(五位):");
scanf("%s",code_num);}
for(i=0;;i++)
{if((strcmp(parking_message[i].code_num,code_num)==0)&&(i<=11))
{printf("您的车停放在%d层%d号车位:",(i+1)<=6?1:2,(i+1)<=6?(i+1):(i-5));
printf("确认要取车(Y/N)?");
scanf("%s",&d);           
if(d=='y'
||d=='Y'){printf("取车成功\n");fee(i);break;}
else  back();
}
if(i>=12)
break;
}
if(i>=12)
{ printf("该停车场没有到车牌号为%s的车!\n",code_num);
printf("1,输入错误,重新输入    请按---1 \n2忘记车牌号,通过车位取车  按---2");
scanf("%d",&a);
switch(a)
{case '1':charge();break;
case '2':chargeplace();break;
default:printf("error\n");
scanf("%s",&c);
if((c=getchar())!='\0') back();}
}
save();
}
void chargeplace()
{void fee(int j); int i=0;int m,n;char d;
printf("请输入层数(1~2)及车位号(1~6):");
scanf("%d,%d",&m,&n);
i=(m=1)?(n-1):(n+5);
while(m>2||n>6||strcpy(parking_message[i].code_num,"")==0)
{printf("您的输入有误,请重新输入车位号(五位):");
scanf("%d,%d",&m,&n);}
printf("车已到,车牌号为%s",parking_message[i].code_num);
printf("\n");
printf("确认要取该车(Y/N)?\n");
scanf("%s",&d);
if(d=='Y'||d=='y') {printf("取车成功\n");fee(i);}
else back();
}
void  fee(int j)            /*取车收费*/
{int p=(parking_message[j].end-parking_message[j].start);
void pingtiao(int k);char q;
local=localtime(&parking_message[j].end);
parking_message[j].end=time(NUL);
printf("您的停车费用为:");
parking_message[j].fee=((p/300)+1)*0.2;
printf("\t%7.1f\n",parking_message[j].fee);
printf("是否需要输出停车收费的信息:需要——Y\t返回——N\n");
scanf("%s",&q);
if(q=='Y'||q=='y') pingtiao(j);
strcpy(parking_message[j].code_num,"");
parking_message[j].ar=parking_message[j].parkingtime2.day=
parking_message[j].=parking_message[j].parkingtime2.hour=
parking_message[j].parkingtime2.min=parking_message[j].ar=
parking_message[j].parkingtime1.day=parking_message[j].=
parking_message[j].parkingtime1.hour=parking_message[j].parkingtime1.min=0;
parking_message[j].start=0;
parking_message[j].end=0;save();
}
void shuchuxinxi(int k)                  /*取车后输出信息*/
{ char str[80];char ptr[80];
printf("********************************************************************************\n");
printf("您的车牌号为%5s,停放在第%d层第%d号车位,停车总费用为%6.2f元。",
parking_message[k].code_num,parking_message[k].floor,parking_message[k].place,parking_message[k].fee);
local=localtime(&parking_message[k].end);
parking_message[k].end=time(NUL);
parking_message[k].parkingtime2.hour=local->tm_hour;
parking_message[k].parkingtime2.min=local->tm_min;
strftime(str,100,"%A, %Y-%B-%d, ",local);
printf("\n日期:停车: ");
printf(str);
printf("%d:%d\n",parking_message[k].parkingtime1.hour,parking_message[k].parkingtime1.min);
printf("      取车: ");
strftime(ptr,100,"%A, %Y-%B-%d, ",local);
printf(ptr);
printf("%d:%d\n",parking_message[k].parkingtime2.hou
r,parking_message[k].parkingtime2.min);
printf("\n********************************************************************************\n");
}
void putout()          /*输出已停车信息函数*/
{int i;printf("车牌号**停车位置***停车时间:星期, 年----月---日, 时:分\n");
for(i=0;;i++)
{if((strcmp(parking_message[i].code_num,"")!=0)&&(i<=11))
{char str[80];
printf("%7s%4d层%3d车位\t",parking_message[i].code_num,(i+1)<=6?1:2,(i+1)<=6?(i+1):(i-5));
strftime(str,100,"  %A, %Y-%B-%d, ",local);
printf(str);
printf("%2d:%2d",parking_message[i].parkingtime1.hour,parking_message[i].parkingtime1.min);
printf("\n");
}
if((strcmp(parking_message[i].code_num,"")==0)&&(i<=11))
printf("(空)\n");
if(i>=12)break;
}
save();
}
void back()
{void menu();
menu();
}
void menu()              /*主菜单*/
{int a;char b;static n=1;
{printf("*****************************选择需要的服务:***********************************\n");
printf("\t\t\t1、停车\n\t\t\t2、取车\n\t\t\t3、输出所有停车信息\n\t\t\t4、退出程序\n");
printf("********************************************************************************\n");
printf("请选择:1,2,3,4\t");
scanf("%d",&a);
switch(a)
{case 1:n++;park();break;
case 2:n++;charge();break;
case 3:n++;putout();break;
exit(0);break;
default:n=2;printf("输入有误,\n");
printf("按任意键返回主菜单.....\n");
scanf("%s",&b);
if((b=getchar())!='\0') back();
}                                     
}
void main()          /*主函数*/
{    int i;
for(i=0;i<=3;i++) 
{  parking_message[i].start=time(NUL);
local=localtime(&parking_message[i].start);
parking_message[i].ar=local->tm_year;
parking_message[i].=local->tm_mon;
parking_message[i].parkingtime1.day=local->tm_mday;
parking_message[i].parkingtime1.hour=local->tm_hour;
parking_message[i].parkingtime1.min=local->tm_min;
parking_message[i].parkingtime1.min=(local->tm_min)-(4-i)*5;
if(parking_message[i].parkingtime1.min<0)
{parking_message[i].parkingtime1.hour=(local->tm_hour)-1;
parking_message[i].parkingtime1.min=(local->tm_min)+(4-i)*10;}
parking_message[i].start=(time(NUL))-(4-i)*5*60;
}
menu();
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。