WEBVTT

00:00.770 --> 00:05.960
We have learned about the fundamental data type in the previous sections of our course.

00:05.960 --> 00:12.260
And this data type is used in defining or initializing a variable to ensure that a variable can store

00:12.260 --> 00:13.530
the selected data type.

00:13.550 --> 00:20.030
However, there are other data types that can be used to define a variable and they are enum, which

00:20.030 --> 00:22.580
is enumeration and struct.

00:22.590 --> 00:31.610
So enumeration is a data type that has several possible values and they are defined as the constant,

00:31.610 --> 00:35.090
which is called the enumerators.

00:35.090 --> 00:37.550
So it is used to create a collection of constants.

00:37.550 --> 00:39.680
So let's actually make an example.

00:39.950 --> 00:46.580
So suppose we want to develop a card game, the card game using.

00:48.230 --> 00:57.890
Which actually the this card game as you know, the deck of playing cards contains 52 cards.

00:58.980 --> 01:02.400
52 cards and.

01:04.080 --> 01:06.240
Oops, let me fix this.

01:08.490 --> 01:11.050
So 52 cards.

01:11.050 --> 01:17.260
The deck of playing contains the 52 cards, which consists of four suits.

01:17.280 --> 01:21.330
The first is Clubs C.

01:21.930 --> 01:25.560
Then we have the diamonds.

01:25.590 --> 01:26.520
The.

01:27.330 --> 01:29.160
Then we have hordes.

01:30.280 --> 01:31.030
Age.

01:31.990 --> 01:42.940
And then we have the spades, which is s so, so we have 13 elements in each suite here.

01:42.970 --> 01:44.560
13 element.

01:44.590 --> 01:47.770
13 cards in each suite.

01:48.400 --> 01:52.300
13 and 13 here.

01:52.510 --> 01:59.370
So we can notate the card in the C plus plus class here as follows here.

01:59.380 --> 02:01.750
Firstly, we're going to create an enum here.

02:01.780 --> 02:04.780
This enum type is going to be card suites.

02:04.780 --> 02:13.120
So as we discussed earlier, we have four card suites, so Club Diamond Heart.

02:15.970 --> 02:17.350
And spade.

02:19.040 --> 02:19.670
Here.

02:19.670 --> 02:27.590
And we also need to create the card elements, which, as we talked about earlier, we have 13 card

02:27.590 --> 02:30.260
elements in each of these suits.

02:30.260 --> 02:45.170
So enum card elements and we here we have ace two, three, four, five, six, seven, eight, nine,

02:46.160 --> 02:46.970
ten.

02:48.230 --> 02:49.340
The jack.

02:50.170 --> 02:52.660
Queen and king.

02:52.840 --> 03:01.600
So if we apply to all the preceding the enum data types, we can create a following initial variable

03:01.600 --> 03:02.650
installation here.

03:02.650 --> 03:03.400
So card.

03:03.730 --> 03:06.100
So we're going to create a new card suits here.

03:06.130 --> 03:06.640
Oops.

03:08.530 --> 03:10.850
And here we're going to cart sweets.

03:10.910 --> 03:12.040
Sweet here.

03:12.040 --> 03:18.010
And it's going to be in this case, it's going to be let's actually make it spayed and we will create

03:18.010 --> 03:20.080
a cart element, choose the cart element.

03:20.080 --> 03:23.710
And this element is going to be the.

03:24.650 --> 03:25.210
Kinkier.

03:25.250 --> 03:30.430
So we have the spade king here.

03:30.440 --> 03:31.670
Actually, let's make this.

03:33.150 --> 03:36.540
However, in this case, we don't have any relations between these cards.

03:37.110 --> 03:40.080
In this cartoons, we choose the suit as a spade.

03:40.080 --> 03:44.200
And in card elements, we choose the element as king.

03:44.220 --> 03:47.460
So actually it always contains integer constant.

03:47.460 --> 03:52.380
So the string we put in the element is the constant name only.

03:52.380 --> 03:56.460
So the first element holds the value zero.

03:56.820 --> 03:58.470
So let's fix that again.

03:58.740 --> 04:01.770
Also for the first element holds our value zero.

04:02.130 --> 04:09.640
And here one, two, two and three.

04:09.660 --> 04:12.240
So here the Diamond Club is zero.

04:12.240 --> 04:17.600
Diamond one, fourth is for two and spades three.

04:17.610 --> 04:19.530
And the same applies here.

04:19.680 --> 04:20.700
The ace.

04:20.730 --> 04:22.890
One, two, three.

04:23.920 --> 04:24.220
Who'd.

04:25.320 --> 04:31.320
Three, four, five, six, seven.

04:32.330 --> 04:33.320
Eight.

04:33.860 --> 04:34.940
Nine.

04:35.950 --> 04:36.700
Ten.

04:38.280 --> 04:42.510
And 11 and 1212 signs.

