Compare commits

..

2 Commits

Author SHA1 Message Date
Matti
68e7176d2e Add SalesStat Main Logic 2024-11-22 14:52:35 +01:00
Matti
92e69846f7 Add Menu Manager 2024-11-22 14:52:07 +01:00
4 changed files with 203 additions and 0 deletions

32
Aufg8/MenuManager.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include <stdlib.h>
class MenuManager {
// public:
// MenuManager();
// int AcceptIntInputInRange(int minInput, int maxInput) {
// int input;
// std::cin >> input;
//
// while (input < minInput || input > maxInput) {
// std::cout << "Enter a number between " << minInput << " and " << maxInput << ": ";
// std::cin >> input;
// }
// return input;
// }
//
// int ShowMainMenu() {
// system("cls");
//
// std::cout<<"Select Information to display" <<std::endl
// << "1. Profit per Metric" <<std::endl
// << "2. Cunt Sales of type X in a Region" <<std::endl
// << "3. Most popular item type in country X" <<std::endl
// << "4. Online vs Offline Sales in country X" <<std::endl
// << "======" <<std::endl
// << "0 to Exit" <<std::endl;
//
// int choice = AcceptIntInputInRange(0,4);
// return choice;
// }
};

79
Aufg8/MenuManager.h Normal file
View File

@ -0,0 +1,79 @@
//
// Created by DH10MBO on 21.11.2024.
//
#ifndef MENUMANAGER_H
#define MENUMANAGER_H
#include <iostream>
class MenuManager {
private:
int* currentMenu;
std::string* selectedMetric;
std::string* selectedRegion;
public:
MenuManager(int* currentMenu, std::string* selectedMetric, std::string* selectedRegion){
this->currentMenu = currentMenu;
this->selectedRegion = selectedRegion;
this->selectedMetric = selectedMetric;
}
int AcceptIntInputInRange(int minInput, int maxInput) {
int input;
std::cin >> input;
while (input < minInput || input > maxInput) {
std::cout << "Enter a number between " << minInput << " and " << maxInput << ": ";
std::cin >> input;
}
return input;
}
int ShowMainMenu() {
// system("cls");
std::cout<<"Select Information to display" <<std::endl
<< "1. Profit per Metric" <<std::endl
<< "2. Cunt Sales of type X in a Region" <<std::endl
<< "3. Most popular item type in country X" <<std::endl
<< "4. Online vs Offline Sales in country X" <<std::endl
<< "======" <<std::endl
<< "0 to Exit" <<std::endl;
int choice = AcceptIntInputInRange(0,4);
return choice;
}
std::string ShowPromptAndGetString(std::string prompt) {
std::cout << prompt <<std::endl;
prompt = "";
std::cin >> prompt;
return prompt;
}
void MainInteraction() {
*currentMenu = ShowMainMenu();
switch (*currentMenu) {
case 0:
return;
case 1:
*selectedMetric = ShowPromptAndGetString("Enter The Metric to get total Profit for"); break;
case 2:
*selectedMetric = ShowPromptAndGetString("Enter The item type to search for");
*selectedRegion = ShowPromptAndGetString("Enter The region to search in");
break;
case 3:
*selectedMetric = ShowPromptAndGetString("Enter The country to get most common type for");
break;
case 4:
*selectedRegion = ShowPromptAndGetString("Select Country to count online vs offline purchases");
break;
default:
std::cout << "You should not be able to reach this point if you entered a legal number";
}
}
};
#endif //MENUMANAGER_H

82
Aufg8/SalesStatMain.cpp Normal file
View File

@ -0,0 +1,82 @@
#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!";
}
}

10
Aufg8/SalesStatMain.h Normal file
View File

@ -0,0 +1,10 @@
//
// Created by DH10MBO on 21.11.2024.
//
#ifndef SALESSTATMAIN_H
#define SALESSTATMAIN_H
void Aufg8Main();
#endif //SALESSTATMAIN_H