-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
288 lines (251 loc) · 11.5 KB
/
Copy pathproject.cpp
File metadata and controls
288 lines (251 loc) · 11.5 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;
// Structure to store car details
struct Car {
string model;
int year;
double price;
};
// Structure to hold details of a service ticket
struct Ticket {
int ticketNumber;
string date;
string serviceType;
string description;
};
// Function prototypes
void welcomeScreen();
int generateTicket();
void carSale(vector<Car>& cars, int& carsSold);
void carPurchase(int& carsBought);
void carModifications();
void carReviewsAndInspections();
// Main program
int main() {
vector<Car> cars;
int carsSold = 0; // Tracks how many cars have been sold
int carsBought = 0; // Tracks how many cars have been bought
welcomeScreen();
int choice;
do {
cout << "\n\n --- Welcome to YSKI Automotive Management System ---\n\n";
cout << " 1. Car Sale\n";
cout << " 2. Car Purchase\n";
cout << " 3. Car Modifications\n";
cout << " 4. Car Reviews and Inspections\n";
cout << " 5. Exit\n";
cout << "\n Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
carSale(cars, carsSold);
break;
case 2:
carPurchase(carsBought);
break;
case 3:
carModifications();
break;
case 4:
carReviewsAndInspections();
break;
case 5:
cout << " -----------------------------------------------------------" << endl;
cout << "\n Thank you for using YSKI Automotive System. Goodbye!\n";
break;
default:
cout << " -----------------------------------------------------------" << endl;
cout << "\n Invalid choice. Please try again.\n";
}
} while (choice != 5);
return 0;
}
// Display welcome message
void welcomeScreen() {
cout << " **************************************\n";
cout << " * *\n";
cout << " * YSKI Automotive *\n";
cout << " * Management System *\n";
cout << " * *\n";
cout << " **************************************\n";
}
// Generate a random ticket number
int generateTicket() {
return rand() % 100000 + 10000;
}
// Process car sales
void carSale(vector<Car>& cars, int& carsSold) {
cout << " ============================================================" << endl;
cout << " Let's Start the Sale Process!" << endl;
char sellAnother;
do {
Car newCar; // Create a new car object to store details
cout << " -----------------------------------------------------------" << endl;
cout << "\n Enter car model: ";
cin.ignore();
getline(cin, newCar.model);
cout << " -----------------------------------------------------------" << endl;
cout << "\n Enter car year: ";
cin >> newCar.year;
cout << " -----------------------------------------------------------" << endl;
cout << "\n Enter asking price: $";
cin >> newCar.price;
int suggestedPrice = newCar.price * 0.975; // Suggest a selling price 2.5% less than the asking price
cout << " -----------------------------------------------------------" << endl;
cout << "\n Suggested selling price: $";
cout.precision(2);
cout << fixed << suggestedPrice << endl;
char confirm;
cout << " -----------------------------------------------------------" << endl;
cout << "\n Do you want to sell the car? (y/n): ";
cin >> confirm;
if (confirm == 'y' || confirm == 'Y') {
int buyerContact = rand() % 100000000 + 1000000; // Generate a random buyer contact number
cout << " -----------------------------------------------------------" << endl;
cout << "\n Car is listed for sale! Contact the buyer at: " << buyerContact << endl;
cars.push_back(newCar); // Add the car to the vector of cars
carsSold++; // Increment the count of cars sold
// Save the sold car details to a file
ofstream saleFile("sold_cars.txt", ios::app);
if (saleFile) {
saleFile << "Model: " << newCar.model << ", Year: " << newCar.year
<< ", Price: $" << newCar.price << ", Suggested Price: $"
<< suggestedPrice << endl;
saleFile.close();
}
} else {
cout << " -----------------------------------------------------------" << endl;
cout << "\n Car will not be listed for sale.\n";
}
cout << " -----------------------------------------------------------" << endl;
cout << "\n Do you want to sell another car? (y/n): ";
cin >> sellAnother;
} while (sellAnother == 'y' || sellAnother == 'Y');
// Save the total number of cars sold to a file
ofstream salesRecord("sales_record.txt", ios::app);
if (salesRecord) {
salesRecord << "Total cars sold: " << carsSold << endl;
salesRecord.close();
}
}
// Process car purchases
void carPurchase(int& carsBought) {
cout << " ============================================================" << endl;
cout << " Let's Start the Purchase Process!" << endl;
vector<Car> availableCars; // Store the available cars in a vector
ifstream file("cars_for_sale.txt"); // Read the available cars from file
if (!file) {
cout << " -----------------------------------------------------------" << endl;
cout << " Error: Unable to open cars_for_sale.txt.\n";
return;
}
string model;
int year; double price;
while (file >> model >> year >> price) { // Read car details from the file
availableCars.push_back({model, year, price});
}
file.close();
if (availableCars.empty()) {
cout << " -----------------------------------------------------------" << endl;
cout << " No cars available for sale at the moment.\n";
return;
}
char buyAnother;
do {
cout << " Available cars for sale:\n\n";
cout << " No. \tModel & Year \tPrice\n";
cout << " -----------------------------------------------------------\n\n";
for (size_t i = 0; i < availableCars.size(); ++i) { // Display all cars
cout << " " << i + 1 << " \t" << availableCars[i].model
<< " \t" << availableCars[i].year
<< " \t$" << availableCars[i].price << endl;
}
int choice;
cout << " -----------------------------------------------------------" << endl;
cout << " Enter the number of the car you want to buy: ";
cin >> choice;
if (choice < 1 || choice > availableCars.size()) {
cout << " Invalid choice. Please try again.\n";
continue;
}
Car purchasedCar = availableCars[choice - 1]; // Get the chosen car
availableCars.erase(availableCars.begin() + (choice - 1)); // Remove it from the list
cout << " -----------------------------------------------------------" << endl;
cout << " Purchase is on the way successfully! \n\n Your ticket number is: " << generateTicket() << endl;
cout << "\n\n Please visit the counter with ticket number and \n pay the amount to get the paperwork done." << endl;
// Save purchased car details to a file
ofstream purchasedFile("purchased_cars.txt", ios::app);
if (purchasedFile) {
purchasedFile << "Model: " << purchasedCar.model
<< ", Year: " << purchasedCar.year
<< ", Price: $" << purchasedCar.price << endl;
purchasedFile.close();
}
carsBought++; // Increment the number of cars bought
cout << " -----------------------------------------------------------" << endl;
cout << "\n Do you want to buy another car? (y/n): ";
cin >> buyAnother;
} while (buyAnother == 'y' || buyAnother == 'Y');
// Update the cars_for_sale.txt file with the remaining cars
ofstream updatedFile("cars_for_sale.txt");
if (updatedFile) {
for (const auto& car : availableCars) {
updatedFile << car.model << " " << car.year << " " << car.price << endl;
}
updatedFile.close();
}
// Save the total number of cars purchased to a file
ofstream purchaseRecord("purchase_record.txt", ios::app);
if (purchaseRecord) {
purchaseRecord << "Total cars purchased: " << carsBought << endl;
purchaseRecord.close();
}
}
// Process car modifications
void carModifications() {
cout << " ============================================================" << endl;
cout << " Let's Start the Modification Process!" << endl;
Ticket modificationTicket;
modificationTicket.ticketNumber = generateTicket();
modificationTicket.serviceType = "Car Modification";
cout << " -----------------------------------------------------------" << endl;
cout << " Enter the modifications you want: (explain) "<< endl;
cin.ignore();
getline(cin, modificationTicket.description); // Get details about the modification
cout << " -----------------------------------------------------------" << endl;
cout << " Your ticket for modifications:\n" << endl;
cout << " Ticket Number: " << modificationTicket.ticketNumber << endl;
cout << " Service Type: " << modificationTicket.serviceType << endl;
cout << " \nDescription: " << modificationTicket.description << endl;
cout << " -----------------------------------------------------------" << endl;
cout << " Please visit the garage and submit \n your ticket number to the mechanic!" << endl;
}
// Process car inspections and reviews
void carReviewsAndInspections() {
cout << " ============================================================" << endl;
cout << " Let's Start the Inspection Process!" << endl;
Ticket inspectionTicket;
inspectionTicket.ticketNumber = generateTicket();
inspectionTicket.serviceType = "Car Review & Inspection";
cout << " -----------------------------------------------------------" << endl;
cout << " Enter the problem you are facing with your car: "<< endl;
cin.ignore();
getline(cin, inspectionTicket.description); // Get the issue description
cout << " -----------------------------------------------------------" << endl;
ofstream file("inspection_requests.txt", ios::app); // Save the inspection request to a file
if (file) {
file << " Ticket: " << inspectionTicket.ticketNumber << ", Service: " << inspectionTicket.serviceType
<< ", Problem: " << inspectionTicket.description << endl;
file.close();
cout << " Inspection request submitted.\n Your ticket number is: " << inspectionTicket.ticketNumber << endl;
cout << " -----------------------------------------------------------" << endl;
cout << " The Inspector will review your car and inform you shortly." << endl;
cout << " Please submit the ticket number on counter to get the report" << endl;
} else {
cout << " Error: Unable to save the inspection request.\n";
}
}