#include <iostream>#include <cstdlib>using namespace std;const int capacity = 10;const int firstClassCapacity = 5;enum SECTION{SECTION_FIRST, SECTION_ECONOM};void menu();int main() { menu(); return 0;}void printMenu() { system("cls"); cout << "Please type 0 to EXIT" << endl; cout << "Please type 1 for \"First class\"" << endl; cout << "Please type 2 for \"Economy\"" << endl; cout << "Choice: ";}void printBoardingPass(int seat, SECTION section) { cout << endl << endl; cout << "Your ticket:" << endl; cout << "Seat number: " << seat + 1 << endl; cout << "Section: " << (section == SECTION_FIRST ? "First Class" : "Economy") << endl; cout << endl << endl;}int firstClassSeat(bool plane[capacity]) { for (int i = 0; i < firstClassCapacity; ++i) { if (plane[i] == false) { return i; } } return -1;}int economSeat(bool plane[capacity]) { for (int i = firstClassCapacity; i < capacity; ++i) { if (plane[i] == false) { return i; } } return -1;}void menu() { bool plane[capacity]; for (int i = 0; i < capacity; ++i) { plane[i] = false; } int choice = -1, seat = 0; while (choice) { printMenu(); cin >> choice; switch(choice) { case 0 : break; case 1 : seat = firstClassSeat(plane); if (seat == -1) { int seatEc = economSeat(plane); if (seatEc != -1) { cout << "First Class is full. Would you like to be place in Economy? \n1.Yes\n2.No\n"; int c2 = -1; cin >> c2; if (c2 == 1) { plane[seatEc] = true; printBoardingPass(seatEc, SECTION_ECONOM); } else { cout << "Next flight leaves in 3 hours." << endl; } } else { cout << "Next flight leaves in 3 hours." << endl; } } else { plane[seat] = true; printBoardingPass(seat, SECTION_FIRST); } break; case 2 : seat = economSeat(plane); if (seat == -1) { int seatFirst = firstClassSeat(plane); if (seatFirst != -1) { cout << "Economy class is full. Would you like to be place in First Class? \n1.Yes\n2.No\n"; int c2 = -1; cin >> c2; if (c2 == 1) { plane[seatFirst] = true; printBoardingPass(seatFirst, SECTION_FIRST); } else { cout << "Next flight leaves in 3 hours." << endl; } } else { cout << "Next flight leaves in 3 hours." << endl; } } else { plane[seat] = true; printBoardingPass(seat, SECTION_ECONOM); } break; default : cout << "Wrong choice! Try again." << endl; } system("pause"); }}
Comments