1
00:00:00,240 --> 00:00:06,570
All right, so now it's time for us to start a very big topic, which is object oriented programming.

2
00:00:07,170 --> 00:00:13,980
This is a programming style that you will most likely use most of the time in your career or whatever

3
00:00:13,980 --> 00:00:19,290
you might do when you're trying to make your own applications or anything like that.

4
00:00:19,290 --> 00:00:26,400
Object oriented programming is kind of the common style of programming these days.

5
00:00:26,400 --> 00:00:29,460
We have been doing procedural programming until now.

6
00:00:30,510 --> 00:00:35,040
And that's kind of just using functions and loops and all that stuff, and we're still going to use

7
00:00:35,040 --> 00:00:35,370
that.

8
00:00:35,970 --> 00:00:42,420
But we're going to add some kind of new structure and some new things into the mix and there's object

9
00:00:42,420 --> 00:00:43,050
going programming.

10
00:00:43,060 --> 00:00:44,820
So let's go ahead and get into it.

11
00:00:46,290 --> 00:00:52,790
Some have to use a decent amount of analogies to correctly explain object or initial programming.

12
00:00:52,830 --> 00:00:55,830
I think that's the easiest way to explain the use for it.

13
00:00:56,970 --> 00:01:03,990
So a common analogy for object oriented programming, also known as OLP, is the relationship between

14
00:01:03,990 --> 00:01:05,040
cars and drivers.

15
00:01:05,040 --> 00:01:05,940
So that's what I'm going to use.

16
00:01:05,950 --> 00:01:09,210
There's a lot of analogies you can use, but this is just one of many.

17
00:01:10,380 --> 00:01:16,980
So think about when you enter a car, you have things like a gear shift, a gas pedal, a brake pedal

18
00:01:16,980 --> 00:01:19,110
steering wheel ignition.

19
00:01:19,590 --> 00:01:23,130
This is all part of the interface for you to operate the vehicle.

20
00:01:23,910 --> 00:01:26,850
So like when you press the gas, the car moves right.

21
00:01:26,850 --> 00:01:32,730
You don't really have to think about exactly how it's moving from the pedal being pressed to the car.

22
00:01:32,730 --> 00:01:39,570
Actually, going forward, you just concern yourself with wanting it to move and pressing the pedal.

23
00:01:39,570 --> 00:01:40,740
That's all you have to do, right?

24
00:01:41,520 --> 00:01:46,230
So the engineers of that car, the one that is the ones that had to design the system that moves the

25
00:01:46,230 --> 00:01:48,300
vehicle and you press the gas pedal, right?

26
00:01:48,570 --> 00:01:52,710
We got some fuel being injected, a bunch of stuff going on in the engine and all of that.

27
00:01:53,550 --> 00:01:57,840
So when you bought the car, you just expect it to work with this simple interface, right?

28
00:01:57,870 --> 00:01:59,860
What was the reason why you bought the car?

29
00:01:59,880 --> 00:02:01,950
Well, you needed to get from A to B.

30
00:02:01,950 --> 00:02:03,680
You probably wanted a nice car.

31
00:02:03,690 --> 00:02:05,610
You wanted to fit people and whatever.

32
00:02:05,610 --> 00:02:08,430
But the main purpose is to get places right.

33
00:02:09,420 --> 00:02:12,570
That's why you buy a car because you need to get places fast.

34
00:02:13,570 --> 00:02:19,480
So you needn't really concern yourself with the blueprints and internals of the car and how it was designed.

35
00:02:19,990 --> 00:02:26,170
But as engineers, we now need to concern ourselves with the design of these objects.

36
00:02:26,320 --> 00:02:32,200
If we're engineering the car, we need to now consider the design and the blueprint.

37
00:02:33,970 --> 00:02:36,010
So how does this relate to software, though?

38
00:02:37,300 --> 00:02:43,630
Well, we can still continue on with the car analogy and think about it kind of in a digital sense.

39
00:02:44,170 --> 00:02:45,910
So what makes up a car?

40
00:02:45,940 --> 00:02:52,420
If we were to design a software version of it, what data would be associated with that car and what

41
00:02:52,420 --> 00:02:54,060
actions would be performed?

42
00:02:54,070 --> 00:02:59,650
So you can use what you know so far about strikes, because that's kind of a way of collecting data,

43
00:02:59,680 --> 00:02:59,950
right?

44
00:02:59,980 --> 00:03:04,710
We had an abstract data type with our strikes.

45
00:03:04,720 --> 00:03:08,830
That was when that's kind of how we introduce structure, right?

46
00:03:08,830 --> 00:03:11,500
It was for us to be able to create an abstract data type.

47
00:03:12,010 --> 00:03:13,930
And we had some variables inside of it, right?

48
00:03:14,260 --> 00:03:19,090
So let's think about just what a car struct would look like as an abstract data type.

49
00:03:21,550 --> 00:03:26,860
So here we have struct cars, so here are some things we can have in it, you know, it's not limited

50
00:03:26,860 --> 00:03:32,110
to this, of course, but I'm just for simplicity's sake, only putting a few things in here.

51
00:03:32,110 --> 00:03:35,600
We have like fuel could be a float type, right?

52
00:03:35,620 --> 00:03:40,810
We can have a paint color, which is a string like the car, blue or red or something.

53
00:03:42,610 --> 00:03:47,980
And then the model of the car is a string.

54
00:03:47,980 --> 00:03:52,440
And then the odometer could also be an integer, you know, because how many miles are in the car,

55
00:03:52,480 --> 00:03:53,920
kilometers or whatever you prefer?

56
00:03:55,340 --> 00:04:02,420
So this is all data, right, like these are just kind of static data members here of this car struct,

57
00:04:02,450 --> 00:04:05,090
but we don't really have any actions, right?

58
00:04:05,120 --> 00:04:06,740
We don't have any functions.

59
00:04:07,580 --> 00:04:09,380
So what about the actions?

60
00:04:11,060 --> 00:04:15,380
So let's think about some functions that might relate to this car, some action.

61
00:04:15,410 --> 00:04:18,050
So here are our members here.

62
00:04:19,100 --> 00:04:20,750
It went ahead and renamed Paint Color.

63
00:04:20,750 --> 00:04:23,860
I'm not sure why I used this syntax in the last one.

64
00:04:23,870 --> 00:04:27,050
It should be kind of camel case like this right here.

65
00:04:28,010 --> 00:04:33,980
So, yeah, anyways, let's think about the functions that could exist for this.

66
00:04:33,980 --> 00:04:35,030
So let's see.

67
00:04:35,060 --> 00:04:37,560
Maybe like a void drive car.

68
00:04:38,210 --> 00:04:41,450
So you get a certain number of miles pass to it.

69
00:04:41,450 --> 00:04:43,790
And what would we have to do in that drive car?

70
00:04:43,820 --> 00:04:47,780
Well, maybe we would modify the odometer, right?

71
00:04:48,470 --> 00:04:55,340
Because if you drive the car and the function gets passed a certain amount of miles, you now know that

72
00:04:55,340 --> 00:04:58,340
the odometer should have those extra miles on it, right?

73
00:04:59,760 --> 00:05:00,370
What else?

74
00:05:00,390 --> 00:05:05,940
Well, it uses feel and you drive the car, so you might need to also subtract from your total fuel

75
00:05:05,940 --> 00:05:06,630
a little bit, right?

76
00:05:08,300 --> 00:05:09,530
That's a set paint.

77
00:05:10,560 --> 00:05:15,510
That could be a function, right, maybe you want to repaint your car or something, so you know, here's

78
00:05:15,510 --> 00:05:22,650
a color being passed to it, the paint color, and you could set this paint color data member variable

79
00:05:22,650 --> 00:05:23,040
here.

80
00:05:23,130 --> 00:05:23,430
Right?

81
00:05:24,690 --> 00:05:31,650
Then we have this returns, an integer says get odometer, so that's just getting this data member for

82
00:05:31,650 --> 00:05:31,890
us.

83
00:05:32,250 --> 00:05:36,420
And you might be wondering, well, why would we need a function to get the odometer?

84
00:05:36,780 --> 00:05:37,610
It's right here.

85
00:05:37,620 --> 00:05:38,680
We could just use it.

86
00:05:39,510 --> 00:05:43,430
So this is something that we're going to talk to talk about in this slideshow.

87
00:05:43,440 --> 00:05:50,640
So there is a reason to make a function that gets this rather than just use the data and access it straight

88
00:05:50,640 --> 00:05:50,910
up.

89
00:05:52,260 --> 00:05:57,510
So that is something about hiding data from the user, and that's something we're going to talk about

90
00:05:57,510 --> 00:05:57,960
in a moment.

91
00:05:59,210 --> 00:06:05,030
So this returns a flow assist, jet fuel is just like odometer, it really just gets this variable and

92
00:06:05,030 --> 00:06:05,690
returned to.

93
00:06:07,400 --> 00:06:12,440
And then we also have add fuel, this is Floyd, so what it's really doing is just modifying this feel

94
00:06:12,440 --> 00:06:12,630
right.

95
00:06:12,640 --> 00:06:15,680
You get some gallons and you're going to add some gallons to the fuel.

96
00:06:18,000 --> 00:06:22,200
So those could be some potential things, of course, there could be a less that could be more.

97
00:06:22,230 --> 00:06:28,320
But you know, this is one of the kind of a potential kind of configuration of data and functions that

98
00:06:28,320 --> 00:06:28,950
you could have here.

99
00:06:31,110 --> 00:06:37,380
So what we're going to be talking about now is something similar to strikes, but they're actually called

100
00:06:37,380 --> 00:06:46,200
classes, and it's kind of going to be a kind of bigger, more robust and slightly more complex version

101
00:06:46,200 --> 00:06:46,890
of a strict.

102
00:06:48,160 --> 00:06:53,740
So classes really are the blueprints for something we call an object, and we're talking about this

103
00:06:53,740 --> 00:06:56,440
object oriented programming, you know, and car.

104
00:06:56,470 --> 00:07:04,000
We have the idea of a car being an object in code, and the class is the berl blueprint of that object,

105
00:07:04,000 --> 00:07:05,560
the blueprint of the car.

106
00:07:06,100 --> 00:07:12,160
So they describe the object and they provide functionality to interact with that object and its data.

107
00:07:13,900 --> 00:07:20,360
So down here I have a box, this is kind of UML style ish diagram right here.

108
00:07:21,880 --> 00:07:26,050
We have the class name would be car involved here.

109
00:07:26,950 --> 00:07:30,040
These items right here would be data members.

110
00:07:30,310 --> 00:07:34,900
So these are the member variables, the member data variables.

111
00:07:35,770 --> 00:07:42,310
And then down here we have the functions which we refer to as member functions.

112
00:07:42,580 --> 00:07:47,920
We call them member because they are members of this car class.

113
00:07:48,710 --> 00:07:52,030
So these are the data members or member variables.

114
00:07:52,540 --> 00:07:55,180
These are the member functions.

115
00:07:55,180 --> 00:07:57,940
So this is the functionality of the car class.

116
00:07:58,780 --> 00:08:01,270
So here we have all of those functions that we listed.

117
00:08:04,250 --> 00:08:11,270
So the syntax for creating classes is pretty close to structs, so we notice instead of struct, we

118
00:08:11,270 --> 00:08:14,450
just put class and then has the same brackets here.

119
00:08:14,480 --> 00:08:20,180
Also note that we have a semicolon coming after the close bracket here or brace?

120
00:08:20,450 --> 00:08:21,200
Curly brace.

121
00:08:22,850 --> 00:08:27,950
And then we have a combination of variables and functions in here.

122
00:08:28,490 --> 00:08:32,930
So all of our information is contained inside here, so here's the member variables.

123
00:08:32,930 --> 00:08:34,790
Here are the member functions.

124
00:08:37,680 --> 00:08:44,540
So an important thing, though, that is very useful in classes is something called access specifies.

125
00:08:44,540 --> 00:08:48,630
So think back to the car, right and the driver.

126
00:08:50,180 --> 00:08:55,430
So remember how we want certain things to be available for the driver, for the interface of the car,

127
00:08:55,760 --> 00:08:57,230
but maybe not others, right?

128
00:08:58,470 --> 00:09:05,170
Like, what if we don't want the user or the driver to be able to modify the original odometer, right?

129
00:09:05,190 --> 00:09:06,930
We want the car to drive.

130
00:09:07,980 --> 00:09:15,330
And we want like Miles, to be added on to the odometer and we want the odometer to be able to be displayed

131
00:09:15,330 --> 00:09:16,350
to the driver.

132
00:09:16,650 --> 00:09:18,960
We want the driver to be able to see the odometer.

133
00:09:19,680 --> 00:09:23,370
I know the kind of you're being technical about it.

134
00:09:23,460 --> 00:09:28,560
Yes, there's like a trip odometer that you might do when you reset the trip odometer just to see how

135
00:09:28,560 --> 00:09:29,400
many miles you've gone.

136
00:09:29,400 --> 00:09:33,480
But we're talking about the overall odometer of the car, right?

137
00:09:33,510 --> 00:09:34,740
How many miles are in the car?

138
00:09:35,850 --> 00:09:41,160
So of course, if you kind of scammy and you're selling your car and you're trying to, like, take

139
00:09:41,160 --> 00:09:44,010
off some miles or something, then that could be possible.

140
00:09:44,010 --> 00:09:46,230
But we don't really want users to do that right.

141
00:09:46,500 --> 00:09:48,870
We want them to only be able to see the odometer.

142
00:09:48,900 --> 00:09:52,230
We don't want them to be able to change the odometer.

143
00:09:52,560 --> 00:09:55,290
The odometer is a member variable, right?

144
00:09:56,470 --> 00:10:05,520
Here we have a get odometer that simply would show the user how many miles are on the odometer, right?

145
00:10:05,560 --> 00:10:06,400
It's an integer.

146
00:10:07,030 --> 00:10:16,150
So this just returns the miles of the odometer to the user, but it doesn't let them modify the odometer.

147
00:10:16,360 --> 00:10:17,140
And why is that?

148
00:10:17,170 --> 00:10:24,490
Well, because the user, if we're thinking about this software version of a car, the user might call

149
00:10:24,490 --> 00:10:25,780
this function.

150
00:10:27,040 --> 00:10:33,130
Because they want to get the odometer, but when they call this function, it's up to us to put the

151
00:10:33,130 --> 00:10:35,650
code that runs inside this function, right?

152
00:10:37,270 --> 00:10:39,600
So we can pull whatever code we want here.

153
00:10:39,610 --> 00:10:42,340
We don't have to modify the odometer and we don't really want to.

154
00:10:42,370 --> 00:10:47,020
We just wanted to give back the number that's stored inside the unarmored array, right?

155
00:10:47,260 --> 00:10:52,970
And that makes it so the user isn't changing our odometer variable.

156
00:10:52,990 --> 00:10:59,620
All they're doing is accessing what the value is stored inside of that, right?

157
00:10:59,830 --> 00:11:01,690
The integer that's stored inside a diameter.

158
00:11:03,690 --> 00:11:11,490
So since we have that function, you know, when the users use these funds that function and maybe when

159
00:11:11,490 --> 00:11:16,230
they use drive car function, we can make our own modifications to odometer right.

160
00:11:16,230 --> 00:11:18,720
When we use to drive car function, we can add miles to it.

161
00:11:19,820 --> 00:11:25,550
But we don't want them to have direct access to this variable to do whatever they want at any point

162
00:11:25,550 --> 00:11:26,300
in time, right?

163
00:11:26,780 --> 00:11:31,700
So this is an important concept and it's something that we call encapsulation.

164
00:11:32,970 --> 00:11:40,620
And we use something called access pacifiers to do just that, we specify the access level, right?

165
00:11:41,190 --> 00:11:49,790
The engineer, ourselves, being engineers, we have the ability to access these variables here, right?

166
00:11:50,080 --> 00:11:57,720
Because we want to change them like Odometer, but we don't want a user to be able to directly change

167
00:11:57,720 --> 00:11:57,890
it.

168
00:11:57,900 --> 00:12:01,410
And so we're not we're going to revoke their access to change it, right?

169
00:12:03,190 --> 00:12:14,110
So what we do to be able to put this in code is have these access specifies here, so we have something

170
00:12:14,110 --> 00:12:16,600
called public and private.

171
00:12:17,230 --> 00:12:20,320
So here these are public member functions now.

172
00:12:20,320 --> 00:12:25,210
So these are available to the user if you want to think about the analogy.

173
00:12:25,420 --> 00:12:27,490
These are available to the driver.

