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
|
#include <iostream>
using namespace std;
void print_menu(); //Prototypes
int input_choice();
void input_reservation(int patron_age[], char sport_type[], int index, double insurance_Rate);
char input_type();
int input_age();
double compute_rate(int patron_age[], char sport_type[], int index);
void print_all(int patron_age[], char sport_type[], int index, int size);
void print_by_sport(int patron_age[], char sport_type[], int index, int size);
int main() //Main Function
{
int patron_age[100];
char sport_type[100];
int index = 0;
int size = 0;
double insurance_Rate;
int menu_choice; //Variable Declaration
do
{
print_menu();
menu_choice = input_choice();
if (menu_choice == 1)
{
input_reservation(patron_age, sport_type, index, insurance_Rate);
size++;
index++;
}
if (menu_choice == 2)
{
print_all(patron_age, sport_type, index, size);
}
if (menu_choice == 3)
{
print_by_sport(patron_age, sport_type, index, size);
}
if (menu_choice == 4)
{
cout << "There were a total of " << index << " reservations" << endl;
}
} while (menu_choice != 4);
return 0;
}
void print_menu() //Function that prints the program menu
{
cout << "Please pick from the following menu " << endl;
cout << "1. Add a new reservation " << endl;
cout << "2. Print all reservations " << endl;
cout << "3. Print all reservations for a given sport " << endl;
cout << "4. Quit" << endl;
}
int input_choice() //Function to get menuchocie from user
{
int menu_selection;
cin >> menu_selection;
while (menu_selection > 4 || menu_selection < 1) //Validates input
{
cout << "\tError: Invalid input, please try again: ";
cin >> menu_selection;
}
return menu_selection; //Returns the menuchocie
}
void input_reservation(int patron_age[], char sport_type[], int index, double insurance_Rate) //Working
{
double insurance;
sport_type[index] = input_type();
patron_age[index] = input_age();
insurance = compute_rate(patron_age, sport_type, index);
cout << "The insurance rate is $" << insurance << endl;
}
char input_type() //Reads and validates the sport being reserved
{
char sport_type_entry;
cout << "Please enter f/F for flying, g/G for gliding and h/H for hang-gliding: "; //Working
cin >> sport_type_entry;
while (sport_type_entry != 'f' && sport_type_entry != 'F' && sport_type_entry != 'g' && sport_type_entry != 'G' && sport_type_entry
!= 'h' && sport_type_entry != 'H')
{
cout << "Error: Invalid input, please try again: ";
cin >> sport_type_entry;
}
return sport_type_entry;
}
int input_age() //Reads and validates the age of the patron
{
int patron_age_entry;
cout << "Please enter the age of the patron, minimum 16: ";
cin >> patron_age_entry;
while (patron_age_entry < 16 || patron_age_entry > 112)
{
cout << "Error: Invalid input, please try again: ";
cin >> patron_age_entry;
}
return patron_age_entry;
}
double compute_rate(int patron_age[], char sport_type[], int index) //Computes the insurance rate of the patron
{
double insurance_Rate;
if (sport_type[index] == 'f' || sport_type[index] == 'F') //If sport index is flying, do this insurance calculation
{
if (patron_age[index] <= 25)
{
insurance_Rate = 68.95;
}
else if (patron_age[index] > 25)
{
insurance_Rate = 55.95;
}
}
else if (sport_type[index] == 'g' || sport_type[index] == 'G')//If sport index is gliding, do this insurance calculation
{
if (patron_age[index] <= 25)
{
insurance_Rate = 73.95;
}
else if (patron_age[index] > 25)
{
insurance_Rate = 65.95;
}
}
else if (sport_type[index] == 'h' || sport_type[index] == 'H') //If sport index is hand gliding, do this insurance calculation
{
if (patron_age[index] <= 25)
{
insurance_Rate = 99.95;
}
else if (patron_age[index] > 25)
{
insurance_Rate = 92.95;
}
}
return insurance_Rate;
}
void print_all(int patron_age[], char sport_type[], int index, int size) //Function to print all reservations
{
for (int i = 0; i < size; i++)
{
cout << "A patron aged " << patron_age[i] << " reserved a session of " << sport_type[i] << endl;
}
}
void print_by_sport(int patron_age[], char sport_type[], int index, int size) //Function to print all reservations based on sport type
{
char sport_type_identifier;
cout << "Please enter f/F for flying, g/G for gliding and h/H for hang-gliding: ";
cin >> sport_type_identifier;
for (int i = 0; i < size; i++)
{
if (sport_type_identifier == sport_type[i])
{
if (sport_type[i] == 'f')
{
cout << "A patron aged " << patron_age[i] << " reserved a session of flying " << endl;
}
else if (sport_type[i] == 'g')
{
cout << "A patron aged " << patron_age[i] << " reserved a session of gliding " << endl;
}
else if (sport_type[i] == 'h')
{
cout << "A patron aged " << patron_age[i] << " reserved a session of hang-gliding ";
}
}
}
}
|