AIRPLANE PROGRAM

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2003
Posts: 1
Reputation: Raineri33 is an unknown quantity at this point 
Solved Threads: 0
Raineri33 Raineri33 is offline Offline
Newbie Poster

AIRPLANE PROGRAM

 
0
  #1
Sep 5th, 2003
I am new to c++, and i have a program to do as follows:
1) fill a 2D array for the seat chart with * ... DONE
2) add a passenger to the plane
I am stuck here, i have the info put into the cin statements etc, but how do i make it so that it makes an 'X' in the seat that they want to sit in ?????
3) sort the list of passengers added
I have written a selection sort as follow: (can anyone tell me why it will not compile with code?
//prototype: void print_list(pass_rec passlist[size] ,int );
//function call: print_list(passlist,count);
void print_list(pass_rec passlist,int count)
{
int min_loc=0;
pass_rec temp;
for(int pass=1; pass < count; pass++)
{
min_loc = pass-1;
for(int i = pass; i < count; i++)
{
if(passlist[min_loc] > passlist[i])
min_loc = i;
}
if(min_loc != pass-1)
{
temp.lname = passlist[min_loc].lname;
passlist[min_loc] = passlist[pass-1];
passlist[pass-1] = temp;
}
cout << passlist[min_loc] << endl;
}
system("pause");
}

PLEASE ANYONE HELP
Reply With Quote Quick reply to this message  
Join Date: Sep 2003
Posts: 22
Reputation: Mike29936 is an unknown quantity at this point 
Solved Threads: 0
Mike29936 Mike29936 is offline Offline
Newbie Poster

Re: AIRPLANE PROGRAM

 
0
  #2
Sep 15th, 2003
From my understanding of your post, it sounds like you want to get a 2D array of seats, add passengers, and sort em'.

A 2D array will be done something like this:

  1. bool **array = new bool*[width];
  2. for (int temp=0;temp<width;temp++)
  3. array[temp] = new bool[height];

Thus, you have an array of boolean values. I'll say they're true if a person's in the seat, false otherwise.

Now then, you want to add a passenger to the array? Simple with our newfound 2D array:

array[x][y] = true;

Or if you want code you can be proud of, you could set up the 2D array to be passenger objects, and edit their name, etc.

Anyways, once you set up the 2D array of anything, accessing any member is doing this:

array[x][y];

Where x is the spot out of the width, and y is the spot out of the height.

If you want to print out their seats, just do 2 for loops, going down the height, having the 2nd scroll across the width:

  1. for (int x=0;x<width;x++)
  2. for (int y=0;y<height;y++)
  3. printf("%c",array[x][y]==true ? 'x':' ';

I don't understand what you mean by sorting the passengers.

And understand this is all off the top of my head. If there's any problems, I might actually go to my compiler and work something out.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC