1
00:00:01,630 --> 00:00:02,440
Hello everyone.

2
00:00:02,440 --> 00:00:07,810
So in the last session we created a friction class and now we will discuss some important concepts that

3
00:00:07,810 --> 00:00:09,790
were not covered in the last session.

4
00:00:09,790 --> 00:00:13,090
Okay so first let us analyze this friction class.

5
00:00:13,210 --> 00:00:17,790
So in this friction glass we have two private properties numerator and denominator.

6
00:00:17,830 --> 00:00:18,970
Then we have a better match.

7
00:00:19,030 --> 00:00:22,930
I used constructor a brain function and I'll add a function.

8
00:00:22,930 --> 00:00:23,480
Okay.

9
00:00:23,500 --> 00:00:26,320
And then we created simplify a function at the last.

10
00:00:27,150 --> 00:00:27,370
Okay.

11
00:00:27,370 --> 00:00:30,700
So this is all about the function glass okay.

12
00:00:30,700 --> 00:00:31,930
Now let's see.

13
00:00:31,930 --> 00:00:35,950
Now let's analyze the function and what is happening in that function

14
00:00:40,610 --> 00:00:47,700
so we have two fractions so the numerator and denominator for first reaction was tending to this is

15
00:00:47,700 --> 00:00:55,700
faction f 1 and numerator ended on the default affection 2 was 15 food and this was our affection to.

16
00:00:55,920 --> 00:01:03,450
So how we are calling this added function f one dot at and b bus F2 US barometer.

17
00:01:04,070 --> 00:01:04,550
Okay.

18
00:01:04,650 --> 00:01:09,670
So what is happening here is we are making a copy of F2 head.

19
00:01:09,780 --> 00:01:10,070
Okay.

20
00:01:10,080 --> 00:01:12,810
So a copy is being generated.

21
00:01:12,810 --> 00:01:24,580
So what is happening here is we can we can write this line is fraction F2 is it to fraction F2 from

22
00:01:24,580 --> 00:01:25,630
the mean.

23
00:01:25,630 --> 00:01:26,200
Okay.

24
00:01:26,350 --> 00:01:32,790
So this barometer reflection F2 disparagement affection F2 is equals to the fraction from the mean.

25
00:01:32,800 --> 00:01:39,570
So what is happening here is we are creating we are creating a new object and all the values are being

26
00:01:39,570 --> 00:01:40,330
getting copied.

27
00:01:40,750 --> 00:01:41,020
Okay.

28
00:01:41,050 --> 00:01:47,420
So what is happening here is copy construct Baz being getting called copy construct that is correlated.

29
00:01:48,540 --> 00:01:49,030
Okay.

30
00:01:49,150 --> 00:01:56,320
So at Line number 17 at line number 17 copy constructor is being getting called a copy constructor is

31
00:01:56,320 --> 00:02:03,360
creating an object and then it copies the value from the fraction which is present in mean okay.

32
00:02:03,420 --> 00:02:04,650
So what our aim is.

33
00:02:04,650 --> 00:02:12,640
So our aim is our aim is very simple we want to avoid the copy we don't want to copy okay.

34
00:02:12,770 --> 00:02:14,670
We want to avoid this copy.

35
00:02:14,900 --> 00:02:17,220
So why do we want to avoid this copy.

36
00:02:17,330 --> 00:02:23,060
Because if you look in the if you look inside the added function we are only accessing the properties

37
00:02:23,060 --> 00:02:24,290
of fraction F2.

38
00:02:24,560 --> 00:02:27,680
We are only using the properties of friction F2.

39
00:02:28,490 --> 00:02:34,610
So why do copy if we will copy then there is time in memory waste because first and object will be created

40
00:02:34,820 --> 00:02:36,830
then all the values will be copied.

41
00:02:36,830 --> 00:02:39,830
Okay but we only need to access its properties.

42
00:02:40,010 --> 00:02:41,360
So there is no need to copy.

43
00:02:41,360 --> 00:02:44,830
So ultimately our aim is we have to avoid this copy.

44
00:02:44,840 --> 00:02:47,840
Now how can we avoid this copy is the question.

45
00:02:48,110 --> 00:02:49,910
So how can we avoid this copy.

46
00:02:49,910 --> 00:02:56,230
So we all know we have started about our offense is variable and passed by it offense in function.

47
00:02:56,360 --> 00:03:00,500
Okay so what we will do we will pass by reference to avoid copy.

48
00:03:00,500 --> 00:03:01,790
So let us take an example.