04:42.510 --> 04:43.650
We have 13 here.

04:43.650 --> 04:45.000
This starts with zero signs.

04:45.000 --> 04:46.500
We now have.

04:46.500 --> 04:54.150
The 13th element in our logic is in programming and in logic is the 12 elements.

04:54.150 --> 04:56.310
So now here.

04:57.330 --> 05:03.540
Now let's create a program that will generate a random card and we can borrow the.

05:04.740 --> 05:07.630
Uh, generate random number function now.

05:07.650 --> 05:10.440
But so actually, you can.

05:12.090 --> 05:22.130
You can also assign a specific value to here elements, but we will discuss about that in next lectures.

05:22.140 --> 05:24.510
So now we're going to create here.

05:25.450 --> 05:30.130
The new function named the Get with String.

05:30.130 --> 05:33.490
But first we need to include our.

05:34.640 --> 05:35.480
Libraries.

05:35.480 --> 05:38.880
So now include the stream.

05:38.930 --> 05:42.050
Your stream here include.

05:42.800 --> 05:54.380
Include the stdlib here include and include the C time C time here.

05:54.980 --> 05:56.420
So now.

05:57.460 --> 05:59.050
We will develop our.

06:01.630 --> 06:02.350
Function here.

06:02.350 --> 06:05.680
So now String is going to return the string.

06:05.710 --> 06:09.670
Type here and get sweet.

06:10.240 --> 06:11.590
String here.

06:11.590 --> 06:13.120
And card.

06:14.130 --> 06:17.520
Card sweets and it's going to be a suite here.

06:18.420 --> 06:20.460
And let's make this here.

06:20.460 --> 06:22.580
So as you can see, we got an error here.

06:22.590 --> 06:23.400
Change?

06:23.520 --> 06:23.730
Yeah.

06:23.730 --> 06:27.240
We also need to use the namespace STD.

06:27.570 --> 06:32.700
Unless we don't want to write the STD at every declaration like this.

06:32.700 --> 06:35.160
So we will use a namespace.

06:35.160 --> 06:39.300
So you learned about the namespace in previous lectures.

06:39.300 --> 06:42.300
So using namespace std.

06:43.620 --> 06:46.890
And here, let's actually close this for now.

06:46.890 --> 06:47.670
Here.

06:51.190 --> 06:52.180
Now Cod.

06:52.180 --> 06:53.530
Sweet, sweet here.

06:53.530 --> 06:57.070
And now we're going to create a new string.

06:58.210 --> 06:59.500
String s.

07:00.520 --> 07:01.780
And switch.

07:03.640 --> 07:04.780
Sudhir.

07:06.250 --> 07:12.580
And in this case, we're going to use the switch and case condition here and here case.

07:12.970 --> 07:15.850
In this case, is the club then s.

07:18.360 --> 07:20.160
As equals of.

07:20.340 --> 07:21.090
Not like this.

07:21.090 --> 07:21.530
Yeah.

07:21.870 --> 07:25.980
Case club as equals club here.

07:26.250 --> 07:28.820
And this in case it's.

07:28.830 --> 07:31.350
And after that, of course, we're going to break it.

07:32.400 --> 07:34.590
Case Diamond.

07:37.490 --> 07:38.450
We're going to make.

07:38.450 --> 07:41.510
This is here, Diamond.

07:44.690 --> 07:48.800
Here and break is hurt.

07:52.090 --> 07:54.190
As 30 year.

07:58.840 --> 08:00.460
As heard here.

08:02.430 --> 08:03.270
Break again.

08:03.270 --> 08:06.190
And lastly case spade.

08:07.920 --> 08:08.820
Spade.

08:09.780 --> 08:10.440
Yeah.

08:10.470 --> 08:12.390
Case Spade.

08:15.140 --> 08:18.990
Here and here equals spade.

08:20.610 --> 08:22.520
And then break again.

08:22.560 --> 08:23.790
And after that?

08:23.790 --> 08:28.170
After this, the switch case statement completes.

08:28.200 --> 08:37.500
We will return our string return s, And in this case, as you can see here, this returns here and

08:37.500 --> 08:40.670
we will use get used with string here.

08:40.680 --> 08:48.750
So now we also need to get so here this was the get switch string which relates the card suits gave

08:48.750 --> 08:55.800
here like this card suits and now we need to write our card elements function.

08:55.800 --> 08:58.710
So now we're going to go down after the card suits.

08:58.710 --> 09:01.500
We're going to create the card elements function.

09:01.770 --> 09:03.900
So now the string.

09:05.200 --> 09:08.650
Get element string here.

09:09.940 --> 09:13.000
And here, let me fix this.

09:13.000 --> 09:13.360
Yeah.

09:14.080 --> 09:15.700
Get element, string.

09:15.730 --> 09:18.940
Card elements and element.

