1
00:00:01,200 --> 00:00:01,860
Hello everyone.

2
00:00:01,890 --> 00:00:06,380
So in this video I will explain you a question that you guys need to implement.

3
00:00:06,390 --> 00:00:09,490
Basically I want you guys to implement a Polynomial class.

4
00:00:09,580 --> 00:00:12,120
OK so you have to implement the polynomial now.

5
00:00:12,120 --> 00:00:13,510
So what is a polynomial.

6
00:00:13,530 --> 00:00:22,410
So in maths the example of a pilot may lose for example three X squared plus four X cube for X to the

7
00:00:22,410 --> 00:00:25,700
power five minus let's say extra the power seven.

8
00:00:25,710 --> 00:00:28,110
So this is the example of a polynomial limit.

9
00:00:28,160 --> 00:00:30,060
So a polynomial has two values.

10
00:00:30,150 --> 00:00:37,230
So one is the coefficient so when is convenient and the second one is third degree.

11
00:00:37,240 --> 00:00:37,770
Okay.

12
00:00:37,840 --> 00:00:42,610
So in class in the upper limit class we will store two things degrees and the coefficient.

13
00:00:42,610 --> 00:00:44,950
So this is the coefficient and this is the degree.

14
00:00:45,040 --> 00:00:47,080
This is the coefficient and this is the degree.

15
00:00:47,080 --> 00:00:50,010
So what we will do in the polemic class we will take.

16
00:00:50,070 --> 00:00:51,460
We will maintain an 80.

17
00:00:51,700 --> 00:00:55,350
Let's say the name of that is the coefficient.

18
00:00:55,390 --> 00:00:59,800
So how we will store for example if we want to store this polynomial so how we will store.

19
00:01:00,070 --> 00:01:00,310
Okay.

20
00:01:00,320 --> 00:01:02,010
So the maximum degree is seven.

21
00:01:02,020 --> 00:01:06,900
So it will do let's say we have an array of say seven

22
00:01:12,230 --> 00:01:18,440
so let's do t for five six and seven.

23
00:01:18,490 --> 00:01:18,750
Okay.

24
00:01:18,760 --> 00:01:23,680
Just a random size you can take the size of the error to be five and or ten thousand.

25
00:01:23,710 --> 00:01:24,150
Okay.

26
00:01:24,250 --> 00:01:26,770
So the size of that is like you can take anything.

27
00:01:26,890 --> 00:01:28,830
So let's say the size there is seven.

28
00:01:28,840 --> 00:01:31,020
So how we will store this polynomial.

29
00:01:31,240 --> 00:01:36,330
So what we will do for storing so go to index to and store three.

30
00:01:36,410 --> 00:01:39,970
So will the index to install three go to index five.

31
00:01:39,980 --> 00:01:40,880
And store food.

32
00:01:41,150 --> 00:01:45,860
So index five will store food go to index 7 and store 1.

33
00:01:46,580 --> 00:01:47,680
Sorry minus one.

34
00:01:47,690 --> 00:01:49,830
So index 7 it will store minus 1.

35
00:01:49,900 --> 00:01:54,690
The rest of the values will be 0 0 0 0 0 0.

36
00:01:54,790 --> 00:01:55,030
OK.

37
00:01:55,040 --> 00:01:57,440
So this is how we will store a polynomial.

38
00:01:57,440 --> 00:02:07,960
Okay so what we'll use we will use indexes as our degrees and the values we will use them as our coefficient.

39
00:02:08,090 --> 00:02:11,450
Okay so this will be our area.

40
00:02:11,490 --> 00:02:13,650
So in this way we will store our polynomial.

41
00:02:14,610 --> 00:02:15,180
Okay.

42
00:02:15,210 --> 00:02:17,560
And we will take one more data member.

43
00:02:18,060 --> 00:02:23,370
So just like the dynamic at glass we will keep a capacity also.

44
00:02:23,370 --> 00:02:28,750
So in this case the capacity of our arrays it okay the size of that is it.

45
00:02:28,770 --> 00:02:30,660
So in this way we will restore a polynomial.

46
00:02:30,960 --> 00:02:31,160
Okay.

47
00:02:31,170 --> 00:02:34,490
So let's discuss the function that you guys need to implement.

48
00:02:34,530 --> 00:02:42,000
Okay so you guys need to implement some basic basic functions so functions that you guys need to implement

49
00:02:45,340 --> 00:02:54,320
so the first function is default custom built again so first I'm writing the name of all the functions

50
00:02:54,350 --> 00:02:56,180
that you guys need to implement.

51
00:02:56,180 --> 00:02:58,310
So default then copy constructor

