栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言实现简单停车场管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言实现简单停车场管理系统

本文实例为大家分享了C语言停车场管理系统的具体代码,供大家参考,具体内容如下


#include
#include
#include 
#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;  
 int Timeinit; 
}Node;
typedef struct QueueNode 
{
 struct Node data; 
 struct QueueNode* next; 
} QueueNode;
typedef struct linkQueue 
{
 struct QueueNode *rear, *front;
} linkQueue;
 
 
typedef struct SqStackNode 
{ 
 int top;
 int bottom;
 struct Node stack_array[MAX_STACK_SIZE+1] ;
}SqStackNode ;
 
/
{ 
 SqStackNode *S=(SqStackNode *)malloc(sizeof(SqStackNode));
 S->bottom=S->top=0; 
 return (S);
}
int FullStack(SqStackNode *S)   
{
 return S->top==MAX_STACK_SIZE;
}
int pushStack(SqStackNode *S,Node data) 
{ 
 if(FullStack(S))
 {
 return ERROR;  
 }
 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;  
 }
 (*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) 
{
 int i;
 if(S->top==0)
 {
 return ERROR;  
 }
 
 for(i=1;i<=S->top;i++)
 {
 if(S->stack_array[i].No == data.No)
 {
  return OK;
 }
 }
 return ERROR; 
}
 
 
 
/
{
 linkQueue *Q=( linkQueue * ) malloc( sizeof ( linkQueue ) );
 Q->rear=Q->front=NULL;
 return Q;
}
 int QueueEmpty ( linkQueue *Q ) 
 {
 return Q->front == NULL;
}
 
int GetFrontQueue ( linkQueue *Q, Node *data ) 
{
 if ( QueueEmpty (Q) ) return 0; 
 (*data).No = (Q->front->data).Timeinit; return 1; 
}
int EnQueue ( linkQueue **Q, Node data) 
{
 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) 
{
 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) 
{ 
 time_t t1; 
 time(&t1); 
 int time=t1%D; 
 return time; 
} 
 
Parking(linkQueue **Q,SqStackNode *S) 
{
 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)
 {
 printf("The Car is existedn");
 return ;
 }
 }
 
 EnQueue(Q,data);
 while(!QueueEmpty(*Q))
 {
 if(FullStack(S)) 
 {
 printf("Please Wait...n");
  break;
 }
 else 
 {
 DeQueue(Q,&data);
 data.Timeinit=now_time();
 pushStack(S,data);
 printf("Park Successn");
 }
 }
 return ;
}
leaving(SqStackNode *S,SqStackNode *B,linkQueue **Q)
{
 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))
 {
 printf("Do not find the carn");
 return ;
 }
 else
 {
 while(S->stack_array[S->top].No != i)
 {
 popStack(S,&data);
 pushStack(B,data);
 }
 popStack(S,&data);
 time_now=now_time();
 parking_time=time_now-data.Timeinit;
 
 h = parking_time/H;
 parking_time = parking_time%H;
 m = parking_time/M;
 s = parking_time%M;
 charge = 6*h+0.1*(m+1);
 printf("The leaving car:%d Parking time:%d:%d:%d Charge($6/h):$%gn",data.No,h,m,s,charge);
 
 while(B->bottom != B->top)
 {
 popStack(B,&data);
 pushStack(S,data);
 }
 while(!FullStack(S)&&(!QueueEmpty(*Q)))
 {
 DeQueue(Q,&data); 
 data.Timeinit=now_time();
 pushStack(S,data);
 } 
 }
 
 }
}
situation(SqStackNode *S,linkQueue **Q)
{
 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)
 {
 printf("Waiting car :0n");
 }
 else
 {
 do
 {
  wait_count++;
 p=p->next;
 }while(p!=NULL);
 printf("Waiting car :%dn",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;
 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; 
 park=InitStack();
 back=InitStack();
 wait=InitQueue();
 while(1)
 {
 system("clearn");
 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:
 {
 system("clearn");
 Parking(&wait,park);
 setbuf(stdin,NULL);
 getchar();
 break;
 }
 case 2:
 {
 leaving(park,back,&wait);
 setbuf(stdin,NULL);
 getchar();
 break;
 }
 case 3:
 {
 
 system("clearn");
 situation(park,&wait);
 setbuf(stdin,NULL);
 getchar();
 break;
 }
 case 4:
 {
 return 0;
 }
 default:
 {
 break;
 }
 }
 }
 return 0; 
}

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/62132.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号