### URGENT: Need help with Array homework

There is this assignment that is due on Monday and it has been really frustrating to me. As you can see by the quote below, the purpose of the program is to assign people seats at a theater.

 A performance theater has 2 sections of seating. Rows 1 to 5 are for premium tickets and rows 6-20 are for regular tickets. Each row has 10 seats - seats are referred as A, B, C, … H, I, and J. Row # and seat position are printed together in the tickets. For example, seats in row 2 are 2A, 2B, 2C, 2D, 2E, 2F, 2G, 2H, 2I, and 2J. Problem statement is to ask the user about the section preference (premium vs regular tickets), get # of attendees as input and assign the best possible seating (start searching for seats from the front row - keep going up until the seats are found. Seat people left to right in each row). If the party cannot be seated together, seat them in multiple rows/segments. Assume that # of tickets in each party does not exceed 10. Your program need not be "too intelligent" when the party has to be seated in multiple rows. Here is the sample input and output to give you an idea about the processing. Here is the sample input & output. Input is shown in bold. Premium(1) or Regular (2): 1 # of tickets: 5 Your seats are: 1A 1B 1C 1D 1E Premium(1) or Regular (2): 2 # of tickets: 4 Your seats are: 6A 6B 6C 6D Premium(1) or Regular (2): 1 # of tickets: 6 Your seats are: 2A 2B 2C 2D 2E 2F Premium(1) or Regular (2): 2 # of tickets: 5 Your seats are: 6E 6F 6G 6H 6I … Premium(1) or Regular (2): 1 # of tickets: 4 Your seats are: 2J 3I 3J 4J ... Premium(1) or Regular (2): 1 # of tickets: 10 Sorry, only 4 premium seats are available.

So basically the program not only has to step through each row and fill up each seat, it also has to take the remaining empty seats into account and fill them up as well even if it means assigning to multiple rows at a time. But this is really frustrating because even though I managed to sort of get it to work, I have not figured out a way to assign tickets/people to multiple rows when they are all getting filled up. Here is my code. I'd like for you to run it as well and see for yourself as I do not know if I am on the right track or not. Also I have only been working with the array for the premium seating. I have not done the regular seating yet.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596`` ``````#include using namespace std; #define PREM_ROWS 5 #define REG_ROWS 20 #define SEATS 10 bool premSeats[PREM_ROWS][SEATS]; bool regSeats [REG_ROWS][SEATS]; char seatLabels[SEATS]; void initializeArrays(){ char letter = 'A'; for(int r = 0;r> premOrReg; cout << "# of tickets: "; cin >> tickets; //if Premium is chosen if(premOrReg == 1) { while(premRowToFill < PREM_ROWS) { // if(tickets <=filledSeatsInRow) cout << "Your seats are: "; while(premSeatIndex < tickets) { premSeats[premRowToFill][premSeatIndex] = true; cout << premRowToFill+1 << seatLabels[premSeatIndex] << " " ; premSeatIndex++; } premRowToFill++; premSeatIndex = 0; break; } cout << endl; } if(premOrReg == 2) { } } while((premOrReg == 1)||(premOrReg == 2)); return 0; } ``````
Last edited on
this is only an example and only takes premium seating into account
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include using namespace std; #define PREM_ROWS 5 #define SEATS 10 bool premSeats[PREM_ROWS][SEATS] = {false}; int main() { int premOrReg; int tickets; int filledSeatsInRow = 0; int premSeatsLeft = SEATS * PREM_ROWS; do { cout << "Premium(1) or Regular (2): "; cin >> premOrReg; cout << "# of tickets: "; cin >> tickets; if(premOrReg == 1 && premSeatsLeft >= tickets) { cout << "Your seats are: "; for (int row = 0; row < PREM_ROWS; row++) { for(int col = 0; col < SEATS; col++) { if(tickets == 0) { break; } else if(premSeats[row][col] == false) { cout << row + 1<< char(col + 65) << ", "; premSeats[row][col] = true; premSeatsLeft--; tickets--; } } } } else cout << "Sorry not enough premium seats to fill your order" << endl; cout << endl; }while((premOrReg == 1)||(premOrReg == 2)); return 0; }``````
Last edited on
Thank you so much for that. I shall experiment with the code you just gave me.
Topic archived. No new replies allowed.