diff --git a/Aufg8/SalesStatMain.cpp b/Aufg8/SalesStatMain.cpp index 961ad39..f2bde5d 100644 --- a/Aufg8/SalesStatMain.cpp +++ b/Aufg8/SalesStatMain.cpp @@ -6,6 +6,7 @@ #include "MenuManager.h" #include "ProductSale.h" +#include "../Aufg1/forLoop.h" std::string readFile(std::string &fileName, std::vector &allSales) { std::string content; @@ -43,107 +44,79 @@ void deleteAllPointers(std::vector &allSales) { } void getTotalProfitFor(std::string metric, std::vector &allSales) { - std::map TotalPerMetric; + std::map TotalPerMetric; - switch (metric) { - case "Region" : - for(auto sale : allSales) { - TotalPerMetric[sale->region] += sale->totalProfit; - } - break; - - case "Country": - for(auto sale : allSales) { - TotalPerMetric[sale->country] += sale->totalProfit; - } - break; - - case "Item_Type": - for(auto sale : allSales) { - TotalPerMetric[sale->itemType] += sale->totalProfit; - } - break; - - case "Sales_Channel" : - for(auto sale : allSales) { - TotalPerMetric[sale->salesChannel] += sale->totalProfit; - } - break; - - case "Order_Priority" : - for(auto sale : allSales) { - TotalPerMetric[sale->orderPriority] += sale->totalProfit; - } - break; - - case "Order_Date" : - for(auto sale : allSales) { - TotalPerMetric[sale->orderDate] += sale->totalProfit; - } - break; - - case "Order_ID" : - for(auto sale : allSales) { - TotalPerMetric[sale->orderId] += sale->totalProfit; - } - break; - - case "Ship_Date" : - for(auto sale : allSales) { - TotalPerMetric[sale->shipDate] += sale->totalProfit; - } - break; - - case "Units_Sold" : - for(auto sale : allSales) { - std::string key = std::to_string(sale->unitsSold); - TotalPerMetric[key] += sale->totalProfit; - } - break; - - case "Unit_Price" : - for(auto sale : allSales) { - std::string key = std::to_string(sale->unitPrice); - TotalPerMetric[key] += sale->totalProfit; - } - break; - - case "Unit_Cost" : - for(auto sale : allSales) { - std::string key = std::to_string(sale->unitCost); - TotalPerMetric[key] += sale->totalProfit; - } - break; - - case "Total_Revenue" : - for(auto sale : allSales) { - std::string key = std::to_string(sale->totalRevenue); - TotalPerMetric[key] += sale->totalProfit; - } - break; - - case "Total_Cost" : - for(auto sale : allSales) { - std::string key = std::to_string(sale->totalCost); - TotalPerMetric[key] += sale->totalProfit; - } - break; - - case "Total_Profit" : - for(auto sale : allSales) { - std::string key = std::to_string(sale->totalProfit); - TotalPerMetric[key] += sale->totalProfit; - } - break; - - default: - std::cout << "Unknown metric :" << metric << std::endl; - return; + if (metric == "Region") { + for(auto sale : allSales) { + TotalPerMetric[sale->region] += sale->totalProfit; + } + } else if (metric == "Country") { + for(auto sale : allSales) { + TotalPerMetric[sale->country] += sale->totalProfit; + } + } else if (metric=="Item_Type") { + for(auto sale : allSales) { + TotalPerMetric[sale->itemType] += sale->totalProfit; + } + }else if (metric=="Sales_Channel") { + for(auto sale : allSales) { + TotalPerMetric[sale->salesChannel] += sale->totalProfit; + } + }else if (metric == "Order_Priority") { + for(auto sale : allSales) { + TotalPerMetric[sale->orderPriority] += sale->totalProfit; + } + }else if (metric == "Order_Date") { + for(auto sale : allSales) { + TotalPerMetric[sale->orderDate] += sale->totalProfit; + } + }else if (metric == "Order_ID") { + for(auto sale : allSales) { + TotalPerMetric[sale->orderId] += sale->totalProfit; + } + }else if (metric == "Ship_Date") { + for(auto sale : allSales) { + TotalPerMetric[sale->shipDate] += sale->totalProfit; + } + }else if (metric == "Units_Sold") { + for(auto sale : allSales) { + std::string key = std::to_string(sale->unitsSold); + TotalPerMetric[key] += sale->totalProfit; + } + }else if (metric == "Unit_Price") { + for(auto sale : allSales) { + std::string key = std::to_string(sale->unitPrice); + TotalPerMetric[key] += sale->totalProfit; + } + }else if (metric=="Unit_Cost") { + for(auto sale : allSales) { + std::string key = std::to_string(sale->unitCost); + TotalPerMetric[key] += sale->totalProfit; + } + }else if (metric == "Total_Revenue") { + for(auto sale : allSales) { + std::string key = std::to_string(sale->totalRevenue); + TotalPerMetric[key] += sale->totalProfit; + } + }else if (metric == "Total_Cost") { + for(auto sale : allSales) { + std::string key = std::to_string(sale->totalCost); + TotalPerMetric[key] += sale->totalProfit; + } + }else if (metric == "Total_Profit") { + for(auto sale : allSales) { + std::string key = std::to_string(sale->totalProfit); + TotalPerMetric[key] += sale->totalProfit; + } + }else{ + std::cout << "Unknown metric :" << metric << std::endl; + return; } for (auto entry : TotalPerMetric) { std::cout << entry.first << " : " << entry.second << std::endl; } + std::cout << std::endl; } void getSaleCount(std::string itemType, std::string country, std::vector &allSales) {