diff --git a/CM2005 Object Oriented Programming/Topic 5/5.1.7/Wallet.cpp b/CM2005 Object Oriented Programming/Topic 5/5.1.7/Wallet.cpp index a0b5794..c0c2ce1 100644 --- a/CM2005 Object Oriented Programming/Topic 5/5.1.7/Wallet.cpp +++ b/CM2005 Object Oriented Programming/Topic 5/5.1.7/Wallet.cpp @@ -7,12 +7,31 @@ Wallet::Wallet() void Wallet::insertCurrency(std::string type, double amount) { - + double balance; + if(amount < 0) + { + throw std::exception{}; + } + if(currencies.count(type) == 0) // not in wallet yet + { + balance = 0; + } + else + { + balance = currencies[type]; + } + balance += amount; + currencies[type] = balance; } bool Wallet::containsCurrency(std::string type, double amount) { - return false; + if(currencies.count(type) == 0) // not in wallet yet + { + return false; + } + else + return currencies[type] >= amount; } std::string Wallet::toString() diff --git a/CM2005 Object Oriented Programming/Topic 5/5.1.7/a.exe b/CM2005 Object Oriented Programming/Topic 5/5.1.7/a.exe index cbd2145..606c3ec 100644 Binary files a/CM2005 Object Oriented Programming/Topic 5/5.1.7/a.exe and b/CM2005 Object Oriented Programming/Topic 5/5.1.7/a.exe differ