From 641795f36f417b5a61ad1410f2d20357c039aa98 Mon Sep 17 00:00:00 2001 From: Matti Date: Thu, 21 Nov 2024 22:04:40 +0100 Subject: [PATCH] Add SalesStats --- Aufg8/ProductSale.cpp | 37 +++++++++++++++++++++++++++++++++++++ Aufg8/ProductSale.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 Aufg8/ProductSale.cpp create mode 100644 Aufg8/ProductSale.h diff --git a/Aufg8/ProductSale.cpp b/Aufg8/ProductSale.cpp new file mode 100644 index 0000000..50ea846 --- /dev/null +++ b/Aufg8/ProductSale.cpp @@ -0,0 +1,37 @@ +// +// Created by DH10MBO on 21.11.2024. +// + +#include "ProductSale.h" + +#include +#include + +#include "../Aufg4/CrimeStats.h" + +ProductSale::ProductSale(std::string line) { + std::vector result; + split(line, ',', result); + + for (int i = 0; i < result.size(); i++) { + switch (i) { + case 0: region = result[0]; break; + case 1: country = result[1]; break; + case 2: itemType = result[2]; break; + case 3: salesChannel = result[3]; break; + case 4: orderPriority = result[4]; break; + case 5: orderDate = result[5]; break; + case 6: shipDate = result[6]; break; + case 7: unitsSold = std::stoi(result[7]); break; + case 8: unitPrice = std::stod(result[8]); break; + case 9: unitCost = std::stod(result[9]); break; + case 10: totalRevenue = std::stod(result[10]); break; + case 11: totalCost = std::stod(result[11]); break; + case 12: totalProfit = std::stod(result[12]); break; + default: + std::cout << "I should not be able to reach, the line probably contains to many items" << std::endl; + std::cout << line << std::endl; + std::cout << "=========================" << std::endl << result[i] << std::endl; + } + } +} diff --git a/Aufg8/ProductSale.h b/Aufg8/ProductSale.h new file mode 100644 index 0000000..fe9c3dd --- /dev/null +++ b/Aufg8/ProductSale.h @@ -0,0 +1,32 @@ +// +// Created by DH10MBO on 21.11.2024. +// + +#ifndef PRODUCTSALE_H +#define PRODUCTSALE_H +#include + + +class ProductSale { +private: + std::string region; + std::string country; + std::string itemType; + std::string salesChannel; + std::string orderPriority; + std::string orderDate; + std::string orderId; + std::string shipDate; + int unitsSold; + double unitPrice; + double unitCost; + double totalRevenue; + double totalCost; + double totalProfit; +public: + ProductSale(std::string line); +}; + + + +#endif //PRODUCTSALE_H