diff --git a/Uebung 5/Uebung5_3/backpack.cpp b/Uebung 5/Uebung5_3/backpack.cpp index 26ca08d..c5c7ca5 100644 --- a/Uebung 5/Uebung5_3/backpack.cpp +++ b/Uebung 5/Uebung5_3/backpack.cpp @@ -1,4 +1,6 @@ #include "backpack.h" +#include +#include /* Optimized insertion sort algorithm utilizing the Item's getRatio() function */ @@ -50,6 +52,15 @@ void Backpack::greedyPack() { << this->availableItems[i].weight << "\t" << this->availableItems[i].value << "\t Factor: 1.00\n"; // output + } else { + float factor = (float)(this->maxWeight - this->currentWeight) / + this->availableItems[i].weight; + factor = std::round(factor * 100) / 100; + std::cout << "\t" << this->availableItems[i].name << ":\t" + << this->availableItems[i].weight << "\t" + << this->availableItems[i].value << "\t Factor: " << factor + << std::endl; + break; } if ((this->currentWeight - this->maxWeight) == 0) { // if the backpack is completely full, the loop can be exited -