cargostorage.cpp

#include "pallet.h" #include "cargostorage.h" using namespace std; Pallet k(0, 7); //Empty Object CargoStorage::CargoStorage() { CargoList.resize(10); } bool CargoStorage::AddPalletAtPosition(int position, Pallet p) { if (position > CargoList.size()) { cout << "Pallets can only be stored in positions 0-10, please enter a valid position." << endl; return false; } if (CargoList[position].PalletContent.size() != 0) // If slot is not empty the program will not use that slot { cout << "Sorry this slot is taken, please enter another position for your pallet" << endl; cin >> position; return false; } CargoList[position] = p; return true; } /*if (CargoList.size() <= 10) { for (int i = 0; CargoList.size() <= 10; i++) { if (CargoList.size() != position) { CargoList.push_back(k); // Adds empty spaces to fill slots untill the inputted position // Because i cannot access a specific slot in the vector CargoList } else { CargoList.push_back(p); // Adds Pallet P to the user inputted slot } } } else { CargoList[position] = p; // }*/ Pallet CargoStorage::RetrievePalletFromPosition(int position) { return CargoList[position]; //returns the element "position" in the vector CargoList } void CargoStorage::ListContents() { for (int i = 0; i < CargoList.size(); i++) { if (CargoList[i].PalletContent.size() == 0) { //Checks if the positition in the vector is empty cout << "pallet: " << i << " is empty" << endl; //Produces empty output } for (int j = 0; j < CargoList[i].PalletContent.size(); j++) { //Produces the pallet position and items in that pallet cout << "pallet: " << i << " item at position: " << j << " is " << CargoList[i].PalletContent[j] << endl; } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.