1、問題描述
設(shè)有一個可以停放n輛汽車的狹長停車場,它只有一個大門可以供車輛進出。車輛按到達停車場時間的早晚依次從停車場最里面向大門口處停放(最先到達的第一輛車放在停車場的最里面)。如果停車場已放滿n輛車,則后來的車輛只能在停車場大門外的便道上等待,一旦停車場內(nèi)有車開走,則排以便道上的第一輛車就進入停車場。停車場內(nèi)如有某輛車要開走,在它之后進入停車場的車都必須先退出停車場為它讓路,待其開出停車場后,這些輛再依原來的次序進場。每輛車在離開停車場時,都應(yīng)根據(jù)它在停車場內(nèi)停留的時間長短交費。如果停留在便道上的車未進停車場時,允許其離去,不收停車費,并且仍然保持在便道上等待的車輛的次序。
2、設(shè)想?
該停車場管理系統(tǒng)由兩個棧和兩個隊列實現(xiàn),一個棧作為停車場,另一個棧作為臨時停車點,便于讓停車場內(nèi)汽車離開,一個隊列作為便道,另一個隊列作為臨時便道,便于讓便道內(nèi)汽車離開。
3、軟件?
使用的軟件是Dev-C++,版本為5.11版本,部分版本可能會提示出錯。
4、要求
(1)系統(tǒng)功能以菜單方式顯示;
(2)車輛編號為字符型;
(3)設(shè)置屏幕字體顏色;
(4)單位時間收費值可以修改。
5、系統(tǒng)的構(gòu)想
(1)該停車場管理系統(tǒng)分為一個總系統(tǒng)和1兩個子系統(tǒng),分別是停車場管理總系統(tǒng)、停車場管理員系統(tǒng)和停車場消費者系統(tǒng);
(2)由停車場管理總系統(tǒng)可以進入兩個子系統(tǒng);
(3)停車場管理員系統(tǒng)功能
①查看停車場內(nèi)車輛信息,輸出該停車場所有車輛的車牌號、位序、進入時間和消費金額;
②查看停車場便道內(nèi)車輛信息,輸出該停車場便道內(nèi)車輛的車牌號和位序;
③查找車輛的目前的信息,客戶輸入車牌號,可輸出目前該車牌號在停車場內(nèi)的所有信息(前? ? ?提:該停車場內(nèi)存在客戶輸入的車牌號的車輛),否則輸出該車牌號不存在;
④更改收費標準; ?
⑤返回停車場總系統(tǒng);
⑥直接退出程序;
(4)停車場消費者系統(tǒng)功能
①查看停車場車輛數(shù)量,輸出該停車場內(nèi)共有多少輛車;
②查看便道的車輛數(shù)量,輸出該停車場便道內(nèi)共有多少量車
③進入停車場,客戶進入該停車場停車(前提:停車場或便道有停車位),否則停車失敗;
④離開停車場,客戶輸入車牌號碼,相應(yīng)車牌的車輛出停車場;
⑤離開停車場便道,客戶輸入車牌號碼,相應(yīng)車牌的車輛出便道;
⑥返回停車場總系統(tǒng);
⑦直接退出程序。
6、運行結(jié)果
(1)首頁界面
?(2)停車場管理員系統(tǒng)界面
?(3)停車場消費者系統(tǒng)
?(4)輸入選擇錯誤的情況
?(5)停車場管理系統(tǒng)部分功能
?
?(6)退出系統(tǒng)
?7、代碼部分
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#define MAX1 5
#define MAX2 MAX1-1
typedef struct{
int TimeIn;
int TimeOut;
char ct[50];
char Lincense[10];
}Car;
typedef struct{
Car Stop[MAX1];
int top;
}Stopping;
typedef struct{
Car Pave[MAX2];
int count;
int front, rear;
}Pavement;
typedef struct{
Car Let[MAX1];
int top;
}Buffer;
typedef struct{
Car Wait[MAX2];
int count;
int front, rear;
}Waiting;
float price=1;
Stopping s;
Pavement p;
Buffer b;
Car c;
Waiting w;
char C[10];
void C_Play1();
void C_Play2();
void C_Play3();
void C_Play3_1();
void C_Play3_2();
void C_Play4();
void C_Play4_1();
void C_Play5();
void C_Play5_1();
void A_Play1();
void A_Play2();
void A_Play3();
void A_Play4();
void A_Play5();
void C_Play1()
{
int i=0,j=0;
i=s.top;
j=i+1;
if(j>0)
{
printf("\n\t該停車場內(nèi)共有%d輛車\n",s.top+1);
}
else
{
printf("\n\t該停車場內(nèi)無車輛");
}
}
void C_Play2()
{
int i=0;
i=p.count;
if(i>0)
{
printf("\n\t該停車場便道內(nèi)共有%d輛車\n",i);
}
else if(i<=0)
{
printf("\n\t該停車場便道內(nèi)無車輛\n");
}
}
void C_Play3()
{
int i=0,j=0,k=0,z=0,y=0;
y=MAX1-1;
k=p.front;
i=s.top;
j=(p.rear)-(p.front);
if(s.top<MAX1&&p.count<MAX2)
{
printf("\n\t請輸入您的車牌號碼:");
scanf("%s",C);
}
else
{
printf("\n\t該停車場和停車場便道已滿,歡迎下次再來!");
return;
}
while(i!=-1)
{
if(strcmp(s.Stop[i].Lincense,C)==0)
{
printf("\t該車輛已在停車場內(nèi),請重新輸入車牌號");
C_Play3();
return;
}
i--;
}
while(j!=0)
{
if(strcmp(p.Pave[k].Lincense,C)==0)
{
printf("\t該車輛已在停車場便道內(nèi),請重新輸入車牌號。");
C_Play3();
return;
}
j--;
k++;
}
if(s.top<MAX1-1)
{
C_Play3_1();
}
else
{
if(p.count==MAX2)
{
printf("\t該停車場與便道已滿,請您下次再來");
}
else
{
C_Play3_2();
}
}
}
void C_Play3_1()
{
time_t t1;
long int t=time(&t1);
char* t2;
t2=ctime(&t1);
s.Stop[++s.top].TimeIn=t;
strcpy(s.Stop[s.top].ct,t2);
strcpy(s.Stop[s.top].Lincense,C);
printf("\n\t車牌號碼為:%s 位置:第%d位 當前時間為:%s",C,s.top+1,t2);
printf("\t車輛已停好!\n");
}
void C_Play3_2()
{
strcpy(p.Pave[p.rear].Lincense,C);
p.rear++;
p.count++;
printf("\t由于停車場內(nèi)已滿,您車牌號為【%s】的車暫時停在便道上",C);
}
void C_Play4()
{
int i=0,k=0;
i=s.top;
k=1;
if(s.top==-1)
{
printf("\n\t該停車場內(nèi)目前無車輛停放");
return;
}
if(s.top>=0)
{
printf("\t請輸入您的車牌號碼:");
fflush(stdin);
scanf("%s",C);
if(s.top>=0)
{
while(i!=-1)
{
if(strcmp(s.Stop[i].Lincense, C)==0)
{
C_Play4_1();
}
i--;
k=k*strcmp(s.Stop[i].Lincense, C);
}
while(k!=0)
{
printf("\n\t您輸入的車牌號碼不在該停車場內(nèi)\n");
break;
}
}
}
}
void C_Play4_1()
{
while(s.top>=0)
{
if(strcmp(s.Stop[s.top].Lincense, C)==0)
{
break;
}
else
{
strcpy(b.Let[b.top++].Lincense,s.Stop[s.top].Lincense);
printf("\t由于停車場后方車輛需出去,車牌號碼為【%s】的汽車暫時退出停車場讓后方車輛駛出停車場\n", s.Stop[s.top--].Lincense);
}
}
printf("\n\t車牌號碼為【%s】的汽車從停車場開走", s.Stop[s.top].Lincense);
time_t t1;
long int t = time(&t1);
s.Stop[s.top].TimeOut = t;
char* t2;
t2 = ctime(&t1);
printf("\n\t離開時間:%s\t停車費用共:%0.2f元\n",t2,price*(s.Stop[s.top].TimeOut-s.Stop[s.top].TimeIn)/60);
s.top--;
while(b.top > 0)
{
strcpy(s.Stop[++s.top].Lincense, b.Let[--b.top].Lincense);
printf("\n\t車牌號碼為【%s】的汽車重新進入停車場,位置為第%d位",b.Let[b.top].Lincense,s.top+1);
}
while(s.top<MAX1-1)
{
if(0==p.count)
{
break;
}
else
{
time_t t1;
long int t=time(&t1);
char* t2;
strcpy(s.Stop[++s.top].Lincense,p.Pave[p.front].Lincense);
printf("\n\n\t車牌號碼為【%s】的汽車從停車場便道進入停車場的第%d個車位",p.Pave[p.front].Lincense,s.top+1);
s.Stop[s.top].TimeIn=t;
p.front++;
p.count--;
}
}
}
void C_Play5()
{
int z=0,i=0,k=0,j=0;
z=p.front;
j=p.count;
k=1;
if(p.count==0)
{
printf("\n\t該停車場便道內(nèi)目前無車輛停放\n");
return;
}
else
{
printf("\n\t請輸入您的車牌號碼:");
fflush(stdin);
scanf("%s",&C);
if(p.count!=0)
{
while(j!=0)
{
if(strcmp(p.Pave[z].Lincense,C)==0)
{
C_Play5_1();
}
k=k*strcmp(p.Pave[z].Lincense,C);
j--;
z++;
}
while(k!=0)
{
printf("\n\t您輸入的車牌號碼不在該停車場便道內(nèi)\n");
break;
}
}
}
}
void C_Play5_1()
{
int i=0;
while(p.count>0)
{
i=p.front;
if(strcmp(p.Pave[i].Lincense,C)==0)
{
break;
}
printf("\n\t由于停車場便道后面的車輛需要出去,車牌號為【%s】的汽車暫時從停車場便道進入臨時便道\n",p.Pave[p.front].Lincense);
strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense);
p.front++;
w.rear++;
w.count++;
p.count--;
}
printf("\n\t車牌號為【%s】的汽車從停車場便道上開走,不收取任何費用!\n\n",p.Pave[i].Lincense);
p.front++;
p.count--;
while(p.count>0)
{
printf("\n\t由于便道內(nèi)的車輛需要出便道,車牌號為【%s】的汽車暫時從停車場便道進入臨時便道\n",p.Pave[p.front].Lincense);
strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense);
p.front++;
w.rear++;
w.count++;
p.count--;
}
while(w.count>0)
{
printf("\n\t牌照為【%s】的汽車返回便道\n",w.Wait[w.front].Lincense);
strcpy(p.Pave[p.rear].Lincense, w.Wait[w.front].Lincense);
w.front++;
p.rear++;
w.count--;
p.count++;
}
}
void A_Play1()
{
int i=0;
i=s.top;
time_t t1;
long int t=time(&t1);
if(i>=0)
{
printf("\n\t停車場內(nèi)車輛信息如下:\n");
printf("\t車牌號 位置 停放時間 目前要支付的停車費用");
for(i;i>=0;i--)
{
printf("\n\t%s 第%d位 %d分%d秒 %0.2f元\n\n",s.Stop[i].Lincense,i+1,(t-s.Stop[i].TimeIn)/60,(t-s.Stop[i].TimeIn)%60,price*(t-s.Stop[i].TimeIn)/60);
}
}
else if(i<0)
{
printf("\n\t該停車場目前沒有車輛停放\n\t");
}
}
void A_Play2()
{
int i=p.front;
int k=1;
if(p.count==0)
{
printf("\t\n\t該停車場便道內(nèi)目前沒有車輛\n");
}
else
{
printf("\t便道內(nèi)車輛信息如下:\n");
printf("\t車牌號 位置\n");
while(i!=p.rear&&p.count>=1)
{
printf("\t%s 第%d位\n", p.Pave[i].Lincense, k++);
i++;
}
}
}
void A_Play3()
{
int i=0,j=0,k=0,f=0,g=0,h=0,z=0;
i=s.top;
f=p.count;
g=p.front;
h=p.rear;
z=(p.rear)-(p.front);
k=1;
time_t t1;
long int t=time(&t1);
if(s.top>=0||p.count>0)
{
printf("\t請輸入要搜索的車牌號:");
fflush(stdin);
scanf("%s",&C);
}
if(s.top>=0)
{
while(i!=-1)
{
if(strcmp(s.Stop[i].Lincense, C)==0)
{
printf("\n\t此汽車在停車場內(nèi),信息如下:\n");
printf("\t車牌號 位置 停車費用 進入時間");
printf("\n\t%s 第%d個 %0.2f元 %s",s.Stop[i].Lincense,i+1,price*(t-s.Stop[i].TimeIn)/60,s.Stop[i].ct);
break;
}
i--;
}
}
if(p.count>0)
{
while(g!=h)
{
if(strcmp(p.Pave[g].Lincense,C)==0)
{
printf("\n\t此汽車在停車場便道上,信息如下:");
printf("\n\t車牌號 位置\n");
printf("\t%s 第%d位",p.Pave[g].Lincense,k);
break;
}
g++;
k++;
}
}
if(s.top<0&&p.count<=0)
{
printf("\n\t該停車場和便道內(nèi)無車輛\n");
return;
}
while(strcmp(s.Stop[i].Lincense, C)!=0&&strcmp(p.Pave[g].Lincense,C)!=0)
{
printf("\n\t此車牌號碼的車輛不在該停車場和停車場便道內(nèi)");
break;
}
}
void A_Play4()
{
printf("\n\t當前的收費為%0.2f元/分鐘\n",price);
printf("\t請輸入更改后的收費標準(元/分鐘):");
fflush(stdin);
scanf("%4f",&price);
printf("\t當前收費標準為%0.2f元/分鐘\n",price);
}
int main()
{
s.top=-1;
b.top=-1;
p.rear=0;
p.count=0;
p.front=0;
w.count=0;
w.front=0;
w.rear=0;
begin:
system("cls");
system("color 0A");
printf("\t**************************************************\n\t");
printf("** 歡迎使用停車場總系統(tǒng) **\n");
printf("\t**************************************************\t\n\t");
printf("** 請選擇您需要進行的操作 **\n\t");
printf("* \t1、進入停車場管理員系統(tǒng) *\n\t");
printf("* \t2、進入停車場消費者系統(tǒng) *\n\t");
printf("* \t3、直接退出程序 *\n\t");
printf("##################################################\n\t");
printf("請輸入您的的選擇:");
int z=0;
fflush(stdin);
scanf("%d",&z);
if(z==1)
{
while(1)
{
system("cls");
system("color 0B");
printf("\t**********************************************************\n\t");
printf("** 歡迎使用停車場管理員系統(tǒng) **\n");
printf("\t**********************************************************\n\t");
printf("** 請選擇您需要進行的操作 **\n\t");
printf("* 1、查看停車場內(nèi)車輛信息 *\n\t");
printf("* 2、查看便道的內(nèi)車輛信息 *\n\t");
printf("* 3、查找車輛的目前的信息 *\n\t");
printf("* 4、更改收費標準 *\n\t");
printf("* 5、返回停車場總系統(tǒng) *\n\t");
printf("* 6、直接退出程序 *\n\t");
printf("##########################################################\n\t");
printf("請輸入您的選擇:");
int i=0,l=0;
fflush(stdin);
scanf("%d",&i);
if(i==1)
{
A_Play1();
}
if(i==2)
{
A_Play2();
}
if(i==3)
{
A_Play3();
}
if(i==4)
{
A_Play4();
}
if(i==5)
{
goto begin;
}
if(i==6)
{
printf("\n\t歡迎下次使用!\n");
sleep(2);
break;
}
if(i>6||i<1)
{
system("cls");
system("color 0C");
printf("\n\t輸入選項錯誤,請在1~6內(nèi)選擇\n\n");
}
printf("\n\n\t輸入鍵繼續(xù)使用停車場管理員系統(tǒng)");
getch();
}
}
else if(z==2)
{
while(1)
{
system("cls");
system("color 0B");
printf("\t**********************************************************\n\t");
printf("** 歡迎使用停車場消費者系統(tǒng) **\n");
printf("\t**********************************************************\n\t");
printf("** 請選擇您需要進行的操作 **\n\t");
printf("* 1、查看停車場車輛數(shù)量 *\n\t");
printf("* 2、查看便道的車輛數(shù)量 *\n\t");
printf("* 3、進入停車場 *\n\t");
printf("* 4、離開停車場 *\n\t");
printf("* 5、離開停車場便道 *\n\t");
printf("* 6、返回停車場總系統(tǒng) *\n\t");
printf("* 7、直接退出程序 *\n\t");
printf("* 收費標準:本停車場按照%0.2f元/分鐘計費,希望您能理解 *\n\t",price);
printf("##########################################################\n\t");
printf("請輸入您的選擇:");
int k=0,l=0;
fflush(stdin);
scanf("%d",&k);
if(k==1)
{
C_Play1();
}
if(k==2)
{
C_Play2();
}
if(k==3)
{
C_Play3();
}
if(k==4)
{
C_Play4();
}
if(k==5)
{
C_Play5();
}
if(k==6)
{
goto begin;
}
if(k==7)
{
printf("\n\t歡迎下次使用!\n");
sleep(2);
break;
}
if(k>7||k<1)
{
system("cls");
system("color 0C");
printf("\n\t輸入選項錯誤,請在1~7內(nèi)選擇\n\n");
}
printf("\n\n\t任意鍵繼續(xù)使用停車場消費者系統(tǒng)");
getch();
}
}
else if(z==3)
{
printf("\n\t歡迎下次使用!\n");
sleep(1);
}
else
{
system("cls");
system("color 0C");
printf("\t輸入錯誤,請重新輸入");
sleep(2);
goto begin;
return 0;
}
}
8、結(jié)語文章來源:http://www.zghlxwxcb.cn/news/detail-759364.html
該停車場管理系統(tǒng)代碼由于是本人和另一位大一舍友一起寫的,代碼的注釋部分我們并沒有寫出來,代碼也可能存在許多不足之處,有疑問可以留言交流。文章來源地址http://www.zghlxwxcb.cn/news/detail-759364.html
到了這里,關(guān)于停車場管理系統(tǒng)(C語言)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!