1
00:00:00,660 --> 00:00:00,960
All right.

2
00:00:00,990 --> 00:00:06,300
Welcome back to another lecture, we are now going to get into a new kind of piece of the course where

3
00:00:06,300 --> 00:00:08,730
we talk about abstract data types.

4
00:00:09,480 --> 00:00:16,540
So abstract data types are things that are going to enable us to bring abstract ideas into our programs.

5
00:00:16,560 --> 00:00:24,930
So when I say abstract, I mean things that are not as well defined like things that we've done so far.

6
00:00:25,230 --> 00:00:32,970
Functions, loops, variables of types that are integers and boolean things that you were just told

7
00:00:33,420 --> 00:00:34,890
how they work and what they do.

8
00:00:34,890 --> 00:00:38,850
And they're kind of part of the language and you were just learning to program with these building blocks.

9
00:00:39,420 --> 00:00:45,780
Now we're going to kind of create our own blocks, our own shapes, our own data types.

10
00:00:46,400 --> 00:00:53,700
This is going to enable us to solve much bigger problems and turn kind of real world issues and real

11
00:00:53,700 --> 00:00:56,550
world world things that we want to build into code.

12
00:00:58,320 --> 00:01:02,520
So up until this point, we've just been dealing with pre-existing data types.

13
00:01:02,530 --> 00:01:07,680
So you've been told what these data types are and what they do, like an integer or float, bool, char,

14
00:01:07,710 --> 00:01:09,330
etc. all those things.

15
00:01:10,290 --> 00:01:13,870
Now comes the time when we're going to make our own data types.

16
00:01:13,890 --> 00:01:15,480
And why would we want to do this?

17
00:01:15,510 --> 00:01:18,090
Well, it's because of what I was just talking about.

18
00:01:18,420 --> 00:01:21,810
We want to represent abstract ideas in code.

19
00:01:22,920 --> 00:01:28,680
A good example is the string data type that we've been using that is actually something that someone

20
00:01:28,680 --> 00:01:29,130
made.

21
00:01:29,130 --> 00:01:35,670
It wasn't originally like baked into the basic fundamental structure of the C++ language.

22
00:01:36,120 --> 00:01:43,230
It was kind of added on was created by someone that wanted to extend the functionality and make programming

23
00:01:43,230 --> 00:01:46,290
in C++ more powerful, more simple.

24
00:01:46,290 --> 00:01:51,390
You kind of keep adding things on to a language and it becomes more abstract.

25
00:01:51,390 --> 00:01:54,960
It becomes closer to spoken language or something.

26
00:01:54,960 --> 00:02:02,220
You know, we're able to kind of use small pieces of code that are very powerful and do a lot, whereas

27
00:02:02,220 --> 00:02:09,120
you used to have to write maybe 10 or even 100 times as much code as far as typing characters just to

28
00:02:09,120 --> 00:02:10,050
do the same thing.

29
00:02:11,660 --> 00:02:19,250
So the data types we create can be a lot more abstract and imaginative, so we're going to go ahead

30
00:02:19,250 --> 00:02:24,380
and look at some simple, maybe somewhat trivial, but just to get us to understand some simple examples.

31
00:02:25,520 --> 00:02:28,490
So let's think back to the string data type.

32
00:02:29,390 --> 00:02:31,880
It had a member function called length, right?

33
00:02:31,890 --> 00:02:35,570
We had to use the dot length to get the length right.

34
00:02:36,890 --> 00:02:39,980
So that gave us the length of the string, of course.

35
00:02:40,820 --> 00:02:45,610
So what if I told you to instead design a car data type?

36
00:02:45,680 --> 00:02:48,920
This may seem weird because you're like, Well, my car's a physical thing.

37
00:02:49,430 --> 00:02:50,890
You know, it's not like a code thing.

38
00:02:50,900 --> 00:02:52,300
A string was like a code thing.

39
00:02:52,310 --> 00:02:58,370
It's a virtual like digital data thing like the car's not that I can see a car, I can drive a car.

40
00:02:58,370 --> 00:02:59,420
You can touch the car well.

41
00:02:59,900 --> 00:03:03,830
We can represent the idea of what a car is in code.

