summaryrefslogtreecommitdiff
path: root/sales_data.hpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-18 16:12:27 +0200
committerOskar <[email protected]>2024-09-18 16:12:27 +0200
commita10a6e35975660b89b465faf5baacd6df9c43a34 (patch)
tree7338cdde8a865904118be77dba5d6db949785680 /sales_data.hpp
parent46dd78806ebac69c88cb07cecb3afae1835b783a (diff)
more, 7.15 not started yet
Diffstat (limited to 'sales_data.hpp')
-rw-r--r--sales_data.hpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/sales_data.hpp b/sales_data.hpp
index 7cb3022..0820cd5 100644
--- a/sales_data.hpp
+++ b/sales_data.hpp
@@ -1,7 +1,16 @@
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <string>
+struct SalesData;
+SalesData add(const SalesData&, const SalesData&);
+std::ostream &print(std::ostream&, const SalesData&);
+std::istream &read(std::istream&, SalesData&);
struct SalesData {
+ SalesData() = default;
+ SalesData(const std::string &s): BookNo(s) { }
+ SalesData(const std::string &s, unsigned n, double p):
+ BookNo(s), UnitsSold(n), Revenue(p*n) { }
+ SalesData(std::istream &sdcin) { read(sdcin, *this); };
std::string isbn() const { return BookNo; }
SalesData &combine(const SalesData&);
double avg_price() const;
@@ -25,8 +34,26 @@ SalesData& SalesData::combine(const SalesData &rhs) {
return *this;
}
-SalesData add(const SalesData&, const SalesData&);
-std::ostream &print(std::ostream&, const SalesData&);
-std::istream &read(std::istream&, SalesData&);
+std::istream &read(std::istream &is, SalesData &item) {
+
+ double price = 0;
+ is >> item.BookNo >> item.UnitsSold >> price;
+ item.Revenue = price * item.UnitsSold;
+ return is;
+}
+
+std::ostream &print(std::ostream &os, const SalesData &item) {
+
+ os << item.isbn() << " " << item.UnitsSold << " "
+ << item.Revenue << " " << item.avg_price();
+ return os;
+}
+
+SalesData add(const SalesData sd1, const SalesData sd2) {
+
+ SalesData sdsum = sd1;
+ sdsum.combine(sd2);
+ return sdsum;
+}
#endif