当前位置:编程学习 > C/C++ >>

用C写的停车收费代码

某市停车场收费标准为:

小型车:首小时内每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,int mi,int ey,int em,int ed,int eh,int emi)
{
    int *point;
 int month_content_day = 0;
 int month_mod_value = 0;
    point =GenerateMonth(yy);
 //count days per month
 month_content_day = point[mm];
 dd++;
 if(dd > month_content_day )
 {
  mm++;
  dd=1;
 }
 //current month
 if(mm > 12)
 {
  month_mod_value = 1;
  yy++;
  mm =1;
 }
 else
 {
  month_mod_value = mm;
 }
 if(ey>yy || em>=month_mod_value && ed>dd || em>=month_mod_value && ed>=dd && eh>hh || em>=month_mod_value && ed>=dd && eh>=hh && emi>=mi)
 {
  return true;
 }
 return false;
}

//Check now of month  or less than target to park car month
bool CheckMonth(int  yy,int mm,int dd,int hh,int mi,int ey,int em,int ed,int eh,int emi)
{
 int sm = mm;
 if (sm+1>12)
 {
  sm =dd = 1;
  yy++;


 }
 
 if((ey>= yy && em>sm && ed>dd) || (ey>= yy && em>sm && ed>=dd &&eh>hh) || (ey>= yy && em>sm && ed>=dd &&eh>=hh && emi>=mi) || (ey>yy && em != 1) || (ey>yy && em == 1 && sm != 12))
 {
  return true;
 }
    return false;

 
}
//statistics how many days  in complete year
int StatisticsYearDays(int yy,int mm,int dd,int ed)
{
 
 int sumday  = 0;
 int *cnt ;
 int idx = 0;
 
 cnt =GenerateMonth(yy);
 //sum current year day

 while (idx <=12)
 {
  if(idx == 0)
  {
   sumday = cnt[mm] - dd;
  }
  else if (idx == 12 && mm != 12)
  {
   sumday = sumday +ed;
  }
  else
  {
   if(mm >12)
   {
    mm=1;
    yy++;
       cnt =GenerateMonth(yy);
   }
   sumday = sumday +cnt[mm];
  }
  idx++;
  mm++;
 }

 //while (idx <= 12)
 //{
 // sumday = sumday+cnt[idx];
 // idx++;
 //}
 //idx = 1;
 //cnt =GenerateMonth(yy+1);
 ////sum next year day
 //while (idx < em)
 //{
 // sumday = sumday+cnt[idx];
 // idx++;
 //}

 return sumday;
}

//statistics how many days  in complete month
int StatisticsMonthDays(int yy,int mm,int dd,int hh,int mi,int ey,int em,int idx)
{
 int sumday  = 0;
 int *cnt ;
 cnt =GenerateMonth(yy);

 //statistics current month
 if(idx == 0 && dd==0  && hh==0 && mi==0)
 {
  //complete month
  sumday = sumday+cnt[mm];
 
 }
 else if( mm < em)
 {
  sumday = sumday+cnt[mm];
 }
 else if(ey>yy)
 {
  sumday = sumday+cnt[mm];
 }
 idx++;
 return sumday;
}
//Statistics all Hour of day
double StatisticsHourOfDay(int car_type,int sumday)
{
 double result  = 0;
 if(car_type == 1)
 {
  //small car
  result = 60/Per_time * Smallcar_att * 14 * sumday;
 }
 else
 {
  result = 60/Per_time * Bigcar_att * 14 * sumday;
 }
 return result;
}
// Statistics all Hour of night
double StatisticsHourOfNight(int car_type,int sumday)
{
 double result = 0;
 if(car_type ==1)
 {
  result =  Smallc

补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,