42
00:03:04,340 --> 00:03:08,510
So that makes me then have another question for you.

43
00:03:08,520 --> 00:03:12,380
So what kind of information would be associated with that?

44
00:03:12,950 --> 00:03:20,720
And then more specifically, what type of member functions like this might you have for that car data

45
00:03:20,720 --> 00:03:21,020
type?

46
00:03:22,800 --> 00:03:27,240
So you could, of course, have a length function, I mean, a car has a length just like a string,

47
00:03:27,240 --> 00:03:27,600
right?

48
00:03:28,200 --> 00:03:32,460
But can you think of things that are a little more specific to cars?

49
00:03:33,630 --> 00:03:41,460
So if I said that this car could hold a collection of variables, so this car data type can hold variables

50
00:03:41,460 --> 00:03:48,090
of other types that you already know, like and charbel and string, what values would you have in these

51
00:03:48,090 --> 00:03:48,870
variables?

52
00:03:48,870 --> 00:03:49,950
What would they be?

53
00:03:49,950 --> 00:03:53,220
What variable names would you put for them?

54
00:03:54,000 --> 00:03:59,530
Let's say you had maybe like an integer, a float in a string or something like that.

55
00:03:59,550 --> 00:04:05,400
What would you put as the names for those if you were going to associate it as information that has

56
00:04:05,400 --> 00:04:06,540
to do with card?

57
00:04:08,920 --> 00:04:10,930
So let's think about the car data type.

58
00:04:11,980 --> 00:04:13,400
What about the price of the car?

59
00:04:13,420 --> 00:04:14,850
A car has the price right.

60
00:04:14,860 --> 00:04:20,800
You could make a price variable for this car data type if you made a price variable, what data type

61
00:04:20,800 --> 00:04:21,400
would that be?

62
00:04:21,430 --> 00:04:23,650
Would you make it an end or would you make it a float?

63
00:04:24,280 --> 00:04:25,870
What about the color of the car?

64
00:04:26,560 --> 00:04:27,850
Would you make that a string?

65
00:04:28,900 --> 00:04:34,750
So these are questions that you're going to need to answer when you're creating your own abstract data

66
00:04:34,750 --> 00:04:35,140
types.

67
00:04:37,190 --> 00:04:42,470
So the first thing that I'm going to discuss as far as implementing abstract data types is something

68
00:04:42,470 --> 00:04:43,670
called structs.

69
00:04:44,000 --> 00:04:50,180
So there's multiple ways to associate a collection of these variables that we're talking about that

70
00:04:50,180 --> 00:04:52,610
have to do with a type that you came up with.

71
00:04:54,010 --> 00:04:59,230
The first one that we go through is structs, it's kind of the most simple one, this was actually part

72
00:04:59,230 --> 00:05:03,190
of the sea language before C++ came around.

73
00:05:04,000 --> 00:05:14,990
So sea has struck, C++ has a lot more than what C++, but see kind of as far as the terms of abstraction

74
00:05:14,990 --> 00:05:16,440
and kind of stopped its structs.

75
00:05:18,520 --> 00:05:22,340
So here we have a struct in an example program.

76
00:05:22,360 --> 00:05:25,780
Nothing is happening in Maine, so it doesn't really do anything.

77
00:05:25,780 --> 00:05:28,510
But this is how you would declare a struct.

78
00:05:29,440 --> 00:05:34,330
And so a struct you can just think of as a structure of data.

79
00:05:35,200 --> 00:05:37,810
So we're saying, OK, we're going to have a structure.

80
00:05:37,810 --> 00:05:43,030
So it's kind of like, you know, a shape or a building or, you know, some type of structure.

81
00:05:43,300 --> 00:05:44,020
That's what it is.

82
00:05:44,020 --> 00:05:45,520
So we say struct for short.

83
00:05:46,300 --> 00:05:47,500
Here's what we call it.

84
00:05:47,500 --> 00:05:51,730
We call it car, and we're going to talk about naming conventions in a bit.

85
00:05:51,760 --> 00:05:55,600
You notice I have a lowercase right now, but that's not necessarily what we're going to do for our