52
00:03:03,340 --> 00:03:04,690
and copy assignment operator

53
00:03:11,450 --> 00:03:19,120
Okay so what are default constructively to so we have to do the members as I work private field.

54
00:03:19,130 --> 00:03:26,070
So it will initialize the degree coefficient dairy and it will initialize our capacity let's say if

55
00:03:26,090 --> 00:03:32,610
you want the size to be 10 so that capacity will become 10 and degree of change will be new and then.

56
00:03:33,160 --> 00:03:37,240
Okay so our work is not finished here we have to do one more thing here.

57
00:03:37,390 --> 00:03:43,480
What we have to do we have to put zeros everywhere in the area we have to initialize this degree coefficient

58
00:03:43,480 --> 00:03:44,630
array with all the zeros.

59
00:03:44,630 --> 00:03:51,520
Okay so we have to initialized this degree of shown that if it all the zeros you can see here above.

60
00:03:51,520 --> 00:03:53,890
So 0 0 0.

61
00:03:53,890 --> 00:03:58,360
So initially this array initially this area will contain zero only.

62
00:03:58,630 --> 00:03:59,910
Okay then what do we do.

63
00:03:59,920 --> 00:04:02,560
We will read the polynomial and then we will feel the values.

64
00:04:02,710 --> 00:04:02,940
Okay.

65
00:04:02,950 --> 00:04:07,150
So initially that it contained zeros only okay.

66
00:04:07,240 --> 00:04:13,000
So you have to do two things inside the default constructor first initialize the degree coefficient

67
00:04:13,000 --> 00:04:18,320
that in the capacity area and then put all the zeros put zeros and the degree coefficient Daddy.

68
00:04:18,340 --> 00:04:21,780
Okay so now let us talk about copy constructor.

69
00:04:21,780 --> 00:04:26,470
Let us take an example so suppose my polynomial even looks something like this

70
00:04:32,920 --> 00:04:41,750
let's head to one zero minus 2 0 so 0 1 2 3 4 OK.

71
00:04:41,760 --> 00:04:43,390
So what does this polynomial.

72
00:04:43,470 --> 00:04:44,640
How can we get this polynomial.

73
00:04:44,640 --> 00:04:51,000
So three plus X minus two.

74
00:04:51,380 --> 00:04:52,130
Excuse me.

75
00:04:52,800 --> 00:04:53,070
Okay.

76
00:04:53,090 --> 00:05:01,570
So this is our polynomial so if I write if I'm creating another polynomial polynomial b2 b1.

77
00:05:01,590 --> 00:05:02,340
So what will happen.

78
00:05:02,340 --> 00:05:03,730
Copy constructor will get called.

79
00:05:04,080 --> 00:05:06,990
So essentially no copy constructor creates shallow copy.

80
00:05:06,990 --> 00:05:11,040
So this bill 2.0 that will point towards this area only.

81
00:05:11,190 --> 00:05:12,580
Okay so this is wrong.

82
00:05:13,020 --> 00:05:18,090
So inside the copy constructor we will what we will do we will create deep copy.

83
00:05:18,430 --> 00:05:21,510
We will create deep copy okay.

84
00:05:21,560 --> 00:05:24,230
Now let us talk about copy assignment operator.

85
00:05:24,230 --> 00:05:28,570
So if you will write B2 equals P1 what will happen.

86
00:05:28,580 --> 00:05:35,350
This will do will point towards this area only so we know copy assignment operator also creates shallow

87
00:05:35,360 --> 00:05:37,520
copy.

88
00:05:37,520 --> 00:05:37,820
Okay.

89
00:05:37,850 --> 00:05:42,020
So inside the copy assignment operator we will all audio operator equal.

90
00:05:42,020 --> 00:05:48,590
Operator we will overlord and we will create deep copy exactly the same function as the copy constructor.

91
00:05:49,120 --> 00:05:49,510
Okay.

92
00:05:49,610 --> 00:05:56,050
So after creating these three function let us talk about some more function that you have to implement.

93
00:05:56,150 --> 00:05:58,480
So brain function.

94
00:05:58,850 --> 00:06:02,710
So how you will bring the polynomial that you can see in the equation.

95
00:06:02,780 --> 00:06:08,490
I will explain in the question that in which format you have to like you have to print the polynomial.

96
00:06:08,510 --> 00:06:09,060
Okay.

97
00:06:09,230 --> 00:06:16,490
So after the brain function we we have to overload some operators which operator we will all load plus

98
00:06:16,490 --> 00:06:20,030
operator minus operator and multiply operator.

99
00:06:20,330 --> 00:06:20,560
Okay.

100
00:06:20,570 --> 00:06:24,160
So four plus operator we will write something like this.

