| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 591 人关注过本帖
标题:停车场系统代码改错-->xu2000转移
只看楼主 加入收藏
yitingkai
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-4-26
收藏
 问题点数:0 回复次数:2 
停车场系统代码改错-->xu2000转移
#include<stdio.h>
#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);
}
}
这是我写的停车场管理系统的代码,只是一个框架,而且错误百出,有兴趣的同志们帮忙改改,呵呵,做为娱乐吧,
搜索更多相关主题的帖子: 停车场 系统 改错 代码 
2007-05-25 00:53
phonbob
Rank: 1
等 级:新手上路
威 望:1
帖 子:57
专家分:0
注 册:2007-4-21
收藏
得分:0 
C啊,不懂

男儿、血如泪、洒沙场
2007-05-25 09:19
yitingkai
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-4-26
收藏
得分: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. the schedule ");
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 position of the car.",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;
}
}
}这个代码怎么运行时出现死循环呢,当选2.the car leave 时出现死循环,请大家帮帮看看啊。


希望大家多多帮忙!呵呵
2007-05-28 15:50
快速回复:停车场系统代码改错-->xu2000转移
数据加载中...
 
   



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

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