forked from 2024ucp1505/OOAD_GROUP_PROJECT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
218 lines (187 loc) Β· 7.46 KB
/
Copy pathmain.cpp
File metadata and controls
218 lines (187 loc) Β· 7.46 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* @file main.cpp
* @brief Console demo entry point for the IRCTC Railway Reservation System.
*/
/**
* @mainpage IRCTC Railway Reservation System
*
* @section intro Overview
* This project is a simplified IRCTC-style railway reservation demo which
* showcases basic object-oriented design principles, including separation of
* concerns, use of services, strategies, and factories.
*
* @section structure Project Structure
* - Root files:
* - main.cpp β demo entry point
* - Makefile β build script for the executable
* - Doxyfile β configuration file for generating this documentation
* - README.md β quick project description and usage
* - include/ β public headers (interfaces and domain models)
* - Admin.h, User.h, Train.h, Ticket.h
* - TrainDatabase.h, TrainService.h, BookingService.h
* - Payment.h, PaymentFactory.h, PaymentService.h
* - FareStrategy.h, SimpleFareStrategy.h
* - CardPayment.h, NetBankingPayment.h, UpiPayment.h
* - src/ β implementations of the headers
* - uml/ β UML diagrams (use-case, class, sequence, activity)
*
* @section build_run Building and Running
* From the project root:
* - To build the program using the provided Makefile:
* - On Linux/macOS: make
* - On Windows (with make installed, e.g., via MinGW/MSYS): make
* - This will produce the executable (for example irctc or irctc.exe).
*
* To run the demo after a successful build:
* - On Linux/macOS: ./irctc
* - On Windows: run irctc.exe from a terminal or by double-clicking it.
*
* @section docs Generating Documentation
* - Ensure Doxygen is installed.
* - From the project root, run: doxygen Doxyfile
*
* @section authors Authors
* - Lokesh
* - Raghunandan
* - Prateek
* - Mahek
* - Rishi
*/
#include <iostream>
#include <memory>
#include <vector>
#include <limits>
#include "User.h"
#include "Admin.h"
#include "Train.h"
#include "Ticket.h"
#include "TrainDatabase.h"
#include "TrainService.h"
#include "PaymentFactory.h"
#include "PaymentService.h"
#include "SimpleFareStrategy.h"
#include "BookingService.h"
void seedTrains(TrainService& trainService) {
auto t1 = std::make_shared<Train>(
1, "Rajdhani Express", "Delhi", "Mumbai", "18:00", "08:00", 200, 1500.0);
auto t2 = std::make_shared<Train>(
2, "Duronto Express", "Delhi", "Mumbai", "20:00", "10:00", 150, 1800.0);
auto t3 = std::make_shared<Train>(
3, "Shatabdi Express", "Delhi", "Chandigarh", "07:00", "10:00", 100, 800.0);
trainService.addTrain(t1);
trainService.addTrain(t2);
trainService.addTrain(t3);
}
int main() {
std::cout << "=== IRCTC Railway Reservation System (Interactive Demo) ===\n\n";
// Setup core components
TrainDatabase& db = TrainDatabase::getInstance();
TrainService trainService(db);
PaymentFactory paymentFactory;
PaymentService paymentService(paymentFactory);
auto fareStrategy = std::make_unique<SimpleFareStrategy>();
BookingService bookingService(trainService, paymentService, std::move(fareStrategy));
// Seed initial trains
seedTrains(trainService);
// Create a user interactively
std::string userName;
std::string userEmail;
std::cout << "Enter your name : ";
std::getline(std::cin, userName);
if (userName.empty()) {
std::getline(std::cin, userName); // handle possible leftover newline
}
std::cout << "Enter your email : ";
std::getline(std::cin, userEmail);
auto user = std::make_shared<User>(1, userName, userEmail);
bool running = true;
while (running) {
std::cout << "\n=== Main Menu ===\n";
std::cout << "1. Search & Book Ticket\n";
std::cout << "2. Exit\n";
std::cout << "Choose an option: ";
int choice = 0;
if (!(std::cin >> choice)) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Please enter a number.\n";
continue;
}
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (choice == 1) {
std::string source;
std::string destination;
std::cout << "\nEnter source station : ";
std::getline(std::cin, source);
std::cout << "Enter destination station : ";
std::getline(std::cin, destination);
std::vector<std::shared_ptr<Train>> trains =
trainService.searchTrains(source, destination);
if (trains.empty()) {
std::cout << "No trains found for this route.\n";
continue;
}
std::cout << "\nAvailable trains:\n";
for (const auto& train : trains) {
std::cout << " ID: " << train->getId()
<< ", Name: " << train->getName()
<< ", Departure: " << train->getDepartureTime()
<< ", Arrival: " << train->getArrivalTime()
<< ", Fare/Seat: " << train->getFarePerSeat()
<< ", Available Seats: " << train->getAvailableSeats()
<< "\n";
}
int selectedTrainId;
std::cout << "\nEnter Train ID to book: ";
if (!(std::cin >> selectedTrainId)) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid Train ID.\n";
continue;
}
int seatsToBook;
std::cout << "Enter number of seats : ";
if (!(std::cin >> seatsToBook) || seatsToBook <= 0) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid seat count.\n";
continue;
}
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::string journeyDate;
std::cout << "Enter journey date (YYYY-MM-DD): ";
std::getline(std::cin, journeyDate);
std::string paymentType;
std::cout << "Select payment method [UPI/CARD/NETBANKING]: ";
std::getline(std::cin, paymentType);
auto ticket = bookingService.bookTicket(
user, selectedTrainId, seatsToBook, journeyDate, paymentType);
if (!ticket) {
std::cout << "Booking failed. Please try again.\n";
continue;
}
std::cout << "\nBooking successful. Ticket details:\n";
ticket->print();
char cancelChoice;
std::cout << "\nDo you want to cancel this ticket? (y/n): ";
std::cin >> cancelChoice;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (cancelChoice == 'y' || cancelChoice == 'Y') {
bool cancelled = bookingService.cancelTicket(ticket);
if (cancelled) {
std::cout << "Ticket cancelled successfully.\n";
} else {
std::cout << "Ticket cancellation failed.\n";
}
std::cout << "\nTicket details after cancellation:\n";
ticket->print();
}
} else if (choice == 2) {
running = false;
} else {
std::cout << "Invalid choice. Please select again.\n";
}
}
std::cout << "\n=== Thank you for using IRCTC Demo ===\n";
return 0;
}