remove article from sale
This commit is contained in:
parent
2fb72f1701
commit
91357d7c7f
3 changed files with 24 additions and 1 deletions
|
@ -8,9 +8,19 @@ void Sale::addArticle(std::shared_ptr<Article> articlePtr)
|
|||
articles_.push_back(articlePtr);
|
||||
}
|
||||
|
||||
void Sale::removeArticle(const Article* articlePtr)
|
||||
{
|
||||
auto it = std::find_if(articles_.begin(), articles_.end(),
|
||||
[&articlePtr](auto art) { return art.get() == articlePtr; });
|
||||
if (it != articles_.end()) {
|
||||
(*it)->setSale(nullptr);
|
||||
articles_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
int Sale::sumInCents()
|
||||
{
|
||||
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
|
||||
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
|
||||
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
|
||||
return sum;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue