停车场管理系统.zip

  • 无铭釉心
    了解作者
  • Dev C++
    开发工具
  • 1KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2020-06-07 11:25
    上传日期
实现了对车辆的入库登记、对停车场内车辆的查询和计费、对车辆的出库结算等功能
停车场管理系统.zip
  • 停车场管理系统.txt
    5.4KB
内容介绍
#include <stdio.h> #include <time.h> #include<stdlib.h> #define Stack_Size 3 typedef int elemtype; typedef struct{ elemtype carnum; char name[20]; int year; int month; int day; int hour; int min; int second; }Car; typedef struct Node { Car *data; struct Node *next; }Node, *LinkList; typedef struct { Node *front; Node *rear; }LinkQueue; typedef struct { Car elem[Stack_Size]; int top; }SeqStack; void InitStack(SeqStack *stop) { stop->top=-1; } int InitQueue(LinkQueue *wait) { wait->front=(Node *)malloc(sizeof(Node)); if(wait->front!=NULL) { wait->rear=wait->front; wait->front->next=NULL; return 1; } else { return 0; } } time_t start, end; struct tm *tb; SeqStack sstop; LinkQueue wwait; SeqStack temp; void menu(); void Arrival(SeqStack *sstop, LinkQueue *wwait); int Departure(SeqStack *sstop, LinkQueue *wwait, SeqStack *temp); void lookthrough(SeqStack *sstop, LinkQueue *wwait); void menu() { printf("\t\t\t\t**************欢迎使用停车场管理系统******************\n\n"); int choice; printf("\t\t\t1.车辆到达\n"); printf("\t\t\t2.车辆离开\n"); printf("\t\t\t3.浏览车辆信息\n"); printf("\t\t\t您要进行的操作是:\n"); scanf("%d", &choice); switch(choice) { case 1: Arrival(&sstop, &wwait); menu(); break; case 2: Departure(&sstop, &wwait, &temp); menu(); break; case 3: lookthrough(&sstop, &wwait); menu(); break; } } int Push(SeqStack *stop, Car *x) { if(stop->top==Stack_Size-1) { return 0; } stop->top++; for(int i=0; i<20; i++) { stop->elem[stop->top].name[i]=x->name[i]; } stop->elem[stop->top].carnum=x->carnum; stop->elem[stop->top].year=x->year; stop->elem[stop->top].month=x->month; stop->elem[stop->top].day=x->day; stop->elem[stop->top].hour=x->hour; stop->elem[stop->top].min=x->min; stop->elem[stop->top].second=x->second; return 1; } int EnterQueue(LinkQueue *wait, Car *x) { Node *NewNode; NewNode=(Node*)malloc(sizeof(Node)); if(NewNode!=NULL) { NewNode->data=x; NewNode->next=NULL; wait->rear->next=NewNode; wait->rear=NewNode; return 1; } else { return 0; } } int Pop(SeqStack *stop,Car *x)//车Car出栈 { if(stop->top==-1) { return 0; } *x=stop->elem[stop->top]; stop->top--; return 1; } Car DeleteQueue(LinkQueue *wait) { Car x; Node *p; if(wait->front!=wait->rear) { p=wait->front->next; wait->front->next=p->next; if(wait->rear==p) { wait->rear==wait->front; } x=*p->data; start=time(NULL); tb=localtime(&start); x.year=tb->tm_year; x.month=tb->tm_mon; x.day=tb->tm_mday; x.hour=tb->tm_hour; x.min=tb->tm_min; x.second=tb->tm_sec; free(p); return x; } } void Arrival(SeqStack *sstop, LinkQueue *wwait) { Car x; if(sstop->top!=Stack_Size-1) { printf("请输入车牌号:"); scanf("%d", &x.carnum); printf("请输入车主姓名:"); scanf("%s", &x.name); start=time(NULL); tb=localtime(&start); x.year=tb->tm_year; x.month=tb->tm_mon; x.day=tb->tm_mday; x.hour=tb->tm_hour; x.min=tb->tm_min; x.second=tb->tm_sec; Push(sstop, &x); fflush(stdin); } else { printf("请输入车牌号:"); scanf("%d", &x.carnum); printf("请输入车主姓名:"); scanf("%s", &x.name); printf("目前停车场内没有车位,请进便道等候\n"); EnterQueue(wwait, &x); } menu(); } int Departure(SeqStack *sstop, LinkQueue *wwait, SeqStack *temp) { int s; float a, c; Car y, x, z; printf("请输入要离开车的车牌号:"); scanf("%d", &s); for(int i=sstop->top; i>=0; i--) { if(s==sstop->elem[i].carnum) { for(int j=sstop->top; j>i; j--) { Pop(sstop, &x); Push(temp, &x); } Pop(sstop, &x); end=time(NULL); tb=localtime(&end); a=(tb->tm_hour-x.hour)*3600+(tb->tm_min-x.min)*60+(tb->tm_sec-x.second); c=a*0.02; printf("车辆成功离开, 每秒钟0.02元,你停车%f秒,一共%f元\n", a, c); if(wwait->front->next!=NULL) { y=DeleteQueue(wwait); Push(sstop, &y); printf("\n通道车辆进入停车场\n"); }else { printf("通道没有车辆\n"); } while(temp->top!=-1) { Pop(temp, &z); Push(sstop, &z); } return 1; } } printf("输入有误,请重新输入"); return 0; } void lookthrough(SeqStack *sstop, LinkQueue *wwait) { Node *x; int y, i=1; printf("\n\n\n\n\n"); printf("停车场内车辆信息\n\n"); for(int i=0; i<=sstop->top; i++) { printf("车位号:%d\n",i+1); printf("车主姓名:%s\n",sstop->elem[i].name); printf("车牌号:%d\n",sstop->elem[i].carnum); printf("入库时间:%d年%d月%d日%d时%d分%d秒\n",sstop->elem[i].year+1900, sstop->elem[i].month+1, sstop->elem[i].day,sstop->elem[i].hour, sstop->elem[i].min, sstop->elem[i].second); printf("\n\n\n"); } if(wwait->front->next==NULL) { printf("便道没有车辆等候\n"); } else { printf("便道车辆信息\n\n"); x=wwait->front->next; while(x->next!=NULL) { y=x->data->carnum; printf("在您前面有%d辆车等候\n",i-1); printf("车主姓名:%s\n",x->data->name); printf("车牌号:%d\n",y); x=x->next; i++; } y=x->data->carnum; printf("在您前面有%d辆车等候\n",i-1); printf("车主姓名:%s\n",x->data->name); printf("车牌号:%d\n",y); x=x->next; } } int main() { InitStack(&sstop); InitQueue(&wwait); InitStack(&temp); menu(); }
评论
    相关推荐