#include #include #include "cAssembly.h" using namespace std; // ---------------------------------------------------------------------- cStation cStation::cStation() { next = NULL; } cStation::~cStation() { } void cStation::add(int item) { items.push(item); } bool cStation::empty() { return items.empty(); } // ---------------------------------------------------------------------- cBucket cBucket::cBucket() { } cBucket::~cBucket() { } void cBucket::work() { } void cBucket::pass() { if (next != NULL && !items.empty()) { next->add(items.front()); items.pop(); } } void cBucket::print() { cout << " Bucket: "; for (int i = 0; i < items.size(); i++) { cout << items.front() << " "; items.push(items.front()); items.pop(); } cout << endl; } // ---------------------------------------------------------------------- cWork cWork::cWork(int t) { maxTime = t; curTime = 0; } cWork::~cWork() { } void cWork::work() { if (!items.empty()) curTime++; } void cWork::pass() { if (curTime == maxTime) { next->add(items.front()); items.pop(); curTime = 0; } } void cWork::print() { cout << " Work: "; for (int i = 0; i < items.size(); i++) { cout << items.front() << " "; items.push(items.front()); items.pop(); } cout << endl; } // ---------------------------------------------------------------------- cAssembly cAssembly::cAssembly() { } cAssembly::~cAssembly() { } void cAssembly::init() { cStation *tmp; tmp = new cBucket; line = tmp; tmp = new cWork(1); tmp->next = line; line = tmp; tmp = new cWork(5); tmp->next = line; line = tmp; tmp = new cWork(1); tmp->next = line; line = tmp; tmp = new cBucket; tmp->next = line; line = tmp; } bool cAssembly::done() { cStation *tmp; bool status = true; tmp = line; while (tmp->next != NULL) { status = status && tmp->empty(); tmp = tmp->next; } return status; } void cAssembly::run() { cStation *tmp; int numItems, count = 0; // Initialize init(); // Load cout << "How many items? "; cin >> numItems; cout << endl; for (int i = 0; i < numItems; i++) line->add(i); // Print cout << "Pass: " << count << endl; tmp = line; while (tmp != NULL) { tmp->print(); tmp = tmp->next; } // Main loop while (!done()) { // Work tmp = line; while (tmp != NULL) { tmp->work(); tmp = tmp->next; } // Pass tmp = line; while (tmp != NULL) { tmp->pass(); tmp = tmp->next; } // Print count++; cout << "Pass: " << count << endl; tmp = line; while (tmp != NULL) { tmp->print(); tmp = tmp->next; } } }