Question: I want to solve the problems of this code and I want to re-submit the code after correction #include #include #include using namespace std; void
I want to solve the problems of this code and I want to re-submit the code after correction
#include
#include
#include
using namespace std;
void addCar(vector
vector
cout << "Enter car type: ";
cin >> newCar[0];
cout << "Enter car color: ";
cin >> newCar[1];
cout << "Enter car plate number: ";
cin >> newCar[2];
cout << "Enter car location: ";
cin >> newCar[3];
newCar.push_back(""); // initialize cleaner name to empty string
cars.push_back(newCar);
cout << "Car added successfully. ";
}
void addCleaner(vector
vector
cout << "Enter cleaner name: ";
cin >> newCleaner[0];
cout << "Enter cleaner phone number: ";
cin >> newCleaner[1];
cout << "Enter cleaning price: ";
cin >> newCleaner[2];
newCleaner.push_back("1"); // initialize available status to true
cleaners.push_back(newCleaner);
cout << "Cleaner added successfully. ";
}
void assignCleaner(vector
string plateNumber, cleanerName;
cout << "Enter car plate number: ";
cin >> plateNumber;
cout << "Enter cleaner name: ";
cin >> cleanerName;
// Find the car and cleaner vectors
int carIndex = -1, cleanerIndex = -1;
for (int i = 0; i < cars.size(); i++) {
if (cars[i][2] == plateNumber) {
carIndex = i;
break;
}
}
for (int i = 0; i < cleaners.size(); i++) {
if (cleaners[i][0] == cleanerName) {
cleanerIndex = i;
break;
}
}
// Check if the car and cleaner vectors were found
if (carIndex == -1) {
cout << "Error: Car not found. ";
return;
}
if (cleanerIndex == -1) {
cout << "Error: Cleaner not found. ";
return;
}
// Check if the cleaner is available
if (cleaners[cleanerIndex][3] != "1") {
cout << "Error: Cleaner is not available. ";
return;
}
// Assign the cleaner to the car
cars[carIndex][4] = cleanerName;
cleaners[cleanerIndex].push_back(plateNumber);
cleaners[cleanerIndex][3] = "0";
cout << "Cleaner assigned successfully. ";
}
void removeCleaner(vector
string plateNumber;
cout << "Enter car plate number: ";
cin >> plateNumber;
// Find the car vector
int carIndex = -1;
for (int i = 0; i < cars.size(); i++) {
if (cars[i][2] == plateNumber) {
carIndex = i;
break;
}
}
// Check if the car vector was found
if (carIndex == -1) {
cout << "Error: Car not found. ";
return;
}
// Remove the cleaner from the car
string cleanerName = cars_cleanerName[carIndex];
cars_cleanerName[carIndex] = "";
for (int i = 0; i < cleaners_name.size(); i++) {
if (cleaners_name[i] == cleanerName) {
for (int j = 0; j < cleaners_assignedCars[i].size(); j++) {
if (cleaners_assignedCars[i][j] == plateNumber) {
cleaners_assignedCars[i].erase(cleaners_assignedCars[i].begin() + j);
break;
}
}
cleaners_available[i] = true;
break;
}
}
cout << "Cleaner removed successfully. ";
}
void printCars(vector
int numCars = cars_type.size(); // Get the number of cars in the vector
// Loop through each car and print its details
for (int i = 0; i < numCars; i++) {
cout << "Car #" << i+1 << endl;
cout << "Type: " << cars_type[i] << endl;
cout << "Color: " << cars_color[i] << endl;
cout << "Plate number: " << cars_plateNumber[i] << endl;
cout << "Year: " << cars_year[i] << endl;
cout << endl;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
