Actually return a string in toString

This commit is contained in:
Matti 2024-11-21 22:58:04 +01:00
parent 6bfaa038a7
commit 763bc1c53e

View File

@ -5,7 +5,9 @@
#include "ProductSale.h" #include "ProductSale.h"
#include <algorithm> #include <algorithm>
#include <cmath>
#include <iostream> #include <iostream>
#include <sstream>
#include "../Aufg4/CrimeStats.h" #include "../Aufg4/CrimeStats.h"
@ -15,34 +17,20 @@ ProductSale::ProductSale(std::string line) {
for (int i = 0; i < result.size(); i++) { for (int i = 0; i < result.size(); i++) {
switch (i) { switch (i) {
case 0: std::cout << result[0] << std::endl; case 0: region = result[0]; break;
region = result[0]; break; case 1: country = result[1]; break;
case 1: std::cout << result[1] << std::endl; case 2: itemType = result[2]; break;
country = result[1]; break; case 3: salesChannel = result[3]; break;
case 2: std::cout << result[2] << std::endl; case 4: orderPriority = result[4]; break;
itemType = result[2]; break; case 5: orderDate = result[5]; break;
case 3: std::cout << result[3] << std::endl; case 6: orderId = result[6]; break;
salesChannel = result[3]; break; case 7: shipDate = result[7]; break;
case 4: std::cout << result[4] << std::endl; case 8: unitsSold = round(std::stoi(result[8])*100)/100; break;
orderPriority = result[4]; break; case 9: unitPrice = round(std::stod(result[9])*100)/100; break;
case 5: std::cout << result[5] << std::endl; case 10:unitCost = round(std::stod(result[10])*100)/100; break;
orderDate = result[5]; break; case 11:totalRevenue = round(std::stod(result[11])*100)/100; break;
case 6: std::cout << result[6] << std::endl; case 12:totalCost = round(std::stod(result[12])*100)/100; break;
orderId = result[6]; break; case 13:totalProfit = round(std::stod(result[13])*100)/100; 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: default:
std::cout << "I should not be able to reach, the line probably contains to many items" << std::endl; 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 << line << std::endl;
@ -52,7 +40,9 @@ ProductSale::ProductSale(std::string line) {
} }
std::string ProductSale::toString() { std::string ProductSale::toString() {
std::cout std::ostringstream content;
content
<< "region : " << region << std::endl << "region : " << region << std::endl
<< "country : " << country << std::endl << "country : " << country << std::endl
<< "itemType : " << itemType << std::endl << "itemType : " << itemType << std::endl
@ -66,5 +56,7 @@ std::string ProductSale::toString() {
<< "unitCost : " << unitCost << std::endl << "unitCost : " << unitCost << std::endl
<< "totalRevenue : " << totalRevenue << std::endl << "totalRevenue : " << totalRevenue << std::endl
<< "totalCost : " << totalCost << std::endl << "totalCost : " << totalCost << std::endl
<< "totalProfit : " << totalProfit << std::endl; << "totalProfit : " << totalProfit;
return content.str();
} }