欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單停車(chē)場(chǎng)管理系統(tǒng)

 更新時(shí)間:2019年12月27日 14:55:55   作者:Static阿健  
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單停車(chē)場(chǎng)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語(yǔ)言停車(chē)場(chǎng)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

/***************************************************************************
項(xiàng)目要求
停車(chē)場(chǎng)管理
問(wèn)題描述:停車(chē)場(chǎng)是一個(gè)能放n輛車(chē)的狹長(zhǎng)通道,
只有一個(gè)大門(mén),汽車(chē)按到達(dá)的先后次序停放。若
車(chē)場(chǎng)滿(mǎn)了,車(chē)要停在門(mén)外的便道上等候,一旦有
車(chē)走,則便道上第一輛車(chē)進(jìn)入。當(dāng)停車(chē)場(chǎng)中的車(chē)
離開(kāi)時(shí),由于通道窄,在它后面的車(chē)要先退出,
待它走后再依次進(jìn)入。汽車(chē)離開(kāi)時(shí)按停放時(shí)間收費(fèi)。
基本功能要求:
(1) 建立三個(gè)數(shù)據(jù)結(jié)構(gòu)分別是:停放棧、讓路
棧、等候隊(duì)列。
(2) 輸入數(shù)據(jù)模擬管理過(guò)程,數(shù)據(jù)(入或出,車(chē)號(hào))。
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<time.h> 
#define D (24*60*60) 
#define H (60*60) 
#define M (60)
#define OK 1
#define ERROR 0
#define MAX_STACK_SIZE 10 /* 棧向量大小 */
typedef int StackData;
typedef int QueueData;
typedef int ElemType;
typedef struct Node
{
 int No;  /* 車(chē)號(hào) */
 int Timeinit; /* 進(jìn)入停車(chē)場(chǎng)的時(shí)間*/
}Node;
typedef struct QueueNode /* 隊(duì)列結(jié)點(diǎn)*/
{
 struct Node data; 
 struct QueueNode* next; 
} QueueNode;
typedef struct LinkQueue /* 鏈?zhǔn)疥?duì)列結(jié)構(gòu)體 */
{
 struct QueueNode *rear, *front;
} LinkQueue;
 
 
typedef struct SqStackNode /* 鏈?zhǔn)綏=Y(jié)構(gòu)體 */
{ 
 int top;
 int bottom;
 struct Node stack_array[MAX_STACK_SIZE+1] ;
}SqStackNode ;
 
//***************************************************************
SqStackNode* InitStack()    /* 初始化棧*/
{ 
 SqStackNode *S=(SqStackNode *)malloc(sizeof(SqStackNode));
 S->bottom=S->top=0; 
 return (S);
}
int FullStack(SqStackNode *S)   /* 滿(mǎn)棧 */
{
 return S->top==MAX_STACK_SIZE;
}
int pushStack(SqStackNode *S,Node data) /* 入棧 */
{ 
 if(FullStack(S))
 {
 return ERROR;  /* 棧滿(mǎn),返回錯(cuò)誤標(biāo)志 */
 }
 S->top++ ;   
 (S->stack_array[S->top]).No=data.No ; 
 (S->stack_array[S->top]).Timeinit=data.Timeinit; 
 return OK;   /* 壓棧成功 */
}
int popStack(SqStackNode *S,Node *data)  /*彈出棧頂元素*/
{ 
 if(S->top==0)
 {
 return ERROR;  /* ???,返回錯(cuò)誤標(biāo)志 */
 }
 (*data).No=(S->stack_array[S->top]).No; 
 (*data).Timeinit=(S->stack_array[S->top]).Timeinit; 
 S->top--; 
 return OK; 
}
int FinfStack(SqStackNode *S,Node data) /* 搜索棧內(nèi)元素data*/
{
 int i;
 if(S->top==0)
 {
 return ERROR;  /* ???,返回錯(cuò)誤標(biāo)志 */
 }
 
 for(i=1;i<=S->top;i++)
 {
 if(S->stack_array[i].No == data.No)
 {
  return OK;
 }
 }
 return ERROR; 
}
 
 
 
//**************************************************** 
LinkQueue* InitQueue (void)  /* 初始化隊(duì)列 */
{
 LinkQueue *Q=( LinkQueue * ) malloc( sizeof ( LinkQueue ) );
 Q->rear=Q->front=NULL;
 return Q;
}
 int QueueEmpty ( LinkQueue *Q ) /* 空隊(duì)列*/
 {
 return Q->front == NULL;
}
 
int GetFrontQueue ( LinkQueue *Q, Node *data ) /* 取隊(duì)首 */
{
 if ( QueueEmpty (Q) ) return 0; 
 (*data).No = (Q->front->data).Timeinit; return 1; 
}
int EnQueue ( LinkQueue **Q, Node data) /* 入隊(duì)*/
{
 QueueNode *p = ( QueueNode * ) malloc( sizeof ( QueueNode ) );
 (p->data).No = data.No; 
 (p->data).Timeinit = data.Timeinit; 
 p->next = NULL;
 if ( (*Q)->front == NULL ) 
 {
 (*Q)->front = (*Q)->rear = p;
 }
 else
 {
 
 (*Q)->rear = (*Q)->rear->next = p;
 }
 return 1;
}
int DeQueue ( LinkQueue **Q, Node *data) /* 出對(duì)*/
{
 if ( QueueEmpty (*Q) ) 
 {
 return 0; 
 }
 QueueNode *p = (*Q)->front; 
 (*data).No = p->data.No;   
 (*data).Timeinit = p->data.Timeinit; 
 (*Q)->front = (*Q)->front->next; 
 if ((*Q)->front == NULL) (*Q)->rear = NULL;
 free (p);
 return 1; 
}
/*********************************************************/
int now_time(void) /* 獲取當(dāng)日時(shí)間,單位秒*/
{ 
 time_t t1; 
 time(&t1); 
 int time=t1%D; 
 return time; 
} 
 
Parking(LinkQueue **Q,SqStackNode *S) /* 停車(chē)*/
{
 int i,time_now;
 Node data;
 printf("Input the Car No:\n");
 scanf(" %d",&data.No);
 
 for(i=1;i<=S->top;i++)
 {
 
 if(S->stack_array[i].No == data.No)/* 車(chē)號(hào)已存在*/
 {
 printf("The Car is existed\n");
 return ;
 }
 }
 
 EnQueue(Q,data);/* 進(jìn)去等待隊(duì)列*/
 while(!QueueEmpty(*Q))
 {
 if(FullStack(S)) /* 停放棧滿(mǎn)*/
 {
 printf("Please Wait...\n");
  break;
 }
 else /* 停放棧未滿(mǎn) */
 {
 DeQueue(Q,&data);/* 等待隊(duì)列車(chē)出對(duì) */
 data.Timeinit=now_time();/* 記錄當(dāng)前時(shí)間*/
 pushStack(S,data);/* 進(jìn)入停放棧*/
 printf("Park Success\n");
 }
 }
 return ;
}
leaving(SqStackNode *S,SqStackNode *B,LinkQueue **Q)/* 離開(kāi)*/
{
 if(S->bottom == S->top)/* 停放???/
 {
 printf("Parking is Empty:\n");
 }
 else
 {
 Node data;
 int i,h,m,s;
 float charge; 
 int time_now,parking_time;
 printf("Leaving No:\n");
 scanf(" %d",&i);
 data.No=i;
 if(!FinfStack(S,data))/* 停放棧內(nèi)無(wú)此車(chē)*/
 {
 printf("Do not find the car\n");
 return ;
 }
 else/* 停放棧內(nèi)有此車(chē)*/
 {
 while(S->stack_array[S->top].No != i)/* 此車(chē)后的車(chē)依次出棧入讓路棧*/
 {
 popStack(S,&data);
 pushStack(B,data);
 }
 popStack(S,&data);/* 此車(chē)出停放棧*/
 time_now=now_time();
 parking_time=time_now-data.Timeinit;/* 計(jì)算停車(chē)時(shí)間*/
 
 h = parking_time/H;
 parking_time = parking_time%H;
 m = parking_time/M;
 s = parking_time%M;
 charge = 6*h+0.1*(m+1);/* 計(jì)算停車(chē)收費(fèi)*/
 printf("The leaving car:%d Parking time:%d:%d:%d Charge($6/h):$%g\n",data.No,h,m,s,charge);
 
 while(B->bottom != B->top)/* 讓路棧內(nèi)的車(chē)依次出棧入停放棧*/
 {
 popStack(B,&data);
 pushStack(S,data);
 }
 while(!FullStack(S)&&(!QueueEmpty(*Q)))/* 停放棧未滿(mǎn)且等待隊(duì)列未空*/
 {
 DeQueue(Q,&data); /* 等待隊(duì)列車(chē)出隊(duì)*/
 data.Timeinit=now_time();
 pushStack(S,data);/* 出隊(duì)的車(chē)入停放棧*/
 } 
 }
 
 }
}
situation(SqStackNode *S,LinkQueue **Q)/* 查看停車(chē)場(chǎng)當(dāng)前情況*/
{
 Node data;
 int i;
 int time_now,parking_time;
 int h,m,s;
 struct QueueNode *p;
 int wait_count=0;
 p=(*Q)->front;
 if(p == NULL)/* 等待隊(duì)列空*/
 {
 printf("Waiting car :0\n");
 }
 else/* 等待隊(duì)列未空*/
 {
 do
 {
  wait_count++;
 p=p->next;
 }while(p!=NULL);/* 計(jì)算等待隊(duì)列內(nèi)車(chē)數(shù)*/
 printf("Waiting car :%d\n",wait_count);
 }
 
 printf("Car No: ");
 for(i=1;i<=S->top;i++)
 {
 printf("%-10d",S->stack_array[i].No);
 
 if(S->stack_array[i].No == data.No)
 {
  return OK;
 }
 }
 printf("\nPark time:");
 for(i=1;i<=S->top;i++)
 {
 time_now = now_time();
 parking_time = time_now - S->stack_array[i].Timeinit;/* 計(jì)算截止當(dāng)前停車(chē)時(shí)間*/
 h = parking_time/H;
 parking_time = parking_time%H;
 m = parking_time/M;
 s = parking_time%M;
 printf("%02d:%02d:%02d ",h,m,s);
 }
 printf("\n");
 
}
 
