| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 920 人关注过本帖
标题:停车场管理系统改错
取消只看楼主 加入收藏
yitingkai
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-4-26
收藏
 问题点数:0 回复次数:0 
停车场管理系统改错

#include<stdio.h>
#include<malloc.h>
#define PACKSIZE 2
#define ROADSIZE 2
#define PRICE 0.55
#include<stdlib.h>
typedef struct time
{
int hour;
int min;
}time;/*时间结点*/
typedef struct Car
{ char num[10];
time reach;
time leave;

}Car;/*汽车信息*/
typedef struct Cpark
{
Car *stack[PACKSIZE+1];
int top;
}Cpark;/*模拟车站,即停车场*/
typedef struct car
{
Car *data;
struct car *next;
}car;
typedef struct Road
{
car *head;
car *rear;
}Road;/*便道*/

/*********************************************/
/*********************************************/
void InitStack(Cpark *);/*初始化停车场*/
int InitQueue(Road *);/*初始化便道*/
int Arrival(Cpark *,Road *);/* 车辆到达*/
void Leave(Cpark *,Cpark *,Road *);/*车辆离开*/
void List(Cpark,Road);/*显示车辆的信息*/
/*********************************************/
/*********************************************/

void main()
{
Cpark Enter,Temp;
Road Wait;
int ch;
InitStack(&Enter);/*初始化停车场*/
InitStack(&Temp); /*初始化让路的临时栈*/
InitQueue(&Wait);/*初始化便道*/
while(1)
{
printf("\n1. the car arrive");
printf(" 2. the car leave");
printf(" 3. show message ");
printf(" 4. exit\n");
while(1)
{
scanf("%d",&ch);
if(ch>=1&&ch<=4)break;
else printf("\nplease choose: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(Cpark *s)/*初始化栈*/
{
int i;
s->top=0;
for(i=0;i<=PACKSIZE;i++)
s->stack[s->top]=NULL;
}
int InitQueue(Road *Q)/*初始化便道*/
{
Q->head=(car *)malloc(sizeof(car));
if(Q->head!=NULL)
{
Q->head->next=NULL;
Q->rear=Q->head;
return(1);
}
else
return(-1);
}
void PRINT(Car *p,int room)/*打印出站车的信息*/
{
int A1,A2,B1,B2;
printf("\nplease input the leaving time:/**:**/");
scanf("%d,%d",&(p->leave.hour),&(p->leave.min));
printf("\nthe number of the car:");
puts(p->num);
printf("\nthe time of the car arrive: %d,%d",p->reach.hour,p->reach.min);
printf("the leaving time: %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("\nThe fares : %2.1f",((B1-A1)*60+(B2-A2))*PRICE);
free(p);
}

int Arrival(Cpark *Enter,Road *W) /*车辆到达*/
{
Car *p;
car *t;
p=(Car *)malloc(sizeof(Car));
flushall();
printf("\ninput the number of the car(for examle:A1234):");
gets(p->num);
if(Enter->top<PACKSIZE) /*车场未满,车进车场*/
{
Enter->top++;

printf("\nthe time thecar arrive:/**:**/");
scanf("%d:%d",&(p->reach.hour),&(p->reach.min));
Enter->stack[Enter->top]=p;
return(1);
}
else /*车场已满,车进便道*/
{
printf("\nThe car should wait on the Road");
t=(car *)malloc(sizeof(car));
t->data=p;
t->next=NULL;
W->rear->next=t;
W->rear=t;
return(1);
}
}
void Leave(Cpark *Enter,Cpark *Temp,Road *W)
{ /*车辆离开*/
int i, room;
Car *p,*t;
car *q;
/*判断车场内是否有车*/
if(Enter->top>0) /*有车*/
{
while(1) /*输入离开车辆的信息*/
{
printf("\nPlease input the position in the Cpark/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<PACKSIZE) /*便道的车辆进入车场*/
{
q=W->head->next;
t=q->data;
Enter->top++;
printf("\nThe car numbered %s enter the positon %d in the Cpark ",t->num,Enter->top);
printf("\nPlease input the current time/**:**/:");
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("\nThere is no car on the Road\n");
}
else printf("\nThere is no car in the Cpark."); /*没车*/
}
void List1(Cpark *S) /*列表显示车场信息*/
{
int i;
if(S->top>0) /*判断车站内是否有车*/
{
printf("\nCpark:");
printf("\n Reachtime Carnum\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("\nThere is no car in the Cpark");
}
void List2(Road *W) /*列表显示便道信息*/
{
car *p;
p=W->head->next;
if(W->head!=W->rear) /*判断通道上是否有车*/
{
printf("\nThe number of the car which waited is:");
while(p!=NULL)
{
puts(p->data->num);
p=p->next;
}
}
else printf("\nThere is no car on the road.");
}
void List(Cpark S,Road W)
{
int flag,tag;
flag=1;
while(flag)
{
printf("\nPlease choose 1|2|3:");
printf("\n1.Cpark\n2.Road\n3.return\n");
while(1)
{
scanf("%d",&tag);
if(tag>=1||tag<=3) break;
else printf("\nplease choose: 1|2|3:");
}
switch(tag)
{
case 1:List1(&S);break; /*列表显示车场信息*/
case 2:List2(&W);break; /*列表显示便道信息*/
case 3:flag=0;break;
default: break;
}
}
}
这个代码有点小bug,就是在车辆离开时,它并不是输出钱数,而是出现一个死循环,也就是void Leave(Cpark *Enter,Cpark *Temp,Road *W)这部分有错误,哪位高手帮忙改一下啊,拜托了,呵呵

搜索更多相关主题的帖子: typedef struct Car int car 
2007-05-29 23:35
快速回复:停车场管理系统改错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036318 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved