停车场管理系统(C语言)

1、问题描述

设有一个可以停放n辆汽车的狭长停车场,它只有一个大门可以供车辆进出。车辆按到达停车场时间的早晚依次从停车场最里面向大门口处停放(最先到达的第一辆车放在停车场的最里面)。如果停车场已放满n辆车,则后来的车辆只能在停车场大门外的便道上等待,一旦停车场内有车开走,则排以便道上的第一辆车就进入停车场。停车场内如有某辆车要开走,在它之后进入停车场的车都必须先退出停车场为它让路,待其开出停车场后,这些辆再依原来的次序进场。每辆车在离开停车场时,都应根据它在停车场内停留的时间长短交费。如果停留在便道上的车未进停车场时,允许其离去,不收停车费,并且仍然保持在便道上等待的车辆的次序。

2、设想 

该停车场管理系统由两个栈和两个队列实现,一个栈作为停车场,另一个栈作为临时停车点,便于让停车场内汽车离开,一个队列作为便道,另一个队列作为临时便道,便于让便道内汽车离开。

3、软件 

使用的软件是Dev-C++,版本为5.11版本,部分版本可能会提示出错。

4、要求

(1)系统功能以菜单方式显示;

(2)车辆编号为字符型;

(3)设置屏幕字体颜色;

(4)单位时间收费值可以修改。

5、系统的构想

(1)该停车场管理系统分为一个总系统和1两个子系统,分别是停车场管理总系统、停车场管理员系统和停车场消费者系统;

(2)由停车场管理总系统可以进入两个子系统;

(3)停车场管理员系统功能

①查看停车场内车辆信息,输出该停车场所有车辆的车牌号、位序、进入时间和消费金额;

②查看停车场便道内车辆信息,输出该停车场便道内车辆的车牌号和位序;

③查找车辆的目前的信息,客户输入车牌号,可输出目前该车牌号在停车场内的所有信息(前     提:该停车场内存在客户输入的车牌号的车辆),否则输出该车牌号不存在;

④更改收费标准;  

⑤返回停车场总系统;

⑥直接退出程序;

(4)停车场消费者系统功能

①查看停车场车辆数量,输出该停车场内共有多少辆车;

②查看便道的车辆数量,输出该停车场便道内共有多少量车

③进入停车场,客户进入该停车场停车(前提:停车场或便道有停车位),否则停车失败;

④离开停车场,客户输入车牌号码,相应车牌的车辆出停车场;

⑤离开停车场便道,客户输入车牌号码,相应车牌的车辆出便道;

⑥返回停车场总系统;

⑦直接退出程序。

6、运行结果

(1)首页界面

 (2)停车场管理员系统界面

 (3)停车场消费者系统

 (4)输入选择错误的情况

 (5)停车场管理系统部分功能

 

 (6)退出系统

 7、代码部分

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#define MAX1 5
#define MAX2 MAX1-1

typedef struct{
	int TimeIn;				
	int TimeOut;			
	char ct[50];
	char Lincense[10];		
}Car;

typedef struct{
	Car Stop[MAX1];		
	int top;			
}Stopping;

typedef struct{
	Car Pave[MAX2];		
	int count;				
	int front, rear;		
}Pavement; 

typedef struct{
	Car Let[MAX1];		
	int top;				 
}Buffer;						

typedef struct{					
	Car Wait[MAX2];		
	int count;				
	int front, rear;		
}Waiting; 

float price=1;
Stopping s;
Pavement p;
Buffer   b;
Car      c;
Waiting  w;
char     C[10];
 
void C_Play1();
void C_Play2();
void C_Play3();
void C_Play3_1();
void C_Play3_2();
void C_Play4();
void C_Play4_1();
void C_Play5();
void C_Play5_1();
void A_Play1();
void A_Play2();
void A_Play3();
void A_Play4();
void A_Play5();

void C_Play1()
{
	int i=0,j=0;
	i=s.top;
	j=i+1;
	if(j>0)
	{
		printf("\n\t该停车场内共有%d辆车\n",s.top+1);
	}
	else
	{
		printf("\n\t该停车场内无车辆"); 
	}
}

void C_Play2()
{
	int i=0;
	i=p.count;
	if(i>0)
	{
		printf("\n\t该停车场便道内共有%d辆车\n",i);
	 } 
	else if(i<=0)
	{
		printf("\n\t该停车场便道内无车辆\n"); 
	}
}

void C_Play3()
{
	int i=0,j=0,k=0,z=0,y=0;
	y=MAX1-1;
	k=p.front;
	i=s.top;
    j=(p.rear)-(p.front);
	if(s.top<MAX1&&p.count<MAX2)
	{
		printf("\n\t请输入您的车牌号码:");
    	scanf("%s",C);
	 } 
	else
	{
		printf("\n\t该停车场和停车场便道已满,欢迎下次再来!");
		return;
	}
	while(i!=-1)
	{
		if(strcmp(s.Stop[i].Lincense,C)==0)
		{
			printf("\t该车辆已在停车场内,请重新输入车牌号");
			C_Play3();
			return;
		}
		i--;
    }
    while(j!=0)
    {
	    if(strcmp(p.Pave[k].Lincense,C)==0)
	    {
	 	    printf("\t该车辆已在停车场便道内,请重新输入车牌号。");
	        C_Play3();
	        return;
	    }
	    j--;
	    k++;
	}
	if(s.top<MAX1-1)
	{
		C_Play3_1();
	}
	else 
	{
       	if(p.count==MAX2)
       	{
  	    	printf("\t该停车场与便道已满,请您下次再来"); 
     	}
		else
		{
	    	C_Play3_2();
	    }
    }
}
 
void C_Play3_1()
{
	time_t t1;
	long int t=time(&t1);	
	char* t2;				
	t2=ctime(&t1); 
	s.Stop[++s.top].TimeIn=t;
	strcpy(s.Stop[s.top].ct,t2);
	strcpy(s.Stop[s.top].Lincense,C);
	printf("\n\t车牌号码为:%s		位置:第%d位		当前时间为:%s",C,s.top+1,t2);
	printf("\t车辆已停好!\n");
}

void C_Play3_2()
{
   	strcpy(p.Pave[p.rear].Lincense,C);
   	p.rear++;
   	p.count++;
   	printf("\t由于停车场内已满,您车牌号为【%s】的车暂时停在便道上",C);
}

void C_Play4()
{
	int i=0,k=0;
	i=s.top;
	k=1;
	if(s.top==-1)
	{
		printf("\n\t该停车场内目前无车辆停放");
		return;
	}
	if(s.top>=0)
	{
		printf("\t请输入您的车牌号码:");
    	fflush(stdin);
	    scanf("%s",C);
	    if(s.top>=0)
      	{
	    	while(i!=-1)
	    	{
		    	if(strcmp(s.Stop[i].Lincense, C)==0)
		       {
	        		C_Play4_1();
     	     	}
		     	i--;
		     	k=k*strcmp(s.Stop[i].Lincense, C);
	     	}
	     	while(k!=0)
	     	{
	     		printf("\n\t您输入的车牌号码不在该停车场内\n");
				break; 
			 }
    	}
	}
}
 