101
00:06:24,220 --> 00:06:27,440
Tres B1 plus B2 okay.

102
00:06:27,540 --> 00:06:33,250
So this will go in this it will going argument and the return type will be a polynomial.

103
00:06:33,300 --> 00:06:34,300
So how do I do.

104
00:06:34,310 --> 00:06:39,560
Well normally so let's say the problem will be when is just like we used to do in maths.

105
00:06:39,720 --> 00:06:46,740
So for X minus two weeks the para five and we have another polynomial to so minus X plus let's say x

106
00:06:46,800 --> 00:06:50,400
squared plus X cube plus extra the powerful.

107
00:06:51,120 --> 00:06:58,290
Okay so B when plus Bill 2 What will happen if the degrees are c you can add them so simply three then

108
00:06:58,290 --> 00:07:01,250
minus X then degrees the same.

109
00:07:01,250 --> 00:07:03,720
So you can add them you can add the coefficient.

110
00:07:03,720 --> 00:07:10,470
So 5 x squared plus X cube plus extra the powerful and minus two extra the power five.

111
00:07:10,980 --> 00:07:11,190
Okay.

112
00:07:11,190 --> 00:07:15,580
So this will be given plus B2 which is B3 man what do you have to do.

113
00:07:15,630 --> 00:07:21,060
You have to like update this in the degree coefficient area off you have to update the degree coefficient

114
00:07:21,060 --> 00:07:21,930
area of P3.

115
00:07:21,960 --> 00:07:28,650
Okay so update the beginning of that of B3 accordingly and the same is the case.

116
00:07:28,750 --> 00:07:31,200
The same is the case for negative subtract.

117
00:07:31,470 --> 00:07:33,860
So be 3s B when minus B two.

118
00:07:34,080 --> 00:07:38,120
I hope you know how to subtract two but let me leave their degrees I assume you can separate the confident

119
00:07:38,500 --> 00:07:44,430
and for multiplication we have to do similar kind of stuff we will write B threes Bill and multiply

120
00:07:44,450 --> 00:07:49,620
b do so the multiplication will be a little bit tough it will be like a little bit tricky.

121
00:07:49,710 --> 00:07:55,830
So first like you can do it on pen and paper you can analyse how the things are working and then I will

122
00:07:55,830 --> 00:07:56,850
suggest you to write the code.

123
00:07:56,940 --> 00:08:01,440
Okay so this will be like a little more complex and a little bit complex.

124
00:08:01,680 --> 00:08:05,160
And now let us talk about the last function that you have to create.

125
00:08:05,250 --> 00:08:06,510
So we have to create.

126
00:08:06,750 --> 00:08:09,470
We have to implement a set coefficient function.

127
00:08:09,720 --> 00:08:12,710
So what this set conversion function really do.

128
00:08:12,750 --> 00:08:15,920
So this set coefficient function.

129
00:08:16,050 --> 00:08:16,490
Okay.

130
00:08:16,500 --> 00:08:26,620
So how we will write this so even Dart said coefficient so this search coefficient function will take

131
00:08:26,680 --> 00:08:28,090
two things as input.

132
00:08:28,180 --> 00:08:31,600
First one is the degree and the second one is the coefficient.

133
00:08:31,660 --> 00:08:49,960
So let's say B one is let's say the capacity is 6 0 1 2 3 4 and 5 and let's see the values are 1 0 minus

134
00:08:49,960 --> 00:08:54,790
2 again 0 1 and 0.

135
00:08:54,790 --> 00:09:03,320
Okay so we will call the function b one dart said coefficient and we will give degree and coefficient

136
00:09:03,320 --> 00:09:08,990
as input Okay so let's say the degrees 3 and the coefficient is 5.

137
00:09:09,010 --> 00:09:10,120
So what do we do.

138
00:09:10,180 --> 00:09:17,410
Go to index tree and make the coefficient 5 and let's say the values are degrees 4 and the coefficients

139
00:09:17,430 --> 00:09:23,240
then so go to index for make the coefficient and override the coefficient.

140
00:09:23,270 --> 00:09:25,170
Okay we have to override the coefficient.

141
00:09:25,190 --> 00:09:30,630
Now the problem will come here is let's say this size the capacity is 6.

142
00:09:30,650 --> 00:09:32,480
So the valid degrees are 0 to 5.

143
00:09:32,480 --> 00:09:37,210
Only okay if the capacity receives the value degrees of zero to five.

144
00:09:37,270 --> 00:09:46,650
And now if I do degrees 7 and let's say the coefficient is 20 so degrees 7 is not a valid index.

145
00:09:46,660 --> 00:09:47,690
Okay so what.

