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>
#include <string>
#include <fstream>
using namespace std;
const int ROWS = 30;
const int COLS = 6 + 3;
void SeatChart(ifstream& eds, string seatChart[][COLS])
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
if (eds.eof()) //if eof, break out of loop
break;
eds >> seatChart[i][j]; //fills array with data from file
cout << seatChart[i][j] << " ";
if (seatChart[i][j] == "F") //endline everytime the letter d is in the array
cout << endl;
}
}
}
void Reserve(string seatChart[][COLS], char row, char column)
{
cout << "Enter a the row (1-30) and seat (A-F) [Example: 5B]:";
cin >> row >> column;
for (int x = 0; x < ROWS; x++) // int x = 0
for (int y = 0; y < COLS; y++)
if (x == row)
{
if (seatChart[x][y][0] == toupper(column))
{
seatChart[x][y] = 'X';
cout << "Seat was successfully reserved!" << endl;
}
}
}
void Cancel(string seatChart[][COLS], char col, char row)
{
}
void SeatChartFile(ofstream& pds, string seatChart[][COLS])
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++) //simple function to put data in array to the file
{
pds << seatChart[i][j];
pds << " ";
if (j == 6) //everytime theres a new row, its a new line
pds << endl;
}
}
}
void Stats()
{
}
void Help()
{
cout << "Hello, seems like youre having trouble with you program." << endl;
cout << "Pressing the letter (A) or a will give you a look at all the seats on the plane thats arer reserved and unreserved." << endl;
cout << "Want to reserve a seat! press (B) and first input the coulumn number 1-30 and a letter A-F for the row seat." << endl;
cout << "Option (C) will let you cancel a reservation by just inputting the seat you initially reserved." << endl;
cout << "Option (D) will save the seating chart to a file you input." << endl;
cout << "Option (E) will list all the statistics to the user." << endl;
cout << "This option (F) will help you understand the program and how to work the program." << endl;
cout << "Lastly Option (G) will the quit the program" << endl;
}
void Quit()
{
cout << "Thank You!" << endl;
cout << "Enjoy your Flight" << endl;
system("pause");
exit(0); //Exit the program
}
int main()
{
string seatChart[ROWS][COLS];
int row = 0;
char col = NULL;
char choice;
ifstream eds;
ofstream pds;
string outputfile;
eds.open("planeSeats.txt");
bool repeat = true;
while (repeat = true)
{
cout << "------------------------ Menu ---------------------------" << endl;
cout << "A.Display Seat Chart" << endl;
cout << "B.Reserve Seat" << endl;
cout << "C.Cancel Reservation" << endl;
cout << "D.Save Seat Chart to File" << endl;
cout << "E.Statistics" << endl;
cout << "F.Help" << endl;
cout << "G.Quit" << endl;
cout << "------------------------------------------------------------" << endl;
cout << "Please Enter Your Choice (A-G):";
cin >> choice;
switch (toupper(choice))
{
case 'A':
SeatChart(eds, seatChart);
system("pause");
break;
case 'B':
Reserve(seatChart, col, row);
system("pause");
break;
case 'C':
Cancel(seatChart, col, row);
system("pause");
break;
case 'D':
cout << "What is the name of the file you want to save the data to:";
cin >> outputfile;
pds.open(outputfile);
SeatChartFile(pds, seatChart);
pds.close();
system("pause");
break;
case 'E':
Stats();
system("pause");
break;
case 'F':
Help();
system("pause");
break;
case 'G':
Quit();
break;
}
eds.close();
}
}
|