This repository was archived by the owner on Jun 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarRentalSystem.cpp
More file actions
175 lines (150 loc) · 5.04 KB
/
CarRentalSystem.cpp
File metadata and controls
175 lines (150 loc) · 5.04 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
#include <iostream>
#include <vector>
#include <limits>
using namespace std;
struct Car {
string name;
string number;
string model;
string rentPrice;
};
struct RentRecord {
string carNumber;
string renterName;
string renterPhone;
string renterAddress;
string startDate;
string endDate;
};
vector<Car> cars;
vector<RentRecord> rentRecords;
string getInput(const string& prompt) {
cout << prompt;
string input;
getline(cin, input);
return input;
}
void showMenu() {
cout << "\nCar Rental System\n";
cout << "1. Check Car\n";
cout << "2. Add Car\n";
cout << "3. Update Car\n";
cout << "4. Remove Car\n";
cout << "5. Show All Cars\n";
cout << "6. Rent Car\n";
cout << "7. Update Rent\n";
cout << "8. Show Rent Records\n";
cout << "0. Exit\n";
cout << "Choose option: ";
}
void checkCar() {
string name = getInput("Enter car name: ");
for (int i = 0; i < cars.size(); i++) {
if (cars[i].name == name) {
cout << "\nCar Details:\n";
cout << "Name: " << cars[i].name << endl;
cout << "Number: " << cars[i].number << endl;
cout << "Model: " << cars[i].model << endl;
cout << "Rent Price: $" << cars[i].rentPrice << "/day\n";
return;
}
}
cout << "Car not found!\n";
}
void addCar() {
Car newCar;
newCar.name = getInput("Enter car name: ");
newCar.number = "C" + to_string(cars.size() + 100);
newCar.model = getInput("Enter car model: ");
newCar.rentPrice = getInput("Enter rent price per day: $");
cars.push_back(newCar);
cout << "Car added successfully! Number: " << newCar.number << endl;
}
void updateCar() {
string number = getInput("Enter car number: ");
for (int i = 0; i < cars.size(); i++) {
if (cars[i].number == number) {
cars[i].name = getInput("New name: ");
cars[i].model = getInput("New model: ");
cars[i].rentPrice = getInput("New rent price: $");
cout << "Car updated!\n";
return;
}
}
cout << "Car not found!\n";
}
void removeCar() {
string number = getInput("Enter car number to remove: ");
for (int i = 0; i < cars.size(); i++) {
if (cars[i].number == number) {
cars.erase(cars.begin() + i);
cout << "Car removed!\n";
return;
}
}
cout << "Car not found!\n";
}
void showAllCars() {
cout << "\nAll Cars (" << cars.size() << ")\n";
cout << "No. Name\tNumber\tModel\tPrice/day\n";
for (int i = 0; i < cars.size(); i++) {
cout << i+1 << ". " << cars[i].name << "\t"
<< cars[i].number << "\t" << cars[i].model << "\t$"
<< cars[i].rentPrice << endl;
}
}
void rentCar() {
RentRecord record;
record.carNumber = getInput("Enter car number: ");
record.renterName = getInput("Enter renter name: ");
record.renterPhone = getInput("Enter renter phone: ");
record.renterAddress = getInput("Enter renter address: ");
record.startDate = getInput("Enter start date (dd-mm-yyyy): ");
record.endDate = getInput("Enter end date (dd-mm-yyyy): ");
rentRecords.push_back(record);
cout << "Car rented successfully!\n";
}
void showRentRecords() {
cout << "\nRent Records (" << rentRecords.size() << ")\n";
cout << "No. Car\tRenter\tEnd Date\n";
for (int i = 0; i < rentRecords.size(); i++) {
cout << i+1 << ". " << rentRecords[i].carNumber << "\t"
<< rentRecords[i].renterName << "\t" << rentRecords[i].endDate << endl;
}
}
void updateRent() {
string number = getInput("Enter car number to update rent: ");
for (int i = 0; i < rentRecords.size(); i++) {
if (rentRecords[i].carNumber == number) {
rentRecords[i].renterName = getInput("New renter name: ");
rentRecords[i].renterPhone = getInput("New renter phone: ");
rentRecords[i].renterAddress = getInput("New renter address: ");
rentRecords[i].startDate = getInput("New start date: ");
rentRecords[i].endDate = getInput("New end date: ");
cout << "Rent updated!\n";
return;
}
}
cout << "Rent record not found!\n";
}
int main() {
cout << "Car Rental System\n";
while (true) {
showMenu();
int choice;
cin >> choice;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
switch (choice) {
case 1: checkCar(); break;
case 2: addCar(); break;
case 3: updateCar(); break;
case 4: removeCar(); break;
case 5: showAllCars(); break;
case 6: rentCar(); break;
case 7: updateRent(); break;
case 8: showRentRecords(); break;
case 0: cout << "Goodbye!\n"; return 0;
default: cout << "Invalid choice!\n";
}
}
}