C語(yǔ)言源碼實(shí)現(xiàn)停車(chē)場(chǎng)管理系統(tǒng)
本文實(shí)例為大家分享了C語(yǔ)言停車(chē)場(chǎng)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
題目要求:
剛開(kāi)始在Codeblocks下用C語(yǔ)言寫(xiě)的,但是用指針傳遞參數(shù)的時(shí)候總是出問(wèn)題。后來(lái)就用C++,但是調(diào)用了C的輸入輸出和文件操作的頭文件,所以代碼都是C的
main.cpp
#include <iostream> #include <cstdio> #include <cstdlib> #include <windows.h> #include <ctime> #include <cstring> #include <conio.h> #define N 100 using namespace std; typedef struct { char num[8];//車(chē)牌號(hào) long int time_in; int pos;//車(chē)輛的狀態(tài),0表示停在便道中,1表示停在停車(chē)場(chǎng) } vehicle; //定義車(chē)輛類型 typedef struct { vehicle veh[N]; int top; } SqStack; //用棧表示停車(chē)場(chǎng) typedef struct LNode { vehicle veh; struct LNode *next; } LinkList; //用單鏈表表示便道 void Load(FILE *,SqStack *,LinkList *); void ShowMenu(int ); int MakeChoice(int ,int ); void Parking(SqStack *,LinkList *); void Back(SqStack *); void EnterPkl(SqStack *,LinkList *); void LeavePath(LinkList *); void View(SqStack *,LinkList *); void Write_and_Quit(FILE *,SqStack *,LinkList *); int main() { SqStack *pkl; LinkList *path; FILE *fp; pkl=(SqStack *)malloc(sizeof(SqStack)); path=(LinkList *)malloc(sizeof(LinkList)); fp=fopen("Parking_lot.txt","r+"); if(fp==NULL) { printf("數(shù)據(jù)加載失敗!按任意鍵退出程序"); getch(); return 0; } Load(fp,pkl,path); while(1) { system("cls"); ShowMenu(pkl->top); switch(MakeChoice(1,6)) { case 1: system("cls"); Parking(pkl,path); break; case 2: system("cls"); Back(pkl); break; case 3: system("cls"); EnterPkl(pkl,path); break; case 4: system("cls"); LeavePath(path); break; case 5: system("cls"); View(pkl,path); break; default: system("cls"); Write_and_Quit(fp,pkl,path); return 0; } } return 0; }
function.cpp
#include <iostream> #include <cstdio> #include <cstdlib> #include <windows.h> #include <ctime> #include <cstring> #include <conio.h> #define N 100 using namespace std; typedef struct { char num[8];//車(chē)牌號(hào) long int time_in; int pos;//車(chē)輛的狀態(tài),0表示停在便道中,1表示停在停車(chē)場(chǎng) } vehicle; //定義車(chē)輛類型 typedef struct { vehicle veh[N]; int top; } SqStack; //用棧表示停車(chē)場(chǎng) typedef struct LNode { vehicle veh; struct LNode *next; } LinkList; //用單鏈表表示便道 void Load(FILE * fp,SqStack * pkl,LinkList * path) { pkl->top=-1; path->next=NULL; LinkList *p; char num[8]; long int time_in; int pos; while(fscanf(fp,"%s %ld %d\n",num,&time_in,&pos)!=EOF) { if(pos==0)//該車(chē)輛在便道中 { //尾插法建立單鏈表 p=(LinkList *)malloc(sizeof(LinkList)); strcpy(p->veh.num,num); p->veh.time_in=time_in; p->veh.pos=pos; path->next=p; path=p; } else//該車(chē)輛在停車(chē)場(chǎng)中 { ++pkl->top; strcpy(pkl->veh[pkl->top].num,num); pkl->veh[pkl->top].time_in=time_in; pkl->veh[pkl->top].pos=pos; } } path->next=NULL; } void ShowMenu(int n) { printf("********一個(gè)簡(jiǎn)單的停車(chē)場(chǎng)管理系統(tǒng)********\n"); if(n+1==N) printf("***************停車(chē)場(chǎng)已滿***************\n"); else printf("**********當(dāng)前停車(chē)場(chǎng)共有%03d輛車(chē)**********\n",n+1); printf("********說(shuō)明:停車(chē)場(chǎng)每小時(shí)收費(fèi)5元********\n"); printf("****************1.停車(chē)******************\n"); printf("****************2.取車(chē)******************\n"); printf("*********3.便道車(chē)輛進(jìn)入停車(chē)場(chǎng)***********\n"); printf("**************4.離開(kāi)便道****************\n"); printf("**************5.查看車(chē)輛****************\n"); printf("****************6.退出******************\n"); } int MakeChoice(int m,int n) { int judge; printf("請(qǐng)輸入%d~%d\n",m,n); scanf("%d",&judge); while(judge<m||judge>n)//確保輸入的是1~n { printf("輸入不合法,請(qǐng)輸入%d~%d\n",m,n); fflush(stdin);//如果不加這句,輸入一些字母會(huì)導(dǎo)致函數(shù)無(wú)限循環(huán) scanf("%d",&judge); } return judge; } void Parking(SqStack *pkl,LinkList *path) { LinkList *r; printf("請(qǐng)輸入車(chē)牌號(hào):"); if(pkl->top<N-1) { fflush(stdin); scanf("%8s",pkl->veh[++pkl->top].num); time(&(pkl->veh[pkl->top].time_in)); pkl->veh[pkl->top].pos=1; printf("您的車(chē)輛已停至%2d號(hào)車(chē)位\n",pkl->top); } else { fflush(stdin); r=(LinkList *)malloc(sizeof(LinkList)); scanf("%8s",r->veh.num); printf("停車(chē)場(chǎng)已滿,您要暫時(shí)停放在便道中嗎?\n"); printf("1.確定 2.取消\n"); if(MakeChoice(1,2)==1) { while(path->next!=NULL) path=path->next; r->veh.time_in=0; r->veh.pos=0; path->next=r; r->next=NULL; printf("您的車(chē)輛已停放到便道中\(zhòng)n"); } else free(r); } printf("按任意鍵返回主菜單"); getch(); return; } void Back(SqStack *pkl) { int n,i=0; long int time_out; double hours; vehicle t_pkl[N]; printf("請(qǐng)輸入您的車(chē)輛所在的車(chē)位(目前還有個(gè)小問(wèn)題,前面的車(chē)走了之后當(dāng)前車(chē)位會(huì)-1):"); n=MakeChoice(0,pkl->top); printf("%2d上的車(chē)輛車(chē)牌號(hào)為%s,您確定要取走該車(chē)輛嗎?\n",n,pkl->veh[n].num); printf("1.確定 2.取消\n"); if(MakeChoice(1,2)==1) { time(&time_out); hours=(time_out-pkl->veh[n].time_in)/3600.0; printf("本次停車(chē)共計(jì)%lf小時(shí),收費(fèi)%lf元,請(qǐng)按任意鍵確認(rèn)支付\n",hours,hours*5); getch(); for(i=0; pkl->top>=n; --pkl->top,++i) //把第n輛到第pkl->top輛車(chē)移到t_pkl t_pkl[i]=pkl->veh[pkl->top]; //此時(shí)pkl->top指向第n-1輛車(chē) for(i-=2; i>=0; --i) //把第n+1輛到第pkl->top輛車(chē)移回pkl pkl->veh[++pkl->top]=t_pkl[i]; printf("支付成功!\n"); printf("取車(chē)成功,按任意鍵返回主菜單"); getch(); return; } else { printf("按任意鍵返回主菜單"); getch(); return; } } void EnterPkl(SqStack *pkl,LinkList *path) { if(pkl->top==N-1) printf("停車(chē)場(chǎng)已滿!"); else { printf("您確定將便道中第一輛車(chē)(車(chē)牌號(hào):%8s)停入停車(chē)場(chǎng)嗎?\n",path->next->veh.num); printf("1.確定 2.取消\n"); if(MakeChoice(1,2)==1) { pkl->veh[++pkl->top]=path->next->veh; time(&pkl->veh[pkl->top].time_in); path->next=path->next->next; printf("已停入停車(chē)場(chǎng)\n"); } } printf("按任意鍵返回主菜單"); getch(); return; } void LeavePath(LinkList *path) { int i=0,n; LinkList *q; printf("請(qǐng)輸入要離開(kāi)便道的車(chē)輛的位序:"); scanf("%d",&n); while(i<n&&path!=NULL) { ++i; q=path;//保存當(dāng)前節(jié)點(diǎn)的前一個(gè)節(jié)點(diǎn),如果找到的位置在鏈表最后,需要將前一個(gè)節(jié)點(diǎn)的指針域置為NULL path=path->next; } if(path!=NULL) { printf("您確定便道中第%03d輛車(chē)(車(chē)牌號(hào):%8s)離開(kāi)便道嗎?\n",n,path->veh.num); printf("1.確定 2.取消\n"); if(MakeChoice(1,2)==1) { if(path->next!=NULL)//確定離開(kāi)并且不是便道中最后一輛車(chē) { q=path->next; path->next=q->next; free(q); printf("第%03d輛車(chē)已離開(kāi)便道\n",n); } else//確定離開(kāi)并且是便道中最后一輛車(chē) { printf("第%03d輛車(chē)已離開(kāi)便道\n",n); q->next=NULL; free(path); } } } else printf("沒(méi)有找到第%03d輛車(chē)\n",n); printf("按任意鍵返回主菜單"); getch(); return; } void View(SqStack *pkl,LinkList *path) { int i; long int time_out; double hours; time(&time_out); printf("停車(chē)場(chǎng)共有%03d輛車(chē):\n",pkl->top+1); for(i=0; i<=pkl->top; ++i) { hours=(time_out-pkl->veh[i].time_in)/3600.0; printf("車(chē)位:%2d 車(chē)牌號(hào):%8s 停車(chē)時(shí)長(zhǎng):%lf 應(yīng)繳費(fèi)用:%lf\n",i,pkl->veh[i].num,hours,hours*5); } printf("便道車(chē)輛:\n"); if(path->next==NULL) printf("無(wú)\n"); while(path->next!=NULL) { path=path->next; printf("車(chē)牌號(hào):%s\n",path->veh.num); } printf("按任意鍵返回主菜單"); getch(); return; } void Write_and_Quit(FILE *fp,SqStack *pkl,LinkList *path) { rewind(fp); LinkList *pre=path,*p=path->next; for(; pkl->top>-1; --pkl->top) fprintf(fp,"%s %ld %d\n",pkl->veh[pkl->top].num,pkl->veh[pkl->top].time_in,pkl->veh[pkl->top].pos); while(p!=NULL) { free(pre); fprintf(fp,"%s %ld %d\n",p->veh.num,p->veh.time_in,p->veh.pos); pre=p; p=pre->next; } free(pre); free(pkl); fclose(fp); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)項(xiàng)目
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)游戲VIP停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)管理
- C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言設(shè)計(jì)圖書(shū)登記系統(tǒng)與停車(chē)場(chǎng)管理系統(tǒng)的實(shí)例分享
- C語(yǔ)言課程設(shè)計(jì)之停車(chē)場(chǎng)管理問(wèn)題
相關(guān)文章
C++左值與右值,右值引用,移動(dòng)語(yǔ)義與完美轉(zhuǎn)發(fā)詳解
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-03-03關(guān)于C語(yǔ)言位運(yùn)算的簡(jiǎn)單示例
這篇文章主要介紹了關(guān)于C語(yǔ)言位運(yùn)算的簡(jiǎn)單示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12C++ 風(fēng)靡一時(shí)的連連看游戲的實(shí)現(xiàn)流程詳解
游戲“連連看”是源自臺(tái)灣的桌面小游戲,自從流入大陸以來(lái)風(fēng)靡一時(shí),也吸引眾多程序員開(kāi)發(fā)出多種版本的“連連看”。這其中,顧芳編寫(xiě)的“阿達(dá)連連看”以其精良的制作廣受好評(píng),這也成為顧方“阿達(dá)系列軟件”的核心產(chǎn)品。并于2004年,取得國(guó)家版權(quán)局的計(jì)算機(jī)軟件登記證書(shū)2021-11-11C語(yǔ)言實(shí)現(xiàn)哈希搜索算法及原理詳解
本文主要介紹了C語(yǔ)言實(shí)現(xiàn)哈希搜索算法及原理詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06C語(yǔ)言關(guān)系運(yùn)算符實(shí)例詳解
本文主要介紹C語(yǔ)言的關(guān)系運(yùn)算符的知識(shí),這里提供實(shí)例代碼以便參考,希望能幫助有需要的小伙伴2016-07-07C語(yǔ)言實(shí)現(xiàn)宿舍管理系統(tǒng)設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)宿舍管理系統(tǒng)設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03