1
00:00:00,600 --> 00:00:09,030
In this lesson, we are going to talk about one of the overloaded logical operators we have already

2
00:00:09,030 --> 00:00:09,880
exposed.

3
00:00:09,900 --> 00:00:16,290
The assignment operator and some other mathematical operators like the plus and minus.

4
00:00:17,220 --> 00:00:24,450
Of course, there are other mathematical binary ones that you can use, like the multiply and even the

5
00:00:24,460 --> 00:00:25,950
divide as well.

6
00:00:26,940 --> 00:00:32,460
But I'm not going over those because you kind of can realize from the plus and minus how you can set

7
00:00:32,460 --> 00:00:32,970
these up.

8
00:00:34,250 --> 00:00:39,530
So what we're going to do kind of a similar thing with biological operators today, I'm going to go

9
00:00:39,530 --> 00:00:45,710
over the quality operator, which is not one equals sign, but two equals sign, right?

10
00:00:45,740 --> 00:00:47,900
That's what you use to check if something is equal.

11
00:00:48,410 --> 00:00:53,510
And just like before, we're going to be comparing objects, right, we're going to see if one car object

12
00:00:53,510 --> 00:01:00,410
is equal to another car object and we are going to decide the logic for the operator for that.

13
00:01:00,410 --> 00:01:05,720
Like, what does it mean to compare one car to another car for equality?

14
00:01:06,320 --> 00:01:10,710
You can also overload the less than and greater than less than equal to greater than equal to.

15
00:01:11,280 --> 00:01:12,800
And a very similar fashion.

16
00:01:13,130 --> 00:01:16,400
So these are going to be logical operators, right?

17
00:01:16,400 --> 00:01:22,220
So they're going to say either true or false, like something is either greater than or less than something

18
00:01:22,640 --> 00:01:25,790
is either equal to or not equal to right.

19
00:01:27,530 --> 00:01:33,500
So because of that, we are going to say that this is going to return a Boolean, so we'll say BOOL

20
00:01:34,010 --> 00:01:41,270
and then I'm going to type operator error just like before, but I'm going to put two equal signs here

21
00:01:42,200 --> 00:01:49,010
and then I'm going to put the same object here when passing a constant car object by reference.

22
00:01:51,750 --> 00:01:56,940
And so are a quality operator is going to look like this as far as a prototype, you notice, I mean,

23
00:01:56,940 --> 00:02:00,900
cargo a year, so now we've got our prototype set up.

24
00:02:01,320 --> 00:02:07,440
Let's go to the CP implementation file so we can implement our operator.

25
00:02:08,970 --> 00:02:10,740
So I guess some space to say here.

26
00:02:10,830 --> 00:02:17,880
So I'm just going to say pool, but car from the scope resolution and I'll say operator equals equals,

27
00:02:18,630 --> 00:02:27,540
we need to put our parameter right so our cars car and of and then now we can think about our implementation.

28
00:02:28,710 --> 00:02:33,630
So what do you think we should put to see if a car is equal to another car?

29
00:02:34,350 --> 00:02:41,490
I think that in my mind, a car would be the same as another car if it was the same model, the same

30
00:02:41,490 --> 00:02:42,060
brand.

31
00:02:44,400 --> 00:02:47,760
The same paint color.

32
00:02:48,780 --> 00:02:52,230
And probably the same upgrade features, right?

33
00:02:53,960 --> 00:03:00,710
I think that it would be fine if the car had different miles, because one thing if one of the vehicle

34
00:03:00,710 --> 00:03:05,090
to another in this instance, at least this is the way I'm going to set it up is that, you know, maybe

35
00:03:05,090 --> 00:03:17,630
someone has a white Subaru Outback, White Subaru Outback with, uh, let's see, like some media upgrade

36
00:03:17,630 --> 00:03:21,530
or something like that, if someone else has a white suit outback with some media upgrade.

37
00:03:21,890 --> 00:03:27,210
It's pretty much like the same car, even if that might have like less miles or more miles.

38
00:03:27,230 --> 00:03:30,180
I think it would be safe to say, Oh, you have the same car as me, you know?

39
00:03:31,460 --> 00:03:37,100
So with that in mind, let's write some code in here and to compare those things, right?

40
00:03:37,120 --> 00:03:44,000
So just like the other operators, we're going to continue with the pattern of looking at the this object's

41
00:03:44,870 --> 00:03:45,770
data members.

42
00:03:46,580 --> 00:03:46,900
Right.

43
00:03:46,910 --> 00:03:50,890
So model paint number or painkiller brand?

44
00:03:50,900 --> 00:03:57,200
So here we got model right and this object's model, this object's brand, and then we have to compare

45
00:03:57,200 --> 00:04:04,490
it to the parameter object and its attributes or data members.

46
00:04:05,680 --> 00:04:06,820
So let's go ahead and do that.

47
00:04:07,720 --> 00:04:12,040
So first off, I'm going to put an a into just kind of looks a little bit like this up here, but we're

48
00:04:12,040 --> 00:04:14,620
going to compare the paint color as well.

49
00:04:14,920 --> 00:04:23,490
And we're also going to compare the upgrade code size to the object that past objects of code size.

50
00:04:24,830 --> 00:04:30,470
So let's go ahead and do that, so I'm going to say if the model is equal to you.

51
00:04:30,500 --> 00:04:33,110
I'm Jake Scott model

52
00:04:36,710 --> 00:04:50,420
and the brand is equal to object brand and we'll say the paint color.

53
00:04:51,080 --> 00:04:58,130
It's also equal to the past objects, paint color and then it's getting me long hair with you.

54
00:04:58,130 --> 00:04:59,570
And no one, I'm going to say.

55
00:04:59,570 --> 00:05:04,100
And what I want to do now is I want to check to see if it has the same upgrades.

56
00:05:04,400 --> 00:05:10,730
But what I'm going to do right off the bat is just see if they have the same size because if they don't

57
00:05:10,730 --> 00:05:16,970
have that, if they don't even have the same amount of upgrade codes so they don't have the same amount

58
00:05:16,970 --> 00:05:19,600
of upgrades, then they're not the same car, right?

59
00:05:19,640 --> 00:05:23,690
Like if one has a media upgrade and you know, that's one item in there.

60
00:05:23,900 --> 00:05:30,440
And then the other one has like a media upgrade and like seats package or something, then you know,

61
00:05:30,770 --> 00:05:35,570
that has two items and the upgrades upgrade codes list.

62
00:05:36,230 --> 00:05:40,430
Then you know that they're not the same just because they're not the same size one lately has one upgrade.

63
00:05:40,440 --> 00:05:47,120
So that's why I can just put that in here, and we will be able to say that it's false if any of these

64
00:05:47,330 --> 00:05:49,250
fail to condition.

65
00:05:51,250 --> 00:05:59,620
So I will say, and we'll do upgrade codes, and since it's a point I to do with aero and the aero size

66
00:06:00,070 --> 00:06:07,690
is equal to the object that upgrade codes aero size.

67
00:06:09,580 --> 00:06:09,970
Cool.

68
00:06:10,270 --> 00:06:12,970
So now we have everything set up.

69
00:06:12,970 --> 00:06:19,960
I'm going to put some brackets here and then now I need to actually see if the upgrade codes are similar

70
00:06:20,350 --> 00:06:20,830
or not.

71
00:06:21,280 --> 00:06:30,820
So I'm going to make a foil loop and I'm just going to say intake or zero, and I is less than upgrade

72
00:06:30,820 --> 00:06:31,830
code size.

73
00:06:31,840 --> 00:06:36,370
I can choose either or right, because at this point, if it makes it inside the if, that means that

74
00:06:36,370 --> 00:06:43,120
they have the same size, the upgrade codes vector has the same size for both objects.

75
00:06:45,670 --> 00:06:53,110
So do I as less than upgrade toaster size so we can go through all of them and then I'll do it first.

76
00:06:54,760 --> 00:07:00,760
And then what we want to do in here is what I'm going to do is if I ever see any that are dissimilar,

77
00:07:01,570 --> 00:07:10,450
I'm going to immediately return false because I know that if they if you suddenly see something that

78
00:07:10,630 --> 00:07:14,560
doesn't match, then that's going to be false.

79
00:07:14,920 --> 00:07:21,640
This kind of would assume that they have the upgrade codes added in the same order.

80
00:07:22,780 --> 00:07:31,960
You could go through and see, I guess, to see if one even exists in the other, so we could do that.

