Welcome to the section 16 challenge.
This challenge is all about polymorphism.
I'm in the section 16 workspace.
And there's going to be a couple of projects here.
First, we've got the challenge project.
This is the base source code that I'm providing for you.
Then we'll break this up into a few parts in several different videos so that we can
take this step by step. So right now we're in the challenge project.
And I'm in the description.txt file which describes this challenge.
So what's the idea. I think you know what you're going to have to do, right.
You've got the solution that we had for
last section's challenge where we have the account class, and it's all working great.
Well, now we need to modify that so that it's polymorphic, so that we're using dynamic
polymorphism, so we can use base class pointers
and get this all working using dynamic polymorphism. It's going to be pretty cool,
but it's going to be some work. So let's see where we're at.
We've got the source code that I provided.
And your challenge is as follows.
Remember, the source code right now has no virtual functions in it.
Therefore, it's all being bound statically.
That's what we want to change. So here's the challenge.
Part one of the challenges modify the account class
so that it's now abstract. How do you do that,
pure virtual functions. We want two of them, and they're right here. I'm giving them to you right there.
Deposit and withdraw will now be pure virtual functions.
Remember, we can implement these in the account class if it makes sense.
In this class, it does make sense. So you may want to consider implementing
a simple deposit and a simple withdrawal in the account class.
Even if you implement these in the account class, the account class
will still be abstract because it's got those pure virtual functions in it.
That's going to take some work because you've got to revamp your class hierarchies,
you've got to think about what you're doing.
Remember, once you put virtual functions in there,
like we are here,
don't forget about the virtual destructor. So there's a lot of little things that you'll have to do along the way,
great.
Now part two.
Create the i printable class interface, similar to what we did in the class.
The idea is that all accounts are going to be printable.
So I've given you the class right here.
I haven't implemented this guy. You guys can do that. And obviously,
the account class can be derived from i printable,
so now it's printable. And all those concrete account objects
can implement that guy right there, and they should be printable, which is pretty cool.
One little hint here, you'll notice this destructor right here.
Obviously, we need virtual destructors. We can use equal default.
Tells the compiler just generate a simple destructor for me.
So this is really the same as you writing that kind of code,
but you don't have to do it at all, just say equal default let the compiler do it for you.
Then the last part of the challenge
is to modify the functions in that account.util file that I gave you.
Remember that one had a display deposit and a withdrawal for,
an account then it had a display in the deposit a withdrawal for a checking account
and it just had a lot of code in there.
What we want is we just want one version of each. So we want
one display function,
one deposit function, one withdraw function,
that will work with any kind of account. And you'll notice what's going on here.
There's our base class pointer, that's why this is going to work.
So in this case when we create these vectors in our main,
we're going to create a vector of base class pointers.
And that's what we're going to pass into these functions here.
Finally, test your code both with base class pointers
as well as local objects. I've given you a main driver that gets you started.
But I'd suggest that you just take it one step at a time, it's really the best way to do it.
What I would suggest that you do for the very first thing is
take that account class and make it abstract.
Add those pure virtual functions to it and start from there,
and then work your way down the class hierarchy
and see what you have to override, what you don't have to override and so forth.
That's it. Have fun.
This is a very very challenging exercise. There's a lot going on here.
So again, take it one step at a time. Don't think that you'll be able to do this in 15 minutes.
This will take some time and some thought
because there's a lot going on, a lot of little pieces to this.
All right. So give it a shot. I'm sure you can do it.
Take your time. Think about everything you learned in the class,
and put it all together in this challenge.
I'll see you in the next video where we'll do part one of the solution,
part one is taking that account class and making it abstract.