commit d8018f647fc13439f01c2f27bcc256ea812c3656 Author: leo Date: Tue Mar 22 18:28:42 2022 +0100 Initial Commit diff --git a/.vimspector.json b/.vimspector.json new file mode 100644 index 0000000..22ec265 --- /dev/null +++ b/.vimspector.json @@ -0,0 +1,24 @@ +{ + "configurations": { + "Launch": { + "adapter": "vscode-cpptools", + "filetypes": [ "cpp", "c", "objc", "rust" ], // optional + "configuration": { + "request": "launch", + "program": "/home/leo/Documents/Code/kaufland/kaufland", + "cwd": "/home/leo/Documents/Code/kaufland", + "externalConsole": true, + "MIMode": "gdb" + } + }, + "Attach": { + "adapter": "vscode-cpptools", + "filetypes": [ "cpp", "c", "objc", "rust" ], // optional + "configuration": { + "request": "attach", + "program": "/home/leo/Documents/Code/kaufland/kaufland", + "MIMode": "gdb" + } + } + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c4f037a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +project(kaufland) + set (CMAKE_CXX_STANDARD 14) + +set(SOURCES + src/source-files/Ware.cpp + src/source-files/WarenStorage.cpp + src/source-files/StorageEditor.cpp + src/source-files/InputManager.cpp +) + +set(COMBINED_SOURCES ${SOURCES} src/main.cpp) +add_executable(kaufland ${COMBINED_SOURCES}) diff --git a/ReadMe.txt b/ReadMe.txt new file mode 100644 index 0000000..0eca392 --- /dev/null +++ b/ReadMe.txt @@ -0,0 +1,41 @@ +#Task: + +Ein Warenhaus der Marke Kaufland möchte ihr Warenmanagement von Papier auf Digital aufrüsten. + +- Sie haben 3 interne Warensegmente, eins für kühlung, eins für sperrige artikel und eins für Standardmaße (unter 20x20x20cm), + wobei nur das Warenhaus für sperrige Artikel solche Lagern kann die die standardmaße überschreiten + +- das Kühllager kann 10000, das Sperrlager 3500 und das Standardlager 25000 Produkte fassen + +- die Managementsoftware soll das eintragen, austragen und auflisten des aktuellen Warenhausstands ermöglichen + +- beim eintragen oder "Ware annehmen" wird ein Typ Produkt geliefert, bekannt sind dabei der Name, Produktnummer, Anzahl, Maße und Kühlungsbedarf + +- zwei LKW können auch das selbe Produkt liefern, wobei dann die Anzahl des Produkts erhöht werden muss anstatt es ein zweites mal ins system zu laden + +- das Warenhaus darf natürlich nicht über sein limit beladen werden + +- beim austragen wird eine Produktnummer und die Anzahl gegeben + +- beim auflisten wird, sortiert nach Warenhaustyp, die gesammten produkte mit ihren eigenschaften angegeben + + +#Project Structure: + +''' +src +├── header-files +│   ├── data-classes +│   │   ├── Ware.h +│   │   └── WarenStorage.h +│   ├── InputManager.h +│   ├── pch.h +│   └── StorageEditor.h +├── main.cpp +└── source-files + ├── InputManager.cpp + ├── StorageEditor.cpp + ├── Ware.cpp + └── WarenStorage.cpp + +''' diff --git a/src/header-files/InputManager.h b/src/header-files/InputManager.h new file mode 100644 index 0000000..a3ae10b --- /dev/null +++ b/src/header-files/InputManager.h @@ -0,0 +1,50 @@ +#include "pch.h" +#include "StorageEditor.h" + +class InputManager { + + public: + typedef int MenuOption; + + private: + StorageEditor editor; + + MenuOption selectedOption; + + MenuOption askMenuOption(std::string question, std::vector answers); + + void displayDialog(std::string question, std::vector answers); + + struct WareAndAmount { + Ware ware; + int amount; + }; + + public: + + InputManager(StorageEditor storageEditor); + + void displayMainMenu(); + + void displayWaren(const std::vector waren); + + + WareAndAmount displayAddWareDialog(); + + WareAndAmount displayRemoveWareDialog(); + + MenuOption getSelectedOption(); + + void setSelectedOption(MenuOption option); + + template + T getInput(std::string message) const; + + bool getNeedsCooling(); + + std::vector sortAndGroupWaren(const std::vector& waren); + + + + +}; diff --git a/src/header-files/StorageEditor.h b/src/header-files/StorageEditor.h new file mode 100644 index 0000000..803b720 --- /dev/null +++ b/src/header-files/StorageEditor.h @@ -0,0 +1,26 @@ +#include "pch.h" +#include "data-classes/WarenStorage.h" + +class StorageEditor { + private: + + WarenStorage storage; + + public: + + StorageEditor(); + + StorageEditor(WarenStorage storage); + + WarenStorage getWarenStorage() const; + + void setWarenStorage(const WarenStorage storage); + + void addWareAndGenerateId(Ware ware); + + void addWaren(const Ware ware, int amount); + + void removeWare(std::string name); + + void removeWaren(std::string name, int amount); +}; diff --git a/src/header-files/data-classes/Ware.h b/src/header-files/data-classes/Ware.h new file mode 100644 index 0000000..3e4f6de --- /dev/null +++ b/src/header-files/data-classes/Ware.h @@ -0,0 +1,60 @@ +#include "../pch.h" + +class Ware { + public: + struct Size { + double width; + double height; + }; + + enum WareType { + DefaultWare, + CoolingWare, + LargeWare + }; + + private: + static int count; + + Id id; + + bool hasCooling; + + std::string name; + + Size size; + + WareType type; + + public: + Ware(); + + ~Ware(); + + Ware(std::string name, bool hasCooling, double width, double height); + + Id getId() const; + + void setId(const Id id); + + bool getHasCooling() const; + + void setHasCooling(const bool isCoolable); + + std::string getName() const; + + void setName(const std::string name); + + Size getSize() const; + + void setSize(const double width, const double height); + + WareType getType() const; + + void setType(const WareType type); + + Id generateId(); + + bool isLargeWare(Size s); + +}; diff --git a/src/header-files/data-classes/WarenStorage.h b/src/header-files/data-classes/WarenStorage.h new file mode 100644 index 0000000..520f228 --- /dev/null +++ b/src/header-files/data-classes/WarenStorage.h @@ -0,0 +1,47 @@ +#include "../pch.h" +#include "Ware.h" + +class WarenStorage { + public: + + //maybe ist das hier einfach garbage + typedef Ware CoolingWare; + + typedef Ware LargeWare; + + private: + + std::vector warenList; + + std::vector coolingWarenList; + + std::vector largeWarenList; + + public: + + WarenStorage(); + + void addWarenListToSum(std::vector* sumList, std::vector itemList) const; + + std::vector getAllWaren() const; + + std::vector getWarenList(); + + void setWarenList(const std::vector waren); + + std::vector getCoolingWarenList(); + + void setCoolingWarenList(const std::vector coolingWaren); + + std::vector getLargeWarenList(); + + void setLargeWarenList(const std::vector largeWaren); + + void addWareAndGenerateId(Ware ware); + + void removeWare(const std::string name); + + //const frage: + // + //wie kann ich die get...Waren() getter wieder als const definieren, ohne dass ich damit StorageEditor die möglichkeit nehme sie zu Editieren. +}; diff --git a/src/header-files/pch.h b/src/header-files/pch.h new file mode 100644 index 0000000..3477d24 --- /dev/null +++ b/src/header-files/pch.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include +#include + +typedef int Id; diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..bce2d0f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,14 @@ +#include "header-files/pch.h" +#include "header-files/InputManager.h" + +int Ware::count; +int main () { + + std::cout << "Kaufland:" << std::endl; + + StorageEditor editor; + InputManager inputManager(editor); + inputManager.displayMainMenu(); + + return 0; +} diff --git a/src/source-files/InputManager.cpp b/src/source-files/InputManager.cpp new file mode 100644 index 0000000..aee0419 --- /dev/null +++ b/src/source-files/InputManager.cpp @@ -0,0 +1,264 @@ +#include "../header-files/InputManager.h" +#include +#include + +InputManager::InputManager(StorageEditor storageEditor) { + this->editor = storageEditor; +} + +InputManager::MenuOption InputManager::getSelectedOption() { + return selectedOption; +} + +void InputManager::setSelectedOption(MenuOption option) { + this->selectedOption = option; +} + +InputManager::MenuOption InputManager::askMenuOption(std::string question, std::vector answers) { + this->displayDialog(question, answers); + int input; + std::cin >> input; + + return input; +} + +void InputManager::displayDialog(std::string question, std::vector answers) { + std::cout << question << std::endl; + std::cout << "-------------------------------" << std::endl; + int counter = 0; + for(std::string answer:answers) { + counter++; + std::cout << counter << ") " << answer << std::endl; + } + std::cout << "-------------------------------" << std::endl; +} + +InputManager::WareAndAmount InputManager::displayAddWareDialog() { + std::string name; + bool hasCooling; + double width, height; + int amount; + + name = getInput("Enter Ware Name:"); + hasCooling = getNeedsCooling(); + width = getInput("Enter Ware width:"); + height = getInput("Enter Ware height:"); + amount = getInput("Enter Ware amount:"); + + InputManager::WareAndAmount wareAndAmount; + wareAndAmount.ware = Ware(name, hasCooling, width, height); + wareAndAmount.amount = amount; + + return wareAndAmount; +} + +InputManager::WareAndAmount InputManager::displayRemoveWareDialog() { + std::string name; + int amount; + + name = getInput("Enter Name of the Ware you want to remove:"); + amount = getInput("Enter amount you want to remove:"); + + InputManager::WareAndAmount wareAndAmount; + + Ware ware = Ware(); + ware.setName(name); + + wareAndAmount.ware = ware; + wareAndAmount.amount = amount; + + return wareAndAmount; +} + + +void InputManager::displayMainMenu() { + std::vector answers; + std::string question = "Wie moechten Sie verfahren?"; + + std::string answer = "Ware/n hinzufuegen."; + answers.push_back(answer); + + answer = "Ware/n entfernen."; + answers.push_back(answer); + + answer = "Ware/n anzeigen."; + answers.push_back(answer); + + answer = "Beenden."; + answers.push_back(answer); + + selectedOption = askMenuOption(question, answers); + switch(selectedOption) { + case 1: { + InputManager::WareAndAmount x = displayAddWareDialog(); + editor.addWaren(x.ware, x.amount); + break; + } + case 2: { + InputManager::WareAndAmount x = displayRemoveWareDialog(); + editor.removeWaren(x.ware.getName(), x.amount); + break; + } + case 3: { + std::vector waren = this->editor.getWarenStorage().getAllWaren(); + displayWaren(waren); + break; + } + case 4: { + return; + break; + } + } + + displayMainMenu(); +} + +// if no more initialization needed --> refactor to setStorageEditor +void InputManager::displayWaren(const std::vector waren) { + std::cout << "Liste der sich im Lager befindlichen Waren:" << std::endl; + std::vector sortedWarenList = sortAndGroupWaren(waren); + + if(sortedWarenList.empty()){ + std::cout << "Das Warenlager ist leer." << std::endl; + std::cout << "---------------------" << std::endl; + return; + } + + for(WareAndAmount wareAndAmount: sortedWarenList){ + std::cout << "Warenname:" << std::endl; + std::cout << wareAndAmount.ware.getName() << std::endl; + + std::cout << "Needs Cooling:" << std::endl; + if(wareAndAmount.ware.getHasCooling()) { + std::cout << "true" << std::endl; + } + else { + std::cout << "false" << std::endl; + } + + std::cout << "Width:" << std::endl; + std::cout << wareAndAmount.ware.getSize().width << std::endl; + + std::cout << "Height:" << std::endl; + std::cout << wareAndAmount.ware.getSize().height << std::endl; + + std::cout << "Amount:" << std::endl; + std::cout << wareAndAmount.amount << std::endl; + + std::cout << "---------------------" << std::endl; + } +} + +//refactor +std::vector InputManager::sortAndGroupWaren(const std::vector& waren) { + std::vector sortedWaren; + + WareAndAmount wareAndAmount; + wareAndAmount.amount = 0; + + for(Ware ware : waren) { + if(ware.getType() == Ware::WareType::DefaultWare) { + if(wareAndAmount.amount == 0) { + wareAndAmount.ware = ware; + wareAndAmount.amount++; + } + else if(wareAndAmount.ware.getName() == ware.getName()) { + wareAndAmount.amount++; + } + else { + sortedWaren.push_back(wareAndAmount); + wareAndAmount.amount = 0; + } + } + } + if(!waren.empty() && wareAndAmount.amount > 0){ + sortedWaren.push_back(wareAndAmount); + wareAndAmount.amount = 0; + } + + for(Ware ware : waren) { + if(ware.getType() == Ware::WareType::CoolingWare) { + if(wareAndAmount.amount == 0) { + wareAndAmount.ware = ware; + wareAndAmount.amount++; + } + else if(wareAndAmount.ware.getName() == ware.getName()) { + wareAndAmount.amount++; + } + else { + sortedWaren.push_back(wareAndAmount); + wareAndAmount.amount = 0; + } + } + } + if(!waren.empty() && wareAndAmount.amount > 0){ + sortedWaren.push_back(wareAndAmount); + wareAndAmount.amount = 0; + } + + for(Ware ware : waren) { + if(ware.getType() == Ware::WareType::LargeWare) { + if(wareAndAmount.amount == 0) { + wareAndAmount.ware = ware; + wareAndAmount.amount++; + } + else if(wareAndAmount.ware.getName() == ware.getName()) { + wareAndAmount.amount++; + } + else { + sortedWaren.push_back(wareAndAmount); + wareAndAmount.amount = 0; + } + } + } + if(!waren.empty() && wareAndAmount.amount > 0){ + sortedWaren.push_back(wareAndAmount); + wareAndAmount.amount = 0; + } + + return sortedWaren; +} + + +bool InputManager::getNeedsCooling() { + std::string input; + bool hasCooling; + + std::cout << "Does Ware need Cooling? (y/n)" << std::endl; + try { + std::cin >> input; + if(input == "y") { + hasCooling = true; + } + else if(input == "n") { + hasCooling = false; + } + else { + std::cout << "That didn't work. Please try again :)" << std::endl; + getNeedsCooling(); + } + } + catch(const std::exception&){ + std::cout << "That didn't work. Please try again :)" << std::endl; + getNeedsCooling(); + } + return hasCooling; +} + +//std::istream +template +T InputManager::getInput(std::string message) const { + std::cout << message << std::endl; + T val; + try { + std::string input; + std::cin >> input; + std::istringstream ss(input); + ss >> val; + } + catch(const std::exception&) { + std::cout << "That didn't work. Please try again :)" << std::endl; + getInput(message); + } + return val; +} diff --git a/src/source-files/StorageEditor.cpp b/src/source-files/StorageEditor.cpp new file mode 100644 index 0000000..37df68d --- /dev/null +++ b/src/source-files/StorageEditor.cpp @@ -0,0 +1,30 @@ +#include "../header-files/StorageEditor.h" + +StorageEditor::StorageEditor() { } + +StorageEditor::StorageEditor(const WarenStorage storage) { + this->storage = storage; +} + +WarenStorage StorageEditor::getWarenStorage() const { + return storage; +} + +void StorageEditor::setWarenStorage(const WarenStorage storage) { + this->storage = storage; +} + + +void StorageEditor::addWaren(const Ware ware, int amount) { + for(auto i = 0; i < amount; i++) { + storage.addWareAndGenerateId(ware); + } +} + + +void StorageEditor::removeWaren(std::string name, const int amount) { + for(auto i = 0; i < amount; i++) { + storage.removeWare(name); + } +} + diff --git a/src/source-files/Ware.cpp b/src/source-files/Ware.cpp new file mode 100644 index 0000000..44a6178 --- /dev/null +++ b/src/source-files/Ware.cpp @@ -0,0 +1,69 @@ +#include "../header-files/data-classes/Ware.h" + +Ware::Ware(){ ++count; } +Ware::~Ware() { --count; } + +Ware::Ware(std::string name, bool hasCooling, double width, double height) { + this->name = name; + this->hasCooling = hasCooling; + this->size = { width, height }; + + if(hasCooling) { + this->type = CoolingWare; + } else if(isLargeWare(this->size)) { + this->type = LargeWare; + } else { + this->type = DefaultWare; + } + count++; + this->id = this->generateId(); +} + +Id Ware::getId() const { + return id; +} + +void Ware::setId(const Id id) { + this->id = id; +} + +Ware::WareType Ware::getType() const { + return type; +} + +void Ware::setType(const WareType type) { + this->type = type; +} + +bool Ware::getHasCooling() const { + return hasCooling; +} + +void Ware::setHasCooling(const bool hasCooling) { + this->hasCooling = hasCooling; +} + +std::string Ware::getName() const { + return name; +} + +void Ware::setName(const std::string name) { + this->name = name; +} + +Ware::Size Ware::getSize() const { + return size; +} + +void Ware::setSize(const double width, const double height) { + this->size = Size{ width, height }; +} + +bool Ware::isLargeWare(Size s) { + return (s.width > 20.0 || s.height > 20.0); +} + +Id Ware::generateId() { + //billige id generation da keine reference benutzt + return (uint64_t) &this->name; +} diff --git a/src/source-files/WarenStorage.cpp b/src/source-files/WarenStorage.cpp new file mode 100644 index 0000000..38174b5 --- /dev/null +++ b/src/source-files/WarenStorage.cpp @@ -0,0 +1,92 @@ +#include "../header-files/data-classes/WarenStorage.h" + + +WarenStorage::WarenStorage() { } + +void WarenStorage::addWarenListToSum(std::vector* sumList, std::vector itemList) const { + //reference ohne const möglich oder ist hier ein pointer notwendig?? + for(Ware ware : itemList) { + sumList->push_back((Ware) ware); //static_cast<> oder ganz weg + } +} + +std::vector WarenStorage::getAllWaren() const { + + std::vector w; + + addWarenListToSum(&w, warenList); + addWarenListToSum(&w, coolingWarenList); + addWarenListToSum(&w, largeWarenList); + + return w; +} + +std::vector WarenStorage::getWarenList() { + return warenList; +} + +void WarenStorage::setWarenList(const std::vector waren) { + this->warenList = waren; +} + +std::vector WarenStorage::getCoolingWarenList() { + return coolingWarenList; +} + +void WarenStorage::setCoolingWarenList(const std::vector coolingWaren) { + this->coolingWarenList = coolingWaren; +} + +std::vector WarenStorage::getLargeWarenList() { + return largeWarenList; +} + +void WarenStorage::setLargeWarenList(const std::vector largeWaren) { + this->largeWarenList = largeWaren; +} + +void WarenStorage::addWareAndGenerateId(Ware ware) { + + ware.generateId(); + switch(ware.getType()) { + case Ware::WareType::DefaultWare: + warenList.push_back(ware); + break; + + case Ware::WareType::CoolingWare: + coolingWarenList.push_back(ware); + break; + + case Ware::WareType::LargeWare: + largeWarenList.push_back(ware); + break; + } +} + +void WarenStorage::removeWare(const std::string name) { + std::vector allWaren = getAllWaren(); + for(size_t i = 0; i < allWaren.size(); i++) { + if(allWaren[i].getName() == name) { + switch(allWaren[i].getType()) { + case Ware::WareType::DefaultWare: + warenList.erase( + warenList.begin() + i + ); + break; + + case Ware::WareType::CoolingWare: + coolingWarenList.erase( + coolingWarenList.begin() + i + ); + break; + + case Ware::WareType::LargeWare: + largeWarenList.erase( + largeWarenList.begin() + i + ); + break; + } + break; //remove only one item + } + } +}