• 停车场规划


    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents


    问题描写叙述:

    因为我国经济发展迅速,车辆的拥有量也跟着大幅上升。城市拥堵的情况越来越严重。停车场越来越成为一种稀缺资源,因此就有了要求高效利用停车场的需求。
    控制稀缺资源的有效办法就是收费。停车场的收费规则是,1小时以内免费。超过1小时,每小时6元钱。

    人工计费费时费力。并且easy出错,希望你们开发一个软件来帮助辛勤的保安们来管理停车场。

    1)对车位进行管理:
    能查询一共同拥有多少车位
    能查询有多少空的车位
    能查询占用车位相应的车牌号和停靠时间
    2)收费管理:
    能查询如今停靠了多少车
    可以记录车辆的停靠时间
    依据依据停靠时间计算出费用

    代码例如以下:

    #include<cstdio>
    #include<cstring>
    #include<malloc.h>
    #include<ctime>
    #define NULL 0
    # define LEN sizeof(struct node)
    
    struct node
    {
    	int num; //序号
    	char numble[47]; //车牌
    	char intime[47]; //进入时间
    	char outtime[47]; //出去时间
    	struct node *next;
    };
    
    struct node *creat()//创建一个有十个车位的停车场链表
    {
    	int n;
    	struct node *head,*p,*tail;
    	head = NULL;
    	for(n = 1 ; n <= 10 ; n++ )
    	{
    		p = (struct node*)malloc(LEN);
    		p->num = n ; 
    		strcpy(p->numble,"0");
    		strcpy(p->intime,"0");
    		strcpy(p->outtime,"0");
    		if(n == 1)
    		{
    			head = p;
    		}
    		else
    			tail->next = p;
    		tail = p;
    	}
    	tail->next = NULL;
    	return(head);
    }
    
    void print(struct node *head)
    {
    	struct node *p;
    	printf("当前停车场信息例如以下:
    
    ");
    	p=head;	
    	if(head!=NULL)
    	{
    		do
    		{
    			printf("车场序号:     %-6d车牌号码:      %5s
    ",p->num,p->numble);
    			printf("进入时间:%32s
    ",p->intime);
    			printf("驶出时间:%32s
    ",p->outtime);
    			printf("*******************************************
    ");
    			p=p->next;
    		}while(p!=NULL);
    	}
    	
    }
    
    void Money(struct node *head)//计费
    {
    	int n,m;
    	struct node *p;
    	time_t rawtime;
    	struct tm*timeinfo;
    	time(&rawtime);
    	timeinfo = localtime(&rawtime);
    	printf("亲、请输入你要计费的车辆序号
    ");
    	scanf("%d",&n);
    	p = head;
    	while(p->num != n)
    	{
    		p = p->next; //寻找相应序号
    	}
    //	int tt = asctime(timeinfo) - p->intime;
    	char time1[47],time2[47];
    	strcpy(time1,asctime(timeinfo));
    	strcpy(time2,p->intime);
    	int len1 = strlen(time1);
    	int len2 = strlen(time2);
    	int t1= 0,t2 = 0;
    	for(int i = 0 ; i < len1 ; i++)
    	{
    		if(time1[i] == ':')
    		{
    			t1 = t1*10+time1[i-2]-'0';
    		}
    	}
    	for( i = 0 ; i < len2 ; i++)
    	{
    		if(time2[i] == ':')
    		{
    			t2 = t2*10+time2[i-2]-'0';
    		}
    	}
    	int tt = t2 - t1;
    	if(tt > 1)
    		m = (tt-1)*6;
    	else
    		m = 0;
    	printf("此次停车共计费用为: %d
    ",m);
    } 
    
    void in(struct node *head)//车辆进入停车场
    {
    	char s[47];
    	time_t rawtime;
    	struct tm*timeinfo;
    	time(&rawtime);
    	timeinfo=localtime(&rawtime);
    	struct node *p;
    	p = head;
    	while((p!=NULL)&&(strcmp(p->numble,"0")!=0))//查找空车位
    	{
    		p=p->next;
    	}
        if(p!=NULL)
    	{
    		printf("请输入当前的车牌号!
    ");
    		scanf("%s",s);
    		printf("您的停车位是:[%d]号!
    ",p->num);
    		strcpy(p->numble,s);
    		strcpy(p->intime,asctime(timeinfo));
    	}
    	else
    	{
    		printf("停车场已满,亲、请退出操作!
    ");
    	}
    	
    }
    
    void out(struct node* head)
    {
    	struct node *p;
    	int n;
    	time_t rawtime;
    	struct tm*timeinfo;
    	time(&rawtime);
    	timeinfo = localtime(&rawtime);
    	printf("请输入车辆的序号!
    ");
    	scanf("%d",&n);
    	p = head;
    	while(p->num != n)
    	{
    		p = p->next; //寻找相应序号
    	}
    	strcpy(p->outtime,asctime(timeinfo));
    	printf("车牌    号码为:[%s]
    ",p->numble);
    	printf("车辆进入时间为:%s
    ",p->intime);
    	printf("车辆驶出时间为:%s
    ",p->outtime);
    	strcpy(p->numble,"0");
    	strcpy(p->intime,"0");
    }
    
    void main()
    {
    	int n;
    	struct node *head;
    	head=NULL;
    	printf("请输入相应的数字,进行操作
    ");
    	printf("0:退出程序
    ");
    	printf("1:创建停车场信息
    ");
    	printf("2:输出停车场信息
    ");
    	printf("3:车辆进入停车场
    ");
        printf("4:车辆驶出停车场
    ");
    	printf("5: 车辆停车所需费用
    ");
    	printf("请输入相应的数字,进行操作
    ");
    	scanf("%d",&n);
    	while(n!=0)
    	{
    		switch(n)
    		{
    		case 1:
    			head=creat();
    			break;
    		case 2: 
    			print(head);
    			break;
    		case 3:
    			in(head); 
    			break;
    		case 4:
    			out(head);
    			break;
    		case 5:
    			Money(head);
    			break;
    		default: 0;
    		}
    		printf("请输入相应的数字。进行操作
    ");
    		scanf("%d",&n);
    	}
    }



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    codephp 自研PHP框架并实现composer包管理
    收藏!17 张程序员专属壁纸(使用频率很高)
    git reset hard HEAD^后显示more?的解决方案
    如果有一天我不得不离开IDE,没有其它原因,一定是ta ?
    centos7 下安装composer失败
    不知道如何技术变现?19个程序员接私活平台汇总
    MySQL常见面试题:什么是主从延时?如何降低主从延时?
    Nginx服务器,修改html 文件后页面不更新生效(已解决)
    《Microsoft SQL Server 2005: 数据库基础由入门到精通》书评
    讲座资源:Silverlight In Action
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4906788.html
Copyright © 2020-2023  润新知