简单停车场管理系统程序设计问题

2024-12-30 08:51:47
推荐回答(1个)
回答1:

#define length 3
#define null 0
#define M length
#define PRICE 5
#ifdef M
typedef struct
{
char status;
int no;
int time;
}data;

typedef struct
{
data *base;
data *top;
int stacksize;
}stack;

void initstack (stack *s)
{
s->base=(data *)malloc(length*sizeof(data));
s->top=s->base;
s->stacksize=length;
}

void pushstack (stack *p)
{
int i=0;
printf("Please push stack data:\n");
while(istacksize)
{
scanf(" %c%d%d",&(p->top->status),&(p->top->no),&(p->top->time));
(p->top)++;
i++;
}
(--p->top);
}

void popstack (stack *p)
{
int i=p->stacksize;
printf("Pop data to check the intput:\n");
while(i>0)
{
printf("%c %d %d\n",p->top->status,p->top->no,p->top->time);
(p->top)--;
i--;
}
}

void popstacksite (stack *p)
{ int i,j;
for(j=0;jstacksize;j++) (++p->top);
i=p->stacksize;
while(i>0)
{printf("status: %c car-no: %d\n",p->top->status,p->top->no);
(p->top)--; i--; }
}

void stackshuzu (stack *p,char a[],int b1[],int b2[],int c1[],int c2[])
{ int i, j;
for(j=0;jstacksize;j++) (++p->top);
printf("stackshuzu:\n");
for(i=0;istacksize;i++)
{ a[i]=p->top->status;
b2[i]=p->top->no; b1[i]=b2[i];
c2[i]=p->top->time; c1[i]=c2[i];
(p->top)--;
}
}

void costmoney (char a[],int b1[],int b2[],int c1[],int c2[])
{ int i,j;
for(i=0;i if(a[i]=='d')
{ j=i;
for(i=0;i if(b2[i]==b1[j]&&i!=j)
printf("number: %d cost=%d\n",b1[j],PRICE*(c1[j]-c2[i]));

}

} /*cost money.*/

typedef struct node
{
char status;
int no;
struct node *next;
}; /*node struct*/

typedef struct
{
struct node *front;
struct node *rear;
}queue; /*queue struct*/

void initqueue (queue *q)
{

q->front=(struct node*)malloc(sizeof(struct node));
q->rear=q->front;

} /*init a queue*/

pushqueue (queue *q)
{ struct node *l0,*l1; l0=l1=q->rear;
printf("Please input queue data and 'e' is end:\n");
scanf(" %c%d",&l1->status,&l1->no);
while(l1->status!='e'&&l1->no!=0)
{ l0=(struct node*)malloc(sizeof(struct node));
l1->next=l0;
scanf(" %c%d",&l0->status,&l0->no);
l1=l0;
}
l1->next=null;
q->rear=l1;

} /*n is q.rear,and bian dao shang de che dou shi kai jin lai.*/

popqueue(queue *q)
{ struct node *l0,*l1; l0=q->front; l1=q->rear;
printf("\n");
while(l0!=l1)
{ printf("car-status: %c car-no: %d\n",l0->status,l0->no);
l0=l0->next;
}
} /*check pushqueue*/

main ()
{queue q; stack s;
char a[M];
int b1[M],b2[M],c1[M],c2[M];
clrscr();
initstack (&s);
pushstack (&s);
popstack (&s);

initqueue(&q);
pushqueue(&q);
popqueue(&q); printf("\n\n");
printf("the cars in the che ku:\n");
popstacksite (&s);
printf("the cars in the bian dao:\n");
popqueue (&q); printf("\n\n");
stackshuzu (&s,a,b1,b2,c1,c2);
costmoney (a,b1,b2,c1,c2);
getch();
}
/*popstack de shun xu bu neng bian,yin wei s->top ke neng bian.*/
#else
main ()
{clrscr();
getch();

}
#endif
功能有:车的位置判断,收费多少,倒车出来那部分没解决,正在写。