Skip to content

Commit 28be548

Browse files
committed
uploaded
1 parent 50d3ba0 commit 28be548

28 files changed

+107
-53
lines changed

Railway Reservation/RailwayReservation.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ int main()
3636
int age, choice;
3737
char gender, berthPreference;
3838

39-
// string c = "!AA";
40-
// passengersList = new Passenger*[95];
41-
42-
// for(int i=0; i<95; i++){
43-
// passengersList[i] = new Passenger(i, c, 19, 'M', 'U', "");
44-
// cout << i;
45-
// c[0]++;
46-
// }
47-
// irctc.bookTickets(passengersList, cheranExpress, 95, pnr);
48-
49-
// free(passengersList);
39+
string c = "!AA";
40+
passengersList = new Passenger*[95];
41+
id = 91;
42+
43+
for(int i=0; i<95; i++){
44+
passengersList[i] = new Passenger(i, c, 19, 'M', 'U', "");
45+
// cout << i;
46+
c[0]++;
47+
}
48+
irctc.bookTickets(passengersList, cheranExpress, 95, pnr);
49+
pnr = 1001;
50+
free(passengersList);
5051

5152
cout << "\n\t\t Welcome to Irctc\n\n";
5253

@@ -81,9 +82,9 @@ int main()
8182
id++;
8283
}
8384

84-
irctc.bookTickets(passengersList, cheranExpress, n, pnr);
85+
if(irctc.bookTickets(passengersList, cheranExpress, n, pnr))
86+
irctc.printList(passengersList);
8587
pnr++;
86-
irctc.printList(passengersList);
8788
break;
8889
}
8990

@@ -127,7 +128,7 @@ int main()
127128
break;
128129
}
129130
case 5: exit(0);
130-
break;
131+
break;
131132
}
132133

133134
}

Railway Reservation/Screenshot1.png

20.6 KB
Loading

Railway Reservation/Screenshot10.png

31.9 KB
Loading

Railway Reservation/Screenshot11.png

37.3 KB
Loading

Railway Reservation/Screenshot12.png

32.6 KB
Loading

Railway Reservation/Screenshot13.png

42.2 KB
Loading

Railway Reservation/Screenshot14.png

39.6 KB
Loading

Railway Reservation/Screenshot15.png

42.1 KB
Loading

Railway Reservation/Screenshot16.png

31.2 KB
Loading

Railway Reservation/Screenshot17.png

30.3 KB
Loading

Railway Reservation/Screenshot18.png

30.5 KB
Loading

Railway Reservation/Screenshot19.png

12.5 KB
Loading

Railway Reservation/Screenshot2.png

59.3 KB
Loading

Railway Reservation/Screenshot20.png

42.3 KB
Loading

Railway Reservation/Screenshot21.png

45.3 KB
Loading

Railway Reservation/Screenshot3.png

19.6 KB
Loading

Railway Reservation/Screenshot4.png

38.7 KB
Loading

Railway Reservation/Screenshot5.png

19.3 KB
Loading

Railway Reservation/Screenshot6.png

27.4 KB
Loading

Railway Reservation/Screenshot7.png

20 KB
Loading

Railway Reservation/Screenshot8.png

30.2 KB
Loading

Railway Reservation/Screenshot9.png

56.4 KB
Loading

Railway Reservation/irctc.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ class IRCTC{
1717
TrainList *head;
1818
public:
1919
void addTrain(Train *obj);
20-
void bookTickets(Passenger **passengers, Train *train, int count, int pnr);
20+
bool bookTickets(Passenger **passengers, Train *train, int count, int pnr);
2121
void cancelTicket(Train *train, int id);
2222
void printList(Passenger **list);
2323
void showAvailableTickets(Train *train);
2424
void showBookedTickets(Train *train);
2525
Passenger** filterTickets(Train *train, int pnr);
2626
};
2727

28-
void IRCTC::bookTickets(Passenger **passengers, Train *train, int count, int pnr)
28+
bool IRCTC::bookTickets(Passenger **passengers, Train *train, int count, int pnr)
2929
{
30+
int failed = 0;
3031
for(int i=0; i<count; i++){
3132
string berth;
3233
berth += passengers[i]->berthPreference;
@@ -55,10 +56,12 @@ void IRCTC::bookTickets(Passenger **passengers, Train *train, int count, int pnr
5556
}
5657
else{
5758
cout << "Unable to book ticket for passenger : " << passengers[i]->name << endl;
59+
failed++;
5860
}
5961
}
6062
}
6163
}
64+
return failed == count? false: true;
6265
}
6366

