Airplane Seating Program

Program Objective: The program is supposet to ask the user of what type of class (business, economy, first class) they want. In my program there are certain rows that are business..etc. For instance, if the user chooses firstclass, then the first two rows will be firstclass. Moreover, it will then ask the user which row they want from first class and the seat number. Once a user selects a seat, it would output "X" on the console as the selected seat and "*" with unselected. It would be outputted in this form (also it has 13 rows)


*****
**X**
*****
...


Problem: Well I have to code working, my problem is that I want it to update itself. Suppose the user wants to enter in another seat, well in my program all it does is clears the previous input and restarts. Generally speaking, if the user is asked again, then my previous seat selected wont be saved again. Another example would be that on the first attempt user selects row 1 and seat 1.


X****
*****
...

This would be the output. In his second attempt, he choose row 1 seat 2. this would be the outputted result then


*X***
...

As you can see, I want it to update itself and add and X also on the first row first seat. I'm awarew I wrote a lot, but may someone be willing to help out here and pottenailty give a clue. Thanks guys :)

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
  
void type_class_selection(char choice, int &rownumber_passenger, int &seatnumber)
{
	switch (choice)
	{
		case 'a':
			{
				//If user selects a. ask them for the seat number
				cout<<"\n\tChoose Row 1 or Row 2: ";
				cin>>rownumber_passenger;
				cout<<"\n\tChoose 1-5 seat number: ";
				cin>>seatnumber;
			}
			break;
		case 'b':
			{
				//if the user selects b do the following commands
				cout<<"\n\tChooose Row 3-10: ";
				cin>>rownumber_passenger;
				cout<<"\n\tChoose 1-5 seat number: ";
				cin>>seatnumber;
			}
			break;
		case 'c':
			{
				//if tuser enters this do the following actrions
				cout<<"\n\tChoose Row 11-13: ";
				cin>>rownumber_passenger;
				cout<<"\n\tChoose 1-5 seat number: ";
				cin>>seatnumber;
			}
			break;
		
		
	}
	



}

void filloutseats(char lists[][5],int list_size,int rowpassenger, int seatnumber)
{
	
	{
	int row_counter=0;
	int col_counter=0;
	for(row_counter=0;row_counter<list_size;row_counter++)
		{
			//Make another for loop
			for (col_counter=0;col_counter<5;col_counter++)
				{
					lists[row_counter][col_counter]='*';
					//if it equals to print out a $
					if (row_counter==rowpassenger-1 &&col_counter==seatnumber-1)
						lists[row_counter][col_counter]='&';

					cout<<lists[row_counter][col_counter];
					cout<<"\t";
				}
			//end the line
			cout<<endl;
	
		}
	}

}
int _tmain(int argc, _TCHAR* argv[])
{
	//Display program information
	display_program();

	//Declare a multidimensional array of airpaly seat that consists of 13 rows and 5 seats in each row
	char airplane_seats[13][5];

	//Display seats
	seat_open(airplane_seats,13);

	//make a variable to store in the class
	char seat_class;

	
	
	
	//Call the function
	class_type(seat_class);

	//Declare a variable for the row number the passenger wants their seat
	int what_rowPassenger;
	int what_seat;
	//call the function to print out an x where the seat is taken
	type_class_selection(seat_class, what_rowPassenger,what_seat);

	//FIl out seats
	cout<<"\n\n\n";
	filloutseats(airplane_seats,13,what_rowPassenger,what_seat);
Last edited on
Line 71 - display_program not defined.
Line 74 - airplane_seats not initialized.
Line 77 - seat_open not defined.
Line 86 - class_type not defined.

If you want to allow multiple seat selections, then you need a loop.

Your filloutseats function is trying to do three things. 1) It's trying to initialize the seat map. 2) It's marking one seat as sold. That works for the first seat, but doesn't work after that. 3) It's printing the seat map.

You should initialize the seat map at the start of the program. Then when a seat is sold, you want to mark that seat as occupied. Printing the seat map should always print the current seat map. Make those separate functions rather than trying to combine them all into one function.


Topic archived. No new replies allowed.