举一个例子说明
《停车场管理》
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#include
"stdio.h"
#include
"malloc.h"
#define
max_stop
5
//
停车场容量//
#define
PRICE
8
//停车单价
//
typedef
struct//汽车//
{
char
*license[20];
//汽车//
}car;
typedef
struct
//停车场//
{
car
stop[max_stop];
//停车场//
int
top;
}parking;
void
come(car
p,parking
*tcc)
{
if(tcc->top>=max_stop-1){printf("已满!!");}
else
{
printf("
输入到来汽车的车牌号码
:
");
scanf("%s",p.license);
printf("\n");
tcc->top++;
tcc->stop[tcc->top]=p;//如果停车场没有满就入场//
}
}
void
display(car
p,parking
*tcc)
{
int
n=0;
if(tcc->top==-1)printf("
停车场内无汽车!\n");
//指针在-1处
停车场内无车//
else{
//
有车
//
printf("●停车场内的车为:\n");
while(n<=tcc->top)
{
printf("第
%d
辆
%s\n",n+1,tcc->stop[n].license);
n++;
}
}
}
void
leave(car
p,parking
*tcc)
{
car
leavecar;
int
num,money,time;
printf("
输入将要离开的汽车车位号码:");
scanf("%d",&num);
num--;
if(num>tcc->top||num<0)printf("
你的输入有误
请检查预备出停车场的车辆号码\n");
else
{
printf("
输入此车停留的时间
:
");
scanf("%d",&time);
if(time<=0)printf("
你的输入有误
请检查停车时间\n");
else
{
leavecar=tcc->stop[num];
while(numtop)
{
tcc->stop[num]=tcc->stop[num+1];
num++;
}
tcc->top--;
}
}
if((num<=tcc->top)
&&
(num>=0))
{
money=time*PRICE;
printf("●
%s
已经离开停车场
停留%d小时
收费%d元",leavecar.license,time,money);
}
}
void
welcome()
//欢迎界面//
{
printf("
●欢迎适用本程序●\n");
printf("
本程序为停车场的模拟管理程序,有车到来时请按
C
键\n");
printf("
然后根据屏幕提示进行相关操作,有车要走时请按
L
键\n");
printf("
然后根据屏幕提示进行相关操作,若需要帮助请按
H
键\n");
printf("
然后根据屏幕提示进行相关操作,要退出程序请按
Q
键\n");
}
void
main()
{
char
key;
car
p;
parking
*tcc;
tcc=(parking
*)malloc(sizeof(parking));
tcc->top=-1;
while(1)
{
flushall();
printf("
请输入您的操作
:
");
scan