1
00:00:00,700 --> 00:00:05,390
OK, so moving on with classes here, you notice that I have the same class that we were discussing

2
00:00:05,390 --> 00:00:06,310
in the last lecture.

3
00:00:06,730 --> 00:00:08,980
I have it here in Visual Studio Code.

4
00:00:09,670 --> 00:00:14,470
So here is the class definition here, and this is our blueprint.

5
00:00:14,710 --> 00:00:22,210
You notice that we have the private member variables section and public member functions section.

6
00:00:23,440 --> 00:00:25,480
So let's see what's below that.

7
00:00:25,780 --> 00:00:31,330
Here we have something we also talked about in the last lecture, which is the actual implementations

8
00:00:31,690 --> 00:00:33,850
of the member functions.

9
00:00:33,910 --> 00:00:37,210
So remember the scope of resolution here.

10
00:00:37,210 --> 00:00:42,220
So this is the scope resolution operator and we are using the name of the class right before it, right?

11
00:00:42,230 --> 00:00:44,320
And then afterwards comes the name of the function.

12
00:00:45,160 --> 00:00:46,750
So this is kind of like one big name.

13
00:00:47,560 --> 00:00:51,980
Here we have the return type of each function is going to be coming before the car, colon, colon.

14
00:00:53,200 --> 00:00:55,330
And these are all of our functions that we discussed.

15
00:00:56,610 --> 00:01:01,620
So down below all these functions, I am putting my main function here.

16
00:01:02,190 --> 00:01:09,650
And so now what we're going to discuss is what to do when we're creating an object of the car class.

17
00:01:09,660 --> 00:01:11,990
So now we want to make a specific car, right?

18
00:01:12,000 --> 00:01:19,350
We have the blueprint up here and we have the function implementations, but now we need to make an

19
00:01:19,350 --> 00:01:20,520
actual car object.

20
00:01:20,980 --> 00:01:23,100
It's going to be just like how it made a structure.

21
00:01:23,100 --> 00:01:26,340
So I can say car capital C, right?

22
00:01:26,340 --> 00:01:28,440
Because that is what we named our class.

23
00:01:29,640 --> 00:01:37,430
In one of my call, this lower case, the car has the variable name so simple as that I make a car and

24
00:01:37,440 --> 00:01:41,310
then so let's try something interesting now I have a car, right?

25
00:01:41,670 --> 00:01:44,580
Well, let's go ahead and use some of these functions, right?

26
00:01:44,590 --> 00:01:53,730
Let's do get odometer and get fuel so I can do see see, our car is my variable right and then we're

27
00:01:53,730 --> 00:01:57,540
going to use a dot just like the struct in real.

28
00:01:57,540 --> 00:02:00,390
In the struct, we use a dot to access the members.

29
00:02:01,080 --> 00:02:05,820
Well, here I put a dot and you notice that it gives me the option to call any one of these functions

30
00:02:05,820 --> 00:02:06,060
here.

31
00:02:06,060 --> 00:02:08,880
So I have drive car, get fuel.

32
00:02:08,910 --> 00:02:10,560
Let's go ahead and get odometer.

33
00:02:11,130 --> 00:02:12,150
That's a function call.

34
00:02:12,150 --> 00:02:14,910
So I need to put some parentheses right here.

35
00:02:15,390 --> 00:02:24,030
You can think of this as like a string dot, dot string dot length or something like that.

36
00:02:24,780 --> 00:02:29,850
Another interesting thing to talk about is the fact that, you know, string.

37
00:02:29,850 --> 00:02:37,580
I'm using it as an example, but string actually is an object and it's actually a class.

38
00:02:37,590 --> 00:02:39,150
There's a string class.

39
00:02:39,630 --> 00:02:46,170
And when you're using that standard namespace, you know, it's kind of just par C++ in general.

40
00:02:46,170 --> 00:02:51,690
You can just use strings, you have access to that class.

41
00:02:51,690 --> 00:02:54,900
And so therefore you can use the member functions of that class.

42
00:02:55,200 --> 00:02:57,570
One of the member functions is length.

43
00:02:57,900 --> 00:03:03,780
So when we make a string like string s or something like that, we do escort length.

44
00:03:04,260 --> 00:03:07,980
It's similar to how we're doing car dot, get odometer.

45
00:03:08,880 --> 00:03:10,050
So I just want to point that out.

46
00:03:10,050 --> 00:03:15,410
That string is a class, so maybe that can kind of tie together some things that you've seen so far.

47
00:03:16,830 --> 00:03:22,170
So this kind of interesting let's see what would print out, I mean, we haven't really said what the

48
00:03:22,170 --> 00:03:25,560
odometer is when you make a new car, right?

49
00:03:25,680 --> 00:03:29,610
So I'm going to be interesting seeing what prints out.

50
00:03:31,020 --> 00:03:31,800
Put it in line.

51
00:03:32,250 --> 00:03:36,780
And then let's also see our car door get fuel.

52
00:03:37,260 --> 00:03:39,930
So this is going to return the fuel to us.

