Implement getting most popular type in a country
This commit is contained in:
parent
2e4efa7833
commit
8af59118c2
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
class ProductSale {
|
||||
private:
|
||||
public:
|
||||
std::string region;
|
||||
std::string country;
|
||||
std::string itemType;
|
||||
@ -23,7 +23,7 @@ private:
|
||||
double totalRevenue;
|
||||
double totalCost;
|
||||
double totalProfit;
|
||||
public:
|
||||
|
||||
ProductSale(std::string line);
|
||||
std::string toString();
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -36,10 +37,41 @@ void deleteAllPointers(std::vector<ProductSale*> &allSales) {
|
||||
|
||||
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
|
||||
// TODO Add Map DataType
|
||||
for (auto singelSale = allSales.begin(); singelSale != allSales.end(); singelSale++) {
|
||||
std::map<std::string, int>TypeCounter;
|
||||
|
||||
for (ProductSale* singelSale : allSales) {
|
||||
// map.add(singleSale)
|
||||
if (singelSale->country != country) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool alreadyExists = false;
|
||||
for (auto element : TypeCounter) {
|
||||
if (element.first == singelSale->itemType) {
|
||||
element.second++;
|
||||
alreadyExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!alreadyExists) {
|
||||
TypeCounter[singelSale->itemType] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// return map.getMostCommon
|
||||
std::string mostPopularType;
|
||||
int counter = 0;
|
||||
for (auto element : TypeCounter) {
|
||||
if (element.second > counter) {
|
||||
counter = element.second;
|
||||
mostPopularType = element.first;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Most popular Type : " << mostPopularType << std::endl
|
||||
<< "Occurences : " << counter << std::endl << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void Aufg8Main() {
|
||||
@ -64,7 +96,6 @@ void Aufg8Main() {
|
||||
MenuManager menu{PcurrentMenu, PselectedRegion, PselectedType};
|
||||
menu.MainInteraction();
|
||||
while (currentMenu) {
|
||||
std::cout << "Deciding if youre allowed to quit" << (currentMenu) << std::endl;
|
||||
switch (currentMenu) { // TODO Finish these
|
||||
case 0:
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user