From the course: Object-Oriented Programming with C++
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Solution: Bank account with audit system - C++ Tutorial
From the course: Object-Oriented Programming with C++
Solution: Bank account with audit system
(bright music) - [Instructor] It wasn't that hard was it? Just in case, here's my solution. First, let's inspect the bank account classes display balance method. This is a const method, yet we're trying to increment the value of transaction count. Remember the const keyword promises this method won't change the object state. The member function doesn't modify the member variables except for one, it needs to track access count, which leads us to the first issue. Now, updating the transaction count does not affect the account's essential state. It's just bookkeeping. This is exactly what the mutable keyword is for. Let's switch to the classes declaration and mark the transaction count member variable as mutable. Now it can be modified in any const method. First problem solved. Next, we have the auditor class that verifies multiple aspects of the account. It needs to check the account number format, the current balance and the transaction count. The bank account class could provide the…
Contents
-
-
-
-
Why should we hide information?1m 44s
-
(Locked)
Doorways to data: Getters and setters7m
-
(Locked)
Applying the DRY principle6m 56s
-
(Locked)
Challenging const correctness3m 3s
-
(Locked)
Friends3m 9s
-
(Locked)
Challenge: Bank account with audit system1m 33s
-
(Locked)
Solution: Bank account with audit system2m 33s
-
-
-
-
-