Hello, everyone. Welcome to the section 15 challenge, that's the inheritance challenge.
This is a very challenging challenge.
You're no longer beginning c++ programmers, that's for sure.
This challenge involves extending a class hierarchy by adding a
few more classes, and I'll talk about them in just a second.
And it also involves understanding someone else's code, which is
something that happens in real life or actually more often than not
you're modifying someone else's code.
We don't write our own code from scratch very often out there.
So this is part of the challenge.
Before you attempt this challenge, watch the video previous to this
video where I go over the classes that are in this project. I go
over the account class and the savings account classes in detail.
If you haven't done that, I encourage you to do so now and then come
back and give the challenge a shot.
So let me go over the challenge and tell you what's involved.
First of all, I'm in the section 15 workspace in the challenge project.
This is your starting point.
This has an account class and a savings account class that's
derived from the account class.
Everything's working.
The tests are there.
The utility functions are there and so forth.
So you're provided with these two classes, as I mentioned here.
You're provided with the account class and the savings account class.
The savings account class is an account so we're
using public inheritance.
So in this case, we have an account that has a name and a balance.
And then the savings account is an account and it adds an interest rate.
And as I mentioned, watch the previous video and you'll get a
good understanding of exactly how the deposit method works and the
withdrawal methods work and so forth.
Also I created some account helper functions in the account util
header and cpp files that make it easy to display deposit to and
withdraw funds from a vector of accounts and savings accounts.
And that's what I'm using in the main driver,
just to make it a little easier.
Otherwise, your main gets really, really convoluted and you're
always checking for was this a successful deposit or was this a
successful withdrawal, and the code just gets really nasty to follow.
So what's this challenge about.
Let me just scroll up just a little bit and -- so this
challenge is we're going to add two classes to this hierarchy.
The first class you see right here it's a checking account class.
And we want to add that to the inheritance hierarchy.
So we want this to be a derived class of either account or
savings account, you decide.
A checking account has a name and a balance and it has a fee of
1.50 per withdrawal transaction.
So every time we do a withdrawal, we're going to assess 1.50 flat fee.
The trust account is the other account I want you to add to the hierarchy.
And again, you decide whether it belongs under account or under
savings aha or under checking account and for that matter is the checking
account under a trust account.
So you figure out what the hierarchy is.
It's pretty straightforward I think once you sit down and think about it.
So a trust account has a name a balance and an interest rate.
But the trust account deposit works just like the savings account deposit
except when we've got deposits that are 5000 dollars or more, we'll get
a fifty dollar bonus by the bank.
The trust account withdrawal is also different.
It only allows three withdrawals per year, and each of these must be less
than 20% of the account balance.
You don't have to keep track of calendar time, as I mentioned here.
So just make it fail on the fourth attempt to withdraw. Sorry, I'll
change that, that should be withdraw.
I'll fix that in the spec.
Okay, so the fourth withdrawal will fail.
So what are some hints.
Well, reuse existing functionality.
That's the whole idea behind inheritance, right.
It's all about reusability.
So don't reinvent the wheel.
Don't duplicate code.
Reuse as much as you can.
Think about what the base class will be for each of these new
classes that we're going to add.
Also I've created those helper functions in the account util file.
You may want to add the trust account and checking account versions to them.
I would recommend that you do that, that just makes it much easier
to use these things in the main.
But you don't have to, you can just test these in
the main, it's up to you.
As always, have fun.
You're no longer beginner c++ programmers, that's for sure.
Once we delve into the world of inheritance, this is no
longer beginning c++, this is more intermediate c++.
So congratulations that you've made it this far in the course.
And the last thing is if you want more practice with operator
overloading, you can overload the plus equal and the minus equal
so that they do deposit and withdrawal, which can be handy.
Okay, so that's it.
I'll be back in the next video with my solution, but give this a shot.
And as I said don't get frustrated with this.
This is not an easy challenge.
There's a lot going on here.
And just take it one step at a time, do one class at a time, implement one
method at a time and test as you go.
And before you know it, you've got a great solution.
All right, so good luck, and I'll see you in the next video.