void C_Play4_1()
{
	while(s.top>=0)
	{	
		if(strcmp(s.Stop[s.top].Lincense, C)==0)
		{
			break;
		}
		else
		{
			strcpy(b.Let[b.top++].Lincense,s.Stop[s.top].Lincense);
	     	printf("\t由于停车场后方车辆需出去,车牌号码为【%s】的汽车暂时退出停车场让后方车辆驶出停车场\n", s.Stop[s.top--].Lincense);	 
		}
	}
	printf("\n\t车牌号码为【%s】的汽车从停车场开走", s.Stop[s.top].Lincense);
	time_t t1;
	long int t = time(&t1);
	s.Stop[s.top].TimeOut = t;
	char* t2;
	t2 = ctime(&t1);
	printf("\n\t离开时间:%s\t停车费用共:%0.2f元\n",t2,price*(s.Stop[s.top].TimeOut-s.Stop[s.top].TimeIn)/60);
	s.top--;
	while(b.top > 0)
	{
		strcpy(s.Stop[++s.top].Lincense, b.Let[--b.top].Lincense);
		printf("\n\t车牌号码为【%s】的汽车重新进入停车场,位置为第%d位",b.Let[b.top].Lincense,s.top+1);
	}
	while(s.top<MAX1-1)
	{
		if(0==p.count)
		{
			break;
		 }
		else
		{
			time_t t1;
			long int t=time(&t1);
			char* t2;
			strcpy(s.Stop[++s.top].Lincense,p.Pave[p.front].Lincense);
			printf("\n\n\t车牌号码为【%s】的汽车从停车场便道进入停车场的第%d个车位",p.Pave[p.front].Lincense,s.top+1);
			s.Stop[s.top].TimeIn=t;
			p.front++;
			p.count--;
		}
	}
}

void C_Play5()
{
    int z=0,i=0,k=0,j=0;
    z=p.front;
    j=p.count;
    k=1;
    if(p.count==0)
    {
        printf("\n\t该停车场便道内目前无车辆停放\n");
		return; 
    }
    else
    {
        printf("\n\t请输入您的车牌号码:");
        fflush(stdin);
        scanf("%s",&C);
        if(p.count!=0)
        {
            while(j!=0)
            {
                if(strcmp(p.Pave[z].Lincense,C)==0)
                {
                    C_Play5_1();
                }
                k=k*strcmp(p.Pave[z].Lincense,C);
                j--;
                z++;
            }
            while(k!=0) 
            {
            	printf("\n\t您输入的车牌号码不在该停车场便道内\n");
            	break;
			}
        }
    }
}

void C_Play5_1()
{
	int i=0; 
	while(p.count>0)
	{					 
		i=p.front; 
		if(strcmp(p.Pave[i].Lincense,C)==0)
		{
			break;	
		}
		printf("\n\t由于停车场便道后面的车辆需要出去,车牌号为【%s】的汽车暂时从停车场便道进入临时便道\n",p.Pave[p.front].Lincense);
		strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense);
		p.front++;	
		w.rear++;	
		w.count++;							
		p.count--;							
	}
	printf("\n\t车牌号为【%s】的汽车从停车场便道上开走,不收取任何费用!\n\n",p.Pave[i].Lincense); 
	p.front++;
	p.count--;
	while(p.count>0)
	{		
		printf("\n\t由于便道内的车辆需要出便道,车牌号为【%s】的汽车暂时从停车场便道进入临时便道\n",p.Pave[p.front].Lincense);
		strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense);
		p.front++;
		w.rear++;
		w.count++;
		p.count--;
	}
	while(w.count>0)
	{		
		printf("\n\t牌照为【%s】的汽车返回便道\n",w.Wait[w.front].Lincense);
		strcpy(p.Pave[p.rear].Lincense, w.Wait[w.front].Lincense);
		w.front++;	 
		p.rear++;
		w.count--;
		p.count++;
	}
}

void A_Play1()
{
	int i=0;
	i=s.top;
	time_t t1;
	long int t=time(&t1);
	if(i>=0)
	{
		printf("\n\t停车场内车辆信息如下:\n");
		printf("\t车牌号		位置		停放时间		目前要支付的停车费用");
		for(i;i>=0;i--)
		{
			printf("\n\t%s		第%d位 		%d分%d秒			%0.2f元\n\n",s.Stop[i].Lincense,i+1,(t-s.Stop[i].TimeIn)/60,(t-s.Stop[i].TimeIn)%60,price*(t-s.Stop[i].TimeIn)/60);
		}
	}
	else if(i<0) 
	{
		printf("\n\t该停车场目前没有车辆停放\n\t"); 
	}
}
 
