sorry for the format errors, I am new but will catch on...
Below is the code I wrote, and following that is the list of passengers that make up the text file manifest.txt.
//FinalTest.cpp -- Compile with manifest.txt
// This program gives choice to user to takes data from
// user input or existing list of passengers/preferences.
// Compile with manifest.txt
//
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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int SIZE = 25;
const int passNum = 2; // must contain the number of passengers on list
char choice;
char q;
char Q;
int k;
int x =0 ;
struct passList // structure for passenger information
{
char fName[SIZE];
char lName[SIZE];
char pref;
int row;
int seat;
};
void showMenu(); // function prototype
void displayLine(); // function prototype
void bookNewmenu(int x, passList[]); // function prototype
int main()
{
passList passInfo[passNum]; // declare the passenger list (an array of structure)
// perhaps the loop to show the menu, get the choices and do the data entry should be here
showMenu(); // SHOW MENU CHOICES
cin >> choice;
switch(choice)
{
case 'A' :
case 'a' :// for (k = 0; k < passNum; k++) // view passenger information list
{
cout << "Run list from file" << endl;
// cout << manifesst.txt
while(choice !='Q' && choice != 'q') // terminate?
{
passInfo[passNum]; // const passNum = 41 type passList objects
ifstream.open("manifest.txt"); inFile used to read manifest.txt
// manifest.open("manifest.txt"); // opens the file(manifest) for data storage
if (!manifest.is_open()) // FAILED to open file
{
cout << "Could not open file " << endl;
cout << "Program terminating.\n";
exit(EXIT_FAILURE);
}
for(x = 0; x < passNum; x++)
{
manifest >> passInfo[x].lName;
manifest >> passInfo[x].fName;
manifest >> passInfo[x].pref;
manifest >> passInfo[x].row;
manifest >> passInfo[x].seat;
}
manifest.close(); // finished with file
}
void displayLine(); // function call
// cin.get();
// system("pause");
return 0;
}
system("pause");
system("CLS");
break;
}
case 'B' :
case 'b' : for (k = 0; k < passNum; k++) // book new flight menu
// should loop inside here to do the booking as long as ?????
{
//int fill_passInfo(passList passInfo[k], int SIZE)
cout << "***New booking menu function should start*
**";
// function calls have the name of the function and the parameters (if any)
// do not put VOID in front of a function call
// VOID belongs in definitions (prototypes)
bookNewmenu(k, passInfo ); // programmer defined function definitions
system("pause");
system("CLS");
cout << "back from the function";
cout << passInfo[k].lName << '\t' << passInfo[k].fName << '\t' << passInfo[k].pref;
break;
}
case 'Q' :
case 'q' :
{
cout << "Quitting the program\n"; // Quit
// exit();
}
system("pause");
system("CLS");
break;
default : cout << "This is not a choice. \n";
}
// ***Function definitions***
void bookNewmenu(int x ,passList passInfo[] ) // programmer defined function definitions
// recommend that you print the passInfo list both here and
// back in main - so you can be sure that the stuff is there
{
cout << "\t\tFAST FLIGHT AIRLIINES\n"
<< "\t -- Passenger Information System --\n";
displayLine();
displayLine();
cout <<" -- Book New Flight --\n";
cout << "Please enter your first name: ";
cin >> passInfo[x].fName;
cout << "Please enter your last name: ";
cin >> passInfo[x].lName;
cout << "Please choose Smoking or Non-smoking: ";
cin >> passInfo[x].pref;
cout << "Please enter seat number: ";
cin >> passInfo[x].row;
cout << "Please enter row number: ";
cin >> passInfo[x].seat;
cout << passInfo[x].lName << '\t' << passInfo[x].fName << '\t' << passInfo[x].pref;
cout << '\t' << passInfo[x].row << '\t' << passInfo[x].seat << endl;
} // end of BookNewmenu
// int fill_array(int fillarray[], int passNum); // trying to figure out how to fill this array
void showMenu() // programmer defined function definition THIS WORKS!
{
cout << "\t\tFAST FLIGHT AIRLIINES\n"
"\t -- Passenger Information System --\n"
"Welcome to the Fast Flight passenger information manager\n"
"__________________________________________________________\n"
"\nPlease choose from the following options: \n\n"
"\ta - View Passenger Information List\n\n"
"\tb - Book new flight\n\n"
"\tq - Quit program\n\n\n"
"Please enter your choice:__\b";
return ;
} // end of showMenu function
void displayLine()
{
}
// << endl; end of displayLine function
// return 0;
|
The following list can be saved as manifest.txt to be used with program;
John Smith n 3 2
Steven Jobs s 9 3
Al Capone n 3 2
Michael Jackson s 8 1
H Humphrey s 8 2
Jim Rineheart n 3 1
Ken Eastman n 1 1
Salem Winston s 8 3
Susan Smythe s 9 1
Al Kendricks s 9 2
Dennis Allison s 9 3
Richard GBlatt s 10 1
Bob Davis s 10 3
Bill Woods s 10 2
MT s 9 2
John Henry N 1 2
E Stevason n 1 2
Ken Williams n 2 1
Martha Smith 2 2 2
Joe Koch n 2 3
HP Packard n 3 3
Jane Rinehart n 3 2
Cecil Swenson n 4 1
Troy Cory n 4 2
Nickoline Byes N 5 3
John Harris n 5 2
Judy Harris n 5 1
FG Hartman n 6 1
DT Souse n 6 2
Magic Johnson n 6 3
George Lampton n 7 1
Linda Thomas n 7 2
Mark Hayward n 7 3
Tom Swift n 8 1
Dr. Dobbs 8 2 2
Vinnie Golden n 8 3
E Hacker n 5 3
Steve Russel n 5 2
Sparky Champion n 3 1
Tex Innerments s 8 2
Master Splinter n 20 1
The problem is that I want to use an array of 10 rows and 3 columns as a passenger list for a flight. I want to create a program that allows a user to choose from 3 choices:
1 - use manifest.txt as input data for passenger list
2 - enter passenger list data manually
3 - quit program
There are 41 passengers on the list (manifest.txt) so any 11 will be sent to one of two waiting lists: one for smoking and one for non-smoking.
If a passengers' seat request is taken, I want the passenger placed in the next closes seat.
Any help will be appreciated.
Thanks!