#include #include #include "cart.h" #include "product.h" Shopping_Cart::Shopping_Cart() : reg{} {} void Shopping_Cart::add_product(Product const& product, int count) { reg.push_back({count, product}); } std::string Shopping_Cart::to_string() const { std::ostringstream oss{}; for ( Pair const& p : reg ) { oss << p.count << "st " << p.product << std::endl; } oss << "Total: " << total() << std::endl; return oss.str(); } double Shopping_Cart::total() const { double tot{0.0}; for ( Pair const& p : reg ) { tot += p.product.get_price() * p.count; } return tot; } std::ostream& operator<<(std::ostream& os, Shopping_Cart const& rhs) { return os << rhs.to_string(); }