53
00:03:42,780 --> 00:03:43,710
And that's all I want to do.

54
00:03:43,720 --> 00:03:46,860
I'm just going to print these two out and that'll be the program.

55
00:03:46,860 --> 00:03:48,840
So I'm going, go ahead and save this.

56
00:03:50,520 --> 00:03:53,820
And then here I have a terminal.

57
00:03:54,940 --> 00:03:56,970
Go ahead and compile.

58
00:03:58,780 --> 00:04:02,680
And then I'm going to run this and let's see what we get as output.

59
00:04:05,260 --> 00:04:09,280
OK, so supposedly we have.

60
00:04:11,500 --> 00:04:19,990
For what is this four million, two hundred one thousand three hundred thirty nine miles on our new

61
00:04:19,990 --> 00:04:20,380
car?

62
00:04:20,410 --> 00:04:22,630
That doesn't seem very good, right?

63
00:04:23,560 --> 00:04:28,750
And then we have, you know, this crazy number right here as our fuel.

64
00:04:29,620 --> 00:04:31,600
So why do we have those numbers?

65
00:04:31,630 --> 00:04:38,300
Well, this is something that you might already know, but what's happening is that this is garbage.

66
00:04:38,320 --> 00:04:40,300
This is some of those garbage values.

67
00:04:40,300 --> 00:04:42,460
This is just coming out of memory.

68
00:04:43,180 --> 00:04:50,770
We've created these variables fuel and odometer, where we make those we define to them here.

69
00:04:52,600 --> 00:04:54,760
Was there float fuel in odometer?

70
00:04:55,090 --> 00:04:59,020
The problem is, is that we never initialized these variables.

71
00:04:59,500 --> 00:05:05,770
So when we make a car object, it basically when it tries to call get odometer, which it does, it

72
00:05:05,770 --> 00:05:10,390
doesn't try, it does call it odometer, it goes here, says return odometer.

73
00:05:10,390 --> 00:05:12,520
We get the value of the odometer back here.

74
00:05:12,520 --> 00:05:14,110
But what is the value of odometer?

75
00:05:14,320 --> 00:05:21,130
It's just some random trash from memory just picks up wherever that variable is sitting and memory is

76
00:05:21,130 --> 00:05:23,020
just going to pick up whatever's there.

77
00:05:23,320 --> 00:05:28,750
And that could be anything, you know, and it's just interpreting that garbage as these bytes as this

78
00:05:28,750 --> 00:05:31,840
decimal number here because of the data type, right?

79
00:05:32,200 --> 00:05:33,520
It's an integer du type.

80
00:05:34,330 --> 00:05:38,170
And then we have a float in that flow is just some crazy number two.

81
00:05:38,620 --> 00:05:40,760
So what do we do about that?

82
00:05:40,780 --> 00:05:42,940
How do we initialize these variables?

83
00:05:42,940 --> 00:05:46,130
So that is something we're going to talk about next.

84
00:05:46,150 --> 00:05:48,880
Now you see that we have created a car.

85
00:05:51,600 --> 00:05:55,230
And this is the syntax is similar to kind of a struct.

86
00:05:55,620 --> 00:06:05,640
But what if we wanted to say exactly what a car is going to start out with as far as the odometer and

87
00:06:05,640 --> 00:06:07,350
the fuel one odometer?

88
00:06:07,350 --> 00:06:13,860
We know what that should start out as it should start out as zero right, like zero miles for a new

89
00:06:13,860 --> 00:06:14,370
car.

90
00:06:15,000 --> 00:06:19,410
So what we can do is actually make something in the code up here.

91
00:06:20,890 --> 00:06:26,800
And this is something pretty interesting, kind of unique to classes, it is called a constructor.

92
00:06:27,310 --> 00:06:34,840
And the reason is called a constructor is because it is what gets called when you build the object.

93
00:06:34,840 --> 00:06:38,050
So constructing is kind of like build, the same thing is building, right?

94
00:06:38,350 --> 00:06:39,760
Those things are kind of synonymous.

95
00:06:40,210 --> 00:06:47,820
So here is where you create a car object right on this line right here.

96
00:06:47,830 --> 00:06:56,050
So you can think of this when you do this, it is going to call a special function called a constructor.

97
00:06:56,560 --> 00:07:02,440
And since we're calling it on this line here, you know, we wouldn't put like a dot right away for

98
00:07:02,440 --> 00:07:09,490
a function because we need to have this style syntax that creates the car variable, right?

99
00:07:09,700 --> 00:07:15,360
So we're not going to put a dot when C++ sees this, it's just going to automatically call our constructor.

100
00:07:15,370 --> 00:07:18,790
So the question now is how do we make a constructor and what is it?

101
00:07:19,420 --> 00:07:28,480
Well, it is going to be here in our public methods function or public member functions area, but it's

102
00:07:28,480 --> 00:07:34,330
going to look like this is just going to literally be the same name as the class with some parentheses.

103
00:07:35,530 --> 00:07:39,340
And so this is an empty default constructor, is what we call this.