void A_Play2()
{
	int i=p.front;
	int k=1;	
	if(p.count==0)
	{
		printf("\t\n\t该停车场便道内目前没有车辆\n"); 
	}
	else
	{
		printf("\t便道内车辆信息如下:\n"); 
    	printf("\t车牌号		位置\n"); 
    	while(i!=p.rear&&p.count>=1) 
     	{
	    	printf("\t%s		第%d位\n", p.Pave[i].Lincense, k++);
	    	i++;
     	}
	} 
}

void A_Play3()
{
	int i=0,j=0,k=0,f=0,g=0,h=0,z=0; 
	i=s.top;
	f=p.count;
	g=p.front;
	h=p.rear;
	z=(p.rear)-(p.front);
	k=1;
	time_t t1;
	long int t=time(&t1);
	if(s.top>=0||p.count>0)
	{
		printf("\t请输入要搜索的车牌号:");
    	fflush(stdin);
    	scanf("%s",&C);
    }
	if(s.top>=0)
	{
		while(i!=-1)
		{
			if(strcmp(s.Stop[i].Lincense, C)==0)
			{
			printf("\n\t此汽车在停车场内,信息如下:\n");
			printf("\t车牌号		位置		停车费用		进入时间");
			printf("\n\t%s		第%d个		%0.2f元		%s",s.Stop[i].Lincense,i+1,price*(t-s.Stop[i].TimeIn)/60,s.Stop[i].ct);
			break; 
			} 
			i--;	
		}
	}
    if(p.count>0)
	{	 		
		while(g!=h)
		{
			if(strcmp(p.Pave[g].Lincense,C)==0)
			{
				printf("\n\t此汽车在停车场便道上,信息如下:");
				printf("\n\t车牌号		位置\n");
				printf("\t%s		第%d位",p.Pave[g].Lincense,k);
				break;
			}
			g++;
			k++;
		}	
	}
	if(s.top<0&&p.count<=0)
	{
		printf("\n\t该停车场和便道内无车辆\n"); 
		return;
	}
	while(strcmp(s.Stop[i].Lincense, C)!=0&&strcmp(p.Pave[g].Lincense,C)!=0)
	{
		printf("\n\t此车牌号码的车辆不在该停车场和停车场便道内");
		break;
	}
}

void A_Play4()
{
	printf("\n\t当前的收费为%0.2f元/分钟\n",price);
	printf("\t请输入更改后的收费标准(元/分钟):");
	fflush(stdin);
	scanf("%4f",&price); 
	printf("\t当前收费标准为%0.2f元/分钟\n",price);
}