81
00:07:33,280 --> 00:07:35,800
So that would be kind of like checking to see.

82
00:07:38,810 --> 00:07:45,470
For each upgrade code and one, if the upgrade code existed and the other one.

83
00:07:46,790 --> 00:07:50,570
So you'd have to do kind of a nested loop for that.

84
00:07:51,660 --> 00:07:53,730
So we could have some upgrade code

85
00:07:57,420 --> 00:07:58,410
equals

86
00:08:01,920 --> 00:08:03,360
upgrade codes.

87
00:08:06,850 --> 00:08:08,470
So I'll have to do reference this.

88
00:08:12,770 --> 00:08:18,170
So I'll say upgrade codes, I sort of mean integer.

89
00:08:20,260 --> 00:08:24,340
And then what I can do is do some other loop here.

90
00:08:24,570 --> 00:08:27,340
So let's say in J equals zero.

91
00:08:28,900 --> 00:08:32,620
And then I will do, I will say.

92
00:08:36,350 --> 00:08:41,570
O.J. is less than and I can just do upgrade codes.

93
00:08:41,750 --> 00:08:43,790
So this is really going through the other one.

94
00:08:44,720 --> 00:08:53,750
So I guess just to make it seem nice, I could say object sort of gay codes exercise, but we know that

95
00:08:53,750 --> 00:08:54,740
they're the same length, right?

96
00:08:54,740 --> 00:08:58,010
Because if it had entered in here, they would be the same length.

97
00:08:58,490 --> 00:09:11,960
So I'll do a J Plus plus and then what I want to do here is I want to see if the upgrade codes I is

98
00:09:11,960 --> 00:09:19,000
inside of the wall exists inside of here at all.

99
00:09:19,010 --> 00:09:24,740
So I would probably want some other Boolean here, so I might just have like bore

100
00:09:28,790 --> 00:09:31,610
the same equals.

101
00:09:34,250 --> 00:09:40,970
Let's just say I want probably want to say false to start it off as because I want to go through here

102
00:09:41,330 --> 00:09:45,220
and if I see the matching code, I'll just set that to true.

103
00:09:46,160 --> 00:09:49,940
So I'll put some f here and I'll say if the

104
00:09:52,580 --> 00:09:53,540
object.

105
00:09:54,290 --> 00:10:00,080
So what we're going to have to do is, do you reference this object dot upgrade codes?

106
00:10:00,230 --> 00:10:02,530
So that will be referenced in parentheses.

107
00:10:02,540 --> 00:10:19,880
And we'll say object of great codes, IE is equal to code, then we will say that the same equals true.

108
00:10:21,640 --> 00:10:27,370
And then each time we'll probably have to reset this to false.

109
00:10:28,270 --> 00:10:35,740
So after this, Lou, I'll go ahead and just say the same.

110
00:10:37,140 --> 00:10:41,460
I actually, I guess, like right before we will set it to boss.

111
00:10:41,470 --> 00:10:46,840
So I'll say the same people also each time we can kind of refresh that.

112
00:10:50,010 --> 00:10:53,040
So make sure that they have.

113
00:10:56,690 --> 00:11:01,400
Did that that upgrade code or at least exist inside there each time?

114
00:11:02,390 --> 00:11:07,820
So we're going to have to go through and we're going to have to check that for each one of them, so

115
00:11:08,240 --> 00:11:11,210
each one of these upgrade codes needs to be checked for.

116
00:11:13,040 --> 00:11:20,570
And so basically after this, we will want to check to see if one of them wasn't contained in there.

117
00:11:21,200 --> 00:11:23,690
So we could put an f here.

118
00:11:23,690 --> 00:11:25,190
And we could say if

119
00:11:28,130 --> 00:11:36,920
let's just say it's not the same, because that means that if it was false, then we would know that

120
00:11:36,920 --> 00:11:40,280
it wasn't contained in there because it would have never gotten set to true.

121
00:11:41,150 --> 00:11:46,250
And so if we can say, if not the same, then we could immediately just return false from this function,

122
00:11:46,250 --> 00:11:49,620
because that means that we never found the upgrade code, right.

123
00:11:49,640 --> 00:11:53,210
We're looking at each one of these upgrade codes and trying to see if it exists in here.

