We have learned about the fundamental data type in the previous sections of our course.
And this data type is used in defining or initializing a variable to ensure that a variable can store
the selected data type.
However, there are other data types that can be used to define a variable and they are enum, which
is enumeration and struct.
So enumeration is a data type that has several possible values and they are defined as the constant,
which is called the enumerators.
So it is used to create a collection of constants.
So let's actually make an example.
So suppose we want to develop a card game, the card game using.
Which actually the this card game as you know, the deck of playing cards contains 52 cards.
52 cards and.
Oops, let me fix this.
So 52 cards.
The deck of playing contains the 52 cards, which consists of four suits.
The first is Clubs C.
Then we have the diamonds.
The.
Then we have hordes.
Age.
And then we have the spades, which is s so, so we have 13 elements in each suite here.
13 element.
13 cards in each suite.
13 and 13 here.
So we can notate the card in the C plus plus class here as follows here.
Firstly, we're going to create an enum here.
This enum type is going to be card suites.
So as we discussed earlier, we have four card suites, so Club Diamond Heart.
And spade.
Here.
And we also need to create the card elements, which, as we talked about earlier, we have 13 card
elements in each of these suits.
So enum card elements and we here we have ace two, three, four, five, six, seven, eight, nine,
ten.
The jack.
Queen and king.
So if we apply to all the preceding the enum data types, we can create a following initial variable
installation here.
So card.
So we're going to create a new card suits here.
Oops.
And here we're going to cart sweets.
Sweet here.
And it's going to be in this case, it's going to be let's actually make it spayed and we will create
a cart element, choose the cart element.
And this element is going to be the.
Kinkier.
So we have the spade king here.
Actually, let's make this.
However, in this case, we don't have any relations between these cards.
In this cartoons, we choose the suit as a spade.
And in card elements, we choose the element as king.
So actually it always contains integer constant.
So the string we put in the element is the constant name only.
So the first element holds the value zero.
So let's fix that again.
Also for the first element holds our value zero.
And here one, two, two and three.
So here the Diamond Club is zero.
Diamond one, fourth is for two and spades three.
And the same applies here.
The ace.
One, two, three.
Who'd.
Three, four, five, six, seven.
Eight.
Nine.
Ten.
And 11 and 1212 signs.
We have 13 here.
This starts with zero signs.
We now have.
The 13th element in our logic is in programming and in logic is the 12 elements.
So now here.
Now let's create a program that will generate a random card and we can borrow the.
Uh, generate random number function now.
But so actually, you can.
You can also assign a specific value to here elements, but we will discuss about that in next lectures.
So now we're going to create here.
The new function named the Get with String.
But first we need to include our.
Libraries.
So now include the stream.
Your stream here include.
Include the stdlib here include and include the C time C time here.
So now.
We will develop our.
Function here.
So now String is going to return the string.
Type here and get sweet.
String here.
And card.
Card sweets and it's going to be a suite here.
And let's make this here.
So as you can see, we got an error here.
Change?
Yeah.
We also need to use the namespace STD.
Unless we don't want to write the STD at every declaration like this.
So we will use a namespace.
So you learned about the namespace in previous lectures.
So using namespace std.
And here, let's actually close this for now.
Here.
Now Cod.
Sweet, sweet here.
And now we're going to create a new string.
String s.
And switch.
Sudhir.
And in this case, we're going to use the switch and case condition here and here case.
In this case, is the club then s.
As equals of.
Not like this.
Yeah.
Case club as equals club here.
And this in case it's.
And after that, of course, we're going to break it.
Case Diamond.
We're going to make.
This is here, Diamond.
Here and break is hurt.
As 30 year.
As heard here.
Break again.
And lastly case spade.
Spade.
Yeah.
Case Spade.
Here and here equals spade.
And then break again.
And after that?
After this, the switch case statement completes.
We will return our string return s, And in this case, as you can see here, this returns here and
we will use get used with string here.
So now we also need to get so here this was the get switch string which relates the card suits gave
here like this card suits and now we need to write our card elements function.
So now we're going to go down after the card suits.
We're going to create the card elements function.
So now the string.
Get element string here.
And here, let me fix this.
Yeah.
Get element, string.
Card elements and element.
So now we're going to write it like this again.
We're going to create a new string.
String E here, and then we're going to switch case statement, create here.
Now switch.
It's going to be element.
And now we will write our code like this case ace the equals ace here and then break.
Face to.
Actually, we can also copy this.
One, two.
So it's an easy way.
One, two, three, four, five, six, seven, eight, nine, ten, 11.
No such thing here.
So the first is Ace.
Now we have the two also change to and then we have three.
That's what we have three here.
Then we have four.
For us.
We have four here.
Then we have five.
Also, we have five here.
Then we have six.
Also, we have six here.
Then we have seven.
Also, we have seven here.
Then we have eight.
Also, we have eight here.
Nine?
Also, we have nine here.
Since we don't have ten here.
Yeah.
Yeah, we have ten.
Now an.
We would also have ten here.
So now we comes Jack, Queen and King.
Jack.
Queen.
And King.
Lastly.
King.
Oops.
Kink here.
So now we're going to generate a random number here.
So here now we're going to create a new function after that and name it.
So this is random number generator will use the will return the integer number here, generate random
numbers, generate random number.
And this is going to be integer a minimum here, integer minimum here and integer maximum.
Let me check the lecture time.
Here.
So now.
We're going to create the here and now.
We're going to.
So we will use static, constant double because of the efficiency.
And so we will only calculate this value once.
So here we're going to create a static constant that and this will also be a double the fraction is
going to be double fraction is going to be 1.0.
Divide by static cast, and it's going to be the double here.
And this novel is going to be around Max and.
After that, we're going to plus.
1.0.
Here.
Now, after that, we will need to evenly distribute the random number across our range.
So we will return return mean plus static cast integer.
And here.
The max minus one plus one multiply by.
Oops.
Um.
Yeah.
Here.
We need to also add this.
And here.
Multiply by.
The rant and we will multiply rant by our fraction.
Here.
So now we have completed our application and in the next lecture we will write the main function here.
So I'm waiting you in next lecture.
See you.