-
Notifications
You must be signed in to change notification settings - Fork 0
/
irctc_main_new_update.cpp
112 lines (95 loc) · 3.1 KB
/
irctc_main_new_update.cpp
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
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
class Ticket {
public:
string departureTime;
string departs;
string arrive;
string arrivalTime;
string duration;
string passengerName;
string ticketClass;
string PNR;
Ticket(string depTime, string dep, string arr, string arrTime, string dur, string name, string tClass, string pnr)
: departureTime(depTime), departs(dep), arrive(arr), arrivalTime(arrTime), duration(dur),
passengerName(name), ticketClass(tClass), PNR(pnr) {}
};
class RailwayMember {
private:
int maxTickets;
public:
RailwayMember(int max) : maxTickets(max) {}
bool bookTicket(vector<Ticket>& tickets, const Ticket& newTicket) {
if (tickets.size() < maxTickets) {
tickets.push_back(newTicket);
cout << "Ticket booked successfully!\n";
writePassengerDetails(newTicket); // Write passenger details to CSV file
return true;
} else {
cout << "Sorry, maximum tickets reached. Cannot book more tickets.\n";
return false;
}
}
void writePassengerDetails(const Ticket& ticket) {
ofstream fout("data.csv", ios::app); // Open file in append mode
fout << ticket.departureTime << ","
<< ticket.departs << ","
<< ticket.arrive << ","
<< ticket.arrivalTime << ","
<< ticket.duration << ","
<< ticket.passengerName << ","
<< ticket.ticketClass << ","
<< ticket.PNR << "\n";
fout.close();
}
};
class Passenger {
public:
void inputDetails(Ticket& ticket) {
cout << "Enter Departure Time: ";
cin >> ticket.departureTime;
cout << "Enter Departs: ";
cin >> ticket.departs;
cout << "Enter Arrive: ";
cin >> ticket.arrive;
cout << "Enter Arrival Time: ";
cin >> ticket.arrivalTime;
cout << "Enter Duration: ";
cin >> ticket.duration;
cout << "Enter Passenger Name: ";
cin >> ticket.passengerName;
cout << "Enter Class: ";
cin >> ticket.ticketClass;
cout << "Enter PNR: ";
cin >> ticket.PNR;
}
};
int main() {
vector<Ticket> tickets;
RailwayMember railwayMember(5); // Limiting to 5 tickets
while (true) {
cout << "\n1. Book Ticket\n"
<< "2. Exit\n"
<< "Choose an option: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
Ticket newTicket("", "", "", "", "", "", "", "");
Passenger passenger;
passenger.inputDetails(newTicket);
railwayMember.bookTicket(tickets, newTicket);
break;
}
case 2:
cout << "Exiting the program.\n";
return 0;
default:
cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}