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
|
/*CSC 160
This is a program where a user picks a customer ID and picks his or her seat on
an airplane flight. It is menu driven and does a series of tasks regarding
airline seating. */
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//declare struct called user
struct user
{
string pin;
string seat;
};
//declare mad amounts of struct users
const int maxsize = 21;
int main()
{
//declare file to read from and to save to
ofstream outdata("manifest.dat");
ifstream indata("manifest.dat");
//declare two dimensional array of seats
char seats[7][4] =
{ {'1', 'A', 'B', 'C'},
{'2', 'A', 'B', 'C'},
{'3', 'A', 'B', 'C'},
{'4', 'A', 'B', 'C'},
{'5', 'A', 'B', 'C'},
{'6', 'A', 'B', 'C'},
{'7', 'A', 'B', 'C'}
};
//declare ints and struct called users.
int row = 0;
int column = 0;
int choice;
int num = 1;
user you, users[maxsize];
//clear screen when i return to main from choices.
system("cls");
//menu of the airline program.
cout <<"1. Enter Customer ID" << endl;
cout <<"2. Enter Requested Seat" <<endl;
cout <<"3. View Assigned Seats" <<endl;
cout <<"4. Print Manifest" <<endl;
cout <<"5. Save to File" <<endl;
cout <<"6. Read Saved file" <<endl;
cout <<"7. Exit" <<endl;
cout <<"Please enter a choice 1-7: " <<endl;
//choice from 1-7
cin >> choice;
//choice number 1
if (choice == 1)
{
//clear screen first
system("cls");
//enter id of 4 numbers
cout << "Please enter a customer id of 4 numbers: "<<endl;
cin >> users[num].pin;
//send pin number to the file
outdata << users[num].pin;
cout<< "Returning to main menu...."<<endl;
system ("pause");
return main();
}
//for choice 2
if (choice == 2)
{
system("cls");
// enter seat you wish to sit in
cout << "Please enter the seat you want to be placed in, starting with"<<endl;
cout << "the row. (For example for seat 1 B, enter: 1 2)"<<endl;
cout <<"Enter choice now: "<<endl;
//out put row and column to file.
cin >> row>>column;
outdata << row << " " << column;
// printing out seating chart for varification
row = row - 1;
seats[row][column] = 'X';
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++)
cout << " " << seats[i][j]<< " ";
cout <<endl;
}
//change user to the next one
num++;
system("pause");
return main();
}
//print out seats
if (choice == 3)
{
system ("cls");
cout << "Seats taken are marked with an 'X'" <<endl;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++)
cout << " " << seats[i][j]<< " ";
cout <<endl;
}
cout << "Returning to main screen"<<endl;
system ("pause");
return main();
}
/* print out manifest
for ex.
Manifest for flight.
1111 1B
2321 3C
etc. */
if (choice == 4)
{
system("cls");
cout << users[0].pin<<endl;
cout << "Manifest for Flight 13 - F" << endl;
for (int i =1; i < num; i++)
{
cout << users[i].pin<<endl;
cout << " " << users[i].seat << endl;
}
cout << "returning to home screen.." << endl;
system("pause");
return main();
}
if (choice == 5)\
{ //save to file
outdata << users[num].pin<<" " <<users[num].seat<<endl;
}
if (choice == 6)
{
//read from file which i do not know how to do
}
//exit
if (choice == 7)
{
return 0;
}
system("pause");
return 0;
}
|