| | |
AIRPLANE PROGRAM
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2003
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Sep 2003
Posts: 22
Reputation:
Solved Threads: 0
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:
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:
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.
A 2D array will be done something like this:
C++ Syntax (Toggle Plain Text)
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:
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)
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.
![]() |
Similar Threads
- Re: AIRPLANE PROGRAM (Java)
- AirPlane Program (C++)
Other Threads in the C++ Forum
- Previous Thread: Great problem in VC++
- Next Thread: makin a table (noob, please help)
| Thread Tools | Search this Thread |
add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory microsoft multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