86
00:05:55,600 --> 00:05:56,260
names.

87
00:05:56,920 --> 00:05:58,620
But I'm just keeping it kind of simple.

88
00:05:58,630 --> 00:06:01,660
You can do this, you can name it all lowercase car.

89
00:06:03,550 --> 00:06:07,750
And then we have some brackets, you know, we're very familiar with the brackets we use, the brackets

90
00:06:07,750 --> 00:06:09,040
for the functions, right?

91
00:06:09,040 --> 00:06:12,040
Like this main function, we use brackets for the F.

92
00:06:12,040 --> 00:06:17,050
We used brackets for the for in the while, right when we're defining a struct.

93
00:06:17,860 --> 00:06:20,890
You know, this is up here in global space.

94
00:06:20,900 --> 00:06:22,300
It's a global variable.

95
00:06:23,110 --> 00:06:25,030
It's accessible to main.

96
00:06:25,060 --> 00:06:31,870
It'll be accessible to the rest of the program if we continue to put other functions in between the

97
00:06:31,880 --> 00:06:32,920
struct in main.

98
00:06:33,520 --> 00:06:36,370
This is going to be accessible throughout the whole file.

99
00:06:37,690 --> 00:06:39,820
So what are we doing here?

100
00:06:40,090 --> 00:06:41,320
Let's take a closer look.

101
00:06:41,440 --> 00:06:44,230
So this struct has three member variables.

102
00:06:44,350 --> 00:06:51,850
You've heard me say member functions like dot length for the string that was a member function right

103
00:06:52,180 --> 00:06:56,560
of string, just like vector dot size, right?

104
00:06:56,710 --> 00:07:02,830
When you make a vector, let's say a vector and you call it my vector and you do my vector size, that

105
00:07:02,830 --> 00:07:05,260
dot size was a member function, remember?

106
00:07:06,390 --> 00:07:11,370
So this drug has three what we're calling member variables.

107
00:07:12,400 --> 00:07:16,990
And it's because they are associated, they are members of the Struct..

108
00:07:18,110 --> 00:07:23,970
So these are price color and miles per gallon, which have just shortened to empty.

109
00:07:26,380 --> 00:07:30,850
So how do we access or use these member variables?

110
00:07:31,220 --> 00:07:33,440
You notice that they've been declared in here?

111
00:07:33,850 --> 00:07:40,040
So you're saying, OK, well, we have a car, this car has three different variables inside of it.

112
00:07:40,750 --> 00:07:43,300
It's got price, colour and miles per gallon.

113
00:07:44,580 --> 00:07:52,370
Kind of looks like this car is this big box and inside the box, we have, you know, three other small

114
00:07:52,370 --> 00:07:52,820
boxes.

115
00:07:52,820 --> 00:07:56,390
This can all store data, so let's say the main big boxes here.

116
00:07:56,390 --> 00:07:58,250
Car stores some data, right?

117
00:07:58,580 --> 00:07:59,480
What does it store?

118
00:07:59,510 --> 00:08:03,060
Well, it stores three other primitive data types.

119
00:08:03,090 --> 00:08:04,820
In fact, this is not primitive.

120
00:08:04,850 --> 00:08:07,670
The strings, not primitive, but the intent to float are.

121
00:08:08,720 --> 00:08:10,460
But it stores three data types, right?

122
00:08:10,490 --> 00:08:15,740
It doesn't they don't have to be primitive, they can be anything, you know, they could even be abstract

123
00:08:15,740 --> 00:08:16,600
data types in here.

124
00:08:16,610 --> 00:08:21,680
The point is the car just has three variables of various types in here.

125
00:08:22,580 --> 00:08:25,280
Each one of those variables has its own type two, right?

126
00:08:26,360 --> 00:08:30,710
So here we have car type and we have a price.

127
00:08:31,720 --> 00:08:37,600
Which is an entity we have color, which is a string type, and we have per gallon, which is a float

128
00:08:37,600 --> 00:08:37,870
type.

129
00:08:40,090 --> 00:08:46,230
So the weather we're going to access these member variables is just like the dot length and the dot