104
00:07:39,760 --> 00:07:46,480
You're going to call the name is basically like a function like drive car, except the name of the function

105
00:07:46,690 --> 00:07:52,210
is the exact same as the class name, and you do not put a data type.

106
00:07:52,220 --> 00:07:53,200
There is no void.

107
00:07:53,200 --> 00:07:54,250
No in no float.

108
00:07:54,280 --> 00:07:55,180
Don't put that.

109
00:07:55,180 --> 00:08:01,420
Just put the name of the class with some parentheses here, and they don't have to be empty.

110
00:08:01,450 --> 00:08:03,310
We're going to get into that in a second.

111
00:08:03,850 --> 00:08:06,020
But right now, we're going to leave them empty.

112
00:08:06,020 --> 00:08:11,350
And so this is a basic default constructor, and you can put it here in the public number functions

113
00:08:11,350 --> 00:08:11,950
area.

114
00:08:13,560 --> 00:08:19,230
So I'm going to have to actually make an implementation of this, just like I did for these functions,

115
00:08:19,240 --> 00:08:21,630
so let's go down here and see what that's going to look like.

116
00:08:21,870 --> 00:08:27,450
I'm going to put it above all of these other functions in terms of top to bottom.

117
00:08:28,080 --> 00:08:33,510
And I'm going to go ahead and put this scope resolution just like this function car call and colon.

118
00:08:33,510 --> 00:08:40,080
So I can actually copy that and I can go over here and I can paste that so I don't have a car.

119
00:08:40,080 --> 00:08:44,010
And then I just put the same thing again, car, because that's the name, right?

120
00:08:44,020 --> 00:08:45,360
That's the name of the constructor.

121
00:08:45,360 --> 00:08:46,230
It's just car.

122
00:08:46,230 --> 00:08:51,690
It's the same as the class name looks kind of weird because we have Capital C car call and call colon

123
00:08:51,690 --> 00:08:54,150
and then just Capital C car coming right after it.

124
00:08:54,870 --> 00:08:56,250
But that's how it's supposed to be.

125
00:08:56,610 --> 00:09:00,120
Syntax was so I'm going to make it just like a function.

126
00:09:00,300 --> 00:09:02,400
I'm going to put some brackets here.

127
00:09:03,900 --> 00:09:12,240
And so this function is constructor is going to get called right here when we make the object.

128
00:09:12,270 --> 00:09:18,240
This is us making the car and so, you know, once we make the car, it's going to be like, Oh, you're

129
00:09:18,240 --> 00:09:22,710
making a car, I'm going to jump and up and try and find this constructor and then I'm going to run

130
00:09:22,710 --> 00:09:24,030
whatever code is in here.

131
00:09:24,040 --> 00:09:26,070
So what do we want to put in here?

132
00:09:26,760 --> 00:09:32,940
Well, the constructor is all about initializing our private variables.

133
00:09:32,970 --> 00:09:35,400
There's other stuff you can do in the constructor.

134
00:09:35,400 --> 00:09:39,390
I mean, technically, you can do whatever you want, but one of the main things that we're going to

135
00:09:39,390 --> 00:09:45,090
start doing is initializing these member variables that we're in this private section here.

136
00:09:45,750 --> 00:09:47,530
So what do we want for fuel?

137
00:09:47,550 --> 00:09:51,960
Well, fuel should probably start out as something other than zero.

138
00:09:52,440 --> 00:10:00,090
So I'm just going to say I don't know how many gallons, let's just say like 12 gallons or something

139
00:10:00,090 --> 00:10:00,600
like that.

140
00:10:01,200 --> 00:10:08,580
And then I'm going to say odometer equals zero because we're going to start out with no miles, right?

141
00:10:09,450 --> 00:10:12,260
And then we can just put some default paint color.

142
00:10:12,300 --> 00:10:17,590
We could say not string sorry and we could save paint color.

143
00:10:17,610 --> 00:10:19,710
Let's say that all of them kind of.

144
00:10:22,610 --> 00:10:28,850
Come off, you know, without really having paint, there's something, you know, maybe maybe the default

145
00:10:28,850 --> 00:10:31,680
color is just metal or something like that.

146
00:10:31,700 --> 00:10:38,060
We just say that and then model and we'll just say this is blank.

147
00:10:38,390 --> 00:10:40,130
Well, you don't have to put metal or something.

148
00:10:40,130 --> 00:10:43,100
We can just put a blank string here for Painkiller as well.

149
00:10:43,580 --> 00:10:50,660
So that way, at least there is something there for the painkiller model, even though it doesn't really

150
00:10:50,660 --> 00:10:52,460
have any meaning, it's just an empty string.

151
00:10:54,170 --> 00:10:59,660
Quite often in the constructor, you'll find yourself initializing these member variables to like the

152
00:10:59,660 --> 00:11:03,710
most basic value you can think of, so integers will often be zero.

153
00:11:04,750 --> 00:11:10,430
But this is actually a float like that, so let's put a four, 12, 12 point zero.

