Hello and welcome.
And in this lecture, we are going to discuss enemies.
So what are enemies?
Enemies are enumerations.
Enumerations allow us to define a list of valid values and allow the program to use them.
So let's begin.
So at the top here, just go Inam.
And we're just going to say Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday,
we have just created an enumeration for weekdays.
If we now go share a equals Monday and we cast that to an integer and then we go print Jeff.
Percent I for integer.
And we pass our variable A..
We should see zero B. Outputted.
Let's compile that GCSE main dot.
C dash show.
Main.
Type Maine, and we see zero.
Now, if you were to put Tuesday in here, we can pull out again.
We see one Wednesday would be to Thursday would be three.
Now, what if we want the.
The days of the week to stop from one?
Then we just simply say Monday equals one.
If we now we can pull that.
Type main, we can see that Tuesdays now, too.
We did Monday.
We can pull that.
Monday is now one.
Let's now give our numeration a name.
Inam week day.
If we now say Inam weekday day equals Monday and then we output day.
Where we can pull that.
Monday, so names are essentially just descriptive names, phone numbers, when we don't set a value,
it counts from zero.
In our case, the first the first element here Monday is zero.
Second, Tuesday is one third.
Wednesday is two.
And so on and so on.
We can give all of these any numbers we like.
If we now change this to Thursday and we compile.
We see 10 now.
Notice Friday doesn't have a value.
But Thursday does.
What do you think Friday will be?
It'll be 11, of course.
Change this to Friday.
We compile.
Eleven.
Excellent.
Now you understand enumerations.
Let me show you how you can use this with an array.
So we're gonna give it of all of the values here.
So it counts from zero again.
And just in the here, we're going to create an array const char week day SDR equals Monday, comma
Tuesday, comma Wednesday, comma Thursday and so on.
So what we've done here is we've created an array of strings here.
Right.
They represent every day of the week.
So one week weekday is equal to Friday.
We should be able to output Friday.
Right.
So what we're gonna do is we're gonna say Kohn's cha.
Weekday to SDR, which means destroying, obviously.
And we're going to expect a weekday pass to us.
And all we're going to do is, is we're going to say return weekday, SDR day.
And obviously in a battery implementation, you would check that the day can fit into the bounds of
the array and so on.
So if we now did print half percent, ask for string back session and we did weekday to SDR.
And let's just pass it on Friday.
We can get rid of this variable declaration here if we now compile that, run it.
We see Friday.
And if we just change the Friday string, the Friday explanation, Mark, we we can pull that.
Run it again.
Now we see Friday explanation.
So how does this work?
Well, we know that the enemies come from zero.
So zeros Monday.
Tuesday is one.
If you hover over it, I'll tell you the number as well.
The idea is just visual studio code will tell you the number is now because these stuff from zeros and
arrays also start from zero.
They're the perfect match for each other because they line up perfectly.
Index zero in our Kohn's char array and our constant points.
You're right here is Monday weak day zero is Monday.
So when we pass Friday in here.
Is getting replaced with four.
And then it is getting index four from this array zero.
One, two, three, four.
So we have Friday returned.