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
|
#include <iostream>
using namespace std;
const int MinsInHour = 60;
const float Hourlyfee = 1.50;
const float minfee = 7.00;
const int NoOfCustomers = 10;
void inputAndValidate(int & entranceH, int & entranceM, int & exitH, int & exitM)
{
do
{
cout << "Enter the entry time: ";
cin >> entranceH >> entranceM;
cout << "Enter the exit time: ";
cin >> exitH >> exitM;
} while(((entranceH < 0) || (entranceM > 24)) && ((entranceM < 0) || (entranceM > 24)) && ((exitH < 0) || (exitH > 24)) && ((exitM < 0) || (exitM > 24)));
if (entranceH == 24)
entranceM = 0;
if (exitH == 24)
exitM = 0;
}
void convertToMinutes(int entranceH, int entranceM, int exitH, int exitM, int & entranceTM, int & exitTM)
{
entranceTM = (60 * entranceH) + entranceM;
exitTM = (60 * exitH) + exitM;
}
void convertBackToTime(int entranceTM, int exitTM, int & parkedH, int & parkedM)
{
int total = exitTM - entranceTM;
parkedH = total / MinsInHour;
parkedM = total % MinsInHour;
}
float calcCharge(int parkedH, int parkedM)
{
float total = 0.0;
if (parkedH >= 3)
{
total += minfee;
total += (parkedH * 1.50);
}
else if (parkedH < 3)
total += parkedH * 1.50;
else
total += 1.50;
return total;
}
int main( )
{
int entranceHour, entranceMinutes;
int exitHour, exitMinutes;
int entranceTimeInMins, exitTimeInMins, minutesParked;
int parkedHours, parkedMinutes;
float charge, totalCharges;
totalCharges = 0.0;
cout << "..............PARKING TIME.............." << endl;
for (int i = 1; i <= NoOfCustomers; i++)
{
cout << endl;
inputAndValidate(entranceHour, entranceMinutes, exitHour, exitMinutes);
cout << "Entry; " << entranceHour << "H" << entranceMinutes << endl;
convertToMinutes(entranceHour, entranceMinutes, exitHour, exitMinutes, entranceTimeInMins, exitTimeInMins);
cout << "Exit: " << exitHour << "H" << exitMinutes << endl;
convertBackToTime(entranceTimeInMins, exitTimeInMins, parkedHours, parkedMinutes);
cout << "Parked Time: " << parkedHours << "H" << parkedMinutes << endl;
charge = calcCharge(parkedHours, parkedMinutes);
totalCharges += charge;
cout << "Charge: R" << charge << endl;
}
cout << " Total charge: R" << totalCharges << endl;
return 0;
}
|