diff options
author | Oskar <[email protected]> | 2024-09-17 16:36:14 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-09-17 16:36:14 +0200 |
commit | 46dd78806ebac69c88cb07cecb3afae1835b783a (patch) | |
tree | 69f5c404612d884d4d6ff12304eb650985a71263 /sales_data.hpp | |
parent | d8d8f1c987f118843d44ea27ac516f8fe866ded4 (diff) |
more
Diffstat (limited to 'sales_data.hpp')
-rw-r--r-- | sales_data.hpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/sales_data.hpp b/sales_data.hpp index 31929af..7cb3022 100644 --- a/sales_data.hpp +++ b/sales_data.hpp @@ -3,14 +3,30 @@ #include <string> struct SalesData { std::string isbn() const { return BookNo; } - SalesData &combine(const SalesData); + SalesData &combine(const SalesData&); double avg_price() const; std::string BookNo; unsigned int UnitsSold = 0; double Revenue = 0.0; }; +double SalesData::avg_price() const { + + if (UnitsSold) + return Revenue / UnitsSold; + else + return 0; +} + +SalesData& SalesData::combine(const SalesData &rhs) { + + UnitsSold += rhs.UnitsSold; + Revenue += rhs.Revenue; + return *this; +} + SalesData add(const SalesData&, const SalesData&); std::ostream &print(std::ostream&, const SalesData&); std::istream &read(std::istream&, SalesData&); + #endif |