Question
I want this same code, but with a smaller number of functions, and their number is only three, and it is in the form of
I want this same code, but with a smaller number of functions, and their number is only three, and it is in the form of FOP and not the object
#include
using namespace std;
struct Car { string type; string color; string plateNumber; string location; string cleanerName; };
struct Cleaner { string name; string phone; double cleaningPrice; bool available; vector
void addCar(vector
void addCleaner(vector
void assignCleaner(vector
// Find the car and cleaner objects int carIndex = -1, cleanerIndex = -1; for (int i = 0; i < cars.size(); i++) { if (cars[i].plateNumber == plateNumber) { carIndex = i; break; } } for (int i = 0; i < cleaners.size(); i++) { if (cleaners[i].name == cleanerName) { cleanerIndex = i; break; } }
// Check if the car and cleaner objects 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].available) { cout << "Error: Cleaner is not available. "; return; }
// Assign the cleaner to the car cars[carIndex].cleanerName = cleanerName; cleaners[cleanerIndex].assignedCars.push_back(plateNumber); cleaners[cleanerIndex].available = false; cout << "Cleaner assigned successfully. "; }
// Function to remove a cleaner from a car void removeCleaner(vector
// Find the car object int carIndex = -1; for (int i = 0; i < cars.size(); i++) { if (cars[i].plateNumber == plateNumber) { carIndex = i; break; } } // Check if the car object was found if (carIndex == -1) { cout << "Error: Car not found. "; return; }
// Remove the cleaner from the car string cleanerName = cars[carIndex].cleanerName; cars[carIndex].cleanerName = ""; for (int i = 0; i < cleaners.size(); i++) { if (cleaners[i].name == cleanerName) { for (int j = 0; j < cleaners[i].assignedCars.size(); j++) { if (cleaners[i].assignedCars[j] == plateNumber) { cleaners[i].assignedCars.erase(cleaners[i].assignedCars.begin() + j); break; } } cleaners[i].available = true; break; } } cout << "Cleaner removed successfully. "; } void printCars(vector
// Function to print all cleaners void printCleaners(vector int main() { vector int choice; cin >> choice; switch (choice) { case 1: addCar(cars); break; case 2: addCleaner(cleaners); break; case 3: assignCleaner(cars, cleaners); break; case 4: removeCleaner(cars, cleaners); break; case 5: printCars(cars); break; case 6: printCleaners(cleaners); break; case 7: cout << "Exiting program... "; return 0; default: cout << "Error: Invalid choice. Please try again. "; break; return 0; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started