130
00:08:46,240 --> 00:08:49,060
size that I was talking about for those functions.

131
00:08:49,660 --> 00:08:57,220
You can do the same thing for the member variables, so you notice that I'm using Dot, the dot operator

132
00:08:57,220 --> 00:08:57,580
here.

133
00:08:58,150 --> 00:09:05,500
Before we do that, though, just like creating a variable of type int in here.

134
00:09:06,250 --> 00:09:13,540
And just like we might create an end inside of our main, we need to create a variable of type car.

135
00:09:14,920 --> 00:09:22,270
So notice that here we are declaring a local variable inside main of type car, just like we would do

136
00:09:22,270 --> 00:09:24,400
with one of these other types in Maine.

137
00:09:24,400 --> 00:09:29,560
We could, of course, say string color and then we could say color equals blue.

138
00:09:30,250 --> 00:09:36,640
But what we're doing here is we're saying, OK, I'm going to declare a variable of type car in Maine,

139
00:09:37,300 --> 00:09:40,600
and I'm giving that variable the name C here.

140
00:09:40,690 --> 00:09:44,170
So rather than like, you know, end my end, it's car.

141
00:09:44,390 --> 00:09:46,360
See, this is the type.

142
00:09:46,600 --> 00:09:47,920
This is the variable name.

143
00:09:49,000 --> 00:09:57,550
The way that we access the variables, and in this example, here I am assigning a value to it after

144
00:09:57,550 --> 00:09:58,300
accessing it.

145
00:09:58,630 --> 00:10:03,970
Accessing happens with the DOT, so we have see which is our variable name, right?

146
00:10:04,210 --> 00:10:05,990
This was a variable name for a car.

147
00:10:06,010 --> 00:10:08,530
It was C with an instance of a car.

148
00:10:09,610 --> 00:10:12,580
And we do see dot price.

149
00:10:13,630 --> 00:10:15,460
So this is the dot operator.

150
00:10:15,460 --> 00:10:17,170
It's similar to those member functions.

151
00:10:17,170 --> 00:10:21,820
We are accessing the variable car dot price.

152
00:10:22,390 --> 00:10:26,350
So imagine here when I say car, right?

153
00:10:26,440 --> 00:10:29,080
So that gives me this box, this big box.

154
00:10:30,390 --> 00:10:37,230
Then I say car dot, and then I have access to all three of these in here, and I say after the DOT,

155
00:10:37,230 --> 00:10:42,570
I put color that gives me access to this specific box inside of the car box.

156
00:10:43,290 --> 00:10:50,660
That's what you can imagine it as kind of as kind of a metaphor or analogy or something like that.

157
00:10:50,670 --> 00:10:55,890
So we use this dot here for all of the different variables and we're setting them.

158
00:10:56,490 --> 00:11:08,190
We now store the value 20000, the integer 20000 into the price member member where we're calling these

159
00:11:08,400 --> 00:11:09,450
member variables.

160
00:11:09,450 --> 00:11:17,130
So the integer twenty thousand is now getting stored and assigned to the price member.

161
00:11:18,210 --> 00:11:20,820
Next, we have these string blue.

162
00:11:21,200 --> 00:11:22,770
Remember, this is a string four color.

163
00:11:23,370 --> 00:11:31,560
The string blue gets assigned to the color member of the car variable that we made, and then the float

164
00:11:31,560 --> 00:11:42,480
22.5 gets assigned to the MPD miles per gallon float member of our car that we made, which was seen

165
00:11:43,230 --> 00:11:43,620
here.

166
00:11:43,620 --> 00:11:45,480
We're just printing those out.

167
00:11:45,660 --> 00:11:47,790
Once again, we need to access them, right?

168
00:11:47,790 --> 00:11:50,100
It does not matter that we're not assigning stuff.

169
00:11:50,400 --> 00:11:56,280
Even if we want to print it out, we're going to have to use a dot to get access to anything inside

170
00:11:56,280 --> 00:11:57,060
the struct.

171
00:11:57,630 --> 00:12:06,330
So here we print to the console the car's price, the car's color and the car's mpg.

