S3_Cpp/Aufg8/SalesStatMain.cpp
2024-11-22 14:52:35 +01:00

82 lines
2.2 KiB
C++

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "MenuManager.h"
#include "ProductSale.h"
std::string readFile(std::string &fileName, std::vector<ProductSale*> &allSales) {
std::string content;
std::ifstream infile;
infile.open(fileName);
if (!infile.is_open()) {
std::cout << "File does not exist" << std::endl;
return "FAILED_TO_READ_FILE";
}
std::string line;
std::getline(infile, line); // Skip first Line
while (std::getline(infile, line)) {
content += line;
ProductSale *temp = new ProductSale(line); // TODO Use Smart Pointers
allSales.push_back(temp);
}
return content;
}
void deleteAllPointers(std::vector<ProductSale*> &allSales) {
for (auto it = allSales.begin(); it != allSales.end(); it++) {
delete (*it);
}
}
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
// TODO Add Map DataType
for (auto singelSale = allSales.begin(); singelSale != allSales.end(); singelSale++) {
// map.add(singleSale)
}
// return map.getMostCommon
}
void Aufg8Main() {
std::vector<ProductSale*> allSales;
std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv";
readFile(fileName, allSales);
for (int i = 0; i < allSales.size(); ++i) {
std::cout << allSales[i]->toString() << std::endl;
std::cout << "==============" << std::endl;
}
deleteAllPointers(allSales);
std::string* selectedRegion;
std::string* selectedType;
int* currentMenu;
MenuManager menu{currentMenu, selectedRegion, selectedType};
menu.MainInteraction();
switch (*currentMenu) { // TODO Finish these
case 0:
return;
case 1:
// getTotalProfitFor(*selectedType);
break;
case 2:
// getSaleCount(*selectedType, *selectedRegion);
break;
case 3:
getMostPopularTypeIn(*selectedRegion, allSales);
break;
case 4:
// getOnlineVsOfflineIn(*selectedRegion);
break;
default:
std::cout << "You should not be able to reach this!";
}
}