Compare commits
18 Commits
763bc1c53e
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
61188b5afd | ||
|
e911510523 | ||
|
ff499e51d8 | ||
|
50e86d6ed5 | ||
|
bbad0349e4 | ||
|
c26dc8415d | ||
|
03ac04c0ff | ||
|
b99e0b45ad | ||
|
00b4e196da | ||
|
a0f05d9130 | ||
|
bff9cf5935 | ||
|
9321ec8d71 | ||
|
dbdd4ade8e | ||
|
e6fedd165e | ||
|
8af59118c2 | ||
|
2e4efa7833 | ||
|
68e7176d2e | ||
|
92e69846f7 |
@@ -8,6 +8,8 @@
|
|||||||
#include "Aufg5/Mastermind.h"
|
#include "Aufg5/Mastermind.h"
|
||||||
#include "Aufg6/MineSweeper.h"
|
#include "Aufg6/MineSweeper.h"
|
||||||
#include "Aufg7/SegFault.h"
|
#include "Aufg7/SegFault.h"
|
||||||
|
#include "Aufg8/SalesStatMain.h"
|
||||||
|
#include "Aufg9/DiabloByteReader.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Aufg1Main();
|
// Aufg1Main();
|
||||||
@@ -16,5 +18,7 @@ int main() {
|
|||||||
// Aufg4Main();
|
// Aufg4Main();
|
||||||
// Aufg5Main();
|
// Aufg5Main();
|
||||||
// Aufg6Main();
|
// Aufg6Main();
|
||||||
Aufg7Main();
|
// Aufg7Main();
|
||||||
|
// Aufg8Main();
|
||||||
|
Aufg9Main();
|
||||||
}
|
}
|
||||||
|
32
Aufg8/MenuManager.cpp
Normal file
32
Aufg8/MenuManager.cpp
Normal 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
79
Aufg8/MenuManager.h
Normal 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. Count 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:
|
||||||
|
*selectedRegion = 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
|
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class ProductSale {
|
class ProductSale {
|
||||||
private:
|
public:
|
||||||
std::string region;
|
std::string region;
|
||||||
std::string country;
|
std::string country;
|
||||||
std::string itemType;
|
std::string itemType;
|
||||||
@@ -23,7 +23,7 @@ private:
|
|||||||
double totalRevenue;
|
double totalRevenue;
|
||||||
double totalCost;
|
double totalCost;
|
||||||
double totalProfit;
|
double totalProfit;
|
||||||
public:
|
|
||||||
ProductSale(std::string line);
|
ProductSale(std::string line);
|
||||||
std::string toString();
|
std::string toString();
|
||||||
};
|
};
|
||||||
|
231
Aufg8/SalesStatMain.cpp
Normal file
231
Aufg8/SalesStatMain.cpp
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "MenuManager.h"
|
||||||
|
#include "ProductSale.h"
|
||||||
|
#include "../Aufg1/forLoop.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 printAllSales(std::vector<ProductSale*> &allSales) {
|
||||||
|
for (int i = 0; i < allSales.size(); ++i) {
|
||||||
|
std::cout << allSales[i]->toString() << std::endl;
|
||||||
|
std::cout << "==============" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteAllPointers(std::vector<ProductSale*> &allSales) {
|
||||||
|
for (auto it = allSales.begin(); it != allSales.end(); it++) {
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getTotalProfitFor(std::string metric, std::vector<ProductSale*> &allSales) {
|
||||||
|
std::map<std::string, long long> TotalPerMetric;
|
||||||
|
|
||||||
|
if (metric == "Region") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->region] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
} else if (metric == "Country") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->country] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
} else if (metric=="Item_Type") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->itemType] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric=="Sales_Channel") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->salesChannel] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Order_Priority") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->orderPriority] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Order_Date") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->orderDate] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Order_ID") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->orderId] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Ship_Date") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->shipDate] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Units_Sold") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->unitsSold);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Unit_Price") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->unitPrice);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric=="Unit_Cost") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->unitCost);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Total_Revenue") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->totalRevenue);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Total_Cost") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->totalCost);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Total_Profit") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->totalProfit);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
std::cout << "Unknown metric :" << metric << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto entry : TotalPerMetric) {
|
||||||
|
std::cout << entry.first << " : " << entry.second << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Filter out wrong countries
|
||||||
|
for (ProductSale* singleSale : allSales) {
|
||||||
|
if (singleSale->country != country) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeCounter[singleSale->itemType]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 getOnlineVsOfflineIn(std::string country, std::vector<ProductSale*> &allSales) {
|
||||||
|
std::map<std::string, int>TypeCounter;
|
||||||
|
|
||||||
|
for (ProductSale* singleSale : allSales) {
|
||||||
|
if (singleSale->country != country) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment the counter for the sales channel directly
|
||||||
|
TypeCounter[singleSale->salesChannel]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int OnlineCounter = TypeCounter["Online"];
|
||||||
|
int OfflineCounter = TypeCounter["Offline"];
|
||||||
|
double ratio = (OfflineCounter == 0) ? 100.0 : static_cast<double>(OnlineCounter) / OfflineCounter * 50.0;
|
||||||
|
|
||||||
|
std::cout << "Online : " << OnlineCounter << std::endl << "Offline : " << OfflineCounter << std::endl;
|
||||||
|
std::cout << "Ratio : " << ratio << "% Online" << std::endl << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Aufg8Main() {
|
||||||
|
std::vector<ProductSale*> allSales;
|
||||||
|
std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv";
|
||||||
|
fileName = "../Aufg8/IO-Files/DANGER-1500000SalesRecords.csv";
|
||||||
|
link : //https://github.com/HopfTorsten/dhbw-cpp-journey/blob/master/day5/DANGER-1500000SalesRecords.csv.zip
|
||||||
|
|
||||||
|
readFile(fileName, allSales);
|
||||||
|
|
||||||
|
// printAllSales(allSales);
|
||||||
|
|
||||||
|
std::string selectedRegion;
|
||||||
|
std::string selectedType;
|
||||||
|
int currentMenu = 0;
|
||||||
|
|
||||||
|
std::string* PselectedRegion = &selectedRegion;
|
||||||
|
std::string* PselectedType = &selectedType;
|
||||||
|
int* PcurrentMenu = ¤tMenu;
|
||||||
|
|
||||||
|
MenuManager menu{PcurrentMenu, PselectedType, PselectedRegion};
|
||||||
|
menu.MainInteraction();
|
||||||
|
while (currentMenu) {
|
||||||
|
switch (currentMenu) {
|
||||||
|
case 0:
|
||||||
|
return; // To quit the programm
|
||||||
|
case 1:
|
||||||
|
getTotalProfitFor(selectedType, allSales);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
getSaleCount(selectedType, selectedRegion, allSales);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
getMostPopularTypeIn(selectedRegion, allSales);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
getOnlineVsOfflineIn(selectedRegion, allSales);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cout << "You should not be able to reach this!";
|
||||||
|
}
|
||||||
|
menu.MainInteraction();
|
||||||
|
}
|
||||||
|
}
|
10
Aufg8/SalesStatMain.h
Normal file
10
Aufg8/SalesStatMain.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//
|
||||||
|
// Created by DH10MBO on 21.11.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SALESSTATMAIN_H
|
||||||
|
#define SALESSTATMAIN_H
|
||||||
|
|
||||||
|
void Aufg8Main();
|
||||||
|
|
||||||
|
#endif //SALESSTATMAIN_H
|
50
Aufg9/DiabloByteReader.cpp
Normal file
50
Aufg9/DiabloByteReader.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
template <typename typ1>
|
||||||
|
typ1 readFromStream(std::ifstream &stream, char *dest) {
|
||||||
|
if (stream.is_open()) {
|
||||||
|
stream.read(dest, sizeof(char[1024]));
|
||||||
|
typ1 *ptr = reinterpret_cast<typ1 *>(dest);
|
||||||
|
return std::move(*ptr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::runtime_error("Could not read from File!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Aufg9Main() {
|
||||||
|
char *dest = new char[1024];
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::string fileName = "../Aufg9/IO-Files/charakter.d2s";
|
||||||
|
std::ifstream stream(fileName);
|
||||||
|
readFromStream<long>(stream, dest);
|
||||||
|
|
||||||
|
// Name
|
||||||
|
char *byte20 = &dest[20];
|
||||||
|
std::cout << "Name: ";
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
// std::cout << byte20[i];
|
||||||
|
std::cout << dest[20 + i];
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
// Status
|
||||||
|
char* byte36 = &dest[36];
|
||||||
|
std::cout << "Status: " << (((int)(*byte36))%8)/4 << std::endl; // geh zu Byte 36, lies genau 1 byte, interpretiere es als int, berechne mod 8 -> wegwerfen der linken Bits, /4 -> wegwerfen der rechten beiden Bits -> Tada, nur das 3. Bit von Rechts bleibt übrig
|
||||||
|
// 0 -> Player is not HardCore?
|
||||||
|
|
||||||
|
// Klasse
|
||||||
|
bool *byte40 = (bool*) &dest[40];
|
||||||
|
std::cout << "Klasse: " << byte40[0] << std::endl;
|
||||||
|
// 2 -> Necromancer
|
||||||
|
|
||||||
|
// Level
|
||||||
|
bool *byte43 = (bool*) &dest[43];
|
||||||
|
std::cout << "Level: " << byte43[0] << std::endl;
|
||||||
|
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
11
Aufg9/DiabloByteReader.h
Normal file
11
Aufg9/DiabloByteReader.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by DH10MBO on 11.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DIABLOBYTEREADER_H
|
||||||
|
#define DIABLOBYTEREADER_H
|
||||||
|
|
||||||
|
void Aufg9Main();
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DIABLOBYTEREADER_H
|
@@ -6,4 +6,7 @@
|
|||||||
- Aufgabe 3 (Telefonbuch mit Speichern in Datei) ☎️
|
- Aufgabe 3 (Telefonbuch mit Speichern in Datei) ☎️
|
||||||
- Aufgabe 4 (Auswertung großer Verbrecher-CSV) 🕵️♂️
|
- Aufgabe 4 (Auswertung großer Verbrecher-CSV) 🕵️♂️
|
||||||
- Aufgabe 5 (Mastermind Code-Guessing-Game) 👺
|
- Aufgabe 5 (Mastermind Code-Guessing-Game) 👺
|
||||||
- Aufgabe 6 (Minesweeper Board Generator) 💣
|
- Aufgabe 6 (Minesweeper Board Generator) 💣
|
||||||
|
- Aufgabe 7 (SEGV. und Signal-Handling) 🤖
|
||||||
|
- Aufgabe 8 (Auswertung riesiger Sales-Datei) 🍇
|
||||||
|
- Aufgabe 9 (Lesen binärer Speicherdatei) 😵💫 (Riesen-Pfusch)🚨
|
Reference in New Issue
Block a user