146
00:09:47,890 --> 00:09:53,330
So what is happening here is degree is greater than the capacity okay.

147
00:09:53,330 --> 00:09:54,650
Degrees good in the capacity.

148
00:09:54,680 --> 00:10:01,350
So in this case what we will do we will double the size of the array we work double the size of the

149
00:10:01,350 --> 00:10:03,720
area and then we will again check.

150
00:10:03,720 --> 00:10:08,480
We will check if their degree is less than the capacity then it's okay.

151
00:10:08,550 --> 00:10:15,750
Otherwise in the edit part we will again double the size of the 80 we will again double the size and

152
00:10:15,780 --> 00:10:16,940
we will again check.

153
00:10:17,000 --> 00:10:19,890
Then again double again check this will continue.

154
00:10:19,920 --> 00:10:24,170
Okay daily until we reach this condition.

155
00:10:24,170 --> 00:10:28,730
So in these two cases the degree is less than the capacity.

156
00:10:28,730 --> 00:10:32,780
So this is fine but in this case the degrees are good at any capacity.

157
00:10:32,810 --> 00:10:36,990
So just like in the dynamic at a class we will double the size.

158
00:10:37,070 --> 00:10:43,150
But here after doubling the size you have to continuously check if a degree is less than the capacity.

159
00:10:43,220 --> 00:10:43,480
Okay.

160
00:10:43,490 --> 00:10:45,400
For example.

161
00:10:45,410 --> 00:10:47,590
So initially the size is six.

162
00:10:47,600 --> 00:10:49,940
So let's say my value is 14.

163
00:10:49,970 --> 00:10:51,660
Let's say the value of degrees is 14.

164
00:10:52,040 --> 00:10:57,100
So I will double the size the size will become cool then I will check to L is less than 14 so I will

165
00:10:57,200 --> 00:10:58,350
again double the size.

166
00:10:58,400 --> 00:10:59,520
So 24.

167
00:10:59,540 --> 00:11:01,400
Now 14 is less than 24.

168
00:11:01,820 --> 00:11:05,120
So now we can override the values.

169
00:11:05,120 --> 00:11:06,350
We can override the coefficient.

170
00:11:06,770 --> 00:11:07,660
Okay so.

171
00:11:08,020 --> 00:11:10,310
And so these are all functions that you have to implement.

172
00:11:10,340 --> 00:11:12,640
Okay so let's see where the less structure have a code.

173
00:11:13,280 --> 00:11:19,430
So we have a class polynomial so inside the class polynomial we discussed that there will be two private

174
00:11:19,430 --> 00:11:22,780
properties first the dynamic Gary.

175
00:11:22,880 --> 00:11:27,890
So let's say the name is beginning coefficient and the second is the capacity.

176
00:11:28,110 --> 00:11:28,630
Okay.

177
00:11:28,790 --> 00:11:31,070
So these are the two private properties.

178
00:11:31,070 --> 00:11:39,990
And now what we have to do we have to create some functions so the first function is default constructor

179
00:11:41,140 --> 00:11:42,400
inside default constructor.

180
00:11:42,400 --> 00:11:48,740
We have to do two things we have to initialize negative coefficient initialize capacity and put zeros

181
00:11:48,860 --> 00:11:56,160
in the beginning coefficient Eddie then we need copy constructor why we need a copy constructor because

182
00:11:56,190 --> 00:12:03,590
we want to create deep copy then we need to copy assignment operator we have to overload copy assignment

183
00:12:03,590 --> 00:12:09,990
operator just like we did in the rich class in the dynamic edit class.

184
00:12:10,010 --> 00:12:19,080
Okay so copy assignment operator you have to overload so after that you have to right print function

185
00:12:19,110 --> 00:12:27,520
which would be very easy see the question to see what is the brand format and then you have to set competent

186
00:12:27,520 --> 00:12:29,650
function that will take two arguments.

187
00:12:29,650 --> 00:12:30,390
Sorry.

188
00:12:30,430 --> 00:12:35,590
Yes it will take two arguments degree and coefficient then you have to overload some operator so plus

189
00:12:35,590 --> 00:12:42,760
operator you have to overload negative operator you have to overload and then multiply operator you

190
00:12:42,760 --> 00:12:43,580
have to overload.

191
00:12:43,630 --> 00:12:47,320
So this will be our structure okay.

192
00:12:47,660 --> 00:12:50,510
So these are all functions you have to implement.

193
00:12:51,410 --> 00:12:54,760
Okay so I hope you understood this question.

194
00:12:54,800 --> 00:12:55,850
Good luck.

195
00:12:55,850 --> 00:12:56,390
Thank you.