int main()
{
	s.top=-1;
	b.top=-1;
	p.rear=0;
	p.count=0;
	p.front=0;
	w.count=0;
	w.front=0;
	w.rear=0; 
	begin: 
	system("cls");
	system("color 0A");
	printf("\t**************************************************\n\t");
	printf("**		欢迎使用停车场总系统		**\n");
	printf("\t**************************************************\t\n\t");
	printf("**		请选择您需要进行的操作		**\n\t");
	printf("*	\t1、进入停车场管理员系统		 *\n\t");
	printf("*	\t2、进入停车场消费者系统		 *\n\t");
	printf("*	\t3、直接退出程序		     	 *\n\t");
	printf("##################################################\n\t"); 
	printf("请输入您的的选择:");
	int z=0;
	fflush(stdin);
	scanf("%d",&z); 
    if(z==1)
	{
		while(1)
		{
	    	system("cls");
	        system("color 0B");
	        printf("\t**********************************************************\n\t");
	     	printf("**		欢迎使用停车场管理员系统		**\n");
	     	printf("\t**********************************************************\n\t");
         	printf("**		请选择您需要进行的操作			**\n\t");
            printf("*		1、查看停车场内车辆信息		 	 *\n\t");
            printf("*		2、查看便道的内车辆信息			 *\n\t");
            printf("*		3、查找车辆的目前的信息			 *\n\t"); 
            printf("*		4、更改收费标准				 *\n\t");
            printf("*		5、返回停车场总系统			 *\n\t");
            printf("*		6、直接退出程序				 *\n\t");
			printf("##########################################################\n\t"); 
            printf("请输入您的选择:");
            int i=0,l=0;
            fflush(stdin);
            scanf("%d",&i);
            if(i==1)
            { 
                A_Play1();
	     	}
	    	if(i==2)
	    	{
	    		A_Play2();
	    	}
	     	if(i==3)
	    	{
	    		A_Play3();
	    	}
	     	if(i==4)
	    	{
	    		A_Play4();
	    	}
	    	if(i==5)
	    	{
	    		goto begin;
	    	 } 
	    	if(i==6)
	    	{
	    		printf("\n\t欢迎下次使用!\n");
	    		sleep(2); 
				break;
			}
			if(i>6||i<1)
			{
				system("cls");
				system("color 0C"); 
				printf("\n\t输入选项错误,请在1~6内选择\n\n");
			}
	    	printf("\n\n\t输入键继续使用停车场管理员系统"); 
	    	getch();
	    }
    }
	else if(z==2)
	{
		while(1)
		{
		    system("cls");
	    	system("color 0B");
	    	printf("\t**********************************************************\n\t");
         	printf("**		欢迎使用停车场消费者系统		**\n");
         	printf("\t**********************************************************\n\t");
            printf("**		请选择您需要进行的操作			**\n\t");
            printf("*		1、查看停车场车辆数量			 *\n\t");
            printf("*		2、查看便道的车辆数量			 *\n\t");
            printf("*		3、进入停车场				 *\n\t");
            printf("*		4、离开停车场				 *\n\t");
            printf("*		5、离开停车场便道			 *\n\t");
            printf("*		6、返回停车场总系统			 *\n\t");
            printf("*		7、直接退出程序				 *\n\t");
            printf("*  收费标准:本停车场按照%0.2f元/分钟计费,希望您能理解   *\n\t",price);
            printf("##########################################################\n\t"); 
            printf("请输入您的选择:"); 
            int k=0,l=0;
            fflush(stdin);
            scanf("%d",&k);
            if(k==1)
            { 
                C_Play1();
	    	}
	     	if(k==2)
     		{
	     		C_Play2();
	    	}
	    	if(k==3)
    		{
	    		C_Play3();
	      	}
    		if(k==4)
    		{
	    		C_Play4();
    		}
    		if(k==5)
    		{
    			C_Play5();
			}
	    	if(k==6)
	    	{
	    		goto begin;
	    	}
	    	if(k==7)
	    	{
	    		printf("\n\t欢迎下次使用!\n");
	    		sleep(2); 
				break;
			}
			if(k>7||k<1)
			{
				system("cls");
				system("color 0C"); 
				printf("\n\t输入选项错误,请在1~7内选择\n\n");
			}
	    	printf("\n\n\t任意键继续使用停车场消费者系统");
			getch(); 
	    }
    }
    else if(z==3)
	{
		printf("\n\t欢迎下次使用!\n");
	    sleep(1); 		
	 } 
    else
	{
		system("cls");
		system("color 0C");
		printf("\t输入错误,请重新输入");
		sleep(2); 
		goto begin;
		return 0; 
	}
}

8、结语

该停车场管理系统代码由于是本人和另一位大一舍友一起写的,代码的注释部分我们并没有写出来,代码也可能存在许多不足之处,有疑问可以留言交流。

  • 50
    点赞
  • 280
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值