174
00:12:29,050 --> 00:12:32,950
So we want the user to be able to call these functions.

175
00:12:34,020 --> 00:12:40,230
As you'll see in the near future, we're going to make car objects, this is a blueprint, and what

176
00:12:40,230 --> 00:12:47,540
we're going to do is make lake car one car to car three as objects in the user code right.

177
00:12:47,550 --> 00:12:53,550
We're going to pretend that we're a user and we want access to all these functions.

178
00:12:53,550 --> 00:12:58,290
But as the user, we shouldn't have access to these necessarily.

179
00:12:58,770 --> 00:13:05,040
It's common practice in programming to make the member variables be private.

180
00:13:05,790 --> 00:13:15,270
And that is because we kind of have this idea of making an additional layer of security by having the

181
00:13:15,270 --> 00:13:18,240
functions only be able to be accessed through a function.

182
00:13:18,960 --> 00:13:25,380
And what that enables us to do is decide what the user is allowed to do with the variables.

183
00:13:27,220 --> 00:13:32,860
In this case, the users are only allowed to get the odometer if they want to see it or if the user

184
00:13:32,860 --> 00:13:39,730
drives the car, we modify the odometer and the fuel in the way that we want to modify it.

185
00:13:40,120 --> 00:13:46,810
We're not going to let the user choose how many miles get taken off the odometer when they drive the

186
00:13:46,810 --> 00:13:51,370
car or how much fuel gets used up when they drive the car.

187
00:13:51,400 --> 00:13:53,500
That is something that we've designed, right?

188
00:13:53,530 --> 00:13:59,410
We are the ones that say how much fuel gets used when the user is driving the car a certain amount of

189
00:13:59,410 --> 00:13:59,890
miles.

190
00:14:00,550 --> 00:14:01,840
Same thing with the odometer.

191
00:14:02,410 --> 00:14:06,310
That is the point in separating out stuff into public and private.

192
00:14:06,700 --> 00:14:12,310
Private means the users cannot access these public means the user can access these.

193
00:14:12,340 --> 00:14:12,700
All right.

194
00:14:13,060 --> 00:14:19,990
Think about another chunk of code where we are trying to access stuff from this car class.

195
00:14:20,620 --> 00:14:24,580
This stuff here will be accessible from this other chunk of code.

196
00:14:25,060 --> 00:14:28,840
This stuff here will not be accessible from that other chunk of code.

197
00:14:29,560 --> 00:14:29,950
All right.

198
00:14:32,850 --> 00:14:38,010
So another thing that you might notice is that these are only function prototypes.

199
00:14:38,040 --> 00:14:45,630
So think back to when we were making some functions and putting them above main versus the low main

200
00:14:45,630 --> 00:14:46,710
and stuff like that.

201
00:14:47,100 --> 00:14:52,680
When we put stuff below main, remember, we had to use some function prototypes here just to be able

202
00:14:52,680 --> 00:14:56,250
to access those so Maine can know that they existed, right?

203
00:14:56,700 --> 00:15:03,150
Because it was kind of in that specific order where, you know, Maine didn't know how to call a function

204
00:15:03,150 --> 00:15:05,460
if it hadn't been previously implemented.

205
00:15:05,470 --> 00:15:13,330
So what we had to do was define the function prototypes just so they were available for use right now.

206
00:15:13,330 --> 00:15:14,240
And that's what we're doing, too.

207
00:15:14,250 --> 00:15:15,600
We're putting prototypes in here.

208
00:15:16,350 --> 00:15:22,500
Not to say that you can't put the implementation here instead of just the prototype.

209
00:15:23,070 --> 00:15:28,350
But what we're going to be doing as we move forward is we're going to be keeping our prototypes here

210
00:15:28,350 --> 00:15:35,580
and we are going to put our implementations outside of the brackets of this class.

211
00:15:36,360 --> 00:15:37,220
That's what we're going to be doing.

212
00:15:37,230 --> 00:15:42,930
We might be putting some stuff in here sometimes, but what we're going to do most of the time is after

213
00:15:42,930 --> 00:15:48,990
this bracket close bracket semicolon, this is where we are going to put implementations or as you'll

214
00:15:48,990 --> 00:15:55,320
see in the future, we're going to put our implementations for these functions where the actual code

