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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<iostream>

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<PREM_ROWS;r++)
	{
		for(int s = 0;s<SEATS;s++)
		{

			premSeats[r][s] = false;

		}
	}

	for(int r = 0;r<REG_ROWS;r++)
	{
		for(int s = 0;s<SEATS;s++)
		{

			regSeats[r][s] = false;

		}
	}

	for(int s = 0;s<SEATS;s++)
    {
        seatLabels[s] = letter;
        letter++;
    }

}

int main()
{
	initializeArrays();

	int premOrReg;
	int tickets;
	int premRowToFill = 0;
	int premSeatIndex = 0;
	int filledSeatsInRow = 0;

	do
    {
        cout << "Premium(1) or Regular (2): ";
        cin >> 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
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.