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
|
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
const int n_of_rows = 15;
const int n_of_columns = 4;
char choose (char seat[][n_of_columns]);
void available (char seat[][n_of_columns]);
void show_seats(char seat[][n_of_columns]);
int main(void)
{
char seat[n_of_rows][n_of_columns] = { {'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},};
char answer;
do
{
cout << endl << "Would you like to make a reservation? (Y/N) ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
cout << endl << "Welcome to Hancock Airline Reservation. Please note that"
<< endl << "any seats shown with a * is taken" << endl << endl ;
ifstream inFile;
int price1, price2, price3;
inFile.open("SeatPrices.txt");
inFile >> price1;
inFile >> price2;
inFile >> price3;
inFile.close();
cout << endl << "All First Class Seats cost: $" << price1 << " "
<< endl << "First Five Coach Rows Cost: $" << price2 << " "
<< endl << "Last Five Coach Rows Cost: $" << price3 << " " << endl << endl;
show_seats (seat);
available (seat);
choose (seat);
seat;
show_seats (seat);
}
else
std::exit(EXIT_FAILURE);
}while(1);
return EXIT_FAILURE;
}
void available (char seats[][n_of_columns])
{
for (int i = 0; i < n_of_rows; i++)
for (int j = 0; j < n_of_columns; j++)
seats[i][j];
return;
}
char choose (char seats[][n_of_columns])
{
int row, column;
double firstClass = 200.00,
firstFiveCoach = 450.00,
lastFiveCoach = 375.00;
char letter;
cout << endl << "Enter Row (0-14): ";
cin >> row;
cout << endl << endl << "Enter Seat (A-D): ";
cin >> letter;
letter = toupper(letter);
column = letter - 65;
if (row < 0 && row > 14)
{
cout << endl << "Invalid Row. " << endl;
row--;
}
if (row >= 0 && row <= 4)
{
cout << endl << "Your total charge is: $" << firstClass << endl << endl;
}
if (row >= 5 && row <= 9)
{
cout << endl << "Your total charge is: $" << firstFiveCoach << endl << endl;
}
if (row >= 10 && row <= 14)
{
cout << endl << "Your total charge is: $" << lastFiveCoach << endl << endl;
}
if (seats[row][column] == '*')
cout << endl << "This seat has been taken. Please try another" << endl << endl;
seats[row][column] = '*';
return seats['*'][n_of_columns];
}
void show_seats (char seats[][n_of_columns])
{
for (int i = 0; i < n_of_rows; i++)
cout << seats[i][0] << "\t"
<< seats[i][1] << "\t"
<< seats[i][2] << "\t"
<< seats[i][3] << "\t" << endl;
return;
}
|