2D Array question

just got assigned a problem dealing with assigning random "seats" to a 2D array that is supposed to represent the seating chart of an airplane. I'm supposed to assign seats at random to 20 people in this 2D array.

Here's the exact question copy and pasted:



1. For the Airplane seating problem, you can think of it as having a 2D array, say 2 by 10. Now assign seats the following people at random (i.e. random row and column)

Alice 24,
Bob 30,
Cat 44,
David, 12
Eric 18
Fred 67
Greg 44
Helen 79
Ike 3
John 33
Kevin 21
Lucy 17
Mary 29
Nancy 41
Oliver 24
Peter 54
Queen 43
Rose 37
Steve 30
Tim 19

Any suggestions would be appreciated.
I assume the numbers next to the names are ages?

You could use a method involving two arrays; one to place passengers names in, and one to check whether that seat position has already been allocated.

Obviously you would use the rand() function - along with srand() - and give it limits so not to go over 10.
You may find this useful in your solution:

http://www.cplusplus.com/reference/algorithm/random_shuffle/
mcleano: how do you assign limits to the rand() and srand() functions? I'm completely a beginner with programming so sorry if my questions are very elementary.
Everyone has to start somewhere right?

http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/

Note that srand() should only ever be called once in your program.
Topic archived. No new replies allowed.