172
00:12:09,490 --> 00:12:21,520
So I tried to be very kind of detailed in my explanation about this initial struct idea.

173
00:12:22,570 --> 00:12:26,080
So I'm hoping that we can go straight into a practice problem right away.

174
00:12:27,100 --> 00:12:32,620
So what I want you to attempt and I say attempt, you know, don't feel bad if you can't figure it out,

175
00:12:32,620 --> 00:12:36,100
but I would like you to try to make a program.

176
00:12:37,140 --> 00:12:43,860
And sorry, this kind of knot doesn't have correct grammar here, but make a program that asks a user

177
00:12:43,860 --> 00:12:46,700
for their name, age and blood type.

178
00:12:46,710 --> 00:12:48,570
So this is going to be like a patient.

179
00:12:48,610 --> 00:12:48,930
Right?

180
00:12:49,350 --> 00:12:53,520
So this information should be stored in a struct called patient.

181
00:12:55,810 --> 00:13:02,080
And then that struct is going to need the appropriate member variables, I just said that a patient

182
00:13:02,080 --> 00:13:05,600
needs a name and age and a blood type.

183
00:13:05,620 --> 00:13:06,040
Right?

184
00:13:07,150 --> 00:13:09,280
So remember what I just talked about.

185
00:13:09,370 --> 00:13:18,270
You can access these variables by using patient whatever the variable name is, right?

186
00:13:18,280 --> 00:13:20,080
So patient is the type.

187
00:13:20,800 --> 00:13:21,100
Right.

188
00:13:21,100 --> 00:13:26,780
So we're calling it patient, but let's say that you name the variable something else.

189
00:13:26,800 --> 00:13:28,560
That's what this really means here.

190
00:13:28,570 --> 00:13:30,520
So it's not going to be the word patient.

191
00:13:31,620 --> 00:13:37,230
Let's just say you call it patient in the variable name is like.

192
00:13:39,010 --> 00:13:40,810
I don't know pee or something like that.

193
00:13:40,870 --> 00:13:48,070
We put patient pee, you would do pee dot and then the member name, right, the member variable name

194
00:13:48,070 --> 00:13:51,850
to have access to that, even for storing input into them.

195
00:13:51,850 --> 00:13:57,920
So if you're reading input in from the console, from the user, which you know how to do.

196
00:13:59,080 --> 00:14:05,740
Remember that when you're doing that, you can act like this whole thing right here, let's say p dot,

197
00:14:06,010 --> 00:14:14,470
whatever variable name that is going to be the same thing as when you just read into another variable.

198
00:14:14,690 --> 00:14:17,140
Right, a normal local variable that you would have created.

199
00:14:17,410 --> 00:14:23,230
So just want to let you know that so your output should look like this, you should make it look exactly

200
00:14:23,230 --> 00:14:23,970
like this.

201
00:14:23,980 --> 00:14:26,050
Of course, this is the user's input.

202
00:14:26,050 --> 00:14:29,050
I'm putting my name and age and a blood type.

203
00:14:29,440 --> 00:14:32,590
You don't have to put these things to test.

204
00:14:32,600 --> 00:14:35,890
You can use whatever test data you'd like as the user.

205
00:14:36,220 --> 00:14:37,600
But this should be the same.

206
00:14:37,600 --> 00:14:40,170
It should say this, it should say.

207
00:14:40,180 --> 00:14:46,000
And then after you enter it, it should say patient colon and the name age, colon in the age and then

208
00:14:46,000 --> 00:14:47,800
blood type colon and the blood type.

209
00:14:49,400 --> 00:14:56,360
All right, so go ahead and pause the video, head to your favorite editor and try and figure this out

210
00:14:56,360 --> 00:15:00,380
for yourself, and then you can continue watching the lecture once you are done.

211
00:15:03,100 --> 00:15:08,110
OK, so what I'm going to do is go over this before I continue the rest of the lecture, so I'm going

212
00:15:08,110 --> 00:15:08,980
to go here.

213
00:15:10,250 --> 00:15:21,050
And what I'm going to do is I am going to go into this program, so I think I can move that simply because

214
00:15:21,050 --> 00:15:21,980
I already made that.

