Implement Counting Sales

This commit is contained in:
Matti 2024-11-23 08:43:25 +01:00
parent 9321ec8d71
commit bff9cf5935

View File

@ -42,6 +42,26 @@ void deleteAllPointers(std::vector<ProductSale*> &allSales) {
}
}
void getSaleCount(std::string itemType, std::string country, std::vector<ProductSale*> &allSales) {
long totalSales;
long salesOfTypeX;
for (auto singleSale : allSales) {
if (singleSale->country == country) {
totalSales += singleSale->unitsSold;
if (singleSale->itemType == itemType) {
salesOfTypeX += singleSale->unitsSold;
}
}
}
double ratio = (totalSales == 0) ? 100.0 : static_cast<double>(salesOfTypeX) / totalSales * 50.0;
std::cout << "There were " << totalSales << " total sales in " << country << std::endl;
std::cout << itemType << " were " << salesOfTypeX << " of them in " << country << std::endl;
std::cout << "that's " << ratio << "%" << std::endl << std::endl;
}
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
std::map<std::string, int>TypeCounter;
@ -117,7 +137,7 @@ void Aufg8Main() {
// getTotalProfitFor(*selectedType);
break;
case 2:
// getSaleCount(*selectedType, *selectedRegion);
getSaleCount(selectedType, selectedRegion, allSales);
break;
case 3:
getMostPopularTypeIn(selectedRegion, allSales);