49
00:03:02,600 --> 00:03:09,760
So when we write in days 5 and into G is I.

50
00:03:09,790 --> 00:03:11,730
What happened at this line.

51
00:03:13,200 --> 00:03:16,850
This is the scenario and at this line a memory block will be created G.

52
00:03:16,880 --> 00:03:24,400
And the value will be copied but we want new blocks should not be there so we will use a reference variable.

53
00:03:24,440 --> 00:03:31,290
So what will the effect of this line the effect of this line is is very simple K okay.

54
00:03:31,310 --> 00:03:37,060
The boat points to the same memory block I n Cape belongs to the same memory block.

55
00:03:37,070 --> 00:03:41,000
So if I were Lou Gabler surplus then this value will become 6.

56
00:03:41,370 --> 00:03:47,410
Okay so if you do see out okay or if you see out I output will be 6.

57
00:03:47,750 --> 00:03:49,130
Order will be 6.

58
00:03:49,130 --> 00:03:53,280
Both AI and key points to this memory block.

59
00:03:53,330 --> 00:03:54,920
Okay I can change.

60
00:03:54,980 --> 00:03:56,090
I can read and write.

61
00:03:56,110 --> 00:04:00,680
Data can also read and write data so we will use a reference variable.

62
00:04:00,680 --> 00:04:10,160
So this scenario will look something like this faction reference variable is main guard F to okay.

63
00:04:10,230 --> 00:04:13,690
So in this way we will be able to avoid copy.

64
00:04:13,740 --> 00:04:15,970
Okay so let's see.

65
00:04:16,090 --> 00:04:21,260
So what we have to do we will avoid copy using the reference variable.

66
00:04:21,320 --> 00:04:23,310
Now there is still a problem.

67
00:04:23,450 --> 00:04:24,820
What is the problem.

68
00:04:24,860 --> 00:04:34,750
So suppose if I do something like this after dot numerator is minus 1 I am changing the values of F2

69
00:04:34,810 --> 00:04:38,400
I'm changing the numerator property of F2.

70
00:04:38,540 --> 00:04:48,510
So my aim is my aim is to avoid this to avoid this.

71
00:04:48,540 --> 00:04:50,840
No one can change the values of numerator.

72
00:04:50,850 --> 00:04:53,640
No one can change the values of F2.

73
00:04:53,640 --> 00:04:56,740
So how can we do this.

74
00:04:56,830 --> 00:04:58,260
So how can we achieve our goal.

75
00:04:59,430 --> 00:05:00,450
So it's very simple.

76
00:05:00,480 --> 00:05:01,110
What do we do

77
00:05:04,610 --> 00:05:13,240
so when we write in day is five and end at events where DeBakey is I.

78
00:05:13,290 --> 00:05:16,120
What happened is this is I.

79
00:05:16,130 --> 00:05:17,300
And this is key.

80
00:05:17,450 --> 00:05:20,130
I can I can read and write data.

81
00:05:20,250 --> 00:05:22,250
Key can also read and write data.

82
00:05:22,550 --> 00:05:31,670
But there should be a V if I do get plus plus then add I should be dead I want cake and only read data.

83
00:05:31,760 --> 00:05:35,020
Gays should not be able to write data gay can only read data.

84
00:05:35,500 --> 00:05:36,210
So what to do.

85
00:05:36,580 --> 00:05:39,680
So we have a constant reference variable.

86
00:05:39,790 --> 00:05:40,460
Where do we.

87
00:05:40,480 --> 00:05:46,450
This index will look something like this and constant reference variable key is I.

88
00:05:47,770 --> 00:05:54,310
So gays a reference variable to won't be the constant gays at offensive Eddie Baldwin Deja constant

89
00:05:54,490 --> 00:05:56,240
so gay is a constant preference.

90
00:05:56,260 --> 00:05:58,490
So if we will use this then what will happen.

91
00:05:58,510 --> 00:06:01,500
So this is five I am gay.

92
00:06:01,580 --> 00:06:02,690
Both points here.

93
00:06:02,840 --> 00:06:08,620
I can read and write data but gay can only lead you down gay cannot write data.

94
00:06:08,900 --> 00:06:09,440
Okay.

95
00:06:09,440 --> 00:06:11,680
Gay Gay cannot write data.

96
00:06:11,960 --> 00:06:16,990
So we need something like this in our program.

97
00:06:17,010 --> 00:06:18,260
So what do we do.

98
00:06:18,300 --> 00:06:24,960
We will create a constant defense so constant reference Okay so whenever we are working on a project

