โ 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
Topics:
ClassesOperator Overloading
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.