View Single Post
Old 12-08-2005, 01:02 AM   #4 (permalink)
subodhgupta1
Registered User
 
Join Date: Sep 2005
Posts: 24
subodhgupta1 is on a distinguished road
Aeroplane Seating

Sory to bother you guys again I had planned out the entire pseudo code but I lost the entire idea behind it after reaching point where I needed help (I guess), below is the question:

Write a C++ program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows:

A B C D
A B C D
A B C D
A B C D
A B C D
A B C D
A B C D

Your program example, after should display the seat pattern with an ‘X’ marking an assigned seat. For seats 1A, 2B, and 4C 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 X D
5 A B C D
6 A B C D
7 A B C D
After displaying 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.
Note: Your program should make use of separate functions to display the seat pattern, to clear (un-assign) all seats, and to mark a user-desired seat as assigned.

And this is what I did

//---------------------------------------------------------------------------
// Symbolic Constants
#define TOTALROWS 7
#define TOTALCOLS 4
//---------------------------------------------------------------------------
// Function Prototypes
bool SeatsRemain ( char [][TOTALCOLS], int);
void DisplaySeats ( char [][TOTALCOLS], int);
void EmptySeats ( char [][TOTALCOLS], int);
//---------------------------------------------------------------------------
int main (void)
{
cout.setf (ios::fixed, ios::floatfield);
cout.setf (ios::showpoint);
cout.precision (2);
char Plane[TOTALROWS][TOTALCOLS] = { 'X' };
int aisle;
char seat;
char position;
char request[3];
bool keepGoing;
EmptySeats( Plane, TOTALROWS);
keepGoing = true;
do{
DisplaySeats( Plane, TOTALROWS);
cout << "Enter desired seat (e.g. 2B): ";
gets(request);
aisle = request[0] - '0';
position = request[1];
seat = toupper(position);
if ( (aisle <= 0) || (aisle > TOTALROWS) ||
(seat < 'A') || (seat >= 'A' + TOTALCOLS)){
keepGoing = false; //validity check
for desired seat


cout << endl << endl << endl << "Press Any Key to Continue...";
getch ();
return 0;

//__________________________________________________ _____________


Let me know if you would like to see the pseudo code that I created.
Thanks
subodhgupta1 is offline   Reply With Quote