summaryrefslogtreecommitdiff
path: root/sales_data.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'sales_data.hpp')
-rw-r--r--sales_data.hpp18
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