215
00:15:55,320 --> 00:15:59,240
goes in the car, sometimes in a completely separate file altogether.

216
00:15:59,250 --> 00:16:01,320
So that is something that we'll be doing in the future.

217
00:16:01,320 --> 00:16:06,720
But just know right now notice that we're only using the prototypes here, only defining the prototypes

218
00:16:06,720 --> 00:16:08,160
in this public public section.

219
00:16:10,530 --> 00:16:13,950
So what would a function implementation look like for this, though?

220
00:16:13,950 --> 00:16:20,460
So let's say we put some code down here after this closed bracket semicolon, what does get odometer

221
00:16:20,460 --> 00:16:21,060
look like?

222
00:16:21,330 --> 00:16:23,250
This is the prototype right here, right?

223
00:16:23,260 --> 00:16:25,560
But what would the implementation of this function look like?

224
00:16:26,370 --> 00:16:28,890
Well, it looks like this, and you're probably like, Oh yeah, this is.

225
00:16:28,890 --> 00:16:29,610
It makes sense.

226
00:16:29,610 --> 00:16:32,010
You know, we got the brackets here, we got the parentheses.

227
00:16:32,010 --> 00:16:33,060
It's doing some stuff.

228
00:16:33,060 --> 00:16:33,750
It's returning, though.

229
00:16:34,200 --> 00:16:35,820
But wait, what is this?

230
00:16:36,910 --> 00:16:38,260
Why is that there?

231
00:16:39,160 --> 00:16:42,400
Where have we seen this before?

232
00:16:43,300 --> 00:16:43,930
Well.

233
00:16:45,360 --> 00:16:50,730
This is something actually called the scope resolution operator, and we've seen it used before whenever

234
00:16:50,730 --> 00:16:54,360
we're not using the namespace STD.

235
00:16:54,570 --> 00:16:57,390
Right, we had to use this scope resolution operator.

236
00:16:58,050 --> 00:17:05,550
So the scope resolution operator is something that can tie a namespace to a variable like type like

237
00:17:05,550 --> 00:17:05,910
this.

238
00:17:06,570 --> 00:17:13,500
It can also be used to tie a class type to a function name here.

239
00:17:15,190 --> 00:17:24,970
So in this case, what we're doing is we're saying get odometer is part of the car class because you're

240
00:17:24,970 --> 00:17:27,530
like, well, get odometer, where's that coming from?

241
00:17:27,550 --> 00:17:29,560
What if we had multiple classes and stuff?

242
00:17:29,560 --> 00:17:32,380
We're like, OK, well, this get odometer function right now.

243
00:17:32,380 --> 00:17:35,650
I just want to let you know that is part of the car class.

244
00:17:35,650 --> 00:17:37,660
So this is part of the function name.

245
00:17:38,080 --> 00:17:45,490
The full function name is car class scope resolution get odometer so you can think of all this being

246
00:17:45,490 --> 00:17:47,050
the specific function name.

247
00:17:48,580 --> 00:17:56,080
Also notice something important is that we put the data type, it returns before the function name.

248
00:17:56,680 --> 00:17:58,780
That's something we've done before too, right?

249
00:17:59,110 --> 00:18:04,700
So we've put the integer return type of the function before get odometer.

250
00:18:04,720 --> 00:18:09,170
Now we're even though we're adding car call and call and get odometer.

251
00:18:09,220 --> 00:18:12,970
We wouldn't put integer after a car call and call in or something like that.

252
00:18:12,970 --> 00:18:16,000
We would always put the return type of this function.

253
00:18:16,990 --> 00:18:21,760
As the first thing, and then we put car Coleman call and get odometer, which is all part of the name.

254
00:18:22,810 --> 00:18:24,280
So just want to make that clear.

255
00:18:24,460 --> 00:18:27,910
It's an integer return type because it's returning the odometer.

256
00:18:28,120 --> 00:18:31,500
And what is the odometer type, well, integer, right?

257
00:18:31,510 --> 00:18:33,130
So that's why we have an integer.

258
00:18:35,320 --> 00:18:39,430
So let's look at the rest of the function implementations for this class.

259
00:18:40,810 --> 00:18:43,370
Another thing that I noticed is there is a small mistake here.

260
00:18:43,390 --> 00:18:45,670
This should have a stage colon colon here.

