用C写的停车收费代码

这是一个用C语言编写的停车收费程序,根据输入的车型、进场和出场时间,计算停车费用。程序考虑了不同车型的收费标准,包括白天和晚上的不同费率,并处理了跨时间段的计算。
摘要由CSDN通过智能技术生成

某市停车场收费标准为:

小型车:首小时内每15分钟收费:2.5元,首小时后每15分钟收费:3.75

大型车:首小时内每15分钟收费:5元,首小时后每15分钟收费:7.5

夜间收费标准(21:00---7:00)一律执行小型车每两小时1元,大型车每两小时2元

请编写程序,输入车型和进场时间(XXXX-XX-XX XX:XX)以及出场时间,计算停车时间,然后算出应收金额(请注意白天和晚上跨时间段问题,比如早上6.30进场,7.15出场;白天不够15分钟部分按照15分钟计算;夜间不够2小时部分也按2小时计算)。

 

// To_park_car.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <math.h>
#include <time.h>
 const int   Bigcar_rule   = 5;     //day per 15 minutes
 const float Smallcar_rule = 2.5;   //day per 15 minutes

 const float Bigcar_att   = 7.5;    //past 15 minutes in day
 const float Smallcar_att =3.75;    //past 15 minutes in day

 const int   Bigcar_night = 2;      //night per an hour
 const int   Smallcar_night = 1;    //night per an hour

 const int   Per_time = 15;         // 15 minutes

//Check input value
bool Compare(int sy,int sm,int sd,int sh,int smi,int ey,int em,int ed,int eh,int emi)
{
 if(ey > sy ||(ey>=sy && em> sm) || (ey>=sy && em>= sm && ed>sd) ||(ey>=sy && em>= sm && ed>=sd && eh>sh)||(ey>=sy && em>= sm && ed>=sd && eh>=sh && emi>smi))
 {
  return true;
 }
 else return false;
}

/// Generates all month of year
int *GenerateMonth(int year)
{
 int *month =new int[13];
 
  month[0] = 0;
  month[1] = 31;
  if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
        {
      month[2] = 29;
  }
  else
  {
   month[2] =28;
  }
  month[3] = 31;
  month[4] = 30;
  month[5] = 31;
  month[6] = 30;
  month[7] = 31;
  month[8] = 31;
  month[9] = 30;
  month[10]= 31;
  month[11]= 30;
  month[12]= 31;
 return month;
}
//Check now of hour  or less than target to park car hour
bool CheckHour(int sy,int sm,int sd,int sh,int smi,int ey,int em,int ed,int eh,int emi)
{
 int hour = sh;
 if(hour >24)
 {
  hour=1;
  sd++;
 }
 if(hour >=21 || sh<7)
 {
  if(em>sm || ed>sd || ed>=sd && eh>hour || ed>=sd && eh>=hour && emi>=smi)
  {
   return true;
  }
 }
    if(ey > sy || ed>sd || ed>=sd && eh>hour+1 || ed>=sd && eh>hour && emi>=smi|| em>sm)
 {
  return true;
 }
 return false;
}
//Check now of day  or less than target to park car date
bool CheckDay(int yy,int mm,int dd,int hh,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值