← Back to Classes
Question 87
Wallet Deposit/Withdraw (operator+= and operator-=)
Wallet Deposit/Withdraw (operator+= and operator-=)
You are implementing deposits and withdrawals for a wallet balance.
Create a class Wallet that stores the balance using TWO ints: dollars and cents.
- cents should always be 0..99 (normalize after operations).
Requirements:
1) Constructor Wallet(int dollars, int cents)
2) int getCents() const (return TOTAL cents)
3) operator+=(int cents) deposits that many cents
4) operator-=(int cents) withdraws that many cents
Do NOT write a main function.Expected Output:
150 30
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
ClassesOperator Overloading
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.