目錄

一、問(wèn)題描述
二、算法結(jié)構(gòu)分析與設(shè)計(jì)
三、算法主模塊的流程及各子模塊的主要功能
四、算法詳細(xì)設(shè)計(jì)
五、源代碼
設(shè)停車(chē)場(chǎng)只有一個(gè)可以停放幾輛汽車(chē)的狹長(zhǎng)通道,且只有一個(gè)大門(mén)可供汽車(chē)進(jìn)出。汽車(chē)在停車(chē)場(chǎng)內(nèi)按車(chē)輛到達(dá)的先后順序依次排列,若車(chē)場(chǎng)內(nèi)已經(jīng)停滿(mǎn)幾輛汽車(chē),則后來(lái)的汽車(chē)只能在門(mén)外的便道上等候,一旦有汽車(chē)開(kāi)走,則排在便道上的第一輛汽車(chē)即可進(jìn)入,當(dāng)停車(chē)場(chǎng)某輛車(chē)要離開(kāi)時(shí),由于停車(chē)場(chǎng)是狹長(zhǎng)通道,在他之后開(kāi)入的車(chē)輛必須先退出車(chē)場(chǎng)為他讓路,待該輛汽車(chē)開(kāi)出大門(mén)之后,為他讓路的車(chē)輛按照原次序進(jìn)入車(chē)場(chǎng)。在這里假設(shè)汽車(chē)不能從便道上開(kāi)走。
2.輸入輸出要求
每一組輸入數(shù)據(jù)要求包括三個(gè)數(shù)據(jù)項(xiàng):汽車(chē)“到達(dá)”或“離去”的信息、汽車(chē)拍照號(hào)碼、汽車(chē)到達(dá)或者離去的時(shí)刻。
二、算法結(jié)構(gòu)分析與設(shè)計(jì)typedef?struct?Time
{
? int?mon=0;
? int?date=0;
? int?hour=0;
? int?min=0;
? int?sec=0;
?
}Time;
2.汽車(chē)
typedef struct Car
{
? string ChePai="";
? Time?in;
? Time out;
}Car;
3.順序棧
typedef struct SeqStack
{
? Car?CheWei[MAXSIZE];
? int?top=-1;
?
}SeqStack;
4.鏈?zhǔn)疥?duì)列
typedef struct QNode
{
? Car?data;
? QNode?*next=NULL;
?
}QNode;
typedef struct LQueue
{
? QNode?*front,*rear;
?
}LQueue;
三、算法主模塊的流程及各子模塊的主要功能子模塊的主要功能:
1)壓棧和出棧:SeqStack* InStack(SeqStack* pl,Car a)
SeqStack* OutStack(SeqStack* pl,Car a)
2)入隊(duì)和出隊(duì):LQueue* InQueue(Car a,LQueue* p)
Car OutQueue(LQueue* p)
3)初始化隊(duì):LQueue* InitLQueue()
4)獲取系統(tǒng)時(shí)間,計(jì)算時(shí)間差:void differ(Time in,Time out)
Time GetTime()
5)算錢(qián):int MoneyCalculate(int MoneyPH,Time in,Time out)
主程序流程:

