#include<malloc.h>
#define PACKSIZE 2
#define ROADSIZE 2
#define PRICE 0.55
#include<stdlib.h>
typedef struct Car
{int carnum;
int time;
int mode;
}Car;
typedef struct cpark
{Car *top;
Car *base;
int size;
}cpark;
typedef struct road
{Car *base;
int front;
int rear;
} ;
void InitPark(Cpark *c)
{c->base=(Car*)malloc(PCARSIZE *sizeof(Car));
if(!c->base)exit(0);
c->size=PCARSIZE;
}
void push car(Cpark *c,Car *a)
{if(c->top-c->base>=PCARSIZE)
printf("The park overflow!");
else{c->top->carnum=a->carnum;
c->top->time=a->time;
c->top->mode=a->mode;
c->top+=1;
}
}
void popcar (Cpark *c,Car *a)
{if(c->top==c->base)
printf("The park empty!");
else{--c->top;
a->carnum=c->top->carnum;
a->time=c->top->time;
a->mode=c->top->mode;
}
}
void InitRoad(Road *c)
{c->base=(Car *)malloc(PCARSIZE*sizeof(Car));
if(!c->base)exit(0);
c->front=c->rear=0;
}
void DeRoad(Road *C,Car *a)
{if(c->front=c->rear)
printf("The Road Empty!");
else{a->carnum=(c->base+c->front)->carnum;
a->time=(c->base+c->front)->time;
a->mode(c->base+c->front)->mode;
(c->base+c->front)->carnum=0;
c->front=(c->front+1)%ROADSIZE;
}
}
void EnRoad(Road *c,Car *a)
{if((c->rear+1)%ROADSIZE==c->front)
printf("The Road Overflow!");
else{(c->base+c->rear)->carnum=a->carnum;
(c->base+c->rear)->time=a->time;
(c->base+c->rear)->mode=a->mode;
c->rear=(c->rear+1)%ROADSIZE;
}
}
viod PRINT(Car*p,int x)
{int A1,A2,B1,B2;
printf("please input the leavetime:**:**");
scanf("%d,%d",&(p->leave.hour),&(p->leave.min));
printf("\nthe car num:");
puts(p->num);
printf("\nplease input the arrive time");
scanf("%d,%d",&(p->arrive.hour),&(p->arrive.min));
A1=p->leave.hour;
A2=p->leave.min;
B1=p->arrive.hour;
B2=p->arrive.min;
printf("\nTHE FEE:",((A1-B1)*60+(A1-A2))*PRICE);
free(p);
}
void main()
{int s;
int *p;
int *y;
CarPark *s1,*s2;
Road *p;
Car *a;
Ininit Park(s1);
Ininit Park(s2);
EnRoad(p);
printf("plese input the stutas:\n(' M' stands for arrive and'D'stands for lever)");
scanf("%c",s);
if(s='D')
{ Popcar(s1,a);
Pushcar(s2,a);
DeRoad(p,a);
Push(s1,a);
PRINT(Car *p,int x);
}
if(s='M')
{if a->top<PACKSIZE
{ a->top++;
{ printf("the place of the car",a->top);
pintf("the time the car arrive:",/**:**/);
scanf("%d,%d",&(p->arrive.hour),&(p->arrive.min));
p->Car.time;
Push Car(s,a);
}
}
}
esle if a->top<ROADSIZE
{EnRoad(D,a);
}
}
这是我写的停车场管理系统的代码,只是一个框架,而且错误百出,有兴趣的同志们帮忙改改,呵呵,做为娱乐吧,