1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#include<iostream>
#include <time.h>
#include<string>
#include<cmath>
using namespace std;
int process_time(int, int, int, int);
int process_total(int, char, int);
string process_day(int);
int process_balance(int, int);
void main( )
{
char date[9];
int hours, hours_out, mins, mins_out, time_spent, total, day, balance, pay_money;
char J_card;
string fday;
//input
cout<<"Enter day, represented by number, 8 for public holidays: ";
cin>>day;
cout<<"Enter time in:";
cin>>hours>>mins;
cout<<"Enter time out:";
cin>>hours_out>>mins_out;
cout<<"Are you a J_card user? Type Y/N: ";
cin>>J_card;
time_spent=process_time(hours, mins, hours_out, mins_out);
total=process_total(time_spent, J_card, day);
fday=process_day(day);
_strdate_s(date);
//output
cout<<"********************************************************************************";
cout<<"RECEIPT: "<<endl;
cout<<"Date is: "<<date<<endl;
cout<<"Day entered is: "<<fday<<endl;
cout<<"Time in is: "<<hours<<":"<<mins<<endl;
cout<<"Time out is: "<<hours_out<<":"<<mins_out<<endl;
cout<<"Time spent is: "<<time_spent<<"min"<<endl;
cout<<"Total price is: RM"<<total<<endl;
cout<<"Enter your money: RM";
cin>>pay_money;
balance=process_balance(total,pay_money);
cout<<"Your balance is: RM"<<balance<<endl;
cout<<"Thank you for coming to aeon shopping centre"<<endl;
system("pause");
}
//Process the total time spent
int process_time(int hours, int mins, int hours_out, int mins_out)
{
int time_in, time_out, time_spent;
time_in=(hours*60+mins);
time_out=(hours_out*60+mins_out);
time_spent=(time_out-time_in);
return time_spent;
}
//To process the total price
int calculateCharge(int minutesparked, int day, char jcard)
{
const int freehours = 1; // hours free
const int maxweekday = 5; // max weekday charge
const int maxweekend = 10; // max weekend/holiday charge
const int weekdayhourlyrate = 1; // weekday rate
const int weekendhourlyrate = 2; // weekend rate
const int jcardallowedhours = 6; // JCard hours before max
const int nonjcardallowedhours = 4; // nonJCard hours before max
int hourscharged = 0; // hours beyond free hour
int parkingcharge = 0; // rate to be calculated and returned by function
//find number of hours over free hours
//round up partial hours with ceil (in <cmath>)
if (minutesparked > freehours*60)
hourscharged=ceil((minutesparked-60)/60.0);
//calculate parking charges
if (jcard == 'y' || jcard == 'Y')
{
//weekday parking
if (day==1 || day==2 || day==3 || day==4 || day==5)
{
if (hourscharged == 0)
parkingcharge = 0;
else if (hourscharged > jcardallowedhours)
parkingcharge = maxweekday;
else
parkingcharge = hourscharged * weekdayhourlyrate;
}
else//weekend parking
{
if (hourscharged == 0)
parkingcharge = 0;
else if (hourscharged > jcardallowedhours)
parkingcharge = maxweekend;
else
parkingcharge = hourscharged * weekendhourlyrate;
}
}
else //not a jcard holder
{
//code here
}
return parkingcharge; // return calculated charge to main
}
//to convert day back to full words form (return 0 problem)
string process_day(int day){
switch (day){
case 1 : return"Monday";break;
case 2 : return"Tuesday";break;
case 3 : return"Wednesday";break;
case 4 : return"Thursday";break;
case 5 : return"Friday";break;
case 6 : return"Saturday";break;
case 7 : return"Sunday";break;
case 8 : return"Public Holiday";break;
default:cout<<"Error code entered!"<<endl; return 0; break;
}
}
//process balance (No problem)
int process_balance(int total, int pay_money)
{
int balance;
if(pay_money<total)
cout<<"Insufficient amount of money! Restart again!";
else
if (pay_money>total)
balance=(pay_money-total);
return balance;
}
|