#include <iostream>
#include <queue>
#include <vector>
#include <string>
// Define a structure for a product
struct Product {
int id;
std::string name;
};
// Define a class for a manufacturing machine
class Machine {
public:
Machine(const std::string& name) : machineName(name) {}
void addProduct(const Product& product) {
queue.push(product);
}
void processProduct() {
if (queue.empty()) {
std::cout << machineName << " has no products to process.\n";
return;
}
Product product = queue.front();
queue.pop();
std::cout << machineName << " processed product ID: " << product.id << ", Name: " << product.name << "\n";
}
bool hasProducts() const {
return !queue.empty();
}
private:
std::string machineName;
std::queue<Product> queue;
};
// Define a class for the manufacturing system
class ManufacturingSystem {
public:
void addMachine(const Machine& machine) {
machines.push_back(machine);
}
void addProductToMachine(int machineIndex, const Product& product) {
if (machineIndex >= 0 && machineIndex < machines.size()) {
machines[machineIndex].addProduct(product);
} else {
std::cout << "Invalid machine index.\n";
}
}
void processAllMachines() {
for (auto& machine : machines) {
machine.processProduct();
}
}
private:
std::vector<Machine> machines;
};
int main() {
// Create machines
Machine machine1("Machine 1");
Machine machine2("Machine 2");
Machine machine3("Machine 3");
// Create a manufacturing system
ManufacturingSystem system;
system.addMachine(machine1);
system.addMachine(machine2);
system.addMachine(machine3);
// Create and add products to machines
system.addProductToMachine(0, {1, "Product A"});
system.addProductToMachine(1, {2, "Product B"});
system.addProductToMachine(2, {3, "Product C"});
system.addProductToMachine(0, {4, "Product D"});
// Process all machines
std::cout << "Processing products:\n";
system.processAllMachines();
return 0;
}