int main()
{
 int i;
 Node data;
 SqStackNode *park;/* 停放棧*/
 SqStackNode *back;/* 讓路棧*/
 LinkQueue *wait; /* 等待隊(duì)列*/
 park=InitStack();
 back=InitStack();
 wait=InitQueue();
 while(1)
 {
 system("clear\n");
 printf("----------Welcome to our Car Parking----------\n");
 printf("  1.Parking \n");
 printf("  2.leaving \n");
 printf("  3.situation \n");
 printf("  4.exit \n");
 scanf(" %d",&i);
 switch(i)
 {
 case 1:/* 停車(chē)*/
 {
 system("clear\n");
 Parking(&wait,park);
 setbuf(stdin,NULL);
 getchar();
 break;
 }
 case 2:/* 離開(kāi) */
 {
 leaving(park,back,&wait);
 setbuf(stdin,NULL);
 getchar();
 break;
 }
 case 3:/* 查看停車(chē)情況*/
 {
 
 system("clear\n");
 situation(park,&wait);
 setbuf(stdin,NULL);
 getchar();
 break;
 }
 case 4:/* 退出*/
 {
 return 0;
 }
 default:
 {
 break;
 }
 }
 }
 return 0; 
}

更多學(xué)習(xí)資料請(qǐng)關(guān)注專(zhuān)題《管理系統(tǒng)開(kāi)發(fā)》。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于C語(yǔ)言char與unsigned char的區(qū)別介紹

    基于C語(yǔ)言char與unsigned char的區(qū)別介紹

    本篇文章小編為大家介紹,基于C語(yǔ)言char與unsigned char的區(qū)別介紹。需要的朋友參考下
    2013-04-04
  • Opencv基于文字檢測(cè)去圖片水印的實(shí)現(xiàn)示例

    Opencv基于文字檢測(cè)去圖片水印的實(shí)現(xiàn)示例

    去水印是個(gè)麻煩事,本文就來(lái)介紹一種方法Opencv基于文字檢測(cè)去圖片水印的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-09-09
  • c語(yǔ)言?xún)?nèi)存泄漏嚴(yán)重的解決方法

    c語(yǔ)言?xún)?nèi)存泄漏嚴(yán)重的解決方法

    這篇文章主要介紹了c語(yǔ)言?xún)?nèi)存泄漏的解決方法,幫助大家更好的理解和使用c語(yǔ)言開(kāi)發(fā),感興趣的朋友可以了解下
    2020-09-09
  • C語(yǔ)言實(shí)現(xiàn)全排列算法模板的方法

    C語(yǔ)言實(shí)現(xiàn)全排列算法模板的方法

    這篇文章主要介紹了C語(yǔ)言實(shí)現(xiàn)全排列算法模板的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • c++中的指針最全總結(jié)

    c++中的指針最全總結(jié)

    指針是整個(gè)C++的精髓所在,只有精通了指針才可以說(shuō)是掌握了C++,可以說(shuō)學(xué)習(xí)C++的過(guò)程是個(gè)熟練掌握和使用指針的過(guò)程,下面這篇文章主要給大家介紹了關(guān)于c++中指針的相關(guān)資料,需要的朋友可以參考下
    2024-04-04
  • VSCode?IDE?配置環(huán)境過(guò)程解析

    VSCode?IDE?配置環(huán)境過(guò)程解析

    這篇文章主要介紹了VSCode?IDE?環(huán)境配置,這里說(shuō)的是僅使用?VSCode?創(chuàng)建C/CPP項(xiàng)目時(shí)的配置,VSCode?有代碼提示,?定位來(lái)源和各種快捷鍵,?更適合日常編碼工作,需要的朋友可以參考下
    2022-02-02
  • C++ STL 序列式容器與配接器的簡(jiǎn)單使用

    C++ STL 序列式容器與配接器的簡(jiǎn)單使用

    本文主要介紹了C++ STL 序列式容器與配接器的簡(jiǎn)單使用,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-06-06
  • C++實(shí)現(xiàn)LeetCode(26.有序數(shù)組中去除重復(fù)項(xiàng))

    C++實(shí)現(xiàn)LeetCode(26.有序數(shù)組中去除重復(fù)項(xiàng))

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(26.有序數(shù)組中去除重復(fù)項(xiàng)),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • c++中try catch的用法小結(jié)

    c++中try catch的用法小結(jié)

    這篇文章主要介紹了c++中try catch的用法小結(jié),需要的朋友可以參考下
    2018-01-01
  • C語(yǔ)言系統(tǒng)調(diào)用約定

    C語(yǔ)言系統(tǒng)調(diào)用約定

    這篇文章介紹了C語(yǔ)言系統(tǒng)調(diào)用約定,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值。需要的朋友可以收藏下,方便下次瀏覽觀(guān)看
    2021-12-12

最新評(píng)論