summaryrefslogtreecommitdiff
path: root/algo1w4d2/WinkelSim.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'algo1w4d2/WinkelSim.cpp')
-rw-r--r--algo1w4d2/WinkelSim.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/algo1w4d2/WinkelSim.cpp b/algo1w4d2/WinkelSim.cpp
new file mode 100644
index 0000000..1e7ad88
--- /dev/null
+++ b/algo1w4d2/WinkelSim.cpp
@@ -0,0 +1,27 @@
+#include "WinkelSim.h"
+#include "Kassa.h"
+
+WinkelSim::WinkelSim() {
+ srand(time(NULL));
+ for (size_t i = 0; i < CHECKOUT_COUNT; i++)
+ _checkouts[i] = new Kassa();
+}
+
+WinkelSim::~WinkelSim() {
+ for (size_t i = 0; i < CHECKOUT_COUNT; i++)
+ delete _checkouts[i];
+}
+
+std::ostream& operator << (std::ostream& output, const WinkelSim& w) {
+ for (size_t i = 0; i < CHECKOUT_COUNT; i++)
+ output << "\tkassa " << i+1 << ": " << *w._checkouts[i] << std::endl;
+ return output;
+}
+
+void WinkelSim::step() {
+ unsigned new_customer_count = std::rand() % MAX_NEW_CUSTOMERS_PER_TIMESTEP;
+ for (unsigned i = 0; i < new_customer_count; i++)
+ _checkouts[std::rand() % CHECKOUT_COUNT]->add_customer({});
+ for (size_t i = 0; i < CHECKOUT_COUNT; i++)
+ _checkouts[i]->step();
+}