Hello everyone.
So in the last five year deals we learned about this object oriented programming but it's a different
concept.
How to create object what our construct built and how to use them.
So we have learned a lot of things in object oriented programming.
So now let us create a class with the help of everything that we have learned till now to gain confidence
and to make things more clear.
Okay.
So let us create a friction class.
So in Matt
in maths the example of affection is like five by seven.
Five is the numerator and seven is the dominator that circle represent these type of numbers.
And to perform operation on these type of numbers we want to create a fraction class.
Okay so infection class we will have two properties numerator and denominator.
These two will be the properties of our friction class.
And both the properties will be private.
Okay.
What the properties will be private.
So 5 is the numerator and seven is the denominator.
Okay.
So let's see in gold.
So here I am creating only one class.
If you want what you can do is you can create a class action lawsuit BP sorry you can create a file
function or TPP and other file fraction use Nazi BP but I am creating only one file.
Okay so it's totally our choice.
So class friction
now we want to properties what the properties will be private.
So and numerator
and denominator.
Now what I want to do is
now what I want to do is whenever we create the object of this class whenever you create the object
of friction class numerator and denominator should not contain God which values.
Okay numerator and denominator should not contain garbage values.
So how can we ensure that.
How can we enforce our user to give the values of numerator and denominator.
So the idea is very simple.
We will we will make a better met based constructor and as soon as we make a parameters constructor
default constructor is not visible to us anymore.
So in this way we can force our user to give the values of numerator and denominator.
Okay so let's create a better make based function it will take numerator and denominator as input and
then we will copy the value of numerator and denominator into our properties so numerator close numerator
and denominator it goes denominator so in this fashion we will force our user to give the values of
numerator and denominator.
Hence if the user wants to create our objective function class numerator and denominator will never
contain garbage values.
Okay.
So are these two lines correct.
Will these two lines work.
No this will not work.
And why will not work because the property name is a mess.
Function name the property name is a mess parameter name.
So we have to use this keyword.
Using this is mandatory here.
Okay.
So now how do we create the object of defection class.
So we will create object in this section.
Fraction let's call it F1.
So the numerator is spent and there the other night is 5.
So the numerator will contain 10 denominator will contain two
and this is our function F1 okay.
Now let us create a print function.
So what does print function will do.
It will print our affection in this manner then followed slash too.
Okay so what do the signature of brain function what was written by between 5 will be void because we
are not returning anything.
Print and then some called.
Okay.
And how we will call this function will call this function with the help of an object.
So if one dot print the value of f1 F1 will be stored in the this keyword of the brain function with
the help of this we can access the properties of F1.
So private function of public or private it will be public because the race object cannot call it certain
type is void because we are not pretending anything.
No input argument no object which will call the print function the object will be stored in this.
So see out
this ad or numerator then forward slash and this ETL denominator.
Okay so using this is optional here if you will not write this Okay so using this is optional here we
can also remove it.
Here so whenever the object will call the print function F1 not print the value of f1 will be stored
in this and with the help of this we can access the properties of the object Okay now let us create
one more function we want to create a function and we want to create a function that lets say we have
to function.
It will create a function that lets say we have to friction.
If when the value of a fund let's say 10 by to an infection F2 which is like 15 by food okay.
So what are the second nature of add a function.
So Ed f1 f2 it will take to function as input.
Is this right or wrong it is wrong.
Why.
Because to call a function we need an object.
Okay to call a function we need an object.
So F1 will call object will call this function.
So what what will be the input parameter the vertically the argument for that function since F1 calls
the ad that this give out of the added function will store F1.
And now we won't have to solve the root pass after his input so it will take only one argument and not
two.
Okay.
Vinod to argument because F1 is stored in this key word of the ad function and we will pass F2 and similarly
it can perform its operation okay.
So what is our expectation what is our aim.
Our aim is we want to update the result of F1 plus F2 into F1 we will add these two friction f1 plus
F2 and we'll store the result in F1 we will update F1 and F2 will remain unchanged and we do not want
to create any new friction.
So the return type will be void.
We do not want to create any new friction the Dalton type will be void and we want to update F1 and
have to will remain unchanged.
Now how to add two functions.
What is the procedure for adding two functions.
So the procedure is very simple.
Let's say the two factions are then by two.
And the second function is 15 by four then by two and 15 by four.
So first of all we will take a team and Sam is four.
But now for simplicity let's make a date for simplicity let's make a date.
Okay.
So here it is not clearly visible.
So let's say the two factions are F1 and have two.
So F1 is then by two and F2 is 15 by four.
So how can we are two functions.
So first of all we have to take the Elysium of the denominator so that she moves forward but for simplicity
let's make a date.
So what will happen to the numerator.
So this 10 will guard multiply it by four.
How four because eight by two is four.
Similarly this 15 will get multiplied by two and from where to game it is simply eight by four is to
so into two.
So a 40 plus 30 by eight.
So our dessert should be 70 by eight okay.
So for now let's call it X and let's call it Y Okay.
So what is x x is simply the LTM divided by the denominator and what is y y is and it's him divided
by the number trough F2.
And where does Elysium Sam is denominator of f1 plus.
So how do you multiply the merit of F2 the amount of F1 multiplied denominator of F2.
Okay so let's include
so we want to create and function and add function will be public or private.
It will be public because we will call it from the mean but it will take it will take function as input
faction F to its name it F2.
So first of all we have to calculate Elysium.
So Elysium is very simple Bernard Madoff.
If one multiply the amount of F2 so F2 dart denominator
so using this is optional here why optional.
Because who will call add an object will call and F when will call add and F1 will be stored in this.
So this simply means F1 here.
So using this is optional here you can also remove this.
OK so Will this Terminator and basically means this added denominator.
OK now let us consider the value of x and y
so X is very simple axiom divided by denominator of F1 so a denominator you can write this entertainment
also.
And similarly Y is also very simple.
Vi is I would see him divided by after dark denominator.
Okay so using this is optional here
and here it is mandated to use this
so using this is optional here.
Okay.
Now what was our aim.
So first of all let us calculate the numerator also.
So in the numerator is X Multiply numerator of f one so you can sum better numerator or you can write
this item numerator plus via multiply F2 dark numerator numerator trough F2
now as we discussed store the desert and effluent stored desert in F1 after will remain unchanged so
this add on numerator
is and you m
this error denominator then write off F1 is Elysium Okay so optional using this is optional because
it is implicit Okay so what will happen
so let's say there are two factions are F1 is 10 by 2 and F2 is 15 by 4 so numerator condensed in detrimental
contains 2 This is F1 numeric res 15 business days for and this is F2 so what else can we do.
What do the effect of line number 18 so they rather multiply after dark matter and so to multiply for
it.
So Elysium is it now what do the value of x axis so X is Elysium which is it divided by the amount of
F1 so it by 2 which is food what is y and see him divided by denominator of F2 which is 2 now what will
be the numerator so the numerator is X which is food multiplied in a trough F1 or we can say this idea
numerator then plus what are the value of y which is to multiply fifteen so this comes out to be seventy
and then we will store the desert in F1 so of destroying the resulting F1 this header numerator is and
you him let's say this addresses seven hundred so this contains that function this given of that function
contains seven hundred.
So this idea the military's and you m so it will become seventy and this will become this Saturday night
it is an essential item is 8 so this will become 8.
So finally for F when the numerator is seventy and their denominator is eight so if one is seventy by
eight and F2 is fifteen by four.
So this was our aim after all remains unchanged after remains unchanged and F1 got abated so F1 became
f1 plus F2 OK now ideally now ideally F1 is seventy by eight but this is not simplified after simplifying
we will divide it by two so it will become thirty five by four.
So this is the simplified manner we should restore is in this matter.
This is simplified to v Okay now how to simplify affection.
So it is very easy to simplify affection but we all know to do is.
So what is our desired result is very simple F1 begins 70 by eight.
Now I want to simplify this function so our zone should be thirty five by four.
So it is very easy to simplify inflection but we all know to do is find the GC Of these two terms.
This really means high used commando either to find you silly you should be will come out to be do and
after finding that you should be dividing numerator and divide denominator so numerator will become
numerator divided by GC and denominator will become denominator Baiji City.
Now how to conclude your city for example you want to calculate the city of two numbers four and twenty.
So what can be the maximum value of the city to the maximum value of the city can before.
OK maximum leave the city can before you study is the highest common device and a number which will
divide both the number four and 20 we have to find a number we have to find the highest number which
divides both the number four and 20 so the highest value of the city can be 4.
Okay so what we will do will start dividing from 1 then we will divide from 2 and so on then the minimum
of two numbers A and B for example and better two numbers.
Would you today want to find so I would start from one.
Tell me now if a and b and I will divide I will divide I will write or divide both in number and B by
these numbers and the mixing of these numbers will be out decently Okay so let's in gold so let's create
a function simplify so we have a function why to simplify
so what it will take it will not take any argument.
Why.
Because I will call this function and object will call this function object dot simplify.
So no object will be sought in this keyword and with the help of this keyword we can access it properties.
So initially let's say G 30 is when and the maximum value of the city can be so g city maximum live
the city can be minimum of numerator and denominator so this add on numerator
this adult denominator.
So using this is optional here
optional why optional.
Because implicitly the intimate term means this ADD or denominator so optional.
Okay.
So the object that will call this function that objectively restored in this keyword and with the help
of this keyword we will be able to access the properties so we will start dividing from one and we will
go below.
J J is the maximum you should devalue
so try to divide numerator and denominator by G.
So if numerator
more i equals equals zero and denominator more i equals equals zero.
That means I use a common factor of a and in the middle.
So we will update disagree.
So you suis I
after calculating the city we have to simplify the function so simplify so for simplifying what we can
do.
We will update the numerator and denominator so numerator is numerator divided by DCD and similarly
denominator is the United divided by DCD.
Okay now we call this function simplify.
So after that add a function our result has been updated the result has been stored in F1 software starting.
That is our day in F1.
We will call the simplify function so simplify not just simplify function will simplify F1.
Now see here how we used to call a function how we used to call a function we used to call a function
something like this object but function name object named dart function name.
Okay but here I simply here I simply write only function name so how it will work.
Basically basically what we're doing here.
F1 dot and F2.
So F1 is stored in this keyword of the add function.
So we are in the end function.
So in their function simplify implicitly means this add to simplify OK implicitly simplify this line
simply means this error simplify and this contains F1 OK.
This contains F1 so F1 will be stored in the F1 will be stored in this keyword or the simpler way function.
So here this Gaillard will stored F1 OK so similarly here it is optional to write this at an imitator
because implicitly it means this also admits this only OK.
Now let us try to create an object and let's see where that our code is working or not.
So function
F1 let's see the numerator is uh what we decided then and also numerator used to be 90 days to certain
number of days in the Middle East.
And I'd say we have one more faction F2 so what was the name attended to 15 and food.
Now let us call our function F1 not ad and we really bus F to now after that Asian let's spend the value
of f1 enough to show F1 dart bent
and after Dortmund
OK let's run this file so a numerator.
Something wrong here.
So what did I do wrong.
Numerator does not name or type
numerator does not name type
O
silly mistake
okay let's give n line you so f in the bank statement after bringing the numerator and denominator let
us give a line
C so the numerator so that one is thirty five by four f one is stratified therefore and have to is fifteen
by four.
So F1 was initially seventy by eight but recall the simplify function so it became thirty five by four
and F2 remains unchanged it was fifteen by four and after the addition function it is fifteen by four
only.
Okay so I will call it is working now I want to just for extra information we also have a function we
also have an inbuilt function to convert DCT so then both function work calculating use it is very simple
so let's come and get out.
So in build function and build function for GC
So this is underscore underscore GST and give the two values a and b for example and B are the two numbers
who you really we want to find so
how can we use this.
So end a let's say in C C will contain the GST off to numbers.
So we you see the overall numbers E and B.
Okay so this is evident world function and that's going to scold you silly it is that embed function
so we can directly use this or we can use it in this function or we can find we can call registry indecision
okay it is our choice Okay so that's all for this video thank you.