1.寫(xiě)出各個(gè)模塊的偽碼算法
得到系統(tǒng)時(shí)間:
{獲取系統(tǒng)時(shí)間
賦值返回
}
尋找車(chē)輛用于查詢(xún):
{遍歷棧,若查詢(xún)到車(chē)牌一致,返回
遍歷隊(duì)列,若查詢(xún)到車(chē)牌一致,返回
}
入棧:
{top指針上移
獲取系統(tǒng)時(shí)間,賦給car進(jìn)入的時(shí)間
裝填數(shù)據(jù)
}
出棧:
{如果內(nèi)部車(chē)輛出棧,外部車(chē)輛壓入輔助棧,內(nèi)部車(chē)輛出棧,外部車(chē)輛壓回;
如果最外邊的車(chē)輛出棧,則直接出棧。
獲取系統(tǒng)時(shí)間,計(jì)算時(shí)間差,計(jì)算應(yīng)繳納的金額。
}
計(jì)算繳納的費(fèi)用:
{計(jì)算停泊了幾個(gè)小時(shí),不超過(guò)半個(gè)小時(shí)的部分忽略不計(jì)
自定義每小時(shí)停泊的價(jià)格,返回總金額
}
初始化隊(duì):
{申請(qǐng)頭節(jié)點(diǎn)空間和第一個(gè)數(shù)據(jù)節(jié)點(diǎn)的空間
頭節(jié)點(diǎn)的頭尾指針均指向第一個(gè)數(shù)據(jù)節(jié)點(diǎn)
第一個(gè)數(shù)據(jù)節(jié)點(diǎn)的后繼置空
返回頭節(jié)點(diǎn)
}
入隊(duì):
{獲取系統(tǒng)時(shí)間,賦給進(jìn)入的車(chē)輛
如果此時(shí)便道內(nèi)沒(méi)有車(chē)輛,第一個(gè)數(shù)據(jù)節(jié)點(diǎn)裝填
如果此時(shí)便道內(nèi)已經(jīng)有了車(chē)輛,申請(qǐng)新的節(jié)點(diǎn)空間,裝填數(shù)據(jù),尾指針后移
返回頭節(jié)點(diǎn)
}
出隊(duì):
{如果便道內(nèi)有多個(gè)車(chē)輛,用一個(gè)node類(lèi)型指針指向待入車(chē)輛,用一個(gè)car變量承接數(shù)據(jù),出隊(duì)之后釋放指針指向的空間,返回承接的數(shù)據(jù)
如果只有一個(gè)車(chē)輛,用一個(gè)car類(lèi)型指針指向數(shù)據(jù),承接數(shù)據(jù)后釋放指針,返回?cái)?shù)據(jù)
}
五、源代碼#include#includeusing namespace std;
#define MAXSIZE 5
typedef int DataType;
//定義時(shí)間
typedef struct Time
{
int mon=0;
int date=0;
int hour=0;
int min=0;
int sec=0;
}Time;
typedef struct Car
{
string ChePai="";
Time in;
Time out;
}Car;
//定義順序棧
typedef struct SeqStack
{
Car CheWei[MAXSIZE];
int top=-1;
}SeqStack;
//定義鏈?zhǔn)疥?duì)列
typedef struct QNode
{
Car data;
struct QNode *next=NULL;
}QNode;
typedef struct LQueue
{
QNode *front=NULL,*rear=NULL;
}LQueue;
void TimePrint(Time a)
{
cout<<"時(shí)間為:"tm_mday;
a.min=p->tm_min;
a.hour=p->tm_hour;
a.sec=p->tm_sec;
return a;
}
Car Search(SeqStack* pl,LQueue* bd,Car op)
{
int j=1;
//先在棧內(nèi)找
for(int i=0;i<=pl->top;i++)
{
if(pl->CheWei[i].ChePai==op.ChePai)
{
cout<<"在第"<CheWei[i];
}
}
//然后在隊(duì)列里找
QNode* p=bd->front;
while(op.ChePai!=p->data.ChePai&&p->next!=NULL)
{
p=p->next;
j++;
}
cout<<"車(chē)在便道的第"<data;
}
SeqStack* InStack(SeqStack* pl,Car a)
{
pl->top++;
a.in=GetTime();
pl->CheWei[pl->top]=a;
TimePrint(a.in);
return pl;
}
//汽車(chē)離去,出棧
SeqStack* OutStack(SeqStack* pl,Car a)
{
SeqStack* fz=new SeqStack();//注意,需要將指針初始化。
while(pl->CheWei[pl->top].ChePai!=a.ChePai)
{
fz->top++;
fz->CheWei[fz->top]=pl->CheWei[pl->top];
pl->top--;
}
while(fz->top!=-1)
{
pl->CheWei[pl->top]=fz->CheWei[fz->top];
pl->top++;
fz->top--;
}
pl->top--;
a.out=GetTime();
TimePrint(a.out);
int MoneyCalculate(int MoneyPH,Time in,Time out);
int money=MoneyCalculate(5,a.in,a.out);//所需要的金額一并輸出
void differ(Time in,Time out);
differ(a.in,a.out);
cout<<"應(yīng)繳納:"<=30)
out.hour++;//超過(guò)半個(gè)小時(shí)部分按一個(gè)小時(shí)計(jì)算
money=MoneyPH*(out.hour-in.hour);
return money;
}
//計(jì)算時(shí)間差
void differ(Time in,Time out)
{
Time d;
if(out.minfront=q;
p->rear=q;
q->next=NULL;
return p;
}
LQueue* InQueue(Car a,LQueue* p)
{//傳入需要入隊(duì)的車(chē)輛信息和便道隊(duì)的地址
a.in=GetTime();
if(p->front->data.ChePai=="")
{
p->front->data=a;
return p;
}
else
{
QNode* q=new QNode();
q->data=a;
p->rear->next=q;
p->rear=q;
return p;
}
}
//出隊(duì),得到車(chē)輛
Car OutQueue(LQueue* p)
{
Car RIn;
Car* op1;
if(p->front!=p->rear)
{
QNode* q=p->front;
p->front=p->front->next;
RIn=q->data;
free(q);
return RIn;
}
else
{
RIn=p->front->data;
op1=&(p->front->data);
free(op1);
return RIn;
}
}
void CarInfPrint(Car a)
{
cout<<"車(chē)牌號(hào)為:"<>a;
//查詢(xún)車(chē)輛信息
if(a=="1")
{
cout<<"請(qǐng)輸入車(chē)牌號(hào):"<>op.ChePai;
op=Search(pl, bd, op);
differ(op.in,GetTime());
CarInfPrint(op);//車(chē)牌號(hào)打印正常。
continue;
}
//錄入車(chē)輛信息
if (a=="2")
{
string b;
cout<<"離去請(qǐng)按1,到達(dá)請(qǐng)按2"<>b;
//離去
if(b=="1")
{
cout<<"請(qǐng)輸入車(chē)牌號(hào):"<>op.ChePai;
op=Search(pl, bd, op);
OutStack(pl, op);
if(bd->front->data.ChePai!="")
{
op1=OutQueue(bd);
InStack(pl,op1);
}
continue;
}
//到達(dá)
if(b=="2")
{
cout<<"請(qǐng)輸入車(chē)牌號(hào):"<>cp;
op.ChePai=cp;
if(pl->top==MAXSIZE-1)
InQueue(op,bd);
if(pl->top 你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
網(wǎng)頁(yè)名稱(chēng):模擬停車(chē)場(chǎng)管理系統(tǒng)(c++,使用棧和隊(duì)列)-創(chuàng)新互聯(lián)
本文鏈接:http://chinadenli.net/article44/hhehe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、小程序開(kāi)發(fā)、網(wǎng)站設(shè)計(jì)公司、定制開(kāi)發(fā)、靜態(tài)網(wǎng)站、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容