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;


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:

bool **array = new bool*[width];
for (int temp=0;temp<width;temp++)
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:


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:

for (int x=0;x<width;x++)
for (int y=0;y<height;y++)
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.