22
33#include < stdexcept>
44
5- Alcohol::Alcohol (const std::string& name, size_t amount, size_t basePrice, size_t percentage)
6- : Cargo(name, amount, basePrice)
7- , percentage_(percentage)
8- {}
5+ Alcohol::Alcohol (const std::string& name, size_t amount, size_t basePrice, size_t percentage)
6+ : Cargo(name, amount, basePrice), percentage_(percentage) {}
97
108Cargo& Alcohol::operator +=(size_t amount) {
119 if (amount_ + amount > MAX_AMOUNT_OF_CARGO) {
@@ -20,9 +18,13 @@ Cargo& Alcohol::operator-=(size_t amount) {
2018 return *this ;
2119}
2220
23- bool Alcohol::operator ==(const Cargo& alcohol) const {
24- // TODO:
25- return alcohol.getAmount () == amount_ ? true : false ;
21+ bool Alcohol::operator ==(const Cargo& cargo) const {
22+ if (typeid (cargo) == typeid (Alcohol)) {
23+ const Alcohol* alcohol = static_cast <const Alcohol*>(&cargo);
24+ return name_ == alcohol->getName () && basePrice_ == alcohol->getBasePrice () &&
25+ percentage_ == alcohol->getPercentage ();
26+ }
27+ return false ;
2628}
2729
2830size_t Alcohol::getPrice () const {
@@ -33,7 +35,6 @@ size_t Alcohol::getPrice() const {
3335void Alcohol::nextDay () {
3436}
3537
36-
3738size_t Alcohol::getPercentage () const {
3839 return percentage_;
3940}
0 commit comments