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
|
#include <iostream>
#include <iomanip>
#include <fstream> // allows for the importing of file.
#include <string>
using namespace std;
// Constants
const int FirstCOLS = 4; // Columns for First class
const int FirstROWS = 5; // Rows for First class
const int CoachCOLS = 6; // Columns for Coach class
const int CoachROWS = 5; // Rows for Coach class
//const string Avail = "#"; // Available
//const string Taken = "*"; // Taken
// Function prototypes
void seatChart(double FirstArray[FirstROWS][FirstCOLS], double Coach1Array [CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS]);
void displayMenu(double, double FirstArray[FirstROWS][FirstCOLS], double Coach1Array[CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS]);
int main()
{
// Variables
double choice = 0;
const int FIRSTCLASS = 1,
FIRSTCOACH= 2,
SECONDCOACH = 3,
DISPLAYSEAT = 4,
EXIT = 5;
//int fcrow, fccol; // first class rows and columns inputs
//int fccrow, fcccol; // first coach class row and columns inputs
//int scrow, sccol; // second coach class row and column inputs
//double seatssold, seatsremainrow, totalsales, totalempty;
// Arrays
double FirstArray[FirstROWS][FirstCOLS];
double Coach1Array[CoachROWS][CoachCOLS];
double Coach2Array[CoachROWS][CoachCOLS];
// intro
cout << "Welcome to my Airline Seat Reservation System" << endl;
cout << "============================================= \n" << endl;
//seatChart(FirstArray, Coach1Array, Coach2Array);
displayMenu(choice, FirstArray,Coach1Array,Coach2Array);
return 0;
}
// This is a function to display the menu
void displayMenu(double, double FirstArray[FirstROWS][FirstCOLS], double Coach1Array[CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS])
{
// Variables
int CHOICE;
int fcrow, fccol; // first class rows and columns inputs
int fccrow, fcccol; // first coach class row and columns inputs
int scrow, sccol; // second coach class row and column inputs
double countFirst = 0, countFirstCoach = 0, countSecondCoach = 0; // stores how many tickets bought
const int FIRSTCLASS = 1,
FIRSTCOACH = 2,
SECONDCOACH = 3,
DISPLAYSEAT = 4,
EXIT = 5;
double firstprice;
double coach1price;
double coach2price;
cout << "Please pick from the following options: 1-5" << endl;
cout << "======================================" << endl;
cout << "1. First Class" << endl;
cout << "2. First Coach Class" << endl;
cout << "3. Second Coach Class" << endl;
cout << "4. Display Available seating" << endl;
cout << "5. Exit\n" << endl;
cin >> CHOICE;
//Opens input files
ifstream inputFile;
inputFile.open("SeatPrices.txt");
// Checks for failure.
if (inputFile.fail())
{
cout << "Sorry File does not exist or can not be found.\n";
exit(1);
}
// read the numbers and load them into doubles
inputFile >> firstprice;
inputFile >> coach1price;
inputFile >> coach2price;
// closing file
inputFile.close();
// Switch statement
switch (CHOICE)
{
case FIRSTCLASS :
cout << "You have chosen: First Class" << endl;
cout << "\nThe price of a ticket for First Class is:" << firstprice << endl;
cout << "\nNow please pick which row you would like to sit in: (1-5) ";
cin >> fcrow;
if (fcrow > 5)
{
cout << "\nYou have entered an invalid row number, please enter in between 1-5 ";
cin >> fcrow;
}
cout << "\nPlease pick which seat you would like to sit in, please enter between 1-4 ";
cin >> fccol;
if (fccol > 4)
{
cout << "\nYou have entered an invalid seat number, please enter between 1-4 ";
cin >> fccol;
}
if (FirstArray[FirstROWS - 1][FirstCOLS - 1] != '*')
{
FirstArray[FirstROWS - 1][FirstCOLS - 1] = '*';
cout << endl << "Your seat has been reserved\n";
countFirst++;
}
else {
cout << "I'm sorry the seat is occupied" << endl;
}
break;
case FIRSTCOACH:
cout << "You have chosen: First Coach Class" << endl;
cout << "\nThe price of a ticket for First Coach Class is $" << coach1price << endl;
cout << "\nNow please pick which row you would like to sit in: ";
cin >> fccrow;
cout << "Please pick which seat you would like to sit in. Please enter between 6-10: ";
cin >> fcccol;
if (fccrow > 10)
{
cout << "\nYou have entered an invalid row number, please enter between 6-10 ";
cin >> fccrow;
}
cout << "\nPlease pick which seat you would like to sit in, please enter between 1-6: ";
cin >> fccol;
if (fcccol > 6)
{
cout << "You have entered an invalid seat number, please enter between 1-6";
cin >> fcccol;
}
if (Coach1Array[CoachROWS - 1][CoachCOLS - 1] != '*')
{
Coach1Array[CoachROWS - 1][CoachCOLS - 1] = '*';
cout << endl << "Your seat has been reserved\n";
countFirstCoach++;
}
else {
cout << "I'm sorry the seat is occupied" << endl;
}
break;
case SECONDCOACH:
cout << "You have chosen: Second Coach Class" << endl;
cout << "\nThe price of a ticket for Second Coach Class is: $"<< coach2price << endl;
cout << "\nNow please pick which row you would like to sit in, please choose between 11-15 ";
cin >> scrow;
if (fccrow > 15)
{
cout << "\nYou have entered an invalid row number, please enter in between 11-15 ";
cin >> scrow;
}
cout << "Please pick which seat you would like to sit in: ";
cin >> sccol;
if (fcccol > 6)
{
cout << "You have entered an invalid seat number, please enter between 1-6";
cin >> sccol;
}
if (Coach2Array[CoachROWS - 1][CoachCOLS - 1] != '*')
{
Coach2Array[CoachROWS - 1][CoachCOLS - 1] = '*';
cout << endl << "Your seat has been reserved\n";
countSecondCoach++;
}
else {
cout << "I'm sorry the seat is occupied" << endl;
}
break;
case DISPLAYSEAT:
seatChart(FirstArray, Coach1Array, Coach2Array);
break;
case EXIT:
cout << "You have chosen to Exit the program" << endl;
cout << "Thank you for using my program, have a good day!" << endl;
exit(1);
break;
default: cout << "You have entered in an invalid choice, please pick between 1-5" << endl;
}
}
// This is a Funciton for the Seating Chart
void seatChart(double FirstArray[FirstROWS][FirstCOLS], double Coach1Array[CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS])
{
cout << "This is the Seating Chart" << endl;
cout << "========================= \n" << endl;
cout << "First Class is seats 1-4, Rows 1-5\n" << endl;
for (int x = 0; x < FirstROWS; x++)
{
for (int y = 0; y < FirstCOLS; y++)
{
FirstArray[x][y] = '#';
cout << FirstArray[x][y];
}
cout << endl;
}
cout << "\nFirst Coach Class are seats 1-6, Rows 6-10:\n" << endl;
for (int x = 0; x < CoachROWS; x++)
{
for (int y = 0; y < CoachCOLS; y++)
{
Coach1Array[x][y] = '#';
cout << Coach1Array[x][y];
}
}
cout << endl;
cout << "\nSecond Coach Class are seats 1-6, Rows 11-15\n" << endl;
for (int x = 0; x < CoachROWS; x++)
{
for (int y = 0; y < CoachCOLS; y++)
{
Coach1Array[x][y] = '#';
cout << Coach2Array[x][y];
}
}
cout << endl;
}
|