154
00:11:12,740 --> 00:11:14,450
And we got to put semicolons here, right?

155
00:11:15,110 --> 00:11:15,590
So.

156
00:11:17,220 --> 00:11:22,050
A lot of the things that you're going to see in here are going to be basic values, so like we're saying

157
00:11:22,050 --> 00:11:27,990
12 for fuel, just because it doesn't make sense to really start out with a car having no fuel when

158
00:11:27,990 --> 00:11:29,370
you want to drive it off the lot, right?

159
00:11:29,670 --> 00:11:32,460
But a lot of times floats will be zero point zero.

160
00:11:32,730 --> 00:11:34,150
Integers will be zero.

161
00:11:34,170 --> 00:11:35,370
Strings will be empty.

162
00:11:35,370 --> 00:11:37,890
String so on and so forth.

163
00:11:38,430 --> 00:11:40,070
But they don't always have to be.

164
00:11:40,080 --> 00:11:46,230
I'm just saying that that's kind of a common thing if you don't really have a specific value in mind

165
00:11:46,440 --> 00:11:50,130
first, just to initialize it to the most basic thing possible.

166
00:11:51,540 --> 00:11:54,620
So we're initialized in all four of our member variables here.

167
00:11:54,630 --> 00:12:00,130
So let's go ahead and save this and recompile it now and see what happens.

168
00:12:00,150 --> 00:12:09,540
So notice I've prototyped it up here, implementations right here and then down here we are still instantiating

169
00:12:09,540 --> 00:12:09,990
our car.

170
00:12:10,440 --> 00:12:17,160
So just another reminder on that when we make an object of a certain class, it's called instantiating

171
00:12:17,160 --> 00:12:17,380
it.

172
00:12:17,400 --> 00:12:19,950
We make an instance of the car class, right?

173
00:12:22,210 --> 00:12:26,050
So let's go ahead and test this out and see what happens.

174
00:12:26,320 --> 00:12:33,600
So I'm going to go ahead and save this, and then we're going to go down here and we compile it and

175
00:12:33,600 --> 00:12:34,360
then run.

176
00:12:35,340 --> 00:12:37,080
All right, so what do we see now?

177
00:12:37,110 --> 00:12:44,130
Well, the get odometer returned to zero because we have zero miles in the jet fuel is 12 gallons.

178
00:12:44,130 --> 00:12:46,050
So this is what we start off with now.

179
00:12:46,290 --> 00:12:54,000
The basic car, so you notice that these values get odometer is just getting the odometer and get fuel

180
00:12:54,000 --> 00:12:55,080
is just getting the fuel.

181
00:12:55,080 --> 00:12:56,890
And why are they zero in 12?

182
00:12:56,910 --> 00:13:02,610
Well, because when we created the car and where do we create the car right here on Line 50, right?

183
00:13:03,030 --> 00:13:09,150
When we created the car, what it did was they called this constructor code right here and it set fuel

184
00:13:09,150 --> 00:13:13,380
to $12 zero in the painkillers in model here to empty string.

185
00:13:14,770 --> 00:13:17,110
So that is a default constructor.

186
00:13:17,770 --> 00:13:24,040
This is when we have no arguments being passed to it, we have no parameters that we've defined.

187
00:13:24,580 --> 00:13:33,970
The thing is is that if we want to, we can say when we make a car, how many miles we want on the car

188
00:13:33,970 --> 00:13:43,330
and how much fuel we want in the tank and what color car we want and what model car we want.

189
00:13:44,050 --> 00:13:45,520
And that's kind of normal, right?

190
00:13:45,880 --> 00:13:52,240
Maybe not how much fuel is in it, but it's normal to say, OK, well, I want a used car that has,

191
00:13:52,510 --> 00:13:58,810
you know, about 50 thousand miles and I want the color to be white and I want the model to be this,

192
00:13:58,810 --> 00:13:59,200
you know?

193
00:14:00,310 --> 00:14:07,060
So that's something pretty normal, so why don't we implement a constructor that can handle stuff from

194
00:14:07,060 --> 00:14:07,720
the user?

195
00:14:07,930 --> 00:14:15,730
It can have a base line car that has the parameters that the user describes if the user can pass those

196
00:14:15,730 --> 00:14:16,420
as arguments.

197
00:14:17,230 --> 00:14:19,030
So I'm going to add one more thing here.

198
00:14:19,030 --> 00:14:25,300
Instead of just model, I'm actually going to say I'm going to have an extra thing here, and I'm just

199
00:14:25,300 --> 00:14:26,780
going to call this like a.

200
00:14:28,360 --> 00:14:30,490
A strange branch, I call it.

201
00:14:31,540 --> 00:14:34,570
Yeah, I guess I'll just call this like the brand of car.

202
00:14:37,660 --> 00:14:41,770
And then I'm not going to have a brand or any of that stuff.

203
00:14:42,340 --> 00:14:46,150
So what are we going to do if we want the user to say this?

204
00:14:46,150 --> 00:14:51,880
So let's go ahead and have the user choose not the.

