Question: I ' m not sure where to put the inventory list of vehicles correctly and I need to list them as is in the program

I'm not sure where to put the inventory list of vehicles correctly and I need to list them as is in the program with the current inventory
1001,2024,Acura,Integra,25
1002,2024,Alfa Romeo,Giulia,35
1003,2024,Cadillac,CT4,50
1004,2023,Chevrolet,Bolt,20
1005,2024,Dodge,Hornet,30
1006,2024,Honda,CR-V,20
1007,2024,Hyundai,Santa Fe,35
1008,2024,Infiniti,Q50,40
1009,2024,Kia,Carnival,30
the code is;
#include #include #include #include #include using namespace std; struct Car { int id; int year; string make; string model; double cost; bool isAvailable; bool isRemoved; }; vector inventory; // Function declarations void greetAgent(); void displayMenu(); void loadInventory(const string &filename); void saveInventory(const string &filename); void viewInventory(); void addCar(); void rentCar(); void returnCar(); void removeCar(); int main(){ greetAgent(); ifstream file("currentCarInventory.txt"); if (file.is_open()){ loadInventory("currentCarInventory.txt"); } else { loadInventory("carInventory.txt"); } int choice; do { displayMenu(); cin >> choice; cin.ignore(); switch (choice){ case 1: viewInventory(); break; case 2: addCar(); break; case 3: rentCar(); break; case 4: returnCar(); break; case 5: removeCar(); break; case 6: saveInventory("currentCarInventory.txt"); cout << "Inventory saved. Exiting program.
"; break; default: cout << "Invalid choice. Please try again.
"; }} while (choice !=6); return 0; } void greetAgent(){ cout << "Welcome to the Rental Car Inventory Management System!
"; } void displayMenu(){ cout <<"
User Menu:
"; cout <<"1. View inventory
"; cout <<"2. Add new car to inventory
"; cout <<"3. Rent car to customer
"; cout <<"4. Process returned vehicle
"; cout <<"5. Remove discontinued car from inventory
"; cout <<"6. Quit
"; cout << "Enter your choice: "; } void loadInventory(const string &filename){ ifstream inFile(filename); if (!inFile){ cout << "Failed to open "<< filename <<" for reading.
"; return; } inventory.clear(); Car car; while (inFile >> car.id >> car.year >> car.make >> car.model >> car.cost){ car.isAvailable = true; car.isRemoved = false; inventory.push_back(car); } inFile.close(); } void saveInventory(const string &filename){ ofstream outFile(filename); if (!outFile){ cout << "Failed to open "<< filename <<" for writing.
"; return; } for (const auto &car : inventory){ if (!car.isRemoved){ outFile << car.id <<""<< car.year <<""<< car.make <<""<< car.model <<""<< fixed << setprecision(2)<< car.cost <<"
"; }} outFile.close(); } void viewInventory(){ cout <<"
Current Inventory:
"; cout << left << setw(10)<<"ID"<< setw(6)<< "Year" << setw(12)<< "Make" << setw(12)<< "Model" << setw(8)<< "Cost" << "Status
"; for (const auto &car : inventory){ if (!car.isRemoved){ cout << left << setw(10)<< car.id << setw(6)<< car.year << setw(12)<< car.make << setw(12)<< car.model <<"$"<< setw(7)<< car.cost <<(car.isAvailable ? "Available" : "Rented")<<"
"; }}} void addCar(){ Car newCar; cout << "Enter car ID: "; cin >> newCar.id; for (const auto &car : inventory){ if (car.id == newCar.id && !car.isRemoved){ cout << "Car with this ID already exists in inventory.
"; return; }} cout << "Enter year: "; cin >> newCar.year; cout << "Enter make: "; cin >> newCar.make; cout << "Enter model: "; cin >> newCar.model; cout << "Enter cost: "; cin >> newCar.cost; newCar.isAvailable = true; newCar.isRemoved = false; inventory.push_back(newCar); cout << "Car added successfully.
"; } void rentCar(){ int id; cout << "Enter car ID to rent: "; cin >> id; for (auto &car : inventory){ if (car.id == id && !car.isRemoved){ if (car.isAvailable){ car.isAvailable = false; int days; cout << "Enter number of rental days: "; cin >> days; double totalCost = days * car.cost; cout << "Collect payment: $"<< fixed << setprecision(2)<< totalCost <<"
"; return; } else { cout << "Car is currently rented.
"; return; }}} cout << "Car not found in inventory.
"; } void returnCar(){ int id; cout << "Enter car ID to return: "; cin >> id; for (auto &car : inventory){ if (car.id == id && !car.isRemoved){ if (!car.isAvailable){ car.isAvailable = true; cout << "Car returned successfully.
"; return; } else { cout << "Car was not rented.
"; return; }}} cout << "Car not found in inventory.
"; } void removeCar(){ int id; cout << "Enter car ID to remove: "; cin >> id; for (auto &car : inventory){ if (car.id == id && !car.isRemoved){ car.isRemoved = true; cout << "Car removed from inventory.
"; return; }} cout << "Car not found in inventory.
"; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!