Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <iostream> #include <iomanip> #include <string> #include <istream> #include <fstream> using namespace std; const int

numberOfRow = 14; const int numberOfCol = 7; void print(char matrix[][7], int numberOfRow, int numberOfCol); int main() { char matrix[numberOfRow][numberOfCol], seat[numberOfRow][numberOfCol]; int i, j,smoke,option; int row,col; bool another =true; for(i = 1; i < numberOfRow; i++) for(j = 1; j < numberOfCol; j++) matrix[i][j] = '*'; while(another) { print( matrix, numberOfRow, numberOfCol ); cout << "\nMenu:\n"; cout << "Ticket type:\n1) First class\n2) Economy class\n"; cout << "Choose your ticket type: "; cin >> option; switch (option) { case 1: { cout <<"Row 1 and 2 are first class" << endl; cout << "Enter row: "; cin >> row; cout << "Enter seat: "; cin >> col; cout << endl; if( matrix[row][col] == '*') { matrix[row][col] = 'X'; } else { cout << "Invalid seat choice.\n"<< endl; } } break; case 2:

{ cout << "Are you smoking?\n1) No\n2) Yes"<<endl; cin >> smoke; if (smoke == 1) { cout << "Choose only row 3 to 7" <<endl; cout << "Enter row: "; cin >> row; cout << "Enter seat: "; cin >> col; cout << endl; if( matrix[row][col] == '*') { matrix[row][col] = 'X'; } else { cout << "Invalid seat choice.\n"<< endl; } } else if (smoke == 2) { cout << "Only row 8 to 13 are available for smoking" << endl; cout << "Enter row: "; cin >> row; cout << "Enter seat: "; cin >> col; cout << endl; if( matrix[row][col] == '*') { matrix[row][col] = 'X'; } else { cout << "Invalid seat choice.\n"<< endl; } } else cout << "Invalid seat" << endl; } break; default : cout << "Invalid choice.\n" << endl; system ("CLS"); } } return 0; } void print(char matrix[][7], int numberOfRow, int numberOfCol) {

int row, col, i, j; cout << "Rows 1 and 2 are first class." << endl; cout << "The remaining rows are economy class." << endl; cout << "Rows 1 through 7 are non smoking." << endl; cout << "* Seats available\n"; cout << "X Reserved Seats\n\n"; cout << " Seat" << setw(3) << "1" << setw(3) << "2" << setw(3) << << setw(3) << "4" << setw(3) << "5" << setw(3) << "6" << endl; for(i = 1; i < numberOfRow; i++) { cout << "Row" << setw(3) << i; for(j=1; numberOfCol > j; j++) cout << setw(3) << matrix[i][j]; cout << endl; } }

"3"

You might also like