124
00:11:55,980 --> 00:12:00,060
So we would return false if something was ever not the same, right?

125
00:12:00,460 --> 00:12:03,360
So that means it didn't get set to truly reset it back up here.

126
00:12:04,320 --> 00:12:11,160
If we're able to successfully go through all of these, then we get rid of the space here.

127
00:12:12,060 --> 00:12:17,340
Then that means that we hadn't returned false at any point, and that means that all of the stuff is

128
00:12:17,340 --> 00:12:18,000
the same.

129
00:12:18,660 --> 00:12:24,900
All of these are the same, and we notice all the upgrade codes and one of them exist in the other.

130
00:12:24,910 --> 00:12:27,300
So at this point, I can just return true.

131
00:12:28,350 --> 00:12:33,750
Then we need to add one last return down here because if it never, if it didn't return true here,

132
00:12:33,750 --> 00:12:35,490
let's say this.

133
00:12:38,260 --> 00:12:44,080
If right here evaluated to foster one of these was not matching, then we're going to return false down

134
00:12:44,080 --> 00:12:44,350
here.

135
00:12:47,090 --> 00:12:47,450
Cool.

136
00:12:47,660 --> 00:12:50,480
So that should be good to go.

137
00:12:52,280 --> 00:12:53,900
So I'm going to make some space here.

138
00:12:56,840 --> 00:12:57,470
All right.

139
00:12:58,800 --> 00:13:07,140
So I'm going to go ahead and save this, and I go ahead and say this, and then let's go over to Maine

140
00:13:07,140 --> 00:13:08,400
and let's add a little check.

141
00:13:08,940 --> 00:13:11,700
So this is how we're going to use it and the client side code.

142
00:13:12,720 --> 00:13:17,810
So what I'm going to do right here is just compare car to and car for to see if they're the same income.

143
00:13:17,820 --> 00:13:23,280
Then we can compare car five and car four because affect different right car five has an upgraded five.

144
00:13:23,670 --> 00:13:28,440
So we know it's not going to be the same as Ford because Ford never got that upgrade five added to it.

145
00:13:29,370 --> 00:13:33,330
But Cartoon Car four should be the same because car for here.

146
00:13:34,410 --> 00:13:41,010
Did car plus car for and what actually happened there was that remember we have that plus operator that

147
00:13:41,010 --> 00:13:45,480
returns like the better one that has more upgrades and CAR two had better upgrades.

148
00:13:45,480 --> 00:13:51,210
So car to essentially car for essentially became car two after this line right here.

149
00:13:51,210 --> 00:13:55,110
So those should be the same so we can put something right here.

150
00:13:55,110 --> 00:14:12,660
And we could say if car for equals equals car two, then we can print out car or or, you know, we'll

151
00:14:12,660 --> 00:14:17,700
just say car four and car to the same

152
00:14:21,810 --> 00:14:22,180
cool.

153
00:14:23,010 --> 00:14:26,880
So let's go ahead and test this out.

154
00:14:26,880 --> 00:14:28,950
So I'm going to go ahead and save this.

155
00:14:29,520 --> 00:14:31,140
Hopefully don't get any errors.

156
00:14:32,250 --> 00:14:36,900
I'm just going to do C++ start CBP.

157
00:14:36,900 --> 00:14:40,050
So it's both main and courtesy.

158
00:14:40,060 --> 00:14:43,890
We get compiled and I'm just going to overwrite this man that he exceeded here.

159
00:14:43,890 --> 00:14:46,540
So I'll say, and you see.

160
00:14:48,690 --> 00:14:51,090
So great looks like it compiled with no problems.

161
00:14:51,480 --> 00:14:53,900
Let's go ahead and run this easy.

162
00:14:56,520 --> 00:14:58,950
So let's go ahead and see what the results are.

163
00:15:00,690 --> 00:15:05,100
Cool, so we actually see this print out here, car four and car two are the same.

164
00:15:05,820 --> 00:15:11,760
And that's because like if you look at the we can actually show the upgrades, we know that they're

165
00:15:11,760 --> 00:15:12,990
going to be a.

166
00:15:14,360 --> 00:15:16,970
These values will be the same because we make her to right here.

167
00:15:17,120 --> 00:15:18,440
It's a white Ford Fiesta.

168
00:15:19,010 --> 00:15:23,210
And then right here we say car four equals car two, so they're totally the same there.