99
00:06:25,200 --> 00:06:27,860
we should keep all these things in our mind.

100
00:06:27,910 --> 00:06:30,340
Now get these small small things matters.

101
00:06:30,550 --> 00:06:36,120
Okay so you should always think that by that I should pass up constraint or offense or simply pass by

102
00:06:36,120 --> 00:06:36,660
value.

103
00:06:36,960 --> 00:06:38,710
Okay so these things matters.

104
00:06:38,790 --> 00:06:40,200
These things really matters a lot.

105
00:06:41,190 --> 00:06:45,440
Okay now let us create one more function a function called Multiply.

106
00:06:45,720 --> 00:06:50,100
Just like that function we are creating one more function which is called multiply so multiply.

107
00:06:50,100 --> 00:06:50,780
We do.

108
00:06:50,970 --> 00:06:59,360
So multiply function will multiply two fractions and how we will call if one dart multiply F2.

109
00:06:59,460 --> 00:06:59,710
Okay.

110
00:06:59,750 --> 00:07:02,130
We will pass one argument.

111
00:07:02,130 --> 00:07:06,520
So our aim is same as the aim which was for our function.

112
00:07:06,900 --> 00:07:13,410
We will multiply F1 and F2 we will multiply if an F2 end store that is right in F1 okay.

113
00:07:13,410 --> 00:07:15,030
F2 will remain unchanged.

114
00:07:15,030 --> 00:07:16,860
It is true that is worked in F1.

115
00:07:16,950 --> 00:07:19,270
So how to multiply two factions.

116
00:07:19,350 --> 00:07:24,630
Suppose F1 is ten by two and we have another function f 2 which is 15 by 4.

117
00:07:25,590 --> 00:07:32,470
So multiplying numerator with the numerator and multiplying denominator with denominator so 150 by 8.

118
00:07:32,670 --> 00:07:38,090
And then we will call simplify function then we will call simplify function.

119
00:07:38,130 --> 00:07:40,680
Okay simple easy.

120
00:07:40,680 --> 00:07:41,610
Now let's write the code

121
00:07:51,060 --> 00:07:53,560
so the return type will be void.

122
00:07:53,610 --> 00:08:00,300
Let's say the name of the function is multiply it will take a function as input.

123
00:08:00,430 --> 00:08:05,560
We will take a constant reference because we do not want our copy construct to be called here because

124
00:08:05,560 --> 00:08:07,750
there is no need to copy okay.

125
00:08:07,840 --> 00:08:13,960
There is no need to copy is a way to call copy constructor and waste our time in memory so we have to

126
00:08:13,960 --> 00:08:15,450
multiply the numerator with the numerator.

127
00:08:15,640 --> 00:08:24,050
So numerator of F1 is numerator of F1 multiply numerator of F2.

128
00:08:24,100 --> 00:08:28,280
So we have to not numerator.

129
00:08:28,300 --> 00:08:31,320
Okay so using this is optional here.

130
00:08:31,500 --> 00:08:32,520
This is optional

131
00:08:35,750 --> 00:08:41,060
so we have to make the better denominator with debt limit as our denominator of F1 is the number of

132
00:08:41,060 --> 00:08:42,070
F1.

133
00:08:42,510 --> 00:08:51,760
Multiply denominator of F2 and then after multiplication is done we have to call simplify function.

134
00:08:52,090 --> 00:08:52,740
Okay.

135
00:08:52,750 --> 00:09:00,550
After multiplication we have to do we have to call simplify function now after degradation let's multiply

136
00:09:00,550 --> 00:09:04,230
a finite F2 so F1 God multiply.

137
00:09:04,690 --> 00:09:13,430
We have to pass off to his argument and now let us spend the value of f1 enough to so F1 not print F1

138
00:09:13,430 --> 00:09:18,310
dart print and similarly large print F2.

139
00:09:18,310 --> 00:09:22,950
So after dot print OK so that's all

140
00:09:30,280 --> 00:09:35,800
so these are the values of our finite F2 after the reason and these are the values of F1 I have two

141
00:09:35,800 --> 00:09:40,420
of them multiplication so we can see here the value of F2 remains unchanged.

142
00:09:40,630 --> 00:09:46,620
And when these two are multiplied we will get this result five twenty five by sixteen.

143
00:09:46,660 --> 00:09:54,640
Okay so go to this code and try to understand each and every line of the code so that's all from my

144
00:09:54,640 --> 00:09:55,470
side.

145
00:09:55,480 --> 00:09:55,900
Thank you.