215
00:15:22,430 --> 00:15:25,520
So what I'm going to do is I'm actually going to make a.

216
00:15:26,620 --> 00:15:34,960
File on a call, it struck out CP, so it's going to be stretched us CP, what I'm going to do is include

217
00:15:34,960 --> 00:15:37,410
extreme as I'm going to need that for sure, right?

218
00:15:38,130 --> 00:15:45,430
And then what I'm going to do is, say, using name base study because I'm feeling lazy.

219
00:15:46,510 --> 00:15:48,140
OK, now it's time to make our struct.

220
00:15:48,160 --> 00:15:49,120
So what are we going to do?

221
00:15:49,270 --> 00:15:50,440
We're going to say struct.

222
00:15:51,490 --> 00:15:52,960
We're going to want to make a patient struct.

223
00:15:53,170 --> 00:16:00,580
But what I want to say right now is that C++ has some style guidelines for naming things and capitalization

224
00:16:00,580 --> 00:16:01,090
and all that.

225
00:16:01,340 --> 00:16:04,180
And so I'm actually going to put a capital p for patient.

226
00:16:05,020 --> 00:16:09,460
This is something we'll discuss in greater detail later on, but you need to make sure to follow the

227
00:16:09,460 --> 00:16:13,840
style guidelines because that's kind of important.

228
00:16:13,840 --> 00:16:15,670
People created these standards of style.

229
00:16:16,540 --> 00:16:18,460
So you should have it be capitalized.

230
00:16:18,460 --> 00:16:20,380
So I'm going to say struct patient.

231
00:16:20,680 --> 00:16:23,650
You don't have to, but you should say capital patient.

232
00:16:24,190 --> 00:16:28,650
What I'm going to do now is think about that blood type, the name the age.

233
00:16:28,660 --> 00:16:32,110
So I'm going to say that the name is going to be a string.

234
00:16:32,110 --> 00:16:38,090
So let's do string name and for age, because it's not going to be a float, write your whole number

235
00:16:38,090 --> 00:16:39,400
of years old.

236
00:16:39,970 --> 00:16:43,180
So then our blood type should also be a string.

237
00:16:43,180 --> 00:16:49,150
I would call it a cha, but we have a I think and B and then O and then a b, right?

238
00:16:49,160 --> 00:16:50,350
I think those are the four blood types.

239
00:16:50,350 --> 00:16:55,360
So since there's a B and that's two characters, I'm going to go ahead and call this the string as well.

240
00:16:55,840 --> 00:17:02,510
So I will say string blood type, and I'll just do some camel case right there for that.

241
00:17:02,530 --> 00:17:08,440
The capitalization of every kind of second word, you know, or subsequent word.

242
00:17:08,770 --> 00:17:11,290
So I'm going to go ahead and leave it at that.

243
00:17:11,980 --> 00:17:13,630
Don't forget the semicolon here.

244
00:17:13,810 --> 00:17:14,860
That's an important thing.

245
00:17:16,090 --> 00:17:17,430
So now I have my struct.

246
00:17:17,440 --> 00:17:25,300
What I'm going to do is make my main function and then I am actually going to read into these variables.

247
00:17:25,300 --> 00:17:27,100
So I will see out something first.

248
00:17:27,100 --> 00:17:37,600
I will say, you want to say, enter your name, age and blood type.

249
00:17:37,890 --> 00:17:38,830
Know for blood type.

250
00:17:39,100 --> 00:17:45,970
We have like a b o a b something like that.

251
00:17:46,870 --> 00:17:47,450
All right.

252
00:17:47,470 --> 00:17:52,390
So and then now I'm going to leave it at that and then I will see in two.

253
00:17:53,230 --> 00:17:57,040
I will say, Oh yeah, we got to make our looks.

254
00:17:57,050 --> 00:17:58,540
We got to make our struct right.

255
00:17:58,570 --> 00:18:01,780
So what I'm going to do is make a struct variable.

256
00:18:01,780 --> 00:18:05,680
So we're going to see type patient, right, because our struct is type patient.

257
00:18:06,190 --> 00:18:07,390
I'm going to call that P.

