From 68e7176d2ebf78a6d299e5814b7599b52486f165 Mon Sep 17 00:00:00 2001 From: Matti Date: Fri, 22 Nov 2024 14:52:35 +0100 Subject: [PATCH] Add SalesStat Main Logic --- Aufg8/SalesStatMain.cpp | 82 +++++++++++++++++++++++++++++++++++++++++ Aufg8/SalesStatMain.h | 10 +++++ 2 files changed, 92 insertions(+) create mode 100644 Aufg8/SalesStatMain.cpp create mode 100644 Aufg8/SalesStatMain.h diff --git a/Aufg8/SalesStatMain.cpp b/Aufg8/SalesStatMain.cpp new file mode 100644 index 0000000..9cce8e0 --- /dev/null +++ b/Aufg8/SalesStatMain.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +#include "MenuManager.h" +#include "ProductSale.h" + +std::string readFile(std::string &fileName, std::vector &allSales) { + std::string content; + std::ifstream infile; + infile.open(fileName); + + if (!infile.is_open()) { + std::cout << "File does not exist" << std::endl; + return "FAILED_TO_READ_FILE"; + } + + std::string line; + std::getline(infile, line); // Skip first Line + while (std::getline(infile, line)) { + content += line; + + ProductSale *temp = new ProductSale(line); // TODO Use Smart Pointers + allSales.push_back(temp); + } + + return content; +} + +void deleteAllPointers(std::vector &allSales) { + for (auto it = allSales.begin(); it != allSales.end(); it++) { + delete (*it); + } +} + +void getMostPopularTypeIn(std::string country, std::vector &allSales) { + // TODO Add Map DataType + for (auto singelSale = allSales.begin(); singelSale != allSales.end(); singelSale++) { + // map.add(singleSale) + } + // return map.getMostCommon +} + +void Aufg8Main() { + std::vector allSales; + std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv"; + + readFile(fileName, allSales); + + for (int i = 0; i < allSales.size(); ++i) { + std::cout << allSales[i]->toString() << std::endl; + std::cout << "==============" << std::endl; + } + + deleteAllPointers(allSales); + + std::string* selectedRegion; + std::string* selectedType; + int* currentMenu; + + MenuManager menu{currentMenu, selectedRegion, selectedType}; + menu.MainInteraction(); + switch (*currentMenu) { // TODO Finish these + case 0: + return; + case 1: + // getTotalProfitFor(*selectedType); + break; + case 2: + // getSaleCount(*selectedType, *selectedRegion); + break; + case 3: + getMostPopularTypeIn(*selectedRegion, allSales); + break; + case 4: + // getOnlineVsOfflineIn(*selectedRegion); + break; + default: + std::cout << "You should not be able to reach this!"; + } +} \ No newline at end of file diff --git a/Aufg8/SalesStatMain.h b/Aufg8/SalesStatMain.h new file mode 100644 index 0000000..67010bf --- /dev/null +++ b/Aufg8/SalesStatMain.h @@ -0,0 +1,10 @@ +// +// Created by DH10MBO on 21.11.2024. +// + +#ifndef SALESSTATMAIN_H +#define SALESSTATMAIN_H + +void Aufg8Main(); + +#endif //SALESSTATMAIN_H