205
00:14:53,060 --> 00:14:57,740
Fuel, because that would just be up to where, you know, the dealership or whatever, but let's say

206
00:14:57,740 --> 00:15:03,290
paint, color, brand model and odometer, so we're going to have three strings.

207
00:15:03,300 --> 00:15:17,810
And so let's just say the string paint a steady string and we'll just call this.

208
00:15:18,170 --> 00:15:19,370
This is the brand.

209
00:15:23,090 --> 00:15:31,800
Let me just call this brand and then I'll say a Stevie string model.

210
00:15:32,270 --> 00:15:38,300
And then and then the last parameter here will be ends in this will be miles.

211
00:15:41,070 --> 00:15:45,060
So we'll see how many miles they want in the car, and we'll say all this stuff, so we notice that

212
00:15:45,060 --> 00:15:51,900
we have a similar named parameters here to this stuff here like brand and model.

213
00:15:52,890 --> 00:15:58,140
So what I'm actually going to do and this is just something that I like to do quite often, is I like

214
00:15:58,140 --> 00:15:59,850
to put a little underscore in front of these.

215
00:16:00,180 --> 00:16:04,410
So I'm actually going to name these with a little underscore.

216
00:16:07,950 --> 00:16:09,840
And this is something this is not just me.

217
00:16:10,260 --> 00:16:15,630
A lot of people like to name their member variables like this actually applies to some other programming

218
00:16:15,630 --> 00:16:16,470
languages as well.

219
00:16:17,640 --> 00:16:22,440
So what we're going to have to do then is put underscores one of returning these things, and I'm going

220
00:16:22,440 --> 00:16:23,340
to have to update this.

221
00:16:23,340 --> 00:16:25,260
So it's going to underscore Odometer.

222
00:16:28,790 --> 00:16:34,880
And then this, of course, will be these I can handle them because I'm going to change that.

223
00:16:35,270 --> 00:16:37,220
And let's see Painkiller.

224
00:16:39,790 --> 00:16:40,540
Phil?

225
00:16:42,930 --> 00:16:43,210
Deal.

226
00:16:43,650 --> 00:16:45,230
All right, cool.

227
00:16:45,270 --> 00:16:50,580
So I have changed these now, and I'll fix those in a second.

228
00:16:51,030 --> 00:16:56,430
So we have these parameters now and we're putting this is remember, this is our prototype here, so

229
00:16:56,430 --> 00:17:00,270
we have to define the parameters in the prototype as well for the constructor.

230
00:17:00,420 --> 00:17:02,040
And of course, all these other functions.

231
00:17:04,170 --> 00:17:06,360
So let's go down here and handle the implementation.

232
00:17:06,360 --> 00:17:06,750
So.

233
00:17:07,770 --> 00:17:12,330
We're going to copy and paste all of this in here, so I'm going to go ahead and copy this.

234
00:17:12,820 --> 00:17:15,150
Let's go ahead and put it here in our implementation.

235
00:17:15,540 --> 00:17:16,230
The parameters?

236
00:17:17,070 --> 00:17:20,640
And so what I'm going to do, remember our field stays the same with the rest of these are going to

237
00:17:20,640 --> 00:17:26,310
get set to these things that get passed now as arguments to the constructor.

238
00:17:27,210 --> 00:17:30,210
So what I'm going to do is I'm actually going to

239
00:17:33,480 --> 00:17:37,440
leave feel the same, but I'll say odometer equals miles.

240
00:17:38,530 --> 00:17:40,000
And then paint color.

241
00:17:40,240 --> 00:17:47,260
Going to be able to paint that the user's passing model is going to be equal to the model that these

242
00:17:47,260 --> 00:17:47,980
are passing.

243
00:17:48,340 --> 00:17:53,530
And let's go ahead and also put the brand here and we'll say brand equals brand.

244
00:17:56,490 --> 00:18:01,830
Cool, so now the user can kind of specify what type of car they want to start out with.

245
00:18:03,140 --> 00:18:04,770
So let's go ahead and check this out.

246
00:18:04,790 --> 00:18:06,680
Let's see how we're going to do it in the code down here.

247
00:18:06,680 --> 00:18:14,020
So what we can do is now we just have this car was like this without any parentheses, right?

248
00:18:14,030 --> 00:18:18,950
Even though that was kind of a function we were calling for, the constructor is still worked without

249
00:18:18,950 --> 00:18:25,670
frenzied, but now we're going to put parentheses because we want to specify the arguments for our car.

250
00:18:26,420 --> 00:18:28,730
So let's see patent brand motto miles.

251
00:18:28,740 --> 00:18:35,210
So let's say we want the paint color to just be like blue.

252
00:18:36,290 --> 00:18:40,970
We want the brand to be like, I'm just going to say something like silver.

253
00:18:41,450 --> 00:18:42,380
I like serious.

254
00:18:43,130 --> 00:18:52,470
And then let's say the model will be something like the X or something like that or.

255
00:18:52,610 --> 00:18:57,230
Yeah, and Impreza or something crazy not to spell that.