169
00:15:23,890 --> 00:15:27,530
Then what we do is we add upgrades to car two, but not to car for.

170
00:15:28,450 --> 00:15:34,300
But then this right here gives us back the same, OK, so we show car for upgrades below, right?

171
00:15:35,020 --> 00:15:40,570
It says one to and four, which is what Car two would have had, because in our constructor up here,

172
00:15:41,800 --> 00:15:45,800
we know that we give everything of code one right off the bat, right?

173
00:15:45,820 --> 00:15:48,370
We have this upgrade coast aero pushback.

174
00:15:48,370 --> 00:15:53,470
One in our constructors there signed multiple constructors.

175
00:15:55,040 --> 00:16:00,980
So we know that Car two, after adding to influence of the upgrades, is going to have one two in four.

176
00:16:01,070 --> 00:16:08,540
And then right here on Line 17, we show what Car four has after this line with the plus operator overloaded.

177
00:16:10,060 --> 00:16:12,010
And so what you can see here.

178
00:16:13,690 --> 00:16:20,260
Is that at that point in time here, it's this one right here, the showing car for upgrades below,

179
00:16:20,260 --> 00:16:24,370
it's the first time that we print this out and it says one two four.

180
00:16:25,300 --> 00:16:28,000
So that's why we see this one two four here.

181
00:16:31,130 --> 00:16:33,630
And we print out, let's see.

182
00:16:33,840 --> 00:16:36,720
So show upgrades for car for.

183
00:16:39,580 --> 00:16:47,530
See, and it'll have the same there, I think, actually so OK, here it no, this is a cartoon show

184
00:16:47,530 --> 00:16:48,010
upgrades.

185
00:16:48,790 --> 00:16:51,520
So I can go ahead and.

186
00:16:51,670 --> 00:16:53,170
Well, here we can just kind of track it.

187
00:16:53,170 --> 00:16:55,120
So car for show of grades, prints, the one.

188
00:16:55,600 --> 00:17:00,370
Then we add two and four to car two and we say car to show a grade so that prints one, two four.

189
00:17:01,120 --> 00:17:03,340
And then we have the.

190
00:17:06,200 --> 00:17:13,190
Car four down here showing the upgrades, and so everything is pretty much set up.

191
00:17:18,620 --> 00:17:23,450
So we probably should also show when it's not true.

192
00:17:23,480 --> 00:17:31,580
Right, so we can count, we saw when it's true, they have the matching, all the matching data members

193
00:17:31,580 --> 00:17:34,040
and the same upgrade codes as well.

194
00:17:34,550 --> 00:17:37,910
So let's go ahead and like if we put car five.

195
00:17:39,380 --> 00:17:47,090
Equals car to then these should not match so right, because Car five has added upgrade five, so that

196
00:17:47,090 --> 00:17:47,970
shouldn't match there.

197
00:17:48,530 --> 00:17:54,830
So I'll go ahead and save this and then I'll go and run this after compiling it, of course.

198
00:17:55,490 --> 00:17:59,980
So we do this and let's scroll up a little bit.

199
00:18:00,950 --> 00:18:03,940
So we noticed that this is showing car for upgrades below.

200
00:18:03,950 --> 00:18:06,080
This is the first it shows twice, right?

201
00:18:06,500 --> 00:18:10,010
Here's the first one, and then we don't see this printout.

202
00:18:10,300 --> 00:18:12,050
That's because it's not true.

203
00:18:13,510 --> 00:18:19,760
You only could say some kind of lights like change this to not equal to you.

204
00:18:20,240 --> 00:18:25,100
So we could say, Well, we can't actually do that because we don't have the equal operator.

205
00:18:25,100 --> 00:18:30,350
So we'll actually say else as to see out.

206
00:18:32,600 --> 00:18:36,800
The cars are not the same.

207
00:18:37,220 --> 00:18:39,470
And I'll actually just change this to you.

208
00:18:41,350 --> 00:18:43,490
The cars are the same.

209
00:18:46,430 --> 00:18:46,880
Cool.

210
00:18:47,300 --> 00:18:52,370
So let me go ahead and save this and compile and run again.

211
00:18:53,360 --> 00:18:58,700
OK, so we scroll up a little bit and we see the cars are not the same prints out.

