blob: 7cb3022194b1252221307f5842eb8ca2595495f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <string>
struct SalesData {
std::string isbn() const { return BookNo; }
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
|