943,312 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5907
  • C++ RSS
Sep 5th, 2003
0

AIRPLANE PROGRAM

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Raineri33 is offline Offline
1 posts
since Sep 2003
Sep 15th, 2003
0

Re: AIRPLANE PROGRAM

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:

C++ Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Mike29936 is offline Offline
22 posts
since Sep 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Great problem in VC++
Next Thread in C++ Forum Timeline: makin a table (noob, please help)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC