-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
246 lines (214 loc) · 7.32 KB
/
main.cpp
File metadata and controls
246 lines (214 loc) · 7.32 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include <iostream>
#include <string>
#include "Vehicle.h"
#include "Customer.h"
#include "RentalTransaction.h"
#include "List.h"
#include "Date.h"
using namespace std;
void displayMenu() {
cout << " ---------------->VRMS<----------------\n";
cout << "1. -> | Book a Vehicle |" << endl;
cout << "2. -> | Search Vehicle by Model |" << endl;
cout << "3. -> | Filter Vehicles by Price Range |" << endl;
cout << "4. -> | Show Rental History by Customer CNIC |" << endl;
cout << "5. -> | Add New Customer |" << endl;
cout << "6. -> | Show All Available Vehicles |" << endl;
cout << "6. -> | Exit |" << endl;
cout << " --------------------------------------" << endl;
cout << "Enter your choice (1-7): ";
}
void initializeSampleData(List<Vehicle*>& vehicles) {
vehicles.add(new Car("Honda Civic", 2020, 4000));
vehicles.add(new Truck("WNR tank91", 2020, 5000));
vehicles.add(new Car("Toyota Corolla", 2019, 3500));
vehicles.add(new Truck("WNR tank91", 2021, 7000));
vehicles.add(new Car("Hyundai Tucson", 2025, 4500));
vehicles.add(new Truck("WNR tank92", 2025, 10000));
}
void showAvailableVehicles(const List<Vehicle*>& vehicles) {
cout << "\n=== Available Vehicles ===" << endl;
bool availableFound = false;
for (int i = 0; i < vehicles.size(); i++) {
if (vehicles[i]->getAvailability()) {
cout << i << ". ";
vehicles[i]->displayInfo();
availableFound = true;
}
}
if (!availableFound) {
cout << "No vehicles currently available." << endl;
}
}
void bookVehicle(List<Vehicle*>& vehicles, List<Customer*>& customers, List<RentalTransaction*>& transactions) {
showAvailableVehicles(vehicles);
if (vehicles.size() == 0) return;
cout << "\nEnter vehicle number to book: ";
int vehicleIndex;
cin >> vehicleIndex;
cin.ignore();
if (vehicleIndex < 0 || vehicleIndex >= vehicles.size()) {
cout << "Invalid vehicle selection!" << endl;
return;
}
if (!vehicles[vehicleIndex]->getAvailability()) {
cout << "Selected vehicle is not available!" << endl;
return;
}
cout << "Enter customer CNIC: ";
string cnic;
getline(cin, cnic);
// Find customer
Customer* customer = nullptr;
for (int i = 0; i < customers.size(); i++) {
if (customers[i]->getCNIC() == cnic) {
customer = customers[i];
break;
}
}
if (!customer) {
cout << "Customer not found! Please add customer first." << endl;
return;
}
Date startDate, endDate;
cout << "Enter rental start date (DD/MM/YYYY): ";
cin >> startDate;
cout << "Enter rental end date (DD/MM/YYYY): ";
cin >> endDate;
if (endDate < startDate) {
cout << "Error: End date must be after start date!" << endl;
return;
}
transactions.add(new RentalTransaction(customer, vehicles[vehicleIndex], startDate, endDate));
vehicles[vehicleIndex]->setAvailability(false);
cout << "\nBooking confirmed!" << endl;
cout << "Customer: " << customer->getName() << endl;
cout << "Vehicle: " << vehicles[vehicleIndex]->getModel() << endl;
cout << "Period: " << startDate << " to " << endDate << endl;
cout << "Total cost: " << vehicles[vehicleIndex]->calculateRentalCost(endDate - startDate) << endl;
cout << "total days: " << endDate - startDate << endl;
}
void searchVehicleByModel(const List<Vehicle*>& vehicles) {
cout << "Enter model to search: ";
string model;
getline(cin, model);
cout << "\n=== Search Results ===" << endl;
bool found = false;
for (int i = 0; i < vehicles.size(); i++) {
if (vehicles[i]->getModel().find(model) != string::npos) {
vehicles[i]->displayInfo();
cout << "Status: " << (vehicles[i]->getAvailability() ? "Available" : "Rented") << endl;
found = true;
}
}
if (!found) {
cout << "No vehicles found with that model." << endl;
}
}
void filterVehiclesByPrice(const List<Vehicle*>& vehicles) {
double minPrice, maxPrice;
cout << "Enter minimum price: ";
cin >> minPrice;
cout << "Enter maximum price: ";
cin >> maxPrice;
cin.ignore();
if (minPrice < 0 || maxPrice < 0 || minPrice > maxPrice) {
cout << "Invalid price range!" << endl;
return;
}
cout << "\n=== Vehicles in Price Range ===" << endl;
bool found = false;
for (int i = 0; i < vehicles.size(); i++) {
double price = vehicles[i]->getRentalPricePerDay();
if (price >= minPrice && price <= maxPrice) {
vehicles[i]->displayInfo();
cout << "Status: " << (vehicles[i]->getAvailability() ? "Available" : "Rented") << endl;
found = true;
}
}
if (!found) {
cout << "No vehicles found in that price range." << endl;
}
}
void showRentalHistory(const List<RentalTransaction*>& transactions) {
cout << "Enter customer CNIC: ";
string cnic;
getline(cin, cnic);
cout << "\n=== Rental History ===" << endl;
bool found = false;
for (int i = 0; i < transactions.size(); i++) {
if (transactions[i]->getCustomer()->getCNIC() == cnic) {
transactions[i]->displayInfo();
cout << "-----------------------" << endl;
found = true;
}
}
if (!found) {
cout << "No rental history found for that customer." << endl;
}
}
void addNewCustomer(List<Customer*>& customers) {
string name, cnic, mobile;
cout << "Enter customer name: ";
getline(cin, name);
cout << "Enter customer CNIC: ";
getline(cin, cnic);
cout << "Enter customer mobile number: ";
getline(cin, mobile);
for (int i = 0; i < customers.size(); i++) {
if (customers[i]->getCNIC() == cnic) {
cout << "Customer with this CNIC already exists!" << endl;
return;
}
}
customers.add(new Customer(name, cnic, mobile));
cout << "Customer added successfully!" << endl;
}
int main() {
List<Vehicle*> vehicles(100);
List<Customer*> customers(50);
List<RentalTransaction*> transactions(200);
initializeSampleData(vehicles);
int choice;
do {
displayMenu();
cin >> choice;
cin.ignore();
switch (choice) {
case 1:
bookVehicle(vehicles, customers, transactions);
break;
case 2:
searchVehicleByModel(vehicles);
break;
case 3:
filterVehiclesByPrice(vehicles);
break;
case 4:
showRentalHistory(transactions);
break;
case 5:
addNewCustomer(customers);
break;
case 7:
showAvailableVehicles(vehicles);
break;
case 6:
cout << "Exiting system. Goodbye!" << endl;
break;
default:
cout << "Invalid choice! Please try again." << endl;
break;
}
} while (choice != 7);
for (int i = 0; i < vehicles.size(); i++) {
delete vehicles[i];
}
for (int i = 0; i < customers.size(); i++) {
delete customers[i];
}
for (int i = 0; i < transactions.size(); i++) {
delete transactions[i];
}
return 0;
}