Implement Counting Sales
This commit is contained in:
parent
9321ec8d71
commit
bff9cf5935
@ -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) {
|
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
|
||||||
std::map<std::string, int>TypeCounter;
|
std::map<std::string, int>TypeCounter;
|
||||||
|
|
||||||
@ -117,7 +137,7 @@ void Aufg8Main() {
|
|||||||
// getTotalProfitFor(*selectedType);
|
// getTotalProfitFor(*selectedType);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// getSaleCount(*selectedType, *selectedRegion);
|
getSaleCount(selectedType, selectedRegion, allSales);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
getMostPopularTypeIn(selectedRegion, allSales);
|
getMostPopularTypeIn(selectedRegion, allSales);
|
||||||
|
Loading…
Reference in New Issue
Block a user