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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#include <iostream>
using namespace std;
//constants for rates
#define firstCarRate 0.00 //first rate for cars.
#define secondCarRate 1.25 //second rate for cars.
#define firstTruckRate 3.75 //first rate for trucks.
#define secondTruckRate 4.50 //second rate for trucks.
#define firstBusRate 2.00 //first rate for buses.
#define secondBusRate 2.50 //second rate for buses.
//getInfo Function Prototype.
void getInfo(char *vehicle, int *hourIn, int *minIn, int *hourOut, int *minOut);
//time function prototype.
void time(int hourIn, int minIn, int hourOut, int minOut, int *houtParkTime, int * minParkTime, int *roundedTotal, int *round);
//rate function prototype.
void rate(char vehicle, int *units, float *firstRate, float *secondRate);
//charge function prototype.
void charge(int roundedTotal, int units, float firstRate, float secondRate, float *totalCharge);
//print bill function prototype.
void printBill (char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge);
//global variables
char vehicle;
int units;
int hourIn;
int minIn;
int hourOut;
int minOut;
int hourParkTime;
int minParkTime;
int roundedTotal;
int round;
float firstRate;
float secondRate;
float totalCharge;
int main(void)
{
getInfo(&vehicle, &hourIn, &minIn, &hourOut, &minOut);
time(hourIn, minIn, hourOut, minOut, &hourParkTime, &minParkTime, &roundedTotal, &round);
rate(vehicle, &units, &firstRate, &secondRate);
charge(roundedTotal, units, firstRate, secondRate, &totalCharge);
printBill(vehicle, hourIn, minIn, hourOut, minOut, hourParkTime, minParkTime, roundedTotal, totalCharge);
return 0;
}//end of main.
//function definition for get info.
void getInfo(char *vehicle, int *hourIn, int minIn, int *hourOut, int *minOut)
{
cout << "\nType of vehicle? ";
cout << "\n(enter C for car,T for truck or B for bus).";
cin >> vehicle;
//check for valid vehicle type
{
switch(*vehicle)
{
{
case 'C': cout << "You entered C.\n";
case 'c': cout << "You entered c.\n";
break;
case 'T': cout << "You entered T.\n";
case 't': cout << "You entered t.\n";
break;
case 'B': cout << "You entered B.\n";
case 'b': cout << "You entered b.\n";
break;
default: cout << "You did not enter a valid vehicle type\n";
cout << "Please Enter C,c,T,t,B, or b\n";
return;
}
//get the hour that the vehicle entered the garage.
cout << "\nHour vehicle entered garage? ";
cin >> *hourIn;
//validate input for hourIn
if(*hourIn < 0 || *hourIn < 23)
{
cout << "invalid input. enter an integer between 0 and 23.";
}
//get the minute that the vehicle entered the garage.
cout << "\nMinute vehicle entered garage? ";
cin >> minIn;
//validate input for minIn.
if(minIn < 0 || minIn > 60)
{
cout << "invalid input. enter a number between 0 and 60.";
}
//get the hour vehicle exits garage.
cout <<"\nHour vehicle exits garage? ";
cin >> *hourOut;
//validate input for hourOut.
if(*hourOut < 0 || *hourOut < 23)
{
cout << "invalid input. enter an integer between 0 and 23.";
}
//get the minute vehicle exits garage.
cout << "\nMinute vehicle exits garage?";
cin >> *minOut;
//validate input for minOut.
if(minOut < 0 || *minOut > 60)
{
cout << "invalid input. enter a number between 0 and 60.";
return;
}
}
//function definition for time.
void time(int hourIn, int minIn, int hourOut, int minOut, int *hourParkTime, int *minParkime, int *roundedTotal, int *rounded)
{
if (*minOut < minIn)
{
minOut = minOut + 60;
hourOut = hourOut - 1;
}
else
{
hourParkTime = hourOut - hourIn;
minParkTime = *minOut - minIn;
}
if(minParkTime >= 1)
{
round = hourParkTime + 1;
}
else
{
round = hourParkTime;
}
roundedTotal = round;
return;
}
//Function definition for rate.
void rate(char vehicle, int *units, float *firstRate, float *secondRate)
{
switch(*vehicle)
{
{
case 'c':
case 'C': units = 3;
firstRate = firstCarRate;
break;
}
{
case 't':
case 'T': units = 1;
firstRate = firstTruckRate;
secondRate = secondTruckRate;
break;
}
case 'b':
case 'B': units = 2;
firstRate = firstBusRate;
secondRate = secondBusRate;
break;
{
default:
cout << "\nEnter a valid vehicle type.";
return;
}
//Function definition for charge.
void charge(int roundedTotal, int units, float firtsRate, float secondRate, float totalCharges)
if(roundedTotal <= units)
{
totalCharge = (roundedTotal * firstRate);
}
else
{
totalCharge = (roundedTotal - units) * (secondRate) + (units * firstRate);
return;
}
//Function definition for print Bill.
void printBill(char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge)
{
cout << "Vehicle Type:/t/t"<< vehicle <<endl;
cout << "Time In:/t/t" <<hourIn<<":"<<minIn <<endl;
cout << "Time Out:/t/t" <<hourOut<<":"<<minOut <<endl;
cout << "Total Park Time:/t/t" <<roundedTotal <<endl;
cout << "Total Charge:/t/t" <<totalCharge<<endl;
return;
}
|