Seating Assignment

I need help doing a seating assignment.Write a program to assign passengers seats. Assume the seat numbering as follows.
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 display the seat pattern, with an X marking the seats already assigned. For example, after seats 1A, 2B, 4D are taken the display should look like this:

1 X B C D
2 A X C D
3 A B C D
4 A B C X
5 A B C D
6 A B C D
7 A B C D

After displaying the the seats available, the program prompts for the seat desired, the user types in a seat, and then the display of available seats is updated. This continues until all seats are filled or until the user signals that the program should end. If the user types in a seat that is already assigned the program should say that that seat is occupied and ask for another choice.

here is the code I have so far. The program should not use pointers. If you can please help me to complete it and also if you can explain what you did so I can learn.

#include <iostream>

#include <cmath>

const int MAX_ROW = 7;

const int MAX_SEAT = 4;

void display_seating(char a[][MAX_SEAT], int rows);

bool assign_seat(char a[][MAX_SEAT], int rows, int row, int col);

int main()
{

using namespace std;
int row, col;

int input_row;
char input_seat;

char seat[MAX_ROW][MAX_SEAT];
for(row = 0; row < MAX_ROW; row++)

for(col = 0; col < MAX_SEAT; col++)seat[row][col] = static_cast<char>(toupper('A') + col);
display_seating(seat,MAX_ROW);

cin >> input_row;

cin >> input_seat;

col = toupper(input_seat) - toupper('A');
return 0;

}


void display_seating(char a[][MAX_SEAT], int rows)
{

using namespace std;for(int row = 0; row < rows; row++)
{

cout << row;

for(int col = 0; col < MAX_SEAT; col++)
{

cout << a[row][col];

}

cout << endl;

}

}
using namespace std should appear beneath the #include headers.
I can`t see anything wrong with your code. Does it compile? What results are you getting?
So your array [7][4] is one of 7 rows and each row holds an array of 4 seats.A,B,C and D.
You now need load this array .
string array [][4]={{A,B,C,D},{A,B,C,D},{A,B,C,D},{A,BC,D},{A,BC,D},{A,B,C,D},{A,B,C,D}};
Now you can refer to any seat and change it from its capital letter designation to 'X'
For example
array[3][2] = 'X' will produce {A,B,C,D},{A,B,C,D},{A,B,C,D},{A,BX,D},{A,BC,D},{A,B,C,D},{A,B,C,D}
closed account (jwC5fSEw)
using namespace std; should be global; that way you wouldn't have to use it multiple times.

Please put this in code tags, as it's very hard to read otherwise.
Buffbill this is the code that i have so far. The only thing that is wrong is when all the seats are filled it is suppose to exit the program and it does not do that. It will ask me to go again. I have two forms of this code the one avboe and another and ther both the same. and also in my choose seats I need help making it say invalid seat it I were to hit a letter A-Z. Because when i hit one of those it will say pick a seat repeatedly like 1000's times. If you can fix those problems i would appreciate it. And if you do can you explain why you did that so I can learn it. this is the code that i got.

#include <iostream>

#include <cmath>
using namespace std;
const int MAX_ROW = 7;

const int MAX_SEAT = 4;
void chooseseat(char[][MAX_SEAT]);

void clearseats(char[][MAX_SEAT]);

void display_seating(char [][MAX_SEAT]);

int main()

{
int row, col;
int input_row,left;
left=MAX_SEAT*MAX_ROW;
char seat[MAX_ROW][MAX_SEAT],more='Y';
clearseats(seat);
display_seating(seat);
while(left>0&&toupper(more)=='Y')
{chooseseat(seat);
display_seating(seat);
cout<<"choose another seat(Y/N)? ";
cin>>more;
}
system("pause");
return 0;

}

void clearseats(char seats[][MAX_SEAT])
{int i,j;
for(i=0;i<MAX_ROW;i++)
for(j=0;j<MAX_SEAT;j++)
seats[i][j]=(char)(65+j); //65='A'
return;
}
void chooseseat(char seats[][MAX_SEAT])
{int row,col;
char seatcol;
do{
cout<<"Enter Seat row desired 1-"<<MAX_ROW<<": ";
cin>>row;
while(row>MAX_ROW||row<1) //valid row?
{cout<<"invalid row\n";
cout<<"Enter Seat row desired 1-"<<MAX_ROW<<": ";
cin>>row;
}
row--;
cout<<"Enter Seat desired A-"<<(char)('A'-1+MAX_SEAT)<<": ";
cin>>seatcol;
seatcol=toupper(seatcol);//change to upper case so that can always subtract 'A'
col=seatcol-'A'; //by subtracting A, it changes A to 0, B to 1, C to 2, D to 3
while(col>=MAX_SEAT||col<0) //valid seat?
{cout<<col<<endl;
cout<<"invalid seat\n";
cout<<"Enter Seat desired A-"<<(char)('A'-1+MAX_SEAT)<<": ";
cin>>seatcol;
seatcol=toupper(seatcol);
col=seatcol-'A';
}
if( seats[row][col]=='X') //if seat valid, mark it as "taken"
cout<<"Seat already chosen-rechoose\n";
}while (seats[row][col]=='X');
seats[row][col]='X';
return;
}
void display_seating(char seats[][MAX_SEAT])
{int i,j;
for(i=0;i<MAX_ROW;i++)
{cout<<(i+1)<<" ";
for(j=0;j<MAX_SEAT;j++)
{cout<<seats[i][j]<<" ";
if(j%2!=0)
cout<<" ";
}
cout<<endl;
}
return;
}
Yes, well somewhere in the relevant function you could include a count++ or equivalent so that you can keep a count of the seats allocated and a break statement if count gets to 28.
You may be able to amend your while condition to include (..... seatcol <'E' ).
BTW it helps others to take an interest if you place you code in code tags by selecting it and hitting <>.
rgds.
Topic archived. No new replies allowed.