plz help(Airline Reservation System)i really stuck

plz help(Airline Reservation System)i really stuck,


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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <iostream>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;

//Declare function proto type
int assignSeat(int seat_num, int row_num, int pass_num);
int num1(char);
int num(char);

int NumSeats = 10;

void InitializeSeats();
void Reserve();
void Cancel();
void ChangeSeat();
void Display();

struct Seat
  {
      char pass_name[80];
      int Available;
  };
  
  struct Seat SeatArray[1][10];
  
int main()
{      
   char seatchioce = 0;
   int row_num = 5;
   char a = 0;
   char w = 0;
  
  int total_passenger = 10;
  
  char arr1[][5] = {"1A","2A","3A","4A","5A",};
  char arr2[][5] = {"6B","7B","8B","9B","10B",};
    
  int MenuChoice;

  InitializeSeats();
  while(1)
  {
      cout << " 1. Reserve" << endl;
      cout << " 2. Cancel" << endl;
      cout << " 3. Change Seat" << endl;
      cout << " 4. Display" << endl;
      cout << " 5. Exit" << endl;

      cout << "Enter your choice: ";
      cin >> MenuChoice;

    if((MenuChoice < 0) && (MenuChoice > 5))
    {
      cout << "Invalid Choice" << endl;
      system("Pause Try Again");
    }
    else
    {
        switch(MenuChoice)
        {
            case 1: Reserve();
                break;
            case 2: Cancel();
                break;
            case 3: ChangeSeat();
                break;
            case 4: Display();
                break;
            case 5:
                exit(1);
        }
    }
    cin.get();  
  }
  
return 0;

}
void Reserve() //This function is for reserv the seats
{
    int pass_num = 10;

    cout << "Wellcome to Airline Passenger seat assignment" << endl;
        
     cout <<"All"<< NumSeats << " seats are available " << endl;
    
     for(int i = 0; i < 10; i++)
     {
         for(int j = 0; j < 10; j++)
         {
             if(SeatArray[i][j].Available == 1)
             {
                 cout << "Please enter the passenger name: ";
                 cin >> SeatArray[i][j].pass_name;
                 SeatArray[i][j].Available = 0;
                 NumSeats--;
                 return;
             }
         }
        
     }
}
void Cancel()// This function is for Cancel the seat
{
    char CancelPassengerName[80];

    cout << "Enter the Passenger to be cancelled: ";
    cin >> CancelPassengerName;
    for(int i =0; i <5; i++)
    {
        for(int j=0; j<2; j++)
        {
            
            if(strcmp(SeatArray[i][j].pass_name, CancelPassengerName) == 0)
            {
                NumSeats++;
                SeatArray[i][j].Available = 1;
                return;
            }
        }
    }
    cout << " Passenger not in the list" << endl;
}
void ChangeSeat()//This function is for Change the seat
{
    char MovePassenger[80];
    int SeatRow, SeatColumn;

    cout << "Enter the passenger name to be moved: ";
    cin >> MovePassenger;

    for(int i = 0; i < 5; i++)
    {    for(int j = 0; j < 2; j++)
        {
            if(strcmp(SeatArray[i][j].pass_name, MovePassenger) == 0)
            {
                SeatRow = i;
                SeatColumn = j;
            }
        }
    }

    if(NumSeats <= 0)
    {
        cout << "No seat available there for you cannot change seat" << endl;
        return;
    }
    else{
        for(int i = 0; i < 5; i++)
        {
            for(int j = 0; j < 2; j++)
            {
                if(SeatArray[i][j].Available == 1)
                {
                    strcpy_s(SeatArray[i][j].pass_name, MovePassenger);
                    SeatArray[SeatRow][SeatColumn].Available = 1;
                    SeatArray[i][j].Available = 0;

                    return;
                }
            }
        }
    }
}
void Display()//Display the seat assingment for the all reservation
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            if(SeatArray[i][j].Available == 0)
            {
                cout << SeatArray[i][j].pass_name << " = " << i+1;
				if (j == 0) { cout << "First Class" << endl; }
				else { cout << "Economy Class" << endl; }
				

            }
            else
            {
                if(j == 1)
                    cout << i+1 << "Economy Class" << endl;
                else
                    cout << i+1 << "first Class" << endl;
            }
        }
    }
}

void InitializeSeats()//Initialy all seats are available
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 6; j++)
            SeatArray[i][j].Available = 1;
    }
}


this is working, am stuck on Reserve,i want to add when 1: for Reserve();
is to ask u to press one for first class or economy
can someone help me to add the codes and tell me where am making the mistake

Last edited on
To get the program to compile I:
1) #include <cstdlib>
2) Line 157: strcpy_s to strcpy

Afterwards, I would run the program and if I pressed a number in the first prompt (Select a number, 1. Reserve, 2. Cancel, etc...) it would instantly tell me the program has stopped responding. So I'm not sure what you have going on :/
for the reserve(), ask economy/first class before looping. Then you would be able to check only economy of only first class.

Looking at some of your previous code:

line 37: "1C" I think is meant to be "1A".

line 43: while(1) is forcing the loop. would be better to use a end loop indicator.
e.g.

endLoop = 0;

while (endLoop == 0)
{
...
case (5) : { endLoop = 1;
break;
}
}

line 54: if ((menuItem < 0) && (menuItem > 5))
this will never be true and the else will always be taken. needs ||.

hope some of this helps.
Line 26: your array is defined seatArray[1][10] but your functions dont loop accordingly. So as you start looping through the array, you are going to change or use data outside of the array.

Last edited on
Topic archived. No new replies allowed.