Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Deven Pace - Course Project
- // Airline Seat Reservation Program
- //Start
- //develop constants and function prototypes
- //declare each col and row values
- //develope display menu functions
- //open seat price File
- //if opened unsuccessful, code error message
- //code switch statement for each seating options
- //seating option functions
- //end
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- using namespace std;
- //!!!Remember * is taken and # is available!!!//
- //------------------------------------------------------------------------------
- //---Constants---//
- //------------------------------------------------------------------------------
- //---First Class---//
- const int firstCOLS = 4;
- const int firstROWS = 5;
- //---Coach---//
- const int coachCOLS = 6;
- const int coachROWS = 5;
- //------------------------------------------------------------------------------
- //---Function Proto---//
- //------------------------------------------------------------------------------
- void seatChart(double firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray [coachROWS][coachCOLS]);
- void displayMenu(double, double firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray [coachROWS][coachCOLS]);
- //------------------------------------------------------------------------------
- //---Main Program---//
- //------------------------------------------------------------------------------
- int main()
- {
- //---Variables---//
- double choice = 0;
- const int firstClass = 1,
- firstCoach = 2,
- secondCoach = 3,
- displaySeat = 4,
- EXIT = 5;
- double firstArray[firstROWS][firstCOLS];
- double coachOneArray[coachROWS][coachCOLS];
- double coachTwoArray[coachROWS][coachCOLS];
- //---Start of Menu---//
- cout << "Rigsby Programming Airline Reservation" << endl;
- cout << "--------------------------------------" << endl;
- //---display menu options---//
- displayMenu(choice, firstArray,coachOneArray, coachTwoArray);
- return 0;
- }
- //------------------------------------------------------------------------------
- //---Display Menu Function---//
- //------------------------------------------------------------------------------
- void displayMenu(double, double, firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray[coachROWS][coachCOLS])
- {
- //---Variables---//
- int CHOICE;
- int firstClassRow, firstClassCol;
- int secondClassRow, secondClassCol;
- double countFirst = 0, countFirstCoach = 0, countSecondCoach = 0;
- const int FIRSTCLASS = 1,
- FIRSTCOACH = 2,
- SECONDCOACH = 3,
- DISPLAYSEAT = 4,
- EXIT = 5;
- double firstPrice;
- double coachOnePrice;
- double coachTwoPrice;
- //---Menu---//
- cout << "Please choose from the following option: (1-5)" << endl;
- cout << "----------------------------------------------\n" << endl;
- cout << "1: First Class" << endl;
- cout << "2: First Coach" << endl;
- cout << "3: Second Coach" << endl;
- cout << "4: Display Available Seating" << endl;
- cout << "5: Exit" << endl;
- //---User Input---//
- cin >> CHOICE;
- //------------------------------------------------------------------------------
- //---Open Input File/Check for failure---//
- //------------------------------------------------------------------------------
- //---Open File---///
- ifstream inputfile;
- inputfile.open("SeatPrices.txt");
- //---Validation Error---//
- if (inputfile.fail())
- {
- cout << "Sorry, that file does not exits or can not be found";
- exit(1);
- }
- //---Colect Numbers From File---//
- inputfile >> firstPrice;
- inputfile >> coachOnePrice;
- inputfile >> coachTwoPrice;
- //---Close File---//
- inputfile.close();
- //------------------------------------------------------------------------------
- //---Switch Statements and Menu---//
- //------------------------------------------------------------------------------
- switch (CHOICE)
- {
- //---First Class Case---//
- case FIRSTCLASS:
- cout << "You have selected to reserve first class" << endl;
- cout << "\nThe price for a first class seat is: $" << firstPrice << endl;
- cout << "\nIf you would like to continue, please choose a seat: (1-5) ";
- cin >> firstClassRow;
- //---If statements---//
- if (firstClassRow > 5)
- {
- cout <<"\nYou have entered an incorrect row number, please choose 1-5 ";
- cin >> firstClassRow;
- }
- cout << "\nPlease select an available seat: (1-4)";
- cin >> firstClassCol;
- if (firstClassCol > 4)
- {
- cout << "You have entered an incorrect seat number, please chose 1-4 ";
- cin >> firstClassCol;
- }
- if (firstArray[firstROWS - 1][firstCOLS - 1] != '*')
- {
- firstArray[firstROWS - 1][firstCOLS - 1] = '*';
- cout << endl << "Your seat has been reserved\n";
- countFirst++;
- }
- else {
- cout << "Sorry, that seat is occupied." << endl;
- }
- break;
- //---First Coach Case---//
- case FIRSTCOACH:
- cout << "You have chosen to reserve first coach class" << endl;
- cout << "\nThe price for a first coach seat is: $" << coachOnePrice << endl;
- cout << "\nNow please pick which row you would like to sit in: ";
- cin >> firstClassCol;
- cout << "Please pick which seat you would like to sit in. Please enter between 6-10: ";
- cin >> firstClassCol;
- if (firstClassCol > 10)
- {
- cout << "\nYou have entered an incorrect row number, please enter between 6-10 ";
- cin >> firstClassCol;
- }
- cout << "\nPlease pick which seat you would like to sit in, please enter between 1-6: ";
- cin >> firstClassCol;
- if (firstClassCol > 6)
- {
- cout << "You have entered an incorrect seat number, please enter between 1-6";
- cin >> firstClassCol;
- }
- if (coachOneArray[coachROWS - 1][coachCOLS - 1] != '*')
- {
- coachOneArray[coachROWS - 1][coachCOLS - 1] = '*';
- cout << endl << "Your seat has been reserved\n";
- countFirstCoach++;
- }
- else {
- cout << "I'm sorry the seat is occupied" << endl;
- }
- break;
- //---Second Coach Case---//
- case SECONDCOACH:
- cout << "You have chosen to reserve second coach class" << endl;
- cout << "\nThe price for a second coach seat is: $" << coachTwoPrice << endl;
- cout << "\n Now please pick which r ow you would like to sit in: ";
- cin >> secondClassRow;
- if (secondClassRow > 15)
- {
- cout << "\n You have entered an invalid row number, please enter between 11-15 ";
- cin >> secondClassRow;
- }
- cout << "\nPlease pick which seat you would like to sit in, please entere between 1-6: ";
- cin >> secondClassCol;
- if (secondClassCol > 6)
- {
- cout << "You have entered an invalid seat number, please pick between 1-6";
- cin >> secondClassCol;
- }
- if (coachTwoArray[coachROWS - 1][coachCOLS - 1] != '*')
- {
- coachTwoArray[coachROWS - 1][coachCOLS - 1] = '*';
- cout << endl << "Your seat has been reserved\n";
- countSecondCoach++;
- }
- else {
- cout <<"I'm sorry, that seat is occupied." << endl;
- }
- break;
- //---Display Case---//
- case DISPLAYSEAT:
- seatChart(firstArray, coachOneArray, coachTwoArray);
- break;
- //---Exit Case---//
- case EXIT:
- cout <<"You have chosen to exit the program." << endl;
- exit(1);
- break;
- }
- }
- //------------------------------------------------------------------------------
- //---Function for the Seating Chart---//
- //------------------------------------------------------------------------------
- void seatChart(double firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray[coachROWS][coachCOLS])
- {
- cout << "The seating chart is as follows:" << endl;
- cout << "--------------------------------" << endl;
- //---First Class Seating---//
- cout << "First Class is seats 1-4 and Row 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;
- }
- //---First Coach seating---//
- cout << "First Coach Class is seats 1-6 and Row 6-10\n" << endl;
- for (int x = 0; x < coachROWS; x++)
- {
- for (int y = 0; y < coachCOLS; y++)
- {
- coachOneArray[x][y] = '#';
- cout << coachOneArray[x][y];
- }
- cout << endl;
- }
- //---Second Coach seating---//
- 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++)
- {
- coachOneArray[x][y] = '#';
- cout << coachTwoArray[x][y];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement