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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cctype>
using namespace std;
const string COMPACT = " C - Compact size at $22.91 per day";
const string MID_SIZE = " M - Mid size at $25.76 per day";
const string FULL_SIZE = " F - Full size at $28.87 per day";
const string SUV = " S - SUV at $98.88 per day";
const string NUM_OF_DAYS = "Enter number of days rented: ";
const string MILES_DRIVEN = "Enter number of miles driven: ";
const double C_CHARGE = 22.91;
const double M_CHARGE = 25.76;
const double F_CHARGE = 28.87;
const double S_CHARGE = 98.88;
const double WEEK_RATE = 6.5;
const double C_MILES = .05;
const double M_MILES = .07;
const double F_MILES = .09;
void displayResults(double chargeForCar, int rentDays, int driveMiles,
double mileageChargeT, double taxed, double totalBillT, string sizeCar);
void calculateTotalBill(double& carCharge, double& milesDrivenCharge, double& tax, double& grandTotal,
char selectedCar, int daysDriven, int miles);
double calculateMileCharge(int milesDriven, char typeOfCar);
double calculateDayCharge(int days, char carSelected);
int numberPrompt(string prompt);
char displayMenu();
int main()
{
char usersCarSelection;
int daysRented;
int milesDriven;
double carCharge;
double milesDrivenCharge;
double tax;
double grandTotal;
string sizeCar;
char userEnters;
tax = .115;
cout << "This program will calculate a car rental bill for Rent2U" << endl << endl;
do
{
usersCarSelection = displayMenu();
daysRented = numberPrompt(NUM_OF_DAYS);
milesDriven = numberPrompt(MILES_DRIVEN);
carCharge = calculateDayCharge(daysRented, usersCarSelection);
milesDrivenCharge = calculateMileCharge(milesDriven, usersCarSelection);
calculateTotalBill(carCharge, milesDrivenCharge, tax, grandTotal,
usersCarSelection, daysRented, milesDriven);
if(usersCarSelection == 'C')
{
sizeCar = "Compact";
}
else if(usersCarSelection == 'M')
{
sizeCar = "Mid-Size";
}
else if(usersCarSelection == 'F')
{
sizeCar = "Full-Size";
}
else if(usersCarSelection == 'S')
{
sizeCar = "SUV";
}
displayResults(carCharge, daysRented, milesDriven,
milesDrivenCharge, tax, grandTotal, sizeCar);
cout << "Calculate another bill (y/n)? ";
cin >> userEnters;
cout << endl;
userEnters == toupper(userEnters);
}
while(userEnters == 'Y');
cout << endl << endl;
system ("PAUSE");
return 0;
}
char displayMenu()
{
char carSelect;
cout << "Car sizes:" << endl;
cout << COMPACT << endl << MID_SIZE << endl << FULL_SIZE << endl << SUV << endl << endl;
cout << "Enter letter for car size rented: ";
cin >> carSelect;
cout << endl << endl;
carSelect = toupper(carSelect);
while((carSelect != 'C') && (carSelect != 'M') && (carSelect != 'F') && (carSelect != 'S'))
{
cout << "Invalid Entry: Must enter either C, M, F, or S. Try again: ";
cin >> carSelect;
cout << endl << endl;
}
return carSelect;
}
int numberPrompt(string prompt)
{
int value;
cout << prompt;
cin >> value;
cout << endl << endl;
while(value < 1)
{
cout << "Invalid Entry: Must be a whole number greater than one: ";
cin >> value;
cout << endl << endl;
}
return value;
}
double calculateDayCharge(int days, char carSelected)
{
double carCharge;
if(days <= 6)
{
if(carSelected == 'C')
{
carCharge = C_CHARGE * days;
}
else if(carSelected == 'M')
{
carCharge = M_CHARGE * days;
}
else if(carSelected == 'F')
{
carCharge = F_CHARGE * days;
}
else if(carSelected == 'S')
{
carCharge = S_CHARGE * days;
}
}
else if (days > 6)
{
if(carSelected == 'C')
{
while(days >= 7)
{
carCharge = C_CHARGE * WEEK_RATE;
days = days - 7;
}
carCharge = C_CHARGE * days;
}
else if(carSelected == 'M')
{
while(days >= 7)
{
carCharge = M_CHARGE * WEEK_RATE;
days = days - 7;
}
carCharge = M_CHARGE * days;
}
else if(carSelected == 'F')
{
while(days >= 7)
{
carCharge = F_CHARGE * WEEK_RATE;
days = days - 7;
}
carCharge = F_CHARGE * days;
}
else if(carSelected == 'S')
{
while(days >= 7)
{
carCharge = S_CHARGE * WEEK_RATE;
days = days - 7;
}
carCharge = S_CHARGE * days;
}
}
return carCharge;
}
double calculateMileCharge(int milesDriven, char typeOfCar)
{
double milesCharge;
if(typeOfCar == 'C')
{
while(milesDriven >= 20)
{
milesCharge = (milesDriven - 20) * C_MILES;
}
}
else if(typeOfCar == 'M')
{
while(milesDriven >= 20)
{
milesCharge = (milesDriven - 20) * M_MILES;
}
}
else if(typeOfCar == 'F')
{
while(milesDriven >= 20)
{
milesCharge = (milesDriven - 20) * F_MILES;
}
}
return milesCharge;
}
void calculateTotalBill(double& carCharge, double& milesDrivenCharge, double& tax, double& grandTotal,
char selectedCar, int daysDriven, int miles)
{
tax = .115;
carCharge = calculateDayCharge(daysDriven, selectedCar);
milesDrivenCharge = calculateMileCharge(miles, selectedCar);
grandTotal = (carCharge + milesDrivenCharge) * tax;
}
void displayResults(double chargeForCar, int rentDays, int driveMiles,
double mileageChargeT, double taxed, double totalBillT, string carSize)
{
cout << "RENT2U RENTAL DETAILS" << endl;
cout << " Car Size:" << setw(20) << carSize << endl;
cout << " Days Rented:" << setw(20) << rentDays << endl;
cout << " Miles Driven:" << setw(20) << driveMiles << endl << endl;
cout << "BILL" << endl;
cout << " Car Charge:" << setw(20) << "$ " << chargeForCar << endl;
cout << " Mileage Charge:" << setw(20) << "$ " << mileageChargeT << endl;
cout << " Tax:" << setw(20) << "$ " << taxed << endl;
cout << "-------------------------------------------------------" << endl;
cout << " Total Bill:" << setw(20) << "$ " << totalBillT << endl;
}
|