261
00:18:45,910 --> 00:18:48,610
You notice that these have colon colon before the string.

262
00:18:48,610 --> 00:18:53,020
So it's kind of implied that I am not using the standard namespace up here.

263
00:18:53,260 --> 00:18:58,390
So I probably should have a steady cold colon right here in this function prototype as well.

264
00:18:58,960 --> 00:19:02,100
I noticed that I put it right here, but just wanted to point that out.

265
00:19:02,110 --> 00:19:03,070
I noticed a little error.

266
00:19:03,790 --> 00:19:09,290
So this is what all of the function implementations for this class would look like.

267
00:19:09,310 --> 00:19:11,050
So here's all the prototypes, right?

268
00:19:11,260 --> 00:19:18,370
And here's all of their implementations that you could potentially put after the class here past this

269
00:19:18,370 --> 00:19:20,050
curly brace with the semicolon.

270
00:19:21,780 --> 00:19:23,580
So let's take a look at some of these.

271
00:19:24,000 --> 00:19:25,200
What is the same?

272
00:19:25,230 --> 00:19:27,530
What is the similarity between all of these?

273
00:19:27,540 --> 00:19:33,480
Well, they have the car, Colin Colin in front of them, just like we noticed before, right here in

274
00:19:33,480 --> 00:19:34,560
front of get odometer.

275
00:19:34,770 --> 00:19:38,070
It's not just get odometer that has car Colin Colin in front of it.

276
00:19:38,430 --> 00:19:42,570
It is all of the member functions here in this class.

277
00:19:43,590 --> 00:19:52,890
We need to put this car call and call in for the C++ compiler to understand that it is attached to this

278
00:19:52,890 --> 00:19:53,370
class.

279
00:19:53,380 --> 00:20:00,510
So when we do this, implementation knows that this drive car function is coming from the car class.

280
00:20:01,470 --> 00:20:07,710
So this drive car function, you notice that what we do is we add some stuff to the odometer, add some

281
00:20:07,710 --> 00:20:09,300
miles that get passed to it, right?

282
00:20:09,300 --> 00:20:11,760
So now there's more miles on the odometer.

283
00:20:12,060 --> 00:20:17,550
We also subtract some fuel where I just have this really basic formula where it's just miles over twenty

284
00:20:17,550 --> 00:20:18,000
two.

285
00:20:18,480 --> 00:20:23,250
So that is what we're going to subtract from the fuel if we're just thinking about gallons.

286
00:20:25,040 --> 00:20:28,340
Or, you know, whatever you're using leaders or something like that.

287
00:20:29,630 --> 00:20:33,800
So here, you know, set paint, we set the paint color.

288
00:20:33,920 --> 00:20:37,400
These are just returning the odometer and returning the fuel.

289
00:20:38,660 --> 00:20:42,200
So this is something to do with that accessibility, right?

290
00:20:42,200 --> 00:20:47,300
And the encapsulation idea, which is where we don't want the user to be able to directly modify the

291
00:20:47,300 --> 00:20:47,780
variables.

292
00:20:47,780 --> 00:20:55,760
So what we've done is we made these functions that are access or functions where you can access the

293
00:20:55,760 --> 00:20:56,870
variables, right?

294
00:20:57,170 --> 00:20:59,800
So the user wants to know what's the odometer?

295
00:20:59,810 --> 00:21:02,840
Well, the user doesn't have access to the variable here.

296
00:21:02,840 --> 00:21:04,290
So what should we do?

297
00:21:04,310 --> 00:21:05,930
We should make a function here.

298
00:21:06,080 --> 00:21:06,890
That's public.

299
00:21:07,550 --> 00:21:12,260
That is called get and then whatever the variable name is, right, get odometer.

300
00:21:12,260 --> 00:21:15,020
So that returns the value of the odometer.

301
00:21:15,020 --> 00:21:16,450
And we have the same thing for fuel.

302
00:21:16,460 --> 00:21:20,870
What if the user wants to know how much gas they have left in the tank?

303
00:21:20,900 --> 00:21:22,320
Well, that's a very normal thing, right?

304
00:21:22,360 --> 00:21:24,350
You want to know if you're about to run out of gas.

305
00:21:24,860 --> 00:21:31,760
So the user could call this get fuel function on the car object and they would get the fuel.

