show last sum
This commit is contained in:
parent
527241a0f3
commit
3efa289b5b
4 changed files with 48 additions and 47 deletions
|
@ -2,6 +2,9 @@
|
|||
#include "database.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
Marketplace::Marketplace()
|
||||
{
|
||||
|
@ -99,4 +102,20 @@ void Marketplace::finishCurrentSale()
|
|||
storeToDb();
|
||||
}
|
||||
|
||||
BasketVec& Marketplace::getBasket() { return basket_; }
|
||||
BasketVec& Marketplace::getBasket() { return basket_; }
|
||||
|
||||
int Marketplace::getBasketSumInCent()
|
||||
{
|
||||
int sum = std::accumulate(basket_.begin(), basket_.end(), 0,
|
||||
[](int a, const auto& b) { return a + b->getPrice(); });
|
||||
return sum;
|
||||
}
|
||||
|
||||
std::string Marketplace::getBasketSumAsString()
|
||||
{
|
||||
int sumInCent = getBasketSumInCent();
|
||||
double sumInEuro = sumInCent / 100.0L;
|
||||
std::stringstream sumStream;
|
||||
sumStream << std::fixed << std::setprecision(2) << sumInEuro << " €";
|
||||
return sumStream.str();
|
||||
}
|
|
@ -30,6 +30,8 @@ class Marketplace
|
|||
int getNextArticleNo();
|
||||
int getNumSellersDelete();
|
||||
BasketVec& getBasket();
|
||||
int getBasketSumInCent();
|
||||
std::string getBasketSumAsString();
|
||||
|
||||
void sortSellers();
|
||||
Seller* findSellerWithSellerNo(int sellerNo);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue