From e6fedd165ed5c62e9201c749d2f1ef422dc24b47 Mon Sep 17 00:00:00 2001 From: Matti Date: Sat, 23 Nov 2024 07:27:03 +0100 Subject: [PATCH] Implement counting Online vs Offline --- Aufg8/MenuManager.h | 4 ++-- Aufg8/SalesStatMain.cpp | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Aufg8/MenuManager.h b/Aufg8/MenuManager.h index 0741b81..448cba1 100644 --- a/Aufg8/MenuManager.h +++ b/Aufg8/MenuManager.h @@ -34,7 +34,7 @@ class MenuManager { std::cout<<"Select Information to display" < &allSales) { } void getMostPopularTypeIn(std::string country, std::vector &allSales) { - // TODO Add Map DataType std::mapTypeCounter; for (ProductSale* singelSale : allSales) { @@ -74,6 +73,38 @@ void getMostPopularTypeIn(std::string country, std::vector &allSal } +void getOnlineVsOfflineIn(std::string country, std::vector &allSales) { + std::mapTypeCounter; + + for (ProductSale* singelSale : allSales) { + // map.add(singleSale) + if (singelSale->country != country) { + continue; + } + + bool alreadyExists = false; + for (auto element : TypeCounter) { + if (element.first == singelSale->salesChannel) { + element.second++; + alreadyExists = true; + break; + } + } + if (!alreadyExists) { + TypeCounter[singelSale->salesChannel] = 1; + } + } + + + int OnlineCounter = TypeCounter["Online"]; + int OfflineCounter = TypeCounter["Offline"]; + double ratio = (OfflineCounter==0) ? 100.0: OnlineCounter/OfflineCounter; + + std::cout << "Online : " << OnlineCounter << std::endl << "Offline : " << OfflineCounter << std::endl; + std::cout << "Ratio : " << ratio << "% Online" << std::endl << std::endl; + +} + void Aufg8Main() { std::vector allSales; std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv"; @@ -93,7 +124,7 @@ void Aufg8Main() { std::string* PselectedType = &selectedType; int* PcurrentMenu = ¤tMenu; - MenuManager menu{PcurrentMenu, PselectedRegion, PselectedType}; + MenuManager menu{PcurrentMenu, PselectedType, PselectedRegion}; menu.MainInteraction(); while (currentMenu) { switch (currentMenu) { // TODO Finish these @@ -109,7 +140,7 @@ void Aufg8Main() { getMostPopularTypeIn(selectedRegion, allSales); break; case 4: - // getOnlineVsOfflineIn(*selectedRegion); + getOnlineVsOfflineIn(selectedRegion, allSales); break; default: std::cout << "You should not be able to reach this!";