258
00:18:08,080 --> 00:18:11,760
Now what we can do is read into these variables by using the dot, right.

259
00:18:11,780 --> 00:18:14,740
So I'm going to do p dot name.

260
00:18:14,740 --> 00:18:15,850
So we're going to read into that.

261
00:18:16,270 --> 00:18:22,480
Then I'll do p that age or in into that and then I'll do P Dot blood type.

262
00:18:23,610 --> 00:18:30,210
All right, now, all we've got to do is print it out, so I'm going to see out and I'm going to say

263
00:18:31,320 --> 00:18:39,450
the name and then I'll put a little space here and I will say Peacock name to print that out.

264
00:18:40,410 --> 00:18:42,000
I do doing in line.

265
00:18:42,010 --> 00:18:43,380
I'll say, see out.

266
00:18:45,300 --> 00:18:54,900
Yeah, age and repeat what age in line, and then I will see out blood type.

267
00:18:56,250 --> 00:18:59,670
And this will be that blood type.

268
00:19:03,530 --> 00:19:08,390
And I'll do an airline and then just to return zero and finish that up right there.

269
00:19:08,690 --> 00:19:11,080
So that is all we should really need.

270
00:19:11,090 --> 00:19:14,150
So we're asking the user for the name, age and blood type.

271
00:19:14,160 --> 00:19:21,200
We specify this these options here, and then we go ahead and read all those in and then we print them

272
00:19:21,200 --> 00:19:23,300
out in an order that was shown.

273
00:19:23,570 --> 00:19:25,310
So let's go ahead and try and run this.

274
00:19:25,310 --> 00:19:28,840
So I'm going to say G-force Plus struck that CBP dash.

275
00:19:28,850 --> 00:19:36,410
Oh, and I'm actually going to call this uh, I think I, I remove my executable before.

276
00:19:36,410 --> 00:19:38,550
It doesn't really matter, but I'm to call it patient out.

277
00:19:38,570 --> 00:19:42,740
So I'm going to say G Plus Plus stretched out CBP and then Dash.

278
00:19:42,740 --> 00:19:44,950
Oh, and patient got out.

279
00:19:46,160 --> 00:19:47,060
All right, so it looks like that.

280
00:19:47,060 --> 00:19:48,980
Comp. OK, so let's go ahead and run it.

281
00:19:50,330 --> 00:20:00,230
So in a name, age, blood type, I'm going to say killing seven and a b, and there we see a printout.

282
00:20:00,380 --> 00:20:00,860
You can go ahead.

283
00:20:00,860 --> 00:20:08,750
And again, I'll just say in a, uh, five type O and then all prints out nicely.

284
00:20:09,500 --> 00:20:15,230
OK, so pretty simple exercise was really just to get you to make your first struct and start feeling

285
00:20:15,230 --> 00:20:17,730
a little bit comfortable with the syntax.

286
00:20:18,710 --> 00:20:20,810
So let's head back to the lecture.

287
00:20:23,740 --> 00:20:28,960
So some important final notes that I want to go over on strokes and abstract data types in general.

288
00:20:30,220 --> 00:20:31,810
Here we have a stark rectangle.

289
00:20:31,900 --> 00:20:35,650
It has on the same line being declared width and height.

290
00:20:35,680 --> 00:20:38,390
These are two variables we have and width and height.

291
00:20:38,410 --> 00:20:40,210
You can just put them on the same line.

292
00:20:40,210 --> 00:20:44,050
You not have to do int width, semicolon and then into height semicolon.

293
00:20:44,050 --> 00:20:46,120
On the next line, you can just put it all on one line.

294
00:20:46,330 --> 00:20:51,370
Not sure if I've gone over that syntax before, but if you have stuff of the same data type, you could

295
00:20:51,370 --> 00:20:57,340
just say and and then with height, something else, something else and else and so on, if they're

296
00:20:57,340 --> 00:20:58,120
all integers.

297
00:20:59,350 --> 00:21:04,270
So we have width and height and then I make a rectangle variable, right?

298
00:21:04,570 --> 00:21:05,860
So type rectangle.

299
00:21:07,200 --> 00:21:13,530
Notice the capitalization to for that, for our abstract data type name, and then I put a variable

