diff options
| author | Fuwn <[email protected]> | 2024-05-31 00:00:12 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-05-31 00:20:41 -0700 |
| commit | 968e1c4af014b7f40bfaa4f57fcc0f38e5e0d847 (patch) | |
| tree | df80525ad0cc9e4b561bfb0772c30ccc5b64b4a2 /include/book_store/price.hh | |
| parent | feat: initial commit (diff) | |
| download | cst_136_assignment_eight-main.tar.xz cst_136_assignment_eight-main.zip | |
Diffstat (limited to 'include/book_store/price.hh')
| -rw-r--r-- | include/book_store/price.hh | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/include/book_store/price.hh b/include/book_store/price.hh index 39f14b8..223b1e9 100644 --- a/include/book_store/price.hh +++ b/include/book_store/price.hh @@ -17,14 +17,16 @@ public: usd(price_type price) : _price(price) {} usd(const std::string &price) : _price(std::stod(price)) {} + [[nodiscard]] auto value() const noexcept -> price_type; + auto operator=(const std::string &value) -> usd & { _price = std::stod(value); return *this; } - friend auto operator<<(std::ostream &output_stream, const usd &price) - -> std::ostream & { + friend auto operator<<(std::ostream &output_stream, + const usd &price) -> std::ostream & { output_stream << price._price; return output_stream; @@ -33,6 +35,18 @@ public: friend auto operator==(const usd &lhs, const usd &rhs) -> bool { return std::abs(lhs._price - rhs._price) < 0.0001; } + + friend auto operator+(const usd &lhs, const usd &rhs) -> usd { + return {lhs._price + rhs._price}; + } + + friend auto operator*(const usd &lhs, const usd &rhs) -> bool { + return std::abs(lhs._price * rhs._price) < 0.0001; + } + + friend auto operator+=(const usd &lhs, const usd &rhs) -> bool { + return std::abs(lhs._price + rhs._price) < 0.0001; + } }; } // namespace book_store::product::price |