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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
const int ROWS = 10;
const int COLS = 4;
char chart[ROWS][COLS];
void readChart(char chart[ROWS][COLS]);
void displaySeatChart(char chart[ROWS][COLS]);
void reserveSeat(int&, int&, string);
void cancelReservation();
void saveSeatChartToFile();
void statisticsOption();
void helpOption();
void quitOption();
void errorOption();
ifstream ins;
int main()
{
ins.open("chartIn.txt");
int choice, row, col;
string seat;
readChart(chart);
ins.close();
do
{
cout << "-----------------------Menu----------------------" << endl;
cout << setw(30) << "1. Display Seat Chart " << endl;
cout << setw(30) << "2. Reserve Seat " << endl;
cout << setw(30) << "3. Cancel Reservation " << endl;
cout << setw(30) << "4. Save Seat Chart To File " << endl;
cout << setw(30) << "5. Statistics " << endl;
cout << setw(30) << "6. Help " << endl;
cout << setw(30) << "7. Quit " << endl << endl;
cout << "Please enter your choice (1-7): ";
cin >> choice;
cout << "--------------------------------" << endl;
switch (choice)
{
case 1:
displaySeatChart(chart);
break;
case 2:
reserveSeat(row, col, seat);
break;
case 3:
cancelReservation();
break;
case 4:
saveSeatChartToFile();
break;
case 5:
statisticsOption();
break;
case 6:
helpOption();
break;
case 7:
quitOption();
break;
default:
errorOption();
}
} while (choice != 7);
return 0;
}
void readChart(char chart[ROWS][COLS])
{
int rowNumber;
char seat1, seat2, seat3, seat4;
while (!ins.eof())
{
ins >> rowNumber;
ins >> seat1 >> seat2 >> seat3 >> seat4;
chart[rowNumber - 1][0] = seat1;
chart[rowNumber - 1][1] = seat2;
chart[rowNumber - 1][2] = seat3;
chart[rowNumber - 1][3] = seat4;
}
}
void displaySeatChart(char chart[ROWS][COLS])
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
cout << chart[i][j] << " ";
cout << endl;
}
}
void reserveSeat(int& row, int& col, string seat)
{
cout << "Please enter your seat number : ";
cin >> seat;
string fragment1, fragment2;
if (seat.length() == 2)
{
fragment1 = seat.substr(0, 1);
fragment2 = seat.substr(1, 1);
}
else if (seat.length() == 3)
{
fragment1 = seat.substr(0, 2);
fragment2 = seat.substr(2, 1);
}
else
{
cout << "Invalid seat!";
row = -1;
col = -1;
}
row = atoi(fragment1.c_str()) - 1;
switch (fragment2[0])
{
case 'A':
case 'a':
col = 0;
break;
case 'B':
case 'b':
col = 1;
break;
case 'C':
case 'c':
col = 2;
break;
case 'D':
case 'd':
col = 3;
break;
}
cout << "This corresponds to Row " << row << " and column " << col << " in the array" << endl;
}
void cancelReservation()
{
cout << "You selected Option 3." << endl << endl;
}
void saveSeatChartToFile()
{
cout << "You selected Option 4." << endl << endl;
}
void statisticsOption()
{
cout << "You selected Help." << endl << endl;
}
void helpOption()
{
cout << "Thank you for using our seat reservation program." << endl;
cout << "You can do any of the follwing: display the current seat chart, " << endl;
cout << "reserve a seat, cancel a reservation, save the seat chart to a file, " << endl;
cout << "or display the statistics of the current seat chart" << endl << endl;
}
void quitOption()
{
cout << "You have quit the program." << endl << endl;
}
void errorOption()
{
cout << "Invalid choice. Please enter a valid number (1-7) and press enter." << endl << endl;
}
|