6467
Passenger** IRCTC::filterTickets(Train *train, int pnr)
@@ -100,8 +103,9 @@ Passenger** IRCTC::filterTickets(Train *train, int pnr)
100103

101104
void IRCTC::printList(Passenger **list)
102105
{
106+
cout << endl << "TicketId" << "\t" << "PassengerName" << "\t" << "BerthPreference" << "\t" << "PNR" << endl;
103107
for(int i=0; list[i]!= nullptr; i++){
104-
cout << endl << list[i]->id << "\t" << list[i]->name << "\t" << list[i]->berthPreference << "\t" << list[i]->PNR << endl;
108+
cout << endl << list[i]->id << "\t\t" << list[i]->name << "\t\t" << list[i]->berthPreference << "\t\t" << list[i]->PNR << endl;
105109
}
106110
}
107111

@@ -149,14 +153,28 @@ void IRCTC::cancelTicket(Train *train,int id)
149153

150154
void IRCTC::showAvailableTickets(Train *train)
151155
{
152-
train->tickets->viewAllEmpty();
153-
cout << endl << "Total Number of Tickets Unoccupied are : " << 63 - train->tickets->count << endl << endl;
156+
train->tickets->viewTickets();
157+
train->Rac->viewRac();
158+
train->waitingTickets->viewWaitingList();
154159
}
155160

156161
void IRCTC::showBookedTickets(Train *train)
157162
{
158-
train->tickets->viewTickets();
159-
cout << endl << "Total Number of Tickets Occupied are: " << train->tickets->count << endl;
163+
int pnr;
164+
Passenger **list;
165+
cout << endl << "Provide the PNR to view tickets info..." << endl;
166+
cin >> pnr;
167+
list = this->filterTickets(train, pnr);
168+
169+
if(list[0] != NULL){
170+
cout << endl << "TicketId" << "\t" << "PassengerName" << "\t" << "Age" << "\t" << "Gender" << "\t" <<"BerthPreference" << endl;
171+
for(int i=0; list[i] != NULL; i++){
172+
cout << list[i]->id << "\t\t" << list[i]->name << "\t\t" << list[i]->age << "\t" << list[i]->gender << "\t" << list[i]->berthPreference << endl;
173+
}
174+
}
175+
else{
176+
cout << "PNR not found" << endl;
177+
}
160178
}
161179

162180
#endif

