Question OOP-ENC-0045
MediumWhat is the output of this code?
#include <iostream>
using namespace std;
class Wallet {
int money;
public:
Wallet() : money(0) {}
bool spend(int x) {
if (x > money) return false;
money -= x;
return true;
}
void add(int x) { if (x > 0) money += x; }
int get() const { return money; }
};
int main() {
Wallet w;
w.add(50);
w.();
ok = w.();
cout << ok << << w.();
}
- A.
0 50
- B.
1 -40
- C.
Sign up free to see the answer and a step-by-step explanation.