306
00:21:31,760 --> 00:21:33,770
And this is another access or function.

307
00:21:34,040 --> 00:21:39,800
We're enabling the user to have public access to the value still inside here, but we're not letting

308
00:21:39,800 --> 00:21:41,770
them modify the fuel directly, right.

309
00:21:41,780 --> 00:21:43,490
That is up to us right here.

310
00:21:43,610 --> 00:21:47,750
The user is allowed to drive the car, but we choose how the fuel gets modified right.

311
00:21:47,780 --> 00:21:54,470
Right here you see that also, when the user adds fuel, of course, we need to let them put more fuel

312
00:21:54,470 --> 00:21:56,110
in the tank at the gas station, right?

313
00:21:56,120 --> 00:22:02,720
So we have this and gallons that they can pass to an add fuel function and that adds fuel function modifies

314
00:22:02,720 --> 00:22:03,740
our car class.

315
00:22:03,980 --> 00:22:05,060
How does it modify it?

316
00:22:05,070 --> 00:22:12,230
Well, it adds the gallons that the user passes to this function to our fuel member variable, right?

317
00:22:12,260 --> 00:22:13,250
This is private.

318
00:22:13,580 --> 00:22:18,650
The user doesn't have direct access to the fuel, so they can't just be like, Oh, I'm just going to

319
00:22:18,650 --> 00:22:22,010
add a million to fuel without putting gallons.

320
00:22:22,010 --> 00:22:27,290
You know, what we do is we say, OK, well, you're going to say how many gallons that you're going

321
00:22:27,290 --> 00:22:30,710
to add and then we're going to modify the fuel however we want.

322
00:22:32,350 --> 00:22:38,670
So another thing to just point out there is it's not just the a dollar, now we have all the functions,

323
00:22:38,680 --> 00:22:41,710
you can kind of see how they all work together with the class.

324
00:22:41,720 --> 00:22:47,290
So I'm going to end this lecture right here because I don't want to stuff too much information into

325
00:22:47,290 --> 00:22:55,090
this, but we're going to continue in quite a few lectures, going over the rest of kind of the stuff

326
00:22:55,090 --> 00:22:56,280
to do with classes.

327
00:22:56,290 --> 00:23:01,120
And there's a lot more that we actually need to do to have a full on class.

328
00:23:01,300 --> 00:23:08,710
We're going to talk about what these get initialized to in the beginning, when the object gets created,

329
00:23:09,340 --> 00:23:10,720
what values they have in them.

330
00:23:10,870 --> 00:23:13,780
We're also going to talk about how, of course, to make an object.

331
00:23:13,780 --> 00:23:18,400
Right now, all I've said was what is the blueprint, the classes, the blueprint.

332
00:23:18,850 --> 00:23:21,760
But the class is not the object itself.

333
00:23:21,760 --> 00:23:24,970
We have to make an object of the car class, right?

334
00:23:25,360 --> 00:23:31,900
When you have a blueprint of a car, you're like, Oh, great, I know I know what a car has now.

335
00:23:31,900 --> 00:23:33,370
But what if you got to build the car?

336
00:23:33,370 --> 00:23:33,790
You got it.

337
00:23:33,790 --> 00:23:37,150
You can't just, you know, the blueprint isn't what the user buys, right?

338
00:23:37,750 --> 00:23:42,270
Does the user buy like a bunch of pages that are blueprints of a car?

339
00:23:42,320 --> 00:23:42,960
No, they don't.

340
00:23:42,970 --> 00:23:46,570
They buy an actual car, so we got to make the actual car right.

341
00:23:47,200 --> 00:23:52,220
We have to make an instance of a car which would be considered a car object.

342
00:23:52,250 --> 00:23:52,450
Right.

343
00:23:52,450 --> 00:23:57,850
And that's the thing that the user is going to want in the user is actually the one that's going to

344
00:23:57,850 --> 00:23:58,360
make it.

345
00:23:59,590 --> 00:24:04,270
So they're going to make a car object and then they're going to be able to use it based on the blueprints

346
00:24:04,270 --> 00:24:05,110
that we've provided.

347
00:24:06,010 --> 00:24:11,920
So all right, with that, I will see you in the next election where we continue on talking about classes.
