-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdriver.cpp
More file actions
427 lines (353 loc) · 14.2 KB
/
driver.cpp
File metadata and controls
427 lines (353 loc) · 14.2 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// Bianca Hernandez
// Coleman Johnston
// Chanel Aquino
// Regie Daquioag
//
//********************************************************
#include<cstdlib>//toupper
#include <iostream> // cin/cout
#include <cassert> // assert unit testing
using namespace std;
char menu();
double climbing(int people);
double scuba(int people);
double skyDive(int people);
double spelunk(int people);
double discount(double baseCharge, int people);
double discount(char choice, int people);
void receipt(double total, int people, double discount);
int main()
{
int people;
char choice;
double total, discountTotal;
cout << "\n\tWelcome to the High Adventure Travel Agency!" << endl;
cout << "We offer four vacation packages for thrill-seeking customers!" << endl;
cout << "\nHow many people will be participating in this trip? ";
cin >> people;
choice = menu();
switch(choice)
{
case '1': total = climbing(people);
break;
case '2': total = scuba(people);
break;
case '3': total =skyDive(people);
break;
case '4': total = spelunk(people);
break;
default: cout << "You enter an invalid input. Please Try Again." << menu();
}
discountTotal = discount(choice, people);
receipt(total, people, discountTotal);
return 0;
} // end of main()
char menu()
{
char choice;
cout << "\n The High Adventure Travel Packages:\n" << endl;
cout << "Enter in '1' for Devil’s Courthouse Adventure Weekend" << endl;
cout << "Enter in '2' for Scuba Bahama" << endl;
cout << "Enter in '3' for Sky Dive Colorado" << endl;
cout << "Enter in '4' for Barron Cliff Spelunk" << endl << endl;
cout<< "Please select one of our packages: ";
cin >> choice;
return choice;
} // end of menu()
double climbing(int people)
{
double
discountTotal = 0,
baseTotal,
totalAmount,
climbOptional,
equipOptional;
int
peopleOptional,
daysOptional;
const double
BASE_CHARGE = 350,
DISCOUNT_RATE = 0.10,
CLIMB_INSTR = 100,
EQUIP_RENT = 40,
NUM_DAYS = 3;
cout
<< "\nThank you for choosing Devil's Courthouse Adventure Weekend!" << endl
<< endl << "Listed below are our rates." << endl
<< "\t⇨ Base Charge: \t\t\t$" << BASE_CHARGE << " per person" << endl
<< "\t⇨ Climbing Instructions: \t$" << CLIMB_INSTR << " per person (optional)" << endl
<< "\t⇨ Equipment Rental: \t\t$" << EQUIP_RENT << "/day per person (optional)" << endl << endl;
// calculate the base total, before discount
baseTotal = BASE_CHARGE * people;
// call discount() to calculate the discount
discountTotal = discount(BASE_CHARGE, people);
cout
<< "You have [" << people << "] people in your party." << endl
<< "Your Base Charge (before discount) is:\t$" << baseTotal << endl
<< "Your Discount Total is:\t\t\t(-$" << discountTotal << ")" << endl;
baseTotal -= discountTotal; // subtract discount total from the base total
totalAmount = baseTotal; // update the total amount
cout << "Your Base Charge (after discount) is:\t$" << baseTotal << endl << endl;
cout << "Enter the number of people who will need a climbing instructor: ";
cin >> peopleOptional;
while (peopleOptional < 0 || peopleOptional > people)
// the people who need instruction (peopleOptional) should not exceed the number of people in the party
{
cout
<< "\tError: You entered more people than are in your party. Please try again."<< endl
<< "Enter the number of people who will need a climbing instructor: ";
cin >> peopleOptional;
} // while()
cout
<< "\n[" << peopleOptional << "] people will need a climbing instructor." << endl
<< "$" << CLIMB_INSTR << " charge x [" << peopleOptional << "] people =" << endl;
climbOptional = CLIMB_INSTR * peopleOptional; // the optional climbing instruction charge is $100/person
cout << "\t⇨ $" << climbOptional << " will be added to your current total of $" << totalAmount << "." << endl;
totalAmount += climbOptional; // add the optional charge of climbing instructions to the totalCharge
cout << "\t⇨ Your updated total is $" << totalAmount << "." << endl << endl;
cout << "Enter the number of people who will need to rent equipment: ";
cin >> peopleOptional;
while (peopleOptional < 0 || peopleOptional > people)
// the people who need instruction (peopleOptional) should not exceed the number of people in the party
{
cout
<< "\tError: You entered more people than are in your party. Please try again." << endl
<< "Enter the number of people who will need to rent equipment: ";
cin >> peopleOptional;
} // while()
cout << "How many days will you be renting equipment? ";
cin >> daysOptional;
while (daysOptional < 0 || daysOptional > NUM_DAYS)
// the number of days needed for equipment (daysOptional) should not exceed the total number of days
{ cout
<< "\tError: You entered more days than this package allows. Please try again." << endl
<< "How many days will you be renting equipment? ";
cin >> daysOptional;
} // while()
cout << "\n$" << EQUIP_RENT << " charge x [" << peopleOptional << "] people x [" << daysOptional << "] days =" << endl;
equipOptional = EQUIP_RENT * peopleOptional * daysOptional; // the optional equipment rental charge is $40/day per person
cout << "\t⇨ $" << equipOptional << " will be added to your current total of $" << totalAmount << "." << endl;
totalAmount += equipOptional; // add the optional charge of equipment rental, equipOptional, to the totalCharge
cout << "\t⇨ Your updated total is $" << totalAmount << "." << endl;
return totalAmount;
} // end of climbing()
double scuba(int people)
{
const double PERSON_PRICE = 350;//price per person
const double INSTRUCRION_PRICE = 100;//price of scuba instruction
int students;//variable to hold the number of people who need scuba instruction
double baseDiscount = 0;//discount off of the base price (positive number!)
cout << "\nThank you for choosing Scuba Bahama!\n" << endl;
do//check and make sure the amount of people who need instruction is <= the number of people going on the trip
{
cout << "How many people need diving lessons?\n";
cout << "(Those with prior experience may dive right in, while beginners should choose\n";
cout << "to take optional, but very affordable lessons.)\n";
cin >> students;
if(students > people)
{
cout << "You have entered a number greater than the number of people in your party.\n";
cout << "Please enter a smaller number.\n\n";
}
else if(students < 0)
{
cout << "Please enter a positive number or 0.\n";
}
}while(students > people || students < 0);
baseDiscount = discount(PERSON_PRICE, people);//find the discount.
return (PERSON_PRICE * people) + (INSTRUCRION_PRICE * students) - baseDiscount;
} // end of scuba()
double skyDive(int people)
{
char housingChoice;
char inn, lodge, both;
double housingCost, innCost, lodgeCost;
double allDiscount;
double baseCost;
int days = 0;
int innDays = 0;
int lodgeDays = 0;
int daysFor2 = 0;
double baseCharge = 700.00;
int wilderness = 65;
int luxury = 120;
baseCost = baseCharge * people;
cout << "\nTHANK YOU FOR CHOOSING THE 4 DAY SKYDIVING PLAN!!!\n"
<< "\tHOPE YOU HAVE A GREAT TIME!!" << endl;
cout << "\nWhere would you like to stay? \n"
<< "Wilderness Lodge: $65/day per person \n"
<< "Luxury Inn: $120/day per person\n"
<< "Please enter in 'w' for Wilderness and 'l' for Luxury and for "
<< "both enter in 'b': ";
cin >> housingChoice;
while (housingChoice != 'w' && housingChoice != 'l' && housingChoice != 'b')
{
cout << "Invalid answer, please enter in 'w' or 'l' or 'b'" << endl;
cin >> housingChoice;
}
if (housingChoice == 'w')
{
lodge = 'w';
cout << "\nHow many days will you be staying there?" << endl;
cin >> days;
}
else if (housingChoice == 'l')
{
inn = 'l';
cout << "\nHow many days will you be staying there?" << endl;
cin >> days;
}
else if (housingChoice == 'b')
{
both = 'b';
cout << "How many days would you like to stay at the Wilderness Lodge?" << endl;
cin >> lodgeDays;
cout << "How many days would you like to stay at the Luxury Inn?" << endl;
cin >> innDays;
daysFor2 = lodgeDays + innDays;
}
while (daysFor2 > 4)
{
cout << "\nToo long of a stay" << endl;
cout << "\nHow many days would you like to stay at the Wilderness Lodge?" << endl;
cin >> lodgeDays;
cout << "How many days would you like to stay at the Luxury Inn?" << endl;
cin >> innDays;
daysFor2 = lodgeDays + innDays;
}
while (days > 4)
{
cout << "That too long of a stay.\nPlease enter in a right amount of days." << endl;
cin >> days;
}
if (lodge == 'w')
{
housingCost = wilderness * (people * days);
}
else if (inn == 'l')
{
housingCost = luxury * (people * days);
}
else if (both == 'b')
{
innCost = luxury * (people * innDays);
cout << "Your inn cost is :$ " << innCost << endl;
lodgeCost = wilderness * (people * lodgeDays);
cout << "Your lodge cost is :$ " << lodgeCost << endl;
housingCost = innCost + lodgeCost;
}
baseCost = baseCharge * people;
if (people > 5)
{
allDiscount = discount(baseCharge, people);
}
else
{
allDiscount = 0;
}
cout << "\nYour base cost is: $" << baseCost << endl;
cout << "Your housing cost is: $" << housingCost << endl;
cout << "Your discount amount is: $" << allDiscount << endl;
return (baseCost + housingCost - allDiscount);
} //end of skydive()
double spelunk(int people)
{
const double PERSON_PRICE = 700;//base price per person
const double RENTAL = 40;//equipment rental per day per person
double baseDiscount = discount(PERSON_PRICE, people);//discount off of base price
int renters;//how many people are renting equipment
int days;//days that a single person is renting equipment for
int totalDays = 0;//total days that equipment is getting rented for
cout << "\nThank you for choosing Barron Cliff Spelunk!\n";
do//error checking for input
{
cout << "Optional equipment rental is $40 per day for every person.\n";
cout << "How many need to rent equipment?\n";
cin >> renters;
if (renters > people)
{
cout << "You have tried to rent equipment for more people than are in your party\n";
cout << "Please enter a smaller number\n";
}
else if(renters < 0)
{
cout << "Please enter a positive number.\n";
}
}while((renters > people) || (renters < 0));//continue until the user has entered valid input
for(int i = 1;i <= renters;i++)//ask how many days each renter needs the equipment for
{
do
{
cout << "How many days does person " << i << " want to rent equipment?\n";
cout << "(The trip is eight days long.)\n";
cin >> days;
if (days > 8)
{
cout << "The trip is only eight days please enter a smaller number\n";
}
else if(days < 0)
{
cout << "Please enter a positive number.";
}
else
{
totalDays += days;//if valid input add to total days
}
}while((days > 8) || (days < 0));//continue until user enters valid input
}
return ((RENTAL * totalDays) + (people * PERSON_PRICE) - baseDiscount);
} // end of spelunk
double discount(char choice, int people)
{
const double DISCOUNT_RATE = 0.10; // 10% discount only applies to parties of 5 or more people
double
baseCharge,
totalDiscount = 0;
if (people >= 5)
{
switch(choice)
{
case '1': // Devil's Courthouse Adventure Weekend
baseCharge = 325;
break;
case '2': // Scuba Bahama
baseCharge = 1000;
break;
case '3': //Sky Dive Colorado
baseCharge = 700;
break;
case '4': // Barron Cliff Spelunk
baseCharge = 700;
break;
default:
cout << "Invalid. Try again." << endl;
break;
} // switch()
totalDiscount = (baseCharge * DISCOUNT_RATE) * people;
return totalDiscount;
} // if()
return totalDiscount;
} //end of discount()
double discount(double baseCharge, int people)
{
baseCharge = people * baseCharge;
if (people >= 5)
{//if five or more people return 10% of the base charge
return (baseCharge * .10);
}
else
{//if less than five people return 0
return 0;
}
} // end of discount()
void receipt(double total, int people, double discount)
{
cout
<< "\nYour charges are as follows:" << endl
<< "\t⇨ Per person: \t$" << total/people << endl
<< "\t⇨ Total people: " << people << endl
<< "Base Charge: \t\t$" << total + discount << endl
<< "\t⇨ Discount: \t-($" << discount << ")" << endl
<< "TOTAL CHARGES: \t\t$" << total << endl
<< "\nThank you for purchasing your vacation package!\n" << endl;
} // end of receipt()