停車場管理系統
做完了課程設計,用C語言寫的。不過挑了個容易點的,停車場管理系統。不過寫得好繁瑣啊,好耐無用C語言了。請大家指教,也幫幫急需的朋友們。呵呵···
終於可以放假啦,嘿嘿·····
/*******************************停車場管理器*************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>
/********************************************************************************/
#define MAXSTACKSIZE 2 /*車庫容量*/
#define price 0.1 /*每車每分鐘費用*/
typedef struct time{
int hour;
int min;
}Time; /*時間結點*/
typedef struct {
char num[10];
Time reach;
Time leave;
}CarNode; /*車輛資訊結點*/
typedef struct {
CarNode *base;
CarNode *top;
int stacksize;
}SqStackCar; /*模擬車站*/
typedef struct car{
CarNode *data;
struct car *next;
}QueueNode;
typedef struct {
QueueNode *front;
QueueNode *rear;
}LinkQueueCar; /*模擬通道*/
int QueueEmpty(LinkQueueCar Q) /*便道判空函式*/
{
if(Q.front==Q.rear) return 1;
else return 0;
}
/********************************************************************************/
void InitStack(SqStackCar *s) /*初始化棧*/
{
s->base=(CarNode *)malloc(MAXSTACKSIZE*sizeof(CarNode));
if(!s->base) exit(0);/*分配失敗*/
s->top=s->base;
s->stacksize=MAXSTACKSIZE;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>
/********************************************************************************/
#define MAXSTACKSIZE 2 /*車庫容量*/
#define price 0.1 /*每車每分鐘費用*/
typedef struct time{
int hour;
int min;
}Time; /*時間結點*/
typedef struct {
char num[10];
Time reach;
Time leave;
}CarNode; /*車輛資訊結點*/
typedef struct {
CarNode *base;
CarNode *top;
int stacksize;
}SqStackCar; /*模擬車站*/
typedef struct car{
CarNode *data;
struct car *next;
}QueueNode;
typedef struct {
QueueNode *front;
QueueNode *rear;
}LinkQueueCar; /*模擬通道*/
int QueueEmpty(LinkQueueCar Q) /*便道判空函式*/
{
if(Q.front==Q.rear) return 1;
else return 0;
}
/********************************************************************************/
void InitStack(SqStackCar *s) /*初始化棧*/
{
s->base=(CarNode *)malloc(MAXSTACKSIZE*sizeof(CarNode));
if(!s->base) exit(0);/*分配失敗*/
s->top=s->base;
s->stacksize=MAXSTACKSIZE;
}
int Push(SqStackCar *s,CarNode *e) /*進站函式*/
{
if(s->top-s->base>=s->stacksize) return 0;
else *s->top++=*e;
return 1;
}
{
if(s->top-s->base>=s->stacksize) return 0;
else *s->top++=*e;
return 1;
}
int Pop(SqStackCar *s,CarNode *e) /*出站函式*/
{
if(s->top==s->base) return 0;
*e=*--s->top;
return 1;
}
{
if(s->top==s->base) return 0;
*e=*--s->top;
return 1;
}
int StackEmpty(SqStackCar s) /*判空函式*/
{
if(s.base==s.top) return 1;
else return 0;
}
int InitQueue(LinkQueueCar *Q) /*初始化便道*/
{
Q->front=Q->rear=(QueueNode *)malloc(sizeof(QueueNode));
if(!Q->front) exit(0);
Q->front->next=NULL;
return 1;
}
/**************************************************************/
int EnQueue(LinkQueueCar *Q,CarNode *e) /*便道插入函式*/
{
QueueNode *p;
p=(QueueNode *)malloc(sizeof(QueueNode));
if(!p) exit(0);
p->data=e;
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
return 1;
}
int DeQueue(LinkQueueCar *Q,CarNode *e) /*便道刪除函式*/
{
QueueNode *p;
if(Q->front==Q->rear) return 0;
p=Q->front->next;
e=p->data;
Q->front->next=p->next;
if(Q->rear==p) Q->rear=Q->front;
free(p);
return 1;
}
{
if(s.base==s.top) return 1;
else return 0;
}
int InitQueue(LinkQueueCar *Q) /*初始化便道*/
{
Q->front=Q->rear=(QueueNode *)malloc(sizeof(QueueNode));
if(!Q->front) exit(0);
Q->front->next=NULL;
return 1;
}
/**************************************************************/
int EnQueue(LinkQueueCar *Q,CarNode *e) /*便道插入函式*/
{
QueueNode *p;
p=(QueueNode *)malloc(sizeof(QueueNode));
if(!p) exit(0);
p->data=e;
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
return 1;
}
int DeQueue(LinkQueueCar *Q,CarNode *e) /*便道刪除函式*/
{
QueueNode *p;
if(Q->front==Q->rear) return 0;
p=Q->front->next;
e=p->data;
Q->front->next=p->next;
if(Q->rear==p) Q->rear=Q->front;
free(p);
return 1;
}
/********************************************************************************/
int Arrive(SqStackCar *In,LinkQueueCar *Wait) /*車輛到達函式*/
{
CarNode *i;
QueueNode *w;
i=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("Input the car number:");
gets(i->num);
if(In->top-In->base<MAXSTACKSIZE) /*車場未滿,車輛進棧*/
{
printf("/nThe time the car arrive(00:00): ");
scanf("%d:%d",&i->reach.hour,&i->reach.min);
Push(In,i);
printf("/nCar in success!!");
sleep(1);
return 1;
}
else /*停車場已滿,車進便道*/
{
w=(QueueNode *)malloc(sizeof(QueueNode));
w->data=i;
w->next=NULL;
Wait->rear->next=w;
Wait->rear=w;
printf("The PART is full,car must wait in the road!");
sleep(1);
return 1;
}
return 0;
}
/********************************************************************************/
int Departure(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait) /*車輛離開函式*/
{
int flag=0,a1,a2,b1,b2, money;
CarNode *p,*t;
QueueNode *q;
p=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("Input the out car number: ");
gets(p->num);
while(!StackEmpty(*In))
{
t=(CarNode *)malloc(sizeof(CarNode));
Pop(In,t);
if(strcmp(p->num,t->num)==0) /*比較車場中有無這輛車,有即出站*/
{
printf("Input the time the car out(00:00):");
scanf("%d:%d",&p->leave.hour,&p->leave.min);
printf("The ");
printf("%s",p->num);
printf(" Car out the part!");
a1= p->leave.hour;
a2= t->reach.hour;
b1= p->leave.min;
b2= t->reach.min;
money = ((a1-a2+24)%24*60+(b1-b2+60)%60)*price; /*計算車輛需要的費用*/
printf("/nThe time the car arrive: %d:%d",t->reach.hour,t->reach.min);
printf("/nThe time the car leave: %d:%d",p->leave.hour,p->leave.min);
printf("/nNeed: %d yuan",money);
flag=1;
getch();
free(t);
break;
}
else
Push(temp,t);
} /*while*/
if(!flag)
{
printf("No this car!!");
getch();
}
while(!StackEmpty(*temp))
{
Pop(temp,p);
Push(In,p);
}
free(p);
if(flag&&Wait->front!=Wait->rear) /*車站中有空位,便道有車,車入站*/
{
q=(QueueNode *)malloc(sizeof(QueueNode));
q=Wait->front->next;
t=q->data;
if(q!=NULL)
{
Push(In,t);
printf("/nThe ");
printf("%s",t->num);
printf(" car in part!");
printf("/nInput the time the car arrive(00:00): ");
scanf("%d:%d",&t->reach.hour,&t->leave.min);
}
Wait->front->next=q->next;
if(q==Wait->rear) Wait->rear=Wait->front;
free(q);
}
return 1;
}
/********************************************************************************/
void Print(SqStackCar *In,SqStackCar *Temp,LinkQueueCar *Wait) /*列印函式*/
{
int c=0;
int count=1;
CarNode *p,*t;
QueueNode *q;
q=(QueueNode *)malloc(sizeof(QueueNode));
p=(CarNode *)malloc(sizeof(CarNode));
t=(CarNode *)malloc(sizeof(CarNode));
while(1&&c!='3')
{
clrscr();
gotoxy(1,10);
printf("1. Print the road!");
gotoxy(1,11);
printf("2. Print the part!");
gotoxy(1,12);
printf("3. return.");
do{
printf("/nInput your choice:");
c = getche();
printf("/n");
}while(c!='1'&&c!='2'&&c!='3');
int Arrive(SqStackCar *In,LinkQueueCar *Wait) /*車輛到達函式*/
{
CarNode *i;
QueueNode *w;
i=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("Input the car number:");
gets(i->num);
if(In->top-In->base<MAXSTACKSIZE) /*車場未滿,車輛進棧*/
{
printf("/nThe time the car arrive(00:00): ");
scanf("%d:%d",&i->reach.hour,&i->reach.min);
Push(In,i);
printf("/nCar in success!!");
sleep(1);
return 1;
}
else /*停車場已滿,車進便道*/
{
w=(QueueNode *)malloc(sizeof(QueueNode));
w->data=i;
w->next=NULL;
Wait->rear->next=w;
Wait->rear=w;
printf("The PART is full,car must wait in the road!");
sleep(1);
return 1;
}
return 0;
}
/********************************************************************************/
int Departure(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait) /*車輛離開函式*/
{
int flag=0,a1,a2,b1,b2, money;
CarNode *p,*t;
QueueNode *q;
p=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("Input the out car number: ");
gets(p->num);
while(!StackEmpty(*In))
{
t=(CarNode *)malloc(sizeof(CarNode));
Pop(In,t);
if(strcmp(p->num,t->num)==0) /*比較車場中有無這輛車,有即出站*/
{
printf("Input the time the car out(00:00):");
scanf("%d:%d",&p->leave.hour,&p->leave.min);
printf("The ");
printf("%s",p->num);
printf(" Car out the part!");
a1= p->leave.hour;
a2= t->reach.hour;
b1= p->leave.min;
b2= t->reach.min;
money = ((a1-a2+24)%24*60+(b1-b2+60)%60)*price; /*計算車輛需要的費用*/
printf("/nThe time the car arrive: %d:%d",t->reach.hour,t->reach.min);
printf("/nThe time the car leave: %d:%d",p->leave.hour,p->leave.min);
printf("/nNeed: %d yuan",money);
flag=1;
getch();
free(t);
break;
}
else
Push(temp,t);
} /*while*/
if(!flag)
{
printf("No this car!!");
getch();
}
while(!StackEmpty(*temp))
{
Pop(temp,p);
Push(In,p);
}
free(p);
if(flag&&Wait->front!=Wait->rear) /*車站中有空位,便道有車,車入站*/
{
q=(QueueNode *)malloc(sizeof(QueueNode));
q=Wait->front->next;
t=q->data;
if(q!=NULL)
{
Push(In,t);
printf("/nThe ");
printf("%s",t->num);
printf(" car in part!");
printf("/nInput the time the car arrive(00:00): ");
scanf("%d:%d",&t->reach.hour,&t->leave.min);
}
Wait->front->next=q->next;
if(q==Wait->rear) Wait->rear=Wait->front;
free(q);
}
return 1;
}
/********************************************************************************/
void Print(SqStackCar *In,SqStackCar *Temp,LinkQueueCar *Wait) /*列印函式*/
{
int c=0;
int count=1;
CarNode *p,*t;
QueueNode *q;
q=(QueueNode *)malloc(sizeof(QueueNode));
p=(CarNode *)malloc(sizeof(CarNode));
t=(CarNode *)malloc(sizeof(CarNode));
while(1&&c!='3')
{
clrscr();
gotoxy(1,10);
printf("1. Print the road!");
gotoxy(1,11);
printf("2. Print the part!");
gotoxy(1,12);
printf("3. return.");
do{
printf("/nInput your choice:");
c = getche();
printf("/n");
}while(c!='1'&&c!='2'&&c!='3');
if(c=='2') /*列印停車場*/
{
printf("The car in the part!/n");
count=1;
{
printf("The car in the part!/n");
count=1;
while(!StackEmpty(*In))
{
Pop(In,t);
Push(Temp,t);
}
while(!StackEmpty(*Temp))
{
Pop(Temp,t);
printf("The ");
printf("%d",count);
printf(" car number is: ");
count++;
puts(t->num);
Push(In,t);
}
printf("Press any key to continue...");
getch();
{
Pop(In,t);
Push(Temp,t);
}
while(!StackEmpty(*Temp))
{
Pop(Temp,t);
printf("The ");
printf("%d",count);
printf(" car number is: ");
count++;
puts(t->num);
Push(In,t);
}
printf("Press any key to continue...");
getch();
}
if(c=='1') /*列印便道*/
{
printf("The car in the road!/n");
count=1;
q=Wait->front->next;
if(Wait->front!=Wait->rear) /**/
{
while(q!=NULL)
{
p=q->data;
printf("The ");
printf("%d",count);
printf(" Car number is: ");
puts(p->num);
q=q->next;
count++;
}
}
else printf("/nNo car in the road.");
printf("Press any key to continue...");
getch();
}
}
}
/***************************主程式***********************************************/
int Arrive(SqStackCar *In,LinkQueueCar *Wait);
int Departure(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait);
void Print(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait);
void initialization();
char readcommand();
void interpret(char cmd);
main()
{
char cmd;
SqStackCar part,temp;
LinkQueueCar road;
InitStack(&part);
InitStack(&temp);
InitQueue(&road);
printf("Press any key to continue......");
getch();
while(1)
{
initialization(); /*初始化介面*/
cmd = readcommand(); /*讀取停車場狀況*/
clrscr();
switch(cmd)
{
case 'a': Arrive(&part,&road); break;
case 'A': Arrive(&part,&road); break;
case 'd': Departure(&part,&temp,&road); break;
case 'D': Departure(&part,&temp,&road); break;
case 'p': Print(&part,&temp,&road); break;
case 'P': Print(&part,&temp,&road); break;
case 'e': printf("Press any to continue...");getch();exit(0); break;
case 'E': printf("Press any to continue...");getch();exit(0); break;
default : printf("ERROR!"); break;
}
}
}
/********************************************************************************/
void initialization() /*初始函式*/
{
int i;
clrscr();
gotoxy(0,0);
for(i=1;i<=240;i++)
printf("/1");
gotoxy(15,8);
printf("THIS IS A CAR PART MANAGE SYSYTEM!");
gotoxy(15,12);
printf("NAME: LIYONGJUN.");
gotoxy(15,13);
printf("NUM: 3104006893.");
gotoxy(15,14);
printf("GRADE: 2004.");
gotoxy(15,15);
printf("CLASS: COMPUTER SCIENCE AND TECHNOLOGY 10");
gotoxy(1,20);
printf("/n********************************************************************************");
printf("1. Car Arrive--A 2. Car Departure--D 3. Print Car--P 4.Exit--E");
printf("/n********************************************************************************");
printf("Input C,D,P,E choose!!/n");
if(c=='1') /*列印便道*/
{
printf("The car in the road!/n");
count=1;
q=Wait->front->next;
if(Wait->front!=Wait->rear) /**/
{
while(q!=NULL)
{
p=q->data;
printf("The ");
printf("%d",count);
printf(" Car number is: ");
puts(p->num);
q=q->next;
count++;
}
}
else printf("/nNo car in the road.");
printf("Press any key to continue...");
getch();
}
}
}
/***************************主程式***********************************************/
int Arrive(SqStackCar *In,LinkQueueCar *Wait);
int Departure(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait);
void Print(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait);
void initialization();
char readcommand();
void interpret(char cmd);
main()
{
char cmd;
SqStackCar part,temp;
LinkQueueCar road;
InitStack(&part);
InitStack(&temp);
InitQueue(&road);
printf("Press any key to continue......");
getch();
while(1)
{
initialization(); /*初始化介面*/
cmd = readcommand(); /*讀取停車場狀況*/
clrscr();
switch(cmd)
{
case 'a': Arrive(&part,&road); break;
case 'A': Arrive(&part,&road); break;
case 'd': Departure(&part,&temp,&road); break;
case 'D': Departure(&part,&temp,&road); break;
case 'p': Print(&part,&temp,&road); break;
case 'P': Print(&part,&temp,&road); break;
case 'e': printf("Press any to continue...");getch();exit(0); break;
case 'E': printf("Press any to continue...");getch();exit(0); break;
default : printf("ERROR!"); break;
}
}
}
/********************************************************************************/
void initialization() /*初始函式*/
{
int i;
clrscr();
gotoxy(0,0);
for(i=1;i<=240;i++)
printf("/1");
gotoxy(15,8);
printf("THIS IS A CAR PART MANAGE SYSYTEM!");
gotoxy(15,12);
printf("NAME: LIYONGJUN.");
gotoxy(15,13);
printf("NUM: 3104006893.");
gotoxy(15,14);
printf("GRADE: 2004.");
gotoxy(15,15);
printf("CLASS: COMPUTER SCIENCE AND TECHNOLOGY 10");
gotoxy(1,20);
printf("/n********************************************************************************");
printf("1. Car Arrive--A 2. Car Departure--D 3. Print Car--P 4.Exit--E");
printf("/n********************************************************************************");
printf("Input C,D,P,E choose!!/n");
}
char readcommand() /*選擇函式*/
{
char cmd;
do{
printf("Input your choice:");
cmd = getche();
printf("/n");
}while((cmd!='a')&&(cmd!='A')&&(cmd!='d')&&(cmd!='D')&&(cmd!='p')&&(cmd!='P')&&(cmd!='E')&&(cmd!='e'));
return cmd;
}
{
char cmd;
do{
printf("Input your choice:");
cmd = getche();
printf("/n");
}while((cmd!='a')&&(cmd!='A')&&(cmd!='d')&&(cmd!='D')&&(cmd!='p')&&(cmd!='P')&&(cmd!='E')&&(cmd!='e'));
return cmd;
}
相關文章
- 停車場無人看管智慧停車系統怎麼停車和找車?
- 停車場智慧尋車系統,大型停車場智慧車位導航技術
- 智慧停車怎麼實現的,停車場找車系統怎麼找車
- 智慧停車場停車怎麼找車
- 智慧停車場解決方案,反向尋車系統解決方案
- 智慧停車場
- 2012年中國停車場管理系統市場分析及發展預測
- 智慧停車系統智慧城市園區管理系統解決方案
- 地下停車場導航方案,智慧反向尋車系統怎麼做
- 資料結構棧和佇列排隊演算法應用的例子【停車場停車位排隊管理系統】資料結構佇列演算法
- 怎樣查車停車什麼停車場技術分析
- 高階停車場停車計費解決方案
- 車庫尋車有什麼好辦法,停車場自動尋車系統怎麼用
- 智慧停車場專案
- 路邊停車系統充電方案
- 停車場室內導航怎麼用,停車場尋車是怎麼實現的
- 停車場地圖怎樣好看,停車場怎麼畫簡單又漂亮地圖
- 停車場的模擬管理(資料結構 C++)資料結構C++
- 停車機器人上崗 實現停車場無人值守機器人
- 地下停車場怎麼導航,停車場導航技術怎麼實現
- 智慧停車場系統開發,智慧園區整體解決方案整合系統開發
- 730【畢設課設】基於STM32的RFID停車場車位車庫管理監測系統設計(全套資料)
- 停車場結構圖怎麼做,地下停車場怎麼畫簡單又好看
- 室內停車場地圖怎麼畫,地下停車場導檢視怎麼畫地圖
- 什麼軟體畫停車場好用,停車場的地圖要怎麼畫才好看地圖
- 停車場導檢視怎麼做,簡單的停車場地圖怎麼畫好看地圖
- 易泊車牌識別 停車計費系統解決方案
- 停車場構造圖怎麼畫好看,簡單的停車場地圖怎麼畫圖地圖
- 停車場結構圖怎麼畫,自己畫停車位需要什麼工具
- 【資料結構】停車場問題資料結構
- 高德地圖附近停車場服務地圖
- 如何在地下停車場快速找到車?地下車庫怎麼快速找車?
- 車間管理資訊系統
- 輸入進入停車場時間,獲取系統當前時間,計算停車費用並按照指定的格式輸入清單
- 地下車庫找不到車子怎麼辦?在停車場怎麼找車?
- 解決公務車Bug:停車費管理中匯入停車費用時報資料庫操作異常資料庫
- 城市智慧停車系統方案的產品設計體系介紹
- [LintCode] Parking Lot 停車場問題