Railway Reservation/rac.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,22 @@ void RAC::viewRac()
7373
{
7474
cout << "\n\nviewRAC\n\n";
7575
RACList *n = this->head;
76-
for(int i=0; i<this->count; i++){
77-
cout << n->passenger->name << "\t";
78-
n = n->next;
76+
77+
for(int i=0; i<18; i++){
78+
if(i < this->count){
79+
cout << n->passenger->id << "\t";
80+
n = n->next;
81+
}
82+
else{
83+
cout << "F ";
84+
}
7985
}
8086
cout << endl;
8187
}
8288

8389
Passenger** RAC::getPassengersListByPNR(int pnr)
8490
{
85-
cout << "rac list" << endl;
91+
// cout << "rac list" << endl;
8692
if(this->head == NULL){
8793
return nullptr;
8894
}
@@ -106,7 +112,7 @@ Passenger** RAC::getPassengersListByPNR(int pnr)
106112

107113
bool RAC::remove(string field, string value)
108114
{
109-
cout << endl << "value :" << value << endl;
115+
// cout << endl << "value :" << value << endl;
110116
int id = stoi(value);
111117
RACList *temp, *d, *prv = NULL;
112118

Railway Reservation/readme.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
### The RailwayReservation code produces the Following output.
3+
4+
![image](./Screenshot1.png)
5+
![image](./Screenshot2.png)
6+
![image](./Screenshot3.png)
7+
![image](./Screenshot4.png)
8+
![image](./Screenshot5.png)
9+
![image](./Screenshot6.png)
10+
![image](./Screenshot7.png)
11+
![image](./Screenshot8.png)
12+
![image](./Screenshot9.png)
13+
14+
<br>
15+
<br>
16+
17+
### Now, the following output are from static data which is uncommented on RailwayReservation to fill all the tickets
18+
![image](./Screenshot10.png)
19+
![image](./Screenshot11.png)
20+
![image](./Screenshot12.png)
21+
![image](./Screenshot13.png)
22+
![image](./Screenshot14.png)
23+
24+
Here the ticket is removed from RAC list and produces a vacancy and therefore first ticket from waiting list moved to RAC List and hence produces a vacancy in waiting list
25+
<br>
26+
27+
![image](./Screenshot15.png)
28+
![image](./Screenshot16.png)
29+
30+
![image](./Screenshot17.png)
31+
![image](./Screenshot18.png)
32+
![image](./Screenshot19.png)
33+
![image](./Screenshot20.png)
34+
![image](./Screenshot21.png)
35+

Railway Reservation/ticket.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int* Ticket::getAvailable(string field, string value)
126126

127127
Passenger** Ticket::getPassengersListByPNR(int pnr)
128128
{
129-
cout << " ticket list" << endl;
129+
// cout << " ticket list" << endl;
130130
Passenger **list = new Passenger*[64];
131131
int k=0;
132132
for(int i=0; i<64; i++){
@@ -168,33 +168,20 @@ int* Ticket::getEmpty()
168168

169169
void Ticket::viewTickets()
170170
{
171-
171+
cout << "LB" << "\t" << "LB" << "\t" << "MB" << "\t" << "MB" <<"\t" << "UB" << "\t" << "UB" << "\t" << "SUB" << endl;
172172
for(int i=0; i<9; i++){
173173
for(int j=0; j<7; j++){
174-
cout << i << j;
174+
// cout << i << j;
175175
if(this->tkts[i][j] ==nullptr)
176176
cout << "F" << "\t";
177177
else {
178-
cout << this->tkts[i][j]->name << "\t";
178+
cout << this->tkts[i][j]->id << "\t";
179179
}
180180
}
181181
cout << endl;
182182
}
183183

184184
}
185185

186-
void Ticket::viewAllEmpty()
187-
{
188-
for(int i=0; i<9; i++){
189-
for(int j=0; j<7; j++){
190-
if(this->tkts[i][j] == nullptr){
191-
cout << i << j << "\t";
192-
}
193-
else
194-
cout << "*\t";
195-
}
196-
cout << endl;
197-
}
198-
199-
}
186+
200187
#endif

Railway Reservation/train.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ void Train::showAvailableTickets()
5959

6060
void Train::allotTicket(Passenger *passenger, int* ind, int pnr)
6161
{
62-
cout << endl << "ticket allocation" << endl;
62+
// cout << endl << "ticket allocation" << endl;
6363
passenger->PNR = pnr;
6464
this->tickets->insert(passenger, ind);
6565
}
6666

6767
void Train::allotRac(Passenger *passenger, int pnr)
6868
{
69-
cout << endl << "RAC Ticket" << endl;
69+
// cout << endl << "RAC Ticket" << endl;
7070
passenger->PNR = pnr;
7171
this->Rac->insertToRacList(passenger);
7272
}
7373

7474
void Train::allotWaiting(Passenger *passenger, int pnr)
7575
{
76-
cout << endl << "Waiting Ticket" << endl;
76+
// cout << endl << "Waiting Ticket" << endl;
7777
passenger->PNR = pnr;
7878
this->waitingTickets->insertToWaitingList(passenger);
7979
}

Railway Reservation/waitinglist.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Passenger **WaitingTickets::getPassengersListByPNR(int pnr)
9191
}
9292
bool WaitingTickets::remove(string field, string value)
9393
{
94-
cout << endl << "value :" << value << endl;
94+
// cout << endl << "value :" << value << endl;
9595
int id = stoi(value);
9696
WaitingList *temp, *d, *prv = NULL;
9797

@@ -124,12 +124,19 @@ bool WaitingTickets::remove(string field, string value)
124124
void WaitingTickets::viewWaitingList()
125125
{
126126
struct WaitingList *n = this->head;
127-
cout << endl << "Waiting list :" << endl;
128-
for(int i=0; i<this->count; i++){
129-
cout << n->passenger->name << "\t";
130-
n= n->next;
127+
cout << endl << "Waiting list :" << endl << endl;
128+
129+
130+
for(int i=0; i<10; i++){
131+
if(i < this->count){
132+
cout << n->passenger->id << "\t";
133+
n= n->next;
134+
}
135+
else{
136+
cout << "F ";
137+
}
131138
}
132-
cout << "\n";
139+
cout << "\n\n";
133140
}
134141

135142
#endif

0 commit comments

Comments
 (0)