00:01
Okay, so in this question, we want to use inline function to find the largest and smallest of three numbers.
00:11
First, i'm going to need to declare my three numbers.
00:14
By the way, this is just a basic c+ + program.
00:17
If i run this program, nothing happens because we haven't done any.
00:26
I'm going to start by declaring three numbers.
00:29
So i will declare a, which will be equal to 12.
00:32
And declare another number b which is going to be equal to 0.
00:37
I'm going to declare a third number c which is going to equal to 5.
00:43
Then i need my small list and largest number.
00:47
I'm going to have small list and largest as two integers.
00:53
Now if i build this program works, maybe you can probably cannot read what's below in the build, but basically blue is just warning, telling me that i haven't i have declared variable but i haven't done anything with them but if there's no red it means my program is okay there's no error so first let's get the min and let's find the smallest of the three numbers so if i were just to write a smallest is equal to min of a and b and i try to build this, i'm going to get errors.
01:45
As you can see, there's red.
01:48
And oh, there's an error two smallest.
01:50
I wrote three l's here.
01:53
But the main error is that min was never declared.
01:57
So one way i can fix this is by using std min.
02:04
And here i could print, could output, for example the smallest number is and then have my smallest number and then i'm going to just have a line return to make sure everything's clear and as you can see this would work just fine it would output the smallest number is zero which is true between 12 and zero zero is the smallest number but the question says to use inline function it doesn't say to you the standard definition function so we're going to have a min function declared as an inline we need to declare before our main the value that we want to return is an integer the name of our function will be min it will take as a parameter two integer accent we're going to call them x and y to avoid confusion and inside my curly bracket i'm going to write my expression so here i can simply use the ternary operator so since i want the minimum i will write if x is less than y that's my condition then if x is lesser than y that means if x is lesser than y that means x is the minimum value so i want to return x i want to return x otherwise if it's false i want to return y so if y is the smallest i want to return y and i'm going to put a semicolon here i'm going to compile here maybe i forget to put a semicolon but this is not the right syntax we're going to figure this together what's the proper way so if i put return here so you see this seems to be working at least in compiles and let's see the result there you go so the smallest number is zero, which is true between 12 and 0, 0 is the smaller.
05:11
So here i'm going to write a comment to make sure that it's clear what's happening here.
05:16
So the dot dot, question mark, that, dot, dot, called, dot, dot, dot, is called the ternary operator.
05:34
If you want to google it and learn more about it in case you don't know.
05:39
It in english it reads as if x is lesser than y then return y otherwise return is the opposite sorry if x is lesser than y so x lesser than y is true return x if this condition is not true so if x is not lesser than y then return y and we're going to do the same thing or i'm going to give more space to code and less space for build message for the max it would be exactly the same so i'm going to copy and paste this but i'm going to write max and here for the max so if x is lesser than y that mean y is greater than x so i want to return y and if x is not lesser than y so if y is lesser than x then i want to return x so that's how we can define our inline function and here i could but i haven't finished yet so now i know that the smallest number between a and b is zero which is true but we need to find the smallest between a b and c so we have the min between smallest and c which should still be zero i mean this won't change so that's correct the smallest number is zero and here let's find the largest number so here i will simply copy paste this but i will replace smallest with largest uh the largest number is largest so i replace it everywhere and i will replace my min with my max and here i have uh oh see the largest number is five why is that because i made a mistake here i wrote the maximum between smallest and steep but i wanted largest i forgot one smallest to replace now that i run it the smallest is zero the largest is 12 so this part of the program is where we find it and this is how we define our inline functions what you could do if you want to put this even further would be you could declare basically a, b, and c like this, without giving them any value...