256
00:18:57,770 --> 00:19:00,140
Others say outback or something like that.

257
00:19:00,800 --> 00:19:01,700
And then we have.

258
00:19:04,560 --> 00:19:10,770
The was it Miles, right, and so we want to use car and we say, well, we just want something like,

259
00:19:11,400 --> 00:19:15,390
you know, forty thousand miles or something like that.

260
00:19:16,110 --> 00:19:18,270
So let's go ahead and try this out now.

261
00:19:18,270 --> 00:19:19,200
So now we have.

262
00:19:20,980 --> 00:19:22,330
All right, get odometer.

263
00:19:23,110 --> 00:19:31,630
And we have our jet fuel, let's as some other stuff, so let's say see out car dot and now see we we

264
00:19:31,630 --> 00:19:32,860
need some more accessories.

265
00:19:32,860 --> 00:19:35,080
So let's see.

266
00:19:37,310 --> 00:19:38,510
We have the.

267
00:19:41,220 --> 00:19:47,940
Painting toilets out of some a couple more minutes in here, so we can test out our our color and brand

268
00:19:47,940 --> 00:19:50,040
and stuff, so let's see.

269
00:19:50,340 --> 00:19:56,940
Steady string and we will say get.

270
00:19:59,520 --> 00:20:01,950
Get paint us give.

271
00:20:04,200 --> 00:20:05,010
Get paint.

272
00:20:05,820 --> 00:20:19,550
And now, let's say a steady string, and I get brand as steady string and get model.

273
00:20:21,360 --> 00:20:24,960
And yeah, that should do that should do for us.

274
00:20:25,110 --> 00:20:28,880
We also have this set paint here, so let's go ahead and test it out as well.

275
00:20:28,890 --> 00:20:31,290
So these are going to need to be implemented now.

276
00:20:31,680 --> 00:20:34,260
So we have this get paint, get brand, get model.

277
00:20:35,270 --> 00:20:36,860
So I'm going to go down here.

278
00:20:37,340 --> 00:20:46,520
Well, let's do it after sit paint, so we will say as TV's string car and colon get paint.

279
00:20:47,270 --> 00:20:51,530
And so this should just return a paint color.

280
00:20:55,880 --> 00:20:56,250
Oops.

281
00:20:56,420 --> 00:20:58,370
Let's go ahead and do that in the other ones.

282
00:20:58,850 --> 00:21:02,320
So this one will be get model.

283
00:21:03,170 --> 00:21:06,890
And so I will just say return model.

284
00:21:09,200 --> 00:21:21,500
And then let's say a steady string car gets brand and we will go ahead and just return France here as

285
00:21:21,500 --> 00:21:21,830
well.

286
00:21:21,860 --> 00:21:23,450
And I believe that was all three.

287
00:21:23,840 --> 00:21:24,590
Right, so.

288
00:21:25,770 --> 00:21:28,110
We have let's go check our function here.

289
00:21:28,140 --> 00:21:30,630
So get paint, get behind your model, those are the new ones.

290
00:21:32,420 --> 00:21:41,720
All right, so let's go ahead and test out here then, so we'll say see out card, get paint.

291
00:21:44,810 --> 00:21:50,870
And then let's go ahead and do a function call right here where we say a car got set paint and now we

292
00:21:50,870 --> 00:21:57,590
change, let's say, like, Oh, I'm going to repaint my car unless paid in black, and then let's go

293
00:21:57,590 --> 00:22:04,250
ahead and do another Seattle card dot get paint right to show how that's changed.

294
00:22:08,350 --> 00:22:13,320
Right, because our get paid here are set paint, we take a string, right?

295
00:22:13,350 --> 00:22:18,030
So sipping here takes a string and then it says the paint color to that color.

296
00:22:18,040 --> 00:22:21,670
So if we can't get paint again, we won't have that new painkiller.

297
00:22:21,910 --> 00:22:24,340
This is a cool thing about classes.

298
00:22:25,870 --> 00:22:32,440
These member variables are shared across the class, so.

299
00:22:33,830 --> 00:22:39,470
We defined all of these member variables here, right in their private private means that down here

300
00:22:39,470 --> 00:22:44,150
in Maine, we don't really have, you know, an access to that.

301
00:22:44,420 --> 00:22:52,430
So but here when we put these functions here that aren't Maine, but they say car colon, colon, the

302
00:22:52,430 --> 00:22:56,710
car colon, colon is giving us access to the private data members.

303
00:22:56,720 --> 00:23:02,630
So the interesting thing is if we change paint color, it stays the same across this whole class.

304
00:23:02,630 --> 00:23:08,540
So when we call this method again, it's going to get the updated paint color right, so it saves the

305
00:23:08,540 --> 00:23:10,250
state of the paint color.

306
00:23:12,420 --> 00:23:14,770
So let's go ahead and prove this right.

307
00:23:14,850 --> 00:23:18,210
So let me go ahead and save it, and then I'm going to compile it.

308
00:23:18,930 --> 00:23:22,040
Let's run it and let's see how this works out.

