Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #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 assignedCars; };

void addCar(vector& cars) { Car newCar; cout << "Enter car type: "; cin >> newCar.type; cout << "Enter car color: "; cin >> newCar.color; cout << "Enter car plate number: "; cin >> newCar.plateNumber; cout << "Enter car location: "; cin >> newCar.location; newCar.cleanerName = ""; // initialize cleaner name to empty string cars.push_back(newCar); cout << "Car added successfully. "; }

void addCleaner(vector& cleaners) { Cleaner newCleaner; cout << "Enter cleaner name: "; cin >> newCleaner.name; cout << "Enter cleaner phone number: "; cin >> newCleaner.phone; cout << "Enter cleaning price: "; cin >> newCleaner.cleaningPrice; newCleaner.available = true; // initialize available status to true cleaners.push_back(newCleaner); cout << "Cleaner added successfully. "; }

void assignCleaner(vector& cars, vector& cleaners) { string plateNumber, cleanerName; cout << "Enter car plate number: "; cin >> plateNumber; cout << "Enter cleaner name: "; cin >> cleanerName;

// 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& cars, vector& cleaners) { string plateNumber; cout << "Enter car plate number: "; cin >> plateNumber;

// 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& cars) { cout << "Car list: "; for (int i = 0; i < cars.size(); i++) { cout << "Type: " << cars[i].type << endl; cout << "Color: " << cars[i].color << endl; cout << "Plate number: " << cars[i].plateNumber << endl; cout << "Location: " << cars[i].location << endl; cout << "Cleaner name: " << cars[i].cleanerName << endl; cout << "==================== "; } }

// Function to print all cleaners void printCleaners(vector& cleaners) { cout << "Cleaner list: "; for (int i = 0; i < cleaners.size(); i++) { cout << "Name: " << cleaners[i].name << endl; cout << "Phone: " << cleaners[i].phone << endl; cout << "Cleaning price: " << cleaners[i].cleaningPrice << endl; cout << "Available: " << (cleaners[i].available ? "yes" : "no") << endl; cout << "Assigned cars: "; for (int j = 0; j

int main() { vector cars; vector cleaners; while (true) { cout << "Menu: "; cout << "1. Add car "; cout << "2. Add cleaner "; cout << "3. Assign cleaner to car "; cout << "4. Remove cleaner from car "; cout << "5. Print all cars "; cout << "6. Print all cleaners "; cout << "7. Exit "; cout << "Enter your choice: ";

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago