-
Notifications
You must be signed in to change notification settings - Fork 14
/
Sales_data.h
62 lines (46 loc) · 1.59 KB
/
Sales_data.h
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <iostream>
#include<string>
#include<unordered_set>
struct Sales_data;
Sales_data operator+(const Sales_data & sa, const Sales_data & sb);
std::istream & operator>>(std::istream & is, Sales_data & sa);
std::ostream & operator<<(std::ostream & os, const Sales_data & sa);
bool operator==(const Sales_data &lhs, const Sales_data &rhs);
bool operator!=(const Sales_data &lhs, const Sales_data &rhs);
template <typename T> class std::hash;
class Sales_data
{
friend class std::hash<Sales_data>;
friend Sales_data operator+(const Sales_data & sa, const Sales_data & sb);
friend std::istream & operator>>(std::istream & is, Sales_data & sa);
friend std::ostream & operator<<(std::ostream & os, const Sales_data & sa);
friend bool operator==(const Sales_data &lhs, const Sales_data &rhs);
public:
Sales_data() = default;
Sales_data(const std::string &s) : ISBN(s) { }
Sales_data(const std::string &s, int a, double t) : ISBN(s), amount(a), totalPrice(t * a) { }
Sales_data(std::istream &is) { is >> *this; }
std::string isbn() const { return ISBN; }
Sales_data & operator+=(const Sales_data & sa);
Sales_data & operator=(const std::string & s);
explicit operator double() const { return totalPrice; }
explicit operator std::string() const { return isbn(); }
private:
std::string ISBN;
double totalPrice = 0.0;
int amount = 0;
inline double avg_price() const;
};
namespace std
{
template<>
struct hash<Sales_data>
{
typedef size_t result_type;
typedef Sales_data argument_type;
size_t operator()(const Sales_data & s) const;
};
}
#endif