309
00:23:22,050 --> 00:23:26,640
So what we do get odometer, it started out at 40000, right?

310
00:23:26,910 --> 00:23:30,180
So when we print this out, it shows 40000 wheels.

311
00:23:30,180 --> 00:23:32,370
The next thing we print out car to get fuel.

312
00:23:32,640 --> 00:23:35,550
We never set our fuel explicitly here.

313
00:23:35,790 --> 00:23:38,430
When we made the object right, that was not for the user.

314
00:23:38,640 --> 00:23:41,730
The default constructor set the fuel to twelve point zero.

315
00:23:42,180 --> 00:23:48,280
So we go ahead and we print that out and we have 12 here, and then we do a get paint well.

316
00:23:48,350 --> 00:23:51,090
The original paint that the user specified was blue.

317
00:23:51,240 --> 00:23:57,510
So when we call it Clinton, says blue, then we say car got set paint, which sets it to black.

318
00:23:57,810 --> 00:23:59,220
What happens with this?

319
00:23:59,910 --> 00:24:06,840
This gets this black right here in this function call it gets sent up here to set paint.

320
00:24:06,870 --> 00:24:08,160
So black is here.

321
00:24:08,160 --> 00:24:10,650
And then it says painkiller now equals black.

322
00:24:11,070 --> 00:24:15,300
The next thing we're doing is doing a C out of get paint, right?

323
00:24:15,750 --> 00:24:17,850
So we see our car get paid.

324
00:24:19,220 --> 00:24:23,660
Go up here and we do get paid paint Painkiller has been set to black.

325
00:24:23,930 --> 00:24:27,620
This state is saved across this whole class.

326
00:24:27,980 --> 00:24:29,960
This is considered as part of the class.

327
00:24:29,960 --> 00:24:33,680
Be here because as car coal and coal in scope resolution operator here.

328
00:24:34,250 --> 00:24:38,300
So that's why we see that it now prints black when we print it out down here.

329
00:24:40,750 --> 00:24:42,250
So pretty cool.

330
00:24:42,490 --> 00:24:51,310
Now we know not only how to make a constructor, but we also know how to pass arguments to it and initialize

331
00:24:51,310 --> 00:24:56,110
the values to the user's choice kind of where they pass these arguments.

332
00:24:57,760 --> 00:25:04,690
So another important thing that we've been doing is using these things called getters and setters,

333
00:25:04,690 --> 00:25:11,570
which would be get paint and set paint, get odometer, get fuel, get paint.

334
00:25:11,590 --> 00:25:20,410
So these are getters when it says get and you also can refer to getters and setters as accessories and

335
00:25:20,770 --> 00:25:21,340
haters.

336
00:25:21,730 --> 00:25:28,420
So a getter is also an accessory, and a setter is also a mutate or mutate.

337
00:25:28,420 --> 00:25:33,130
Or just mean to change a setter is something that changes the color, right?

338
00:25:33,490 --> 00:25:38,950
So we have set paint changes the color to black, but get paid just gets you.

339
00:25:38,950 --> 00:25:42,160
Whatever the current state of paint, color is right.

340
00:25:42,160 --> 00:25:48,400
We have paint color here and whatever the current state of paint color is, when we call get paint,

341
00:25:48,400 --> 00:25:51,850
all it doesn't just return you whatever value is currently stored in there.

342
00:25:52,750 --> 00:26:00,200
This access, this mutate or here or this center is to change is for change it, for modifying.

343
00:26:00,200 --> 00:26:05,650
It makes a modification to this variable right and it makes the modification based on whatever color

344
00:26:05,650 --> 00:26:09,020
gets passed as an argument because you see this parameter here.

345
00:26:10,510 --> 00:26:13,360
So it's pretty cool.

346
00:26:14,020 --> 00:26:19,380
Another cool thing is that we're not limited to making one car, we can make as many cars as we want,

347
00:26:19,390 --> 00:26:20,950
so let's go ahead and make another car.

348
00:26:21,160 --> 00:26:27,550
I'm actually going to just call this car to car car two, and I'm going to say this one was white and

349
00:26:27,550 --> 00:26:29,200
this is a Ford.

350
00:26:29,560 --> 00:26:30,850
And it is.

351
00:26:32,170 --> 00:26:32,860
Let's see.

352
00:26:33,220 --> 00:26:37,930
The model is like a Ford Fiesta.

353
00:26:38,320 --> 00:26:42,550
And then we have the miles are only ten thousand.

354
00:26:43,060 --> 00:26:43,690
How about that?

355
00:26:44,410 --> 00:26:48,580
So let's go ahead and print these separate things out.

356
00:26:48,580 --> 00:26:56,860
So what we can do is we could see out and we can say, let's say car one.

357
00:26:58,480 --> 00:27:02,290
Uh, let's say car one miles.

358
00:27:04,930 --> 00:27:08,170
And we'll say car get odometer.

359
00:27:11,540 --> 00:27:15,230
And now we can actually say a car to.

