Seneca OOP244 C++ Workshop Walkthroughs
Workshop 5 - Member Operators, Helper functions
FALL 2024Workshop #5: Member Operators, Helper functions
LAB Execution example
Using bool conversion overload and operator ~ to print the accounts:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 111.11 |
|002| 22222 | 222.22 |
|003| BAD | ACCOUNT |
|004| 44444 | 4444.44 |
|005| 55555 | 555.55 |
|006| BAD | ACCOUNT |
|007| 77777 | 777.77 |
|008| NEW | 0.00 |
|009| NEW | 0.00 |
|010| NEW | 0.00 |
+---+-------+--------------+
Depositing $50.02 into account #1 using += operator:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 161.13 |
+---+-------+--------------+
Withdrawing $100.01 from account #2 using -= operator:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 22222 | 122.21 |
+---+-------+--------------+
Attempting to withdraw too much from account #4 using -= operator:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 44444 | 4444.44 |
+---+-------+--------------+
Attempting to deposit and withdraw negative amounts on account #4:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 44444 | 4444.44 |
+---+-------+--------------+
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 44444 | 4444.44 |
+---+-------+--------------+
Having these two accounts:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 161.13 |
|002| 22222 | 122.21 |
+---+-------+--------------+
Moving funds from first account to second:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 0.00 |
|002| 22222 | 283.34 |
+---+-------+--------------+
Moving funds from second account to first:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 283.34 |
|002| 22222 | 0.00 |
+---+-------+--------------+
Attempting to move funds from an account to itself
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 283.34 |
+---+-------+--------------+
Sum of the balance of accounts 5 and 7
in three different ways: 1333.32, 1333.32, and 1333.32
Setting the account number of account#8 to 88888:
before:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| NEW | 0.00 |
+---+-------+--------------+
After:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 88888 | 0.00 |
+---+-------+--------------+
Moving the Account from Account# 8 to Account #9 using operator=:
Before:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 88888 | 0.00 |
|002| NEW | 0.00 |
+---+-------+--------------+
After:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| NEW | 0.00 |
|002| 88888 | 0.00 |
+---+-------+--------------+
Displaying all accounts:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 11111 | 283.34 |
|002| 22222 | 0.00 |
|003| BAD | ACCOUNT |
|004| 44444 | 4444.44 |
|005| 55555 | 555.55 |
|006| BAD | ACCOUNT |
|007| 77777 | 777.77 |
|008| NEW | 0.00 |
|009| 88888 | 0.00 |
|010| NEW | 0.00 |
+---+-------+--------------+
Attempting to change the account number of the valid account#7:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 77777 | 777.77 |
+---+-------+--------------+
Attempting to set a account that are not new: (7 and 6)
This attempt should not affect either account
Before:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| BAD | ACCOUNT |
|002| 77777 | 777.77 |
+---+-------+--------------+
After:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| BAD | ACCOUNT |
|002| 77777 | 777.77 |
+---+-------+--------------+
Setting a new account (#8) to a valid account(#7)
Before:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| 77777 | 777.77 |
|002| NEW | 0.00 |
+---+-------+--------------+
After:
+---+-------+--------------+
|ROW| ACC# | BALANCE |
+---+-------+--------------+
|001| NEW | 0.00 |
|002| 77777 | 777.77 |
+---+-------+--------------+
Display raw account numbers of all the accounts
using int conversion operator
11111 22222 -1 44444 55555 -1 0 77777 88888 0
Display raw balances of the accounts:
using double conversion operator
283.34 0.00 0.00 4444.44 555.55 0.00 0.00 777.77 0.00 0.00
Total of 2 new accounts
Total of 2 invalid accountsMembers only
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 4 more lessons in Seneca OOP244 C++ Workshop Walkthroughs.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.