(upbeat music)
- [Instructor] For our final project,
you're writing a deck of cards class,
here's a brief demonstration of how my solution works,
I wrote my solution without the use of the STL.
My reason for avoiding the STL is because
I may want to use this in a mobile application
and while the STL may be available on some mobile platforms,
it's not an efficient use of resources
for something like this.
You're welcome to use the STL if you prefer,
but it's really not necessary for this exercise.
Here is a simple function for dealing a hand of cards.
And I pass it a deck,
and I tell it, how many cards I am dealing,
and I simply have a loop for that many number of cards,
and I deal a card from the deck using the dealCard method,
and I display the card using card str,
which returns a C string of the card representation,
the two digit representation of the card.
And I call this from within a try block in main,
and I simply deal nine,
I'll deal five, 13, 10 I'm just dealing
different numbers of cards and displaying them.
I start out by saying,
here's how many cards are remaining in the deck,
it's a brand new deck, and so there should be 52 cards.
And then after there'll be 52 minus this many.
And that's really the whole thing,
so when I build and run,
you'll notice that here we have the nine cards, five cards,
13 cards, 10 cards, and that leaves 15 cards remaining.
If we look over here in the sidebar,
we see I have an exception class,
I have the deck of cards class and the header for it,
which I've included up here.
And you notice this is in a try block
and that's because I'm using exceptions
for my error messages.
If I take this and I have 15 cards remaining,
and if I try to deal 20 cards,
you'll notice that I get an error message
I'm going to build and run
and it says, deck: cannot deal from empty deck,
it tried to deal more cards than it had.
I can change the number of decks when I construct my object,
I can give it an argument and say I want five decks,
and now when I build and run,
we don't start with 52 cards anymore.
Now we start with 260 cards.
And we have 223 cards remaining when I'm done.
And here we are in Windows and Microsoft Visual Studio,
and you'll notice I have the same four files loaded
I've got my deal cards,
which has my main deck deck.h, exception.h,
and I can build and run here.
So here's the build.
And you see it generates code
and I can come over here to my PowerShell
and I can run it and you see we get exactly the same result.
In the next movie,
we'll go over the details of my solution to this challenge.