300
00:21:13,530 --> 00:21:20,580
name R1 and I make another rectangle R2, I say R1 dot with has the value of five now and R2 Dot with

301
00:21:20,580 --> 00:21:21,660
has a value of five.

302
00:21:22,110 --> 00:21:23,070
Then I'm like, huh?

303
00:21:23,190 --> 00:21:26,280
They both have the with five, and I haven't said what the height is.

304
00:21:26,280 --> 00:21:28,410
They're pretty much the same thing, right?

305
00:21:28,770 --> 00:21:34,040
So can I say if R1 equals equals R2, then print out same?

306
00:21:34,590 --> 00:21:36,900
No, you cannot do this.

307
00:21:37,350 --> 00:21:44,280
You cannot compare structs to each other or any other abstract data types that we will be going over

308
00:21:44,280 --> 00:21:46,650
in the future to each other by default.

309
00:21:46,650 --> 00:21:47,310
Like this?

310
00:21:47,850 --> 00:21:52,890
You know how you can compare an integer to an integer in a string to a string and a chart to a char?

311
00:21:53,250 --> 00:21:54,480
That was fine, right?

312
00:21:54,900 --> 00:22:01,830
Let's just say you had it with equals five and with two equals five.

313
00:22:01,830 --> 00:22:03,120
Like two integers like that.

314
00:22:03,120 --> 00:22:07,500
And you said with two equals with one, that's fine.

315
00:22:08,010 --> 00:22:08,640
That's fine.

316
00:22:08,640 --> 00:22:10,120
C++ is OK with that.

317
00:22:10,560 --> 00:22:15,690
You cannot compare structs because they are more complex.

318
00:22:15,690 --> 00:22:19,350
They have these inner variables and it's a user defined type.

319
00:22:19,860 --> 00:22:31,070
C++ actually expects you to describe what this comparison really means in terms of your data type,

320
00:22:31,080 --> 00:22:33,930
so you have to kind of create a new.

321
00:22:34,960 --> 00:22:41,110
Equality operator and a new less than operator are greater than operators, so on and so forth.

322
00:22:41,530 --> 00:22:43,320
And we're not going to get into that quite yet.

323
00:22:43,370 --> 00:22:48,700
That's something that we're going to do with abstract data types pretty soon, not too far away.

324
00:22:48,790 --> 00:22:51,100
But, you know, we're a little bit away.

325
00:22:52,390 --> 00:22:57,490
Just want to let you know you can't do this in case you try this, you cannot compare two strikes directly

326
00:22:57,490 --> 00:23:04,030
with these operators that you've learned these kind of, you know, less than greater than all that

327
00:23:04,030 --> 00:23:04,350
stuff.

328
00:23:04,360 --> 00:23:07,060
So don't try and do that.

329
00:23:07,390 --> 00:23:10,420
Another thing is don't forget the semicolon.

330
00:23:10,420 --> 00:23:12,670
So this has a semicolon.

331
00:23:12,670 --> 00:23:15,130
After the brackets you notice, the other things you've done.

332
00:23:15,130 --> 00:23:16,120
Look at the F here.

333
00:23:17,050 --> 00:23:22,150
The if doesn't need a semicolon after the brackets, the loops don't need a semicolon after the brackets,

334
00:23:22,150 --> 00:23:22,480
right?

335
00:23:23,260 --> 00:23:28,960
Neither do functions, but the struct do need a semicolon after the brackets.

336
00:23:28,960 --> 00:23:30,510
So just remember that.

337
00:23:30,520 --> 00:23:30,880
All right.

338
00:23:32,470 --> 00:23:37,360
So with that, this kind of I think enough to not overload you.

339
00:23:37,390 --> 00:23:42,820
I don't want to go over too much in this lecture other than introduce you to the idea of an abstract

340
00:23:42,820 --> 00:23:49,600
data type and one of the ways that you can implement your own abstract data type, which is a struct.

341
00:23:49,990 --> 00:23:56,410
So with that, I will see you in the next lectures where we will continue on talking about abstract

342
00:23:56,410 --> 00:23:57,040
data types.