09:19.390 --> 09:22.330
So now we're going to write it like this again.

09:22.330 --> 09:24.210
We're going to create a new string.

09:24.220 --> 09:30.400
String E here, and then we're going to switch case statement, create here.

09:30.400 --> 09:31.690
Now switch.

09:33.390 --> 09:34.920
It's going to be element.

09:35.160 --> 09:46.260
And now we will write our code like this case ace the equals ace here and then break.

09:48.150 --> 09:49.380
Face to.

09:54.320 --> 09:56.810
Actually, we can also copy this.

10:00.440 --> 10:01.480
One, two.

10:01.490 --> 10:02.700
So it's an easy way.

10:02.720 --> 10:10.220
One, two, three, four, five, six, seven, eight, nine, ten, 11.

10:11.630 --> 10:12.980
No such thing here.

10:13.310 --> 10:15.200
So the first is Ace.

10:15.230 --> 10:22.010
Now we have the two also change to and then we have three.

10:23.520 --> 10:25.320
That's what we have three here.

10:27.470 --> 10:30.170
Then we have four.

10:31.910 --> 10:33.710
For us.

10:33.710 --> 10:35.540
We have four here.

10:35.630 --> 10:37.460
Then we have five.

10:38.030 --> 10:40.220
Also, we have five here.

10:40.850 --> 10:42.590
Then we have six.

10:43.760 --> 10:45.680
Also, we have six here.

10:46.370 --> 10:47.900
Then we have seven.

10:49.090 --> 10:50.950
Also, we have seven here.

10:51.520 --> 10:52.930
Then we have eight.

10:53.800 --> 10:55.630
Also, we have eight here.

10:56.770 --> 10:57.730
Nine?

10:59.200 --> 11:00.910
Also, we have nine here.

11:03.490 --> 11:04.930
Since we don't have ten here.

11:04.930 --> 11:05.350
Yeah.

11:05.500 --> 11:06.820
Yeah, we have ten.

11:07.830 --> 11:09.300
Now an.

11:12.130 --> 11:14.320
We would also have ten here.

11:14.860 --> 11:19.150
So now we comes Jack, Queen and King.

11:21.190 --> 11:22.030
Jack.

11:26.210 --> 11:27.290
Queen.

11:30.100 --> 11:31.340
And King.

11:31.360 --> 11:32.260
Lastly.

11:32.800 --> 11:33.610
King.

11:35.260 --> 11:35.590
Oops.

11:38.450 --> 11:39.320
Kink here.

11:40.590 --> 11:45.270
So now we're going to generate a random number here.

11:45.990 --> 11:52.100
So here now we're going to create a new function after that and name it.

11:52.110 --> 11:59.560
So this is random number generator will use the will return the integer number here, generate random

11:59.560 --> 12:03.060
numbers, generate random number.

12:03.330 --> 12:11.670
And this is going to be integer a minimum here, integer minimum here and integer maximum.

12:12.900 --> 12:14.790
Let me check the lecture time.

12:16.840 --> 12:17.380
Here.

12:17.590 --> 12:18.940
So now.

12:22.350 --> 12:25.410
We're going to create the here and now.

12:25.410 --> 12:25.890
We're going to.

12:26.280 --> 12:33.030
So we will use static, constant double because of the efficiency.

12:33.030 --> 12:36.770
And so we will only calculate this value once.

12:36.780 --> 12:45.600
So here we're going to create a static constant that and this will also be a double the fraction is

12:45.600 --> 12:52.800
going to be double fraction is going to be 1.0.

12:54.440 --> 13:01.250
Divide by static cast, and it's going to be the double here.

13:04.100 --> 13:08.570
And this novel is going to be around Max and.

13:09.550 --> 13:11.800
After that, we're going to plus.

13:12.550 --> 13:13.990
1.0.

13:15.960 --> 13:16.890
Here.

13:17.070 --> 13:25.150
Now, after that, we will need to evenly distribute the random number across our range.

13:25.170 --> 13:32.400
So we will return return mean plus static cast integer.

13:33.180 --> 13:34.590
And here.

13:35.970 --> 13:44.100
The max minus one plus one multiply by.

13:46.390 --> 13:46.800
Oops.

13:46.810 --> 13:47.170
Um.

13:47.710 --> 13:48.370
Yeah.

13:49.030 --> 13:49.420
Here.

13:49.420 --> 13:51.850
We need to also add this.

13:51.850 --> 13:54.280
And here.

13:55.240 --> 13:56.620
Multiply by.

13:58.940 --> 14:03.740
The rant and we will multiply rant by our fraction.

14:05.010 --> 14:05.610
Here.

14:06.510 --> 14:14.310
So now we have completed our application and in the next lecture we will write the main function here.

14:14.310 --> 14:16.560
So I'm waiting you in next lecture.

14:16.590 --> 14:17.160
See you.