212
00:18:58,700 --> 00:19:05,930
And that's because Car five, even though, well, actually, no, it doesn't even have the complete

213
00:19:05,930 --> 00:19:08,300
matching outfits, so it doesn't even have the same painkiller.

214
00:19:08,300 --> 00:19:10,010
So it's for sure not going to match.

215
00:19:10,010 --> 00:19:16,790
But even if we were to put white here well for a white Ford Fiesta, it still wouldn't work because

216
00:19:16,790 --> 00:19:18,460
they don't have matching attributes.

217
00:19:18,470 --> 00:19:27,680
So if I put white here and I go ahead and save this and then I compile it and run it, if we choose

218
00:19:27,680 --> 00:19:36,020
up here, we noticed it still says the cars are not the same if I was to not add.

219
00:19:37,580 --> 00:19:45,890
This here, like if CAR two had let's just say I comment this out, right?

220
00:19:47,880 --> 00:19:52,500
And we're actually I have this one to upgrade, right, and I just add five.

221
00:19:53,940 --> 00:19:56,910
So a car five is going to be pretty much the same.

222
00:19:57,210 --> 00:20:01,530
And then I add five to two and I add five to car five.

223
00:20:02,100 --> 00:20:03,750
Then they should be the same, right?

224
00:20:04,110 --> 00:20:06,030
So let's go ahead and save this.

225
00:20:07,020 --> 00:20:08,010
Let's compile it.

226
00:20:08,820 --> 00:20:09,510
Let's run it.

227
00:20:10,940 --> 00:20:14,540
Let's cruise up here and it says the cars are the same now.

228
00:20:15,950 --> 00:20:21,570
OK, so you can actually do similar things with the other operators, so you notice there's like not

229
00:20:21,590 --> 00:20:29,780
equal as well, but we can have like less than or greater than or greater than or equal to or less than

230
00:20:29,780 --> 00:20:30,530
or equal to.

231
00:20:31,130 --> 00:20:34,660
And you're going to end up implementing them in a very similar way.

232
00:20:34,670 --> 00:20:35,120
So.

233
00:20:36,690 --> 00:20:41,100
We scroll down here to the operator, the quality operator we made.

234
00:20:41,490 --> 00:20:46,980
Then you could basically choose your own logic for comparing like a car, whether it was greater than

235
00:20:46,980 --> 00:20:51,900
or less than and probably be very similar to our class, right, because we tried to find out what the

236
00:20:51,900 --> 00:20:52,860
better car was.

237
00:20:52,860 --> 00:20:59,460
But rather than returning a new car object here, like we wanted to just give the better car back,

238
00:20:59,730 --> 00:21:01,680
you can actually just return of Boolean right?

239
00:21:01,680 --> 00:21:04,770
Because less than and greater, then that's going to be a Boolean.

240
00:21:05,970 --> 00:21:08,820
So, you know, is it less than true or false, right?

241
00:21:08,850 --> 00:21:09,630
Is it greater then?

242
00:21:09,630 --> 00:21:10,400
That's true or false.

243
00:21:10,410 --> 00:21:15,960
So you would just return Boolean once you find out whether one is greater than the other.

244
00:21:16,200 --> 00:21:22,250
You can just use something similar to this and then you can return true or false instead of the car

245
00:21:22,260 --> 00:21:26,490
object so that that would kind of be like what those less than a great advance would be.

246
00:21:26,850 --> 00:21:31,830
And I challenge you to definitely try to implement those yourself.

247
00:21:32,490 --> 00:21:37,050
And because, you know, all these operators are very important and they come in handy a lot and they

248
00:21:37,050 --> 00:21:44,190
make kind of your code base really nice because the user can go ahead and just use these basic operators

249
00:21:44,190 --> 00:21:47,970
to perform operations on your abstract data types.

250
00:21:49,410 --> 00:21:56,400
So with that, I will see you in the next lecture where we're going to go over a last type of overloaded

251
00:21:56,400 --> 00:21:57,240
operators.

252
00:21:58,110 --> 00:22:03,180
And then after that, we will kind of move on to some other object oriented programming concepts.

253
00:22:03,840 --> 00:22:04,080
All right.

254
00:22:04,080 --> 00:22:05,790
So with that, I'll see you in the next lecture.
