C++ 2D ARRAY, Continue this codes and change the array to seat[6][6]. Include a loop that asks the user if he wants to try again or no. If the user enters the reserved seat again then display "this seat is taken already". Upon trying again, the reserved seat displayed as (X) must be displayed. My Code: #include using namespace std; int main() { cout << "Bus Seats:\n"; cout << "* A B C D\n" << "1 * * * *\n" << "2 * * * *\n" << "3 * * * *\n" << "4 * * * *\n"; char seat[5][5]; int row, column; char col; cout << "Enter the row of your selected seat: "; cin >> row; cout << "Enter the column of your selected seat: "; cin >> col; for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ if(i==0){ switch (j) { case 0: seat[i][j]='*'; break; case 1: seat[i][j]='A'; break; case 2: seat[i][j]='B'; break; case 3: seat[i][j]='C'; break; case 4: seat[i][j]='D'; break; } } else if (j==0) { switch(i) { case 1: seat[i][j]='1'; break; case 2: seat[i][j]='2'; break; case 3: seat[i][j]='3'; break; case 4: seat[i][j]='4'; break; } } else { seat[i][j]='*'; } } } switch (col) { case 'A': seat[row][1]='X'; break; case 'B': seat[row][1]='X'; break; case 'C': seat[row][1]='X'; break; case 'D': seat[row][1]='X'; break; } for(int k=0; k<5; k++){ for(int l=0; l<5; l++){ cout << seat[k][l] << " "; } cout << endl; } return 0; }
C++ 2D ARRAY, Continue this codes and change the array to seat[6][6]. Include a loop that asks the user if he wants to try again or no. If the user enters the reserved seat again then display "this seat is taken already". Upon trying again, the reserved seat displayed as (X) must be displayed. My Code: #include <iostream> using namespace std; int main() { cout << "Bus Seats:\n"; cout << "* A B C D\n" << "1 * * * *\n" << "2 * * * *\n" << "3 * * * *\n" << "4 * * * *\n"; char seat[5][5]; int row, column; char col; cout << "Enter the row of your selected seat: "; cin >> row; cout << "Enter the column of your selected seat: "; cin >> col; for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ if(i==0){ switch (j) { case 0: seat[i][j]='*'; break; case 1: seat[i][j]='A'; break; case 2: seat[i][j]='B'; break; case 3: seat[i][j]='C'; break; case 4: seat[i][j]='D'; break; } } else if (j==0) { switch(i) { case 1: seat[i][j]='1'; break; case 2: seat[i][j]='2'; break; case 3: seat[i][j]='3'; break; case 4: seat[i][j]='4'; break; } } else { seat[i][j]='*'; } } } switch (col) { case 'A': seat[row][1]='X'; break; case 'B': seat[row][1]='X'; break; case 'C': seat[row][1]='X'; break; case 'D': seat[row][1]='X'; break; } for(int k=0; k<5; k++){ for(int l=0; l<5; l++){ cout << seat[k][l] << " "; } cout << endl; } return 0; }
Step by step
Solved in 2 steps with 2 images