Hi, my assignment is to assign passengers seats in an airplane. assuming the airplane with seat numbering like this:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
The program should show the seat pattern, with an X marking the seats already assigned. For example, after seat 1A, 2B, 4C are taken, the display should be:
1 X B C D
2 A X C D
3 A B C D
4 A B X D
5 A B C D
6 A B C D
7 A B C D
I know this assignment has been asked several times, and I read some posts about this assignment too, however, none really addresses the problem I am having right now.
(1) My program run fine for the first time, it was able to assign X to ONE seat, however, when I try to repeat the process, it would not assign another X to the second seat.
(2) My program has a do while loop that is supposed to repeat the above process for as long as the user wishes. However, due to unknown reason I am only able to repeat the process one time, and the program terminates after the second loop.
Below is my code:
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
|
#include <iostream>
using namespace std;
const int num_row = 7;
const int num_column = 5;
int main()
{
int index1, index2;
char arr[num_row][num_column];
char letter = 'A';
char num = '1';
char in1, in2, again;
for (index1 =0; index1 < 7; index1++) // this loop assign A B C D to all 7 rows
{
for (index2 = 1; index2 <5; index2++)
{
arr[index1][index2] = letter;
letter++;
}
letter = 'A';
}
for (index1= 0; index1< 7; index1++) //This loop assign the number 1 to 7 to the 7 rows
{
arr[index1][0] = num;
num++;
}
for (index1 = 0; index1 < 7; index1++) // this loop shows the plane seats
{
for (index2 = 0; index2 < 5; index2++)
{
cout << arr[index1][index2] << " ";
}
cout << endl;
}
cout << endl;
do // this loop repeat the process
{
cout << "type a seat \n";
cin.get(in1); // getting first character
cin.get(in2); //getting second character
in2 = toupper(in2);
for (index1 = 0; index1 < 7; index1++) //this loop mark X to a seat
{
if (in1 == arr[index1][0])
{for (index2 = 1; index2 < 5; index2++)
{if (in2 == arr[index1][index2])
{arr[index1][index2] = 'X';}
}
}
}
for (index1 = 0; index1 < 7; index1++) //This loop shows whats happen after the seat is marked
{
{
for (index2 = 0; index2 < 5; index2++)
{
cout << arr[index1][index2] << " ";
}
cout << endl;
}
}
cout << "Again? \n";
cin >> again;
}while (toupper(again) == 'Y');
}
|
Thank you very much again and any comments or help is greatly appreciated.