S3_Cpp/Aufg8/ProductSale.cpp

71 lines
2.9 KiB
C++

//
// Created by DH10MBO on 21.11.2024.
//
#include "ProductSale.h"
#include <algorithm>
#include <iostream>
#include "../Aufg4/CrimeStats.h"
ProductSale::ProductSale(std::string line) {
std::vector<std::string> result;
split(line, ',', result);
for (int i = 0; i < result.size(); i++) {
switch (i) {
case 0: std::cout << result[0] << std::endl;
region = result[0]; break;
case 1: std::cout << result[1] << std::endl;
country = result[1]; break;
case 2: std::cout << result[2] << std::endl;
itemType = result[2]; break;
case 3: std::cout << result[3] << std::endl;
salesChannel = result[3]; break;
case 4: std::cout << result[4] << std::endl;
orderPriority = result[4]; break;
case 5: std::cout << result[5] << std::endl;
orderDate = result[5]; break;
case 6: std::cout << result[6] << std::endl;
orderId = result[6]; break;
case 7: std::cout << result[7] << std::endl;
shipDate = result[7]; break;
case 8: std::cout << result[8] << std::endl;
unitsSold = std::stoi(result[8]); break;
case 9: std::cout << result[9] << std::endl;
unitPrice = std::stod(result[9]); break;
case 10: std::cout << result[10] << std::endl;
unitCost = std::stod(result[10]); break;
case 11: std::cout << result[11] << std::endl;
totalRevenue = std::stod(result[11]); break;
case 12: std::cout << result[12] << std::endl;
totalCost = std::stod(result[12]); break;
case 13: std::cout << result[13] << std::endl;
totalProfit = std::stod(result[13]); 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;
}
}
}
std::string ProductSale::toString() {
std::cout
<< "region : " << region << std::endl
<< "country : " << country << std::endl
<< "itemType : " << itemType << std::endl
<< "salesChannel : " << salesChannel << std::endl
<< "orderPriority : " << orderPriority << std::endl
<< "orderDate : " << orderDate << std::endl
<< "orderId : " << orderId << std::endl
<< "shipDate : " << shipDate << std::endl
<< "unitsSold : " << unitsSold << std::endl
<< "unitPrice : " << unitPrice << std::endl
<< "unitCost : " << unitCost << std::endl
<< "totalRevenue : " << totalRevenue << std::endl
<< "totalCost : " << totalCost << std::endl
<< "totalProfit : " << totalProfit << std::endl;
}