360
00:27:19,860 --> 00:27:21,000
Let me just do this.

361
00:27:21,520 --> 00:27:24,360
I'm sorry for the struggle at the time, this kind of real right now.

362
00:27:25,980 --> 00:27:43,500
So we say car two miles and here I can put up this year and then we can say car two dogs get odometer

363
00:27:44,000 --> 00:27:44,200
right?

364
00:27:46,590 --> 00:27:52,740
So this will put ice probably for a space after this, so let's actually put a couple of spaces there.

365
00:27:55,680 --> 00:27:56,590
Yeah, there we go.

366
00:27:56,620 --> 00:28:03,030
And so we'll have the car, one miles will for now and we're doing car to get odometer right and then

367
00:28:03,030 --> 00:28:10,650
the second one would do a cartoon odometer and it will show us the values, default values of the second

368
00:28:10,650 --> 00:28:12,920
car so we can make as many objects as we want.

369
00:28:12,930 --> 00:28:15,120
Let's go ahead and just print this out to see what it looks like.

370
00:28:18,840 --> 00:28:19,350
All right.

371
00:28:19,890 --> 00:28:25,870
So we see a car one starts out with 40000 miles as expected and car to start out with 10000 miles,

372
00:28:25,870 --> 00:28:27,870
so you notice that we initialized it here.

373
00:28:28,380 --> 00:28:31,770
It knows which object has which data, right?

374
00:28:31,770 --> 00:28:37,710
We explicitly said Car two is an object that has this data that is held somewhere in memory.

375
00:28:38,130 --> 00:28:45,720
This object, when we refer to get odometer of car to it, is different, then referring to get odometer

376
00:28:45,720 --> 00:28:48,660
of the original car object that we made.

377
00:28:49,140 --> 00:28:49,430
Right.

378
00:28:49,440 --> 00:28:55,890
So you can make different objects now, and they can, of course, have different data associated with

379
00:28:55,890 --> 00:28:56,250
them, right?

380
00:28:56,270 --> 00:28:59,250
One is a Ford Fiesta with 10000 miles.

381
00:28:59,250 --> 00:29:01,440
The other one is a blue Subaru Outback.

382
00:29:01,440 --> 00:29:04,530
That's 40000 miles that later gets painted to black.

383
00:29:06,320 --> 00:29:10,680
OK, so I think I'm going to stop here for this lesson, I'm not trying to overload too much.

384
00:29:10,700 --> 00:29:14,050
We have a lot to go over with objects and classes.

385
00:29:14,060 --> 00:29:17,390
There's just a ton of stuff you can do with object oriented programming.

386
00:29:17,930 --> 00:29:23,120
Right now, the focus is just trying to get you comfortable with making classes.

387
00:29:23,420 --> 00:29:30,380
So making the blueprint, understanding what public and private are the difference between them being

388
00:29:30,380 --> 00:29:35,690
able to implement all of the prototypes that you put it here in the blueprint and the implementation

389
00:29:35,690 --> 00:29:36,420
goes here?

390
00:29:36,950 --> 00:29:37,250
Right?

391
00:29:37,280 --> 00:29:40,430
These are all the implementations understanding you have to use this.

392
00:29:41,030 --> 00:29:44,240
The class name Colin Colin before the member functions.

393
00:29:45,560 --> 00:29:50,810
And then, of course, now after this lecture, I expect you to understand what a constructor is, how

394
00:29:50,810 --> 00:29:59,630
to declare a constructor here in the public function section and how to implement a constructor here

395
00:29:59,630 --> 00:30:06,740
down past the class blueprint where and also not only know how to do it with empty parentheses here,

396
00:30:06,740 --> 00:30:11,630
but have parameters and know how to initialize all of your member variables.

397
00:30:11,630 --> 00:30:18,950
The private number of variables to either the parameters that have arguments being passed or just initialize

398
00:30:18,950 --> 00:30:24,710
them like feel here to some default value that was decided by you as the software engineer.

399
00:30:26,390 --> 00:30:31,850
Also, of course, knowing how to instantiate everything and knowing how to call methods on it, you

400
00:30:31,850 --> 00:30:34,790
know, it's just like string se length.

401
00:30:35,360 --> 00:30:39,830
Remember, like I said, string is a class just like car.

402
00:30:40,220 --> 00:30:47,090
Somebody else made class in this word right here was string and they had all kinds of functions.

403
00:30:47,330 --> 00:30:50,390
One of these functions is what is a length.

404
00:30:50,870 --> 00:30:52,430
So the name of it is length.

405
00:30:52,940 --> 00:30:56,840
And they made an implementation that said, String Colin, call in length, you know, and it's going

406
00:30:56,840 --> 00:31:00,740
to tell you how it's going to give you back the length of the string.

407
00:31:02,280 --> 00:31:03,990
So pretty cool, right?

408
00:31:04,920 --> 00:31:09,330
So with that, I think I'm going to stop here and I will see you in the next lesson where we continue

409
00:31:09,330 --> 00:31:13,680
on with more of these object oriented programming practices and concepts.
