1
00:00:00,570 --> 00:00:06,870
So last lesson kind of ended abruptly, but I'm going to continue on kind of where we left off.

2
00:00:08,310 --> 00:00:13,140
We're going to talk about a couple of new subjects today, but I'm not really going to have a slideshow

3
00:00:13,140 --> 00:00:13,780
associated with that.

4
00:00:13,800 --> 00:00:16,410
I'm just going to kind of go straight into the code.

5
00:00:17,340 --> 00:00:26,220
So we left off talking about using a pointer to a struct object and kind of how it changed things in

6
00:00:26,220 --> 00:00:27,030
our loop, right?

7
00:00:27,750 --> 00:00:34,500
So it changed the output that we saw because when we modified the pointer, it modified that same memory

8
00:00:34,500 --> 00:00:38,970
and we were actually just storing pointers in the vector that we're all point the same memory.

9
00:00:38,970 --> 00:00:40,950
So it kept getting changed.

10
00:00:41,190 --> 00:00:44,730
And so the pretty much everything in the vector.

11
00:00:45,910 --> 00:00:51,820
Ended up just being like a another plant of the same memory and the last thing that was in that file

12
00:00:51,820 --> 00:00:53,490
right here, person input that.

13
00:00:55,110 --> 00:00:59,590
Was in fact, you know, it was everything was Nancy, like, for example, you.

14
00:01:01,050 --> 00:01:06,030
So what if we just want to not have it do that and not change it, but we still want to use dynamic

15
00:01:06,030 --> 00:01:07,580
memory, and that's why we're going over right now.

16
00:01:07,590 --> 00:01:12,480
So what am I doing off the bat is I'm going to get rid of these because I'm actually going to use variables

17
00:01:12,480 --> 00:01:14,910
now like we were before.

18
00:01:16,140 --> 00:01:19,800
So what I'm going to do, I'm actually going to get rid of this as well.

19
00:01:20,090 --> 00:01:20,730
Copy it.

20
00:01:20,730 --> 00:01:26,670
But what I'm going to do is say, I'm going to say string name and age like we were before and then

21
00:01:27,420 --> 00:01:27,930
wait.

22
00:01:29,720 --> 00:01:34,940
And then what we're going to do is we're going to read into these variables and then I am going to make

23
00:01:34,940 --> 00:01:38,510
a new person object and then I'm going to set them here.

24
00:01:38,990 --> 00:01:49,670
So I'm going to say Parrow name equals name P Arrow age, eagle's age and P arrow weight equals weight.

25
00:01:51,890 --> 00:01:57,530
So now what happens is I read everything in first from the file into variables.

26
00:01:57,590 --> 00:02:00,770
Then I make a new person object each time.

27
00:02:00,770 --> 00:02:01,400
So this is.

28
00:02:02,470 --> 00:02:06,310
Actually going to be not the same person.

29
00:02:06,610 --> 00:02:13,450
It's actually going to be a new dynamically allocated person before we had it up here, and we were

30
00:02:13,450 --> 00:02:17,380
essentially just using the same person each time.

31
00:02:17,650 --> 00:02:19,600
And so we're pointing to the same memory.

32
00:02:21,130 --> 00:02:27,610
But now what we're doing is we're making we're explicitly making a new piece of memory on the heap for

33
00:02:27,610 --> 00:02:32,400
our person and then we're making a pointer to that on the heap.

34
00:02:32,410 --> 00:02:38,980
So each time it's going to be a new pointer to a new area of memory Hempstead of the same variable name.

35
00:02:38,980 --> 00:02:43,990
But it's actually going to be a new chunk of memory each time, rather than just sharing the same chunk

36
00:02:43,990 --> 00:02:45,130
of memory like before.

37
00:02:45,910 --> 00:02:48,430
Then we set all these to the appropriate variables.

38
00:02:48,850 --> 00:02:52,990
The reason I did this is just so it was kind of clean to be able to read into the variables here, make

39
00:02:52,990 --> 00:02:58,570
a new object and then set them rather than read them straight into these data members.

40
00:02:59,650 --> 00:03:04,120
And then what we can do down here is just push it back to the vector edge because our present fact is

41
00:03:04,120 --> 00:03:05,470
of type person pointer.

42
00:03:05,470 --> 00:03:09,910
So we're going to say person vector pushed back and put P there.

43
00:03:12,500 --> 00:03:16,940
So now let's see what happens, so I still left these like arrows down here.

44
00:03:17,990 --> 00:03:21,980
But now we're making a new object each time and adding that to the vector, we're adding the pointer

45
00:03:21,980 --> 00:03:24,260
to the new object each time to the vector.

46
00:03:24,830 --> 00:03:26,930
So let's go ahead and save this.

47
00:03:27,770 --> 00:03:29,720
I will do it, C++.

48
00:03:30,470 --> 00:03:32,360
This is just a copy.

49
00:03:32,630 --> 00:03:32,820
Hmm.

50
00:03:36,620 --> 00:03:37,030
All right.

51
00:03:37,040 --> 00:03:39,050
So let's go ahead and run it with

52
00:03:41,780 --> 00:03:44,900
five easy person input.

53
00:03:48,050 --> 00:03:48,320
All right.

54
00:03:48,320 --> 00:03:55,880
So now let's go ahead and scroll up, and we noticed that we see three different people now, so we

55
00:03:55,880 --> 00:03:58,700
have Bob, Jeff and Nancy.

56
00:03:59,030 --> 00:04:00,620
So in this order here.

57
00:04:00,920 --> 00:04:05,720
And if I switch this back to how it was before.

58
00:04:08,320 --> 00:04:16,390
I say this will go ahead and run this again, and you notice now Jeff is at the end, so we have different

59
00:04:16,390 --> 00:04:23,890
people now because what we are doing is we are actually creating a new person each time in a separate

60
00:04:23,890 --> 00:04:25,240
region of memory.

61
00:04:25,330 --> 00:04:32,860
Right now, new keep allocated person struct and then we're making a pointer to that each time to that

62
00:04:32,860 --> 00:04:33,640
new area.

63
00:04:33,640 --> 00:04:38,860
So each person has their own area of memory, and we're adding the pointer to each one of those areas

64
00:04:38,860 --> 00:04:41,920
of memory to the person that each time.

65
00:04:42,970 --> 00:04:46,900
So if we wanted it dynamically allocated and we didn't want to change the same region of memory, we

66
00:04:46,900 --> 00:04:49,840
would just need to put this inside of the well.

67
00:04:50,050 --> 00:04:51,730
And of course, you notice I changed.

68
00:04:52,060 --> 00:04:58,360
I added this kind of changed this over reading into variables so I could accommodate for this new style

69
00:04:58,600 --> 00:04:59,560
of code in here.

70
00:05:01,510 --> 00:05:01,960
All right.

71
00:05:01,970 --> 00:05:06,790
So with that, I'm going to go kind of into something else.

72
00:05:06,790 --> 00:05:13,180
I want us to look over another subject and another practice problem.

73
00:05:14,380 --> 00:05:19,450
And so what we're going to do for this is talk about how structs can.

74
00:05:21,030 --> 00:05:30,320
Actually, not only have primitive data types in them, but they can also have like another struct,

75
00:05:30,330 --> 00:05:36,900
so you can have some other name in here like, let's say it was person and like dog or something, you

76
00:05:36,900 --> 00:05:42,720
know, dog like a person's dog, something like that.

77
00:05:42,720 --> 00:05:44,760
Like, we had some structure called dog.

78
00:05:45,660 --> 00:05:51,390
You don't have to be limited to only having, you know, strings and ensign floats and doubles and all

79
00:05:51,390 --> 00:05:53,250
these other things that you've learned thus far.

80
00:05:54,310 --> 00:06:00,910
As the data types of your struct, you can have other structures, as members write, like I said with

81
00:06:00,910 --> 00:06:01,360
the dog.

82
00:06:01,870 --> 00:06:04,210
I'm actually going to demo a quick program I wrote here.

83
00:06:04,210 --> 00:06:09,430
And what we're going to do is instead of me writing the code in front of you, I'm actually just going

84
00:06:09,430 --> 00:06:11,470
to go through this code.

85
00:06:11,470 --> 00:06:12,670
We're going to go through it together.

86
00:06:12,670 --> 00:06:17,220
It's already written and we're going to comment some stuff and kind of talk about what's going on there.

87
00:06:17,230 --> 00:06:19,840
So let's go ahead and run this.

88
00:06:19,840 --> 00:06:23,880
You see that I have compiled an executable called S2 for ICSI.

89
00:06:24,520 --> 00:06:27,550
So if I run this, it says, enter known buildings.

90
00:06:28,630 --> 00:06:32,860
I'm going to say to into the number of employees for building zero.

91
00:06:33,610 --> 00:06:37,690
I'll say to Inter employee select employees your name.

92
00:06:38,260 --> 00:06:44,230
I just say Jeff Programmer number of employees for building one.

93
00:06:46,600 --> 00:06:58,840
I will go ahead and say to employees for this, and I'll just say, we'll say Jessica, and then maybe

94
00:06:58,840 --> 00:07:02,140
just like a manager or something like that, another name.

95
00:07:02,800 --> 00:07:06,020
Bob, how about Janet or something like that?

96
00:07:06,040 --> 00:07:12,390
OK, and then what it does is it prints out the employees for each building, right?

97
00:07:12,400 --> 00:07:12,820
So.

98
00:07:15,490 --> 00:07:21,760
We have employee list for building zero, it was only Jeffrey Shipload, programmer and the only person

99
00:07:21,760 --> 00:07:26,710
in that building kind of said then we have employee list for building number one.

100
00:07:27,070 --> 00:07:32,800
And this has desk and manager and bob janitor and some IDs there.

101
00:07:32,800 --> 00:07:37,750
So it's associating employees with buildings, and it's also keeping track of buildings as well.

102
00:07:37,760 --> 00:07:39,100
So let's just keep that in mind.

103
00:07:39,100 --> 00:07:42,380
We know how the program functions as far as running it.

104
00:07:43,330 --> 00:07:44,920
So let's take a look at the code here.

105
00:07:46,510 --> 00:07:50,770
So I've obviously included I don't really need I am have been here.

106
00:07:51,370 --> 00:07:54,430
This is something yeah, I'll leave it for now, but I don't think I actually use it.

107
00:07:55,120 --> 00:08:00,340
We have a vector and I stream in here because we're using vectors and we're of course, having output.

108
00:08:01,420 --> 00:08:04,300
So first off, let's take a look at this structure right here.

109
00:08:04,570 --> 00:08:08,390
So we have this struct employee, right?

110
00:08:08,420 --> 00:08:11,350
The employee has an ID and name a job title.

111
00:08:13,210 --> 00:08:15,010
So let's go down a little bit now.

112
00:08:15,010 --> 00:08:17,380
We have another struct right here.

113
00:08:18,250 --> 00:08:20,200
This struct is called building.

114
00:08:20,920 --> 00:08:26,200
It has a building number, which is an integer and has no employees or assistant, which is an integer.

115
00:08:26,530 --> 00:08:28,350
And then here it has a vector.

116
00:08:28,360 --> 00:08:33,850
So this isn't this is something we haven't seen as part of a struct yet, but you can have a vector

117
00:08:33,850 --> 00:08:38,800
inside of a strict and this vector is of type employee pointers.

118
00:08:38,800 --> 00:08:42,030
So it is one of our abstract data types, right?

119
00:08:42,220 --> 00:08:43,270
Employee right here.

120
00:08:43,280 --> 00:08:49,390
So each building that we create will have its own vector of employees.

121
00:08:49,630 --> 00:08:53,170
And actually, it's not going to be a vector of the employee structure.

122
00:08:53,170 --> 00:08:56,110
It's actually going to be employee pointers, right?

123
00:08:56,770 --> 00:09:04,030
So we have this employee's variable right here that we will use for that vector of employee pointers.

124
00:09:05,410 --> 00:09:10,720
So it was kind of connecting it's important to connect like these abstract data types to one another.

125
00:09:11,080 --> 00:09:13,690
This is something that we would call a composition.

126
00:09:13,690 --> 00:09:23,400
So employee, basically a building has employees, but employees do not have buildings, right?

127
00:09:23,410 --> 00:09:24,660
That's the relationship.

128
00:09:25,480 --> 00:09:29,070
So this building contains multiple employees.

129
00:09:29,080 --> 00:09:32,980
That's why we have a vector of employee pointers in here.

130
00:09:34,450 --> 00:09:40,390
So something new, you don't have to only have primitive data types and some of the other data types

131
00:09:40,390 --> 00:09:42,130
you've seen so far, like string.

132
00:09:43,280 --> 00:09:49,040
You can also have your own data types, so this doesn't have to be a vector of employees, it can also

133
00:09:49,040 --> 00:09:55,550
honestly, just let's say the building had like just one manager or something like that.

134
00:09:55,550 --> 00:10:04,100
So you could also say employee, employee manager, something like that, you know?

135
00:10:04,790 --> 00:10:12,350
So now there is a variable in here that is of type employee and it is the manager, so you can have

136
00:10:12,350 --> 00:10:13,010
that as well.

137
00:10:15,690 --> 00:10:18,780
So let's go ahead and look at the rest of the code, how do we set this up?

138
00:10:22,010 --> 00:10:25,080
So let's go ahead and comment some stuff to you.

139
00:10:25,100 --> 00:10:25,880
So this is,

140
00:10:28,790 --> 00:10:34,120
let's just say, elite for employing use.

141
00:10:35,750 --> 00:10:43,580
This will be our and 80s forces for abstract data type affected time for buildings.

142
00:10:48,520 --> 00:10:54,550
So right here we declare no buildings, and we're doing that because we're going to get the number of

143
00:10:54,550 --> 00:10:57,160
buildings from the user, if you remember here.

144
00:10:59,000 --> 00:11:01,310
We said internet buildings, right?

145
00:11:01,670 --> 00:11:05,810
And that's what we see right here, internet buildings, and then we read in the number of buildings.

146
00:11:07,070 --> 00:11:10,790
We also make a vector that is super annoying and that comes up.

147
00:11:11,000 --> 00:11:12,740
We also make a vector here.

148
00:11:14,530 --> 00:11:15,970
Of building plaintiffs.

149
00:11:17,240 --> 00:11:26,500
So let's go ahead and comment this, so I'm just going to say actually right here, so we'll say when

150
00:11:26,500 --> 00:11:30,430
you say container building meters.

151
00:11:32,400 --> 00:11:35,160
So you can think of it as a container of buildings.

152
00:11:35,190 --> 00:11:43,380
Right, because I mean, even though they're there pointers, we're going to be making new buildings

153
00:11:43,380 --> 00:11:44,520
for each like point.

154
00:11:44,520 --> 00:11:47,100
That's going to point to a new building in memory, right?

155
00:11:47,100 --> 00:11:48,690
Because we're going to be doing this down here.

156
00:11:50,220 --> 00:11:57,360
So container building pointers and then right here, we're going to get the number of buildings from

157
00:11:57,360 --> 00:11:57,990
the user.

158
00:12:04,470 --> 00:12:04,890
All right.

159
00:12:05,130 --> 00:12:09,030
And then right here we start looping.

160
00:12:09,660 --> 00:12:17,130
So what are we doing in this loop where we're looping as long as I as less than number of buildings?

161
00:12:17,130 --> 00:12:18,090
So no buildings?

162
00:12:18,660 --> 00:12:25,530
So what we're going to do in this outer loop that I've declared here we are going to use that to create

163
00:12:25,890 --> 00:12:28,230
as many buildings as the user said, right?

164
00:12:28,230 --> 00:12:32,040
The users specified how many buildings we should have.

165
00:12:33,120 --> 00:12:37,770
So we're going to loop for as many times as the number of buildings is.

166
00:12:38,280 --> 00:12:43,560
And so what we do right off the bat is we're going to create a building right for each one of those

167
00:12:43,560 --> 00:12:48,990
buildings that the number specified, the amount of buildings is well, I mean, we're going to make

168
00:12:48,990 --> 00:12:51,270
a new building right now, actually put the comment over here.

169
00:12:51,270 --> 00:12:58,620
So we'll just say great new building.

170
00:12:59,610 --> 00:13:02,070
And I'll just say dynamic, right?

171
00:13:02,580 --> 00:13:05,580
Because we're making like a dynamically allocated building.

172
00:13:09,030 --> 00:13:09,630
Let's do that.

173
00:13:11,050 --> 00:13:14,650
All right, so now we have some more of this syntax with the little arrow.

174
00:13:14,890 --> 00:13:20,530
So what we are doing is since we've made a new building and it's a pointer to dynamically allocated

175
00:13:20,530 --> 00:13:23,170
building, we now want to set the building number.

176
00:13:23,170 --> 00:13:26,860
And all I'm really doing here is I'm setting the building number to I.

177
00:13:26,870 --> 00:13:31,370
So if the user says, you know, I'll I want, you know.

178
00:13:32,440 --> 00:13:33,340
Two buildings.

179
00:13:35,750 --> 00:13:43,370
Then the first building will be building zero, right, so I said I will be zero and I'll set the building

180
00:13:43,370 --> 00:13:47,810
number two, I and then when I make the next building, how said the building number two again, but

181
00:13:47,810 --> 00:13:52,370
it will be one as it would move four, zero and one if we had two buildings, right?

182
00:13:54,620 --> 00:13:57,500
So this is like set the building, no.

183
00:13:59,990 --> 00:14:04,760
Then we enter the number of employees for the building, we're going to get that from the user, right?

184
00:14:04,780 --> 00:14:06,140
So we're going to ask them.

185
00:14:06,410 --> 00:14:06,860
All right.

186
00:14:07,220 --> 00:14:11,540
Each building has a vector of employee pointers, right?

187
00:14:12,790 --> 00:14:13,360
So.

188
00:14:14,750 --> 00:14:20,960
We want the user to now say how many employees are going to be in this specific building that we're

189
00:14:20,960 --> 00:14:22,850
on in this loop iteration, right?

190
00:14:24,020 --> 00:14:27,550
So we say in a number of ways for building AI, which is just a building number, right?

191
00:14:27,560 --> 00:14:32,180
And then we read it in with CNN and we're using this pointer syntax again.

192
00:14:32,540 --> 00:14:34,550
So we're doing B Arrow.

193
00:14:34,550 --> 00:14:40,340
No employees were reading it directly into this, no employee's variable.

194
00:14:40,340 --> 00:14:47,540
So where is that we have right here in our building structure says aren't enough employees.

195
00:14:47,810 --> 00:14:54,510
We are accessing this variable in the struct by doing our variable name right.

196
00:14:54,530 --> 00:15:01,550
B is the pointer to the new building that we made and we're doing b arrow instead of a dot, right?

197
00:15:01,970 --> 00:15:03,950
Because it's a pointer, so it's an arrow.

198
00:15:05,200 --> 00:15:09,580
Be era and have employees, so we're reading directly into that variable right here with see it.

199
00:15:10,570 --> 00:15:15,850
So read into no employees variable.

200
00:15:19,750 --> 00:15:20,140
All right.

201
00:15:21,430 --> 00:15:30,430
So now what, we're in this outer loop we read in the now employees will now what we have to do is to

202
00:15:30,970 --> 00:15:33,160
deal with all the employees for this building, right?

203
00:15:33,190 --> 00:15:35,890
The user specified the number of buildings.

204
00:15:36,100 --> 00:15:38,920
So we're looking for that number of buildings with this outer loop.

205
00:15:39,190 --> 00:15:45,160
Now the user has specified inside of this with the number of employees for this building.

206
00:15:45,520 --> 00:15:52,390
So now we have to initiate a nested loop that's inside of here that loops for the amount of employees

207
00:15:52,750 --> 00:15:53,860
that the user entered.

208
00:15:54,250 --> 00:15:56,320
And I'm using the variable j for that.

209
00:15:57,400 --> 00:15:58,670
So what am I doing right here?

210
00:15:58,690 --> 00:16:01,210
Well, I'm just straight up using be employees, right?

211
00:16:01,210 --> 00:16:04,990
Because we read that we read straight into that struct variable.

212
00:16:05,770 --> 00:16:09,280
And so what I want to do is I want to loop based on that.

213
00:16:09,280 --> 00:16:13,530
So I'm going to loop as long as chains less than be Arrow.

214
00:16:13,540 --> 00:16:14,260
No employees.

215
00:16:16,550 --> 00:16:22,100
So just like we created the building pointer, we're going to create an employee point array and dynamically

216
00:16:22,100 --> 00:16:25,670
allocate a new piece of memory with an employee struct.

217
00:16:27,560 --> 00:16:33,680
So great new employee dynamic

218
00:16:35,710 --> 00:16:36,740
allocation.

219
00:16:42,570 --> 00:16:53,790
OK, so here we set the employee ID is kind of similar to the building, no I.D. So set your employee

220
00:16:53,790 --> 00:16:54,450
I.D..

221
00:16:57,510 --> 00:17:02,760
All right, so now what we do is we're going to read into the employee's name because we asked the user,

222
00:17:02,760 --> 00:17:08,310
say employee, and this is employee ID basically right j is the same thing as it.

223
00:17:08,610 --> 00:17:12,600
So they say employee j name and then the user's going to enter the name.

224
00:17:13,950 --> 00:17:17,250
So this is the employee's name.

225
00:17:19,330 --> 00:17:20,530
Employees at the.

226
00:17:21,580 --> 00:17:25,270
And then here in the job title, right, so we're doing the same thing, it's just like that with the

227
00:17:25,270 --> 00:17:31,150
B in the arrow right now we're doing E Arrow ID, so that's accessing this variable.

228
00:17:32,540 --> 00:17:38,240
And then we're doing, you know, name and job title, and these are these other ones right here that

229
00:17:38,240 --> 00:17:39,200
we're accessing, right?

230
00:17:40,010 --> 00:17:41,870
And remember, the E!

231
00:17:41,900 --> 00:17:48,620
Is the variable name that we have, for instance, of the we have one instance of this church created

232
00:17:48,620 --> 00:17:51,470
here, and that's happening each time that we look.

233
00:17:52,040 --> 00:17:56,150
This is dynamically allocated instance of district.

234
00:17:57,700 --> 00:17:58,420
Called E!

235
00:17:58,450 --> 00:18:00,650
And so that's why you see the Arrow I.D..

236
00:18:01,840 --> 00:18:07,630
So we're making new employees each time that's based off that strict setting, the information for the

237
00:18:07,670 --> 00:18:13,720
employees to set an employee's job title.

238
00:18:15,490 --> 00:18:22,120
And then we push it back to the vector, so we have our employee vector, so this is kind of interesting

239
00:18:22,120 --> 00:18:22,630
here, so.

240
00:18:23,670 --> 00:18:27,330
B is the building that we're currently on, right, so right here.

241
00:18:29,140 --> 00:18:30,460
This is the outer loop, right?

242
00:18:30,580 --> 00:18:38,320
So we're on this building B was created, we now initiated a loop inside this loop.

243
00:18:38,320 --> 00:18:40,900
So we're we're still referring to this building, right?

244
00:18:40,900 --> 00:18:43,510
But now we're creating the all the employees for this building.

245
00:18:43,510 --> 00:18:43,840
So.

246
00:18:44,930 --> 00:18:52,910
Each time we create a new employee, we now need to we've set all the information here for the employee.

247
00:18:53,240 --> 00:18:56,480
Now we need to say, OK, let's refer to the building we're on.

248
00:18:56,480 --> 00:18:59,840
It's this right here, right, because we're on this outer loop iteration.

249
00:19:00,740 --> 00:19:05,030
So the current building, let's get the employee's vector, right?

250
00:19:05,030 --> 00:19:11,210
So we're able to refer to the employees vector by doing an arrow since it's a pointer, right?

251
00:19:11,390 --> 00:19:12,200
It's a pointer.

252
00:19:13,880 --> 00:19:22,610
We want to access this variable right here, employees, employees, so we're doing the arrow employees

253
00:19:22,610 --> 00:19:25,430
that gives us this vector.

254
00:19:26,750 --> 00:19:27,110
All right.

255
00:19:29,180 --> 00:19:34,340
Then what we have to do, or sorry, that Vector is not a pointer.

256
00:19:35,390 --> 00:19:40,420
The building is a pointer and the employee is a pointer, but that vector in the building structure

257
00:19:40,490 --> 00:19:42,730
is not a pointer, so we're going to use the dot.

258
00:19:43,520 --> 00:19:44,360
Again, we do it.

259
00:19:44,720 --> 00:19:49,640
We refer to we use the arrow when it's a pointer, but if it's not a pointer, we're going to use a

260
00:19:49,650 --> 00:19:50,240
dart, right?

261
00:19:50,240 --> 00:19:52,390
So we're going to employees dot pushback.

262
00:19:52,400 --> 00:19:55,680
This is just the standard method for the vector right dot push back.

263
00:19:55,700 --> 00:19:56,720
You've used that before.

264
00:19:57,110 --> 00:20:01,400
What are we pushing back or pushing back the employee pointer, right?

265
00:20:01,430 --> 00:20:06,350
This guy right here, we've already said all the data, so it's set up and we're ready to push it back.

266
00:20:06,590 --> 00:20:09,560
And why does that work if it's a pointer, how do we push it back?

267
00:20:09,800 --> 00:20:15,950
Because the data type is employee pointer, that's the data type of vector that's in each building.

268
00:20:18,220 --> 00:20:26,020
All right, so the prints out in line and now right here, since we have set up all the employees for

269
00:20:26,020 --> 00:20:29,410
the building and we've also set the information for the building.

270
00:20:30,070 --> 00:20:38,140
We are now ready to push back the building pointer, this building pointer that has all this stuff associated

271
00:20:38,140 --> 00:20:38,860
with it now.

272
00:20:39,040 --> 00:20:42,460
All the employees have been pushed back to the vector in their.

273
00:20:43,800 --> 00:20:48,570
We're now going to push the building back to the building vector, right, this building pointer type,

274
00:20:49,230 --> 00:20:52,230
the vector of type building pointer called buildings.

275
00:20:52,620 --> 00:20:54,780
And you notice here we push back the building to it.

276
00:20:54,780 --> 00:21:01,170
So we have a vector for each building and then we have an overall vector that holds all the buildings

277
00:21:01,170 --> 00:21:01,380
right.

278
00:21:01,560 --> 00:21:04,320
The vector for each building holds all the employees.

279
00:21:06,030 --> 00:21:10,020
The vector with all the buildings is something that was created locally here in Maine, and it holds

280
00:21:10,020 --> 00:21:10,800
all the buildings there.

281
00:21:12,730 --> 00:21:18,190
OK, so that will create all of our buildings with all the employees in each building, with all the

282
00:21:18,190 --> 00:21:19,750
data for each employee.

283
00:21:20,940 --> 00:21:26,340
Now here is where we start to loop over and print it out, so.

284
00:21:27,530 --> 00:21:33,350
I'm just going to write a couple more notes here that we didn't write, yes, I'm going to say push

285
00:21:33,920 --> 00:21:34,430
back

286
00:21:37,370 --> 00:21:41,360
new employee to.

287
00:21:43,770 --> 00:21:58,110
Let's just say it more in abstract terms, so a sign employee to building to buildings, the employee

288
00:21:58,390 --> 00:22:05,340
that must do that and say the typing is yes, it's still struggle for me.

289
00:22:05,340 --> 00:22:05,610
So.

290
00:22:05,980 --> 00:22:08,490
So buildings don't push back.

291
00:22:10,110 --> 00:22:11,010
This is just

292
00:22:14,070 --> 00:22:22,500
adding the completed building to building effect.

293
00:22:23,040 --> 00:22:23,550
How about that?

294
00:22:24,540 --> 00:22:35,880
So now here comes the time to print out all employees for each building.

295
00:22:38,080 --> 00:22:41,020
So that's what we're doing, we have a nested loop and why do we have in the loop?

296
00:22:41,020 --> 00:22:44,830
Because we're basically having to go over each building and for.

297
00:22:45,220 --> 00:22:45,820
So I say.

298
00:22:46,880 --> 00:22:48,380
For each building.

299
00:22:49,530 --> 00:22:57,510
We have to go for each employee in the building, right?

300
00:22:59,110 --> 00:23:02,980
So that's what this interlude is for, it's for all the employees of the current building that we're

301
00:23:02,980 --> 00:23:05,020
on, this is for each building.

302
00:23:05,350 --> 00:23:07,930
This loop is for each employee of that building.

303
00:23:09,180 --> 00:23:10,560
Of each one of those buildings.

304
00:23:12,150 --> 00:23:17,850
So interesting looking syntax here, let's go ahead and look through it, so it says see our employee

305
00:23:17,850 --> 00:23:19,260
list for building number.

306
00:23:20,610 --> 00:23:21,840
And what do we do?

307
00:23:21,870 --> 00:23:26,670
Well, we're looping over buildings that size buildings is the vector that was created locally here,

308
00:23:26,670 --> 00:23:26,970
right?

309
00:23:28,000 --> 00:23:30,340
Right here, the local building inspector.

310
00:23:31,680 --> 00:23:37,020
So we're going as long as ISIS and building societies that will print out each building and give us

311
00:23:37,020 --> 00:23:38,070
access to each building.

312
00:23:38,640 --> 00:23:45,060
So what we are doing is we are using AI to index the buildings vector.

313
00:23:45,960 --> 00:23:54,330
So this highlighted thing right here is going to resolve to a building pointer.

314
00:23:54,660 --> 00:23:54,960
Right.

315
00:23:54,970 --> 00:23:59,640
Because what type is that vector that's local to main that says buildings?

316
00:23:59,940 --> 00:24:01,250
It's type building pointer.

317
00:24:01,260 --> 00:24:03,930
So this highlighted thing right here.

318
00:24:03,930 --> 00:24:10,470
When we index that vector, it will give us a building pointer, and that is why we now need to use

319
00:24:10,470 --> 00:24:13,830
an arrow to access the building.

320
00:24:13,830 --> 00:24:18,220
No variable of that building pointer, right?

321
00:24:18,270 --> 00:24:21,380
So that building pointer has a building number right.

322
00:24:21,400 --> 00:24:23,520
We have a building number for each building.

323
00:24:24,740 --> 00:24:27,060
We know that we making building pointers here.

324
00:24:28,640 --> 00:24:34,760
So this building pointer is going to have this building no variable and we are accessing it through

325
00:24:34,760 --> 00:24:37,940
an arrow once we have it right and we're going to print that out.

326
00:24:39,590 --> 00:24:44,960
Similar thing is going on with the rest of this, right, we're just using arrows to resolve each one

327
00:24:44,960 --> 00:24:47,150
of the layers of data here, so.

328
00:24:48,580 --> 00:24:53,800
This inside loop loops for the what is the current building we're on, and that's what we're asking

329
00:24:53,800 --> 00:24:54,340
right here.

330
00:24:54,370 --> 00:24:58,990
Current building and that's a building pointer, so we use an arrow.

331
00:25:00,100 --> 00:25:03,790
Now we're getting the vector of employees out of the building, right?

332
00:25:03,820 --> 00:25:08,500
We know that that has each building has a vector of employee pointers.

333
00:25:11,620 --> 00:25:19,480
So this is the vector of employees that we access, and then we say, since the vector itself is not

334
00:25:19,960 --> 00:25:25,150
a pointer like we're not have any pointer to the vector, we're just going to use the dot right, just

335
00:25:25,150 --> 00:25:27,160
like we did Dot push back here.

336
00:25:27,880 --> 00:25:29,320
We're going to need size.

337
00:25:29,320 --> 00:25:29,740
So.

338
00:25:31,180 --> 00:25:32,740
Let's kind of recap again.

339
00:25:34,000 --> 00:25:38,380
Let's get the current building we're on, right, because we're looping over the buildings in this outer

340
00:25:38,380 --> 00:25:38,650
loop.

341
00:25:40,060 --> 00:25:46,900
Once we have that building that we're currently on here, we say, OK, let's get the vector from that

342
00:25:46,900 --> 00:25:47,410
building.

343
00:25:47,860 --> 00:25:50,080
And how big is that vector?

344
00:25:50,380 --> 00:25:53,200
Let's make sure that we loop as long as just less than.

345
00:25:54,760 --> 00:25:57,670
The size of this vector for the current building.

346
00:26:00,210 --> 00:26:05,430
So that's just looping over for all of the given employees in one vector, you know, because this enables

347
00:26:05,430 --> 00:26:07,770
us to have different sizes, of course.

348
00:26:08,760 --> 00:26:13,290
For the buildings like we did in our example, you know, one of the buildings only had one employee,

349
00:26:13,290 --> 00:26:15,180
but another building had two employees.

350
00:26:15,840 --> 00:26:22,950
So that's why we want to refer to the specific size of that building's employee, Victor.

351
00:26:24,840 --> 00:26:28,200
Then in here, we print out all the stuff for each employee and how do we do that?

352
00:26:28,470 --> 00:26:29,520
It's kind of redundant.

353
00:26:29,520 --> 00:26:33,690
I have this set with here, but I don't really need to use it.

354
00:26:34,740 --> 00:26:39,000
So you can kind of ignore that I'm not really using that correctly here.

355
00:26:40,050 --> 00:26:41,580
I'm just having this over.

356
00:26:41,580 --> 00:26:45,480
So I'm actually going to get rid of these right here.

357
00:26:45,720 --> 00:26:46,200
So.

358
00:26:48,220 --> 00:26:51,520
Let's go ahead and get rid of that.

359
00:26:54,960 --> 00:26:55,370
OK.

360
00:26:56,070 --> 00:27:01,650
So I just have some stuff tabbed over, like, for example, here is says See Out tab.

361
00:27:02,370 --> 00:27:03,210
This is a tab.

362
00:27:04,140 --> 00:27:05,250
And then we say I'd.

363
00:27:06,930 --> 00:27:09,660
We do a space and then what are we going to do?

364
00:27:09,690 --> 00:27:14,670
Well, we're going to access the current buildings employee vector.

365
00:27:14,700 --> 00:27:15,750
And that's right here.

366
00:27:16,110 --> 00:27:18,230
Current building is what I have highlighted here.

367
00:27:19,970 --> 00:27:21,740
Then what is this?

368
00:27:21,830 --> 00:27:26,330
It's a pointer, so we're going to access the Good Lord.

369
00:27:26,650 --> 00:27:35,570
OK, we're going to access the employee vector of that current building and that is going to be what

370
00:27:35,570 --> 00:27:41,270
we're going to do is not only access that vector right here, but we are going to index the employee

371
00:27:41,270 --> 00:27:41,820
vector.

372
00:27:41,840 --> 00:27:46,400
I'm just hoping that I can not have so much stuff pop up when I'm trying to show you.

373
00:27:47,970 --> 00:27:53,460
But so what are we doing, we're accessing the employee vector of the building, right?

374
00:27:55,160 --> 00:28:00,440
So we have this employee vector, but this time we're not only just accessing the vector, we're indexing

375
00:28:00,440 --> 00:28:02,500
that vector and what's stored inside of it.

376
00:28:03,590 --> 00:28:05,000
Employee pointers.

377
00:28:05,180 --> 00:28:05,510
All right.

378
00:28:05,900 --> 00:28:06,470
So.

379
00:28:07,420 --> 00:28:08,800
Get the building pointer.

380
00:28:09,220 --> 00:28:10,360
Use the arrow.

381
00:28:12,980 --> 00:28:15,340
Get the employee vector.

382
00:28:17,630 --> 00:28:21,950
Get an employee out of that vector with the index operator there.

383
00:28:23,390 --> 00:28:28,700
Use the arrow since the employee is a pointer to employee pointer.

384
00:28:28,880 --> 00:28:31,940
Get the idea from that employee, right?

385
00:28:32,750 --> 00:28:34,010
So the employee has the ID.

386
00:28:34,970 --> 00:28:39,740
So just trying to break down this whole thing for you and I'm just not going to hover over it too much

387
00:28:39,740 --> 00:28:47,000
more because it's just bringing up so much kind of information about each thing that I have here.

388
00:28:47,000 --> 00:28:50,720
So that's kind of annoying for this purpose.

389
00:28:51,890 --> 00:28:56,600
So we have each time that we print something out, I can just kind of go down here and go over it.

390
00:28:56,610 --> 00:29:02,600
So we're getting a building out of the building inspector that's going to be a pointer, a building

391
00:29:02,600 --> 00:29:02,930
pointer.

392
00:29:02,930 --> 00:29:09,170
So we use the arrow that with that, we go to access that specific building's employees vector.

393
00:29:09,500 --> 00:29:16,160
We're also going to index that employees vector to get the current JS employee right because we're looping

394
00:29:16,160 --> 00:29:18,950
over the employees for that building.

395
00:29:19,550 --> 00:29:26,480
Once we get that employee out, it's an employee pointer because we have been making the employees dynamically

396
00:29:26,480 --> 00:29:31,400
with a pointer and putting that pushing that back to this employee's vector, right?

397
00:29:31,940 --> 00:29:38,930
Once we have that employee pointer, we can get information about the employee like I.D. name, job

398
00:29:38,930 --> 00:29:39,710
title, right?

399
00:29:41,210 --> 00:29:47,150
And what are those again, just to once again recap on that, they're coming from here because we defined

400
00:29:47,150 --> 00:29:49,080
our strike to have those variables right?

401
00:29:50,200 --> 00:29:54,040
So this is us printing out all that data about the employees, right?

402
00:29:55,740 --> 00:30:00,450
OK, so that is pretty much all I'm going to go over in this.

403
00:30:00,480 --> 00:30:08,250
Listen, I just wanted to show you that you can have strokes inside of strokes.

404
00:30:08,520 --> 00:30:15,090
This was not just a struct variable inside of another struct, it was a vector of the other type of

405
00:30:15,090 --> 00:30:15,570
struct.

406
00:30:15,780 --> 00:30:16,000
Right.

407
00:30:16,080 --> 00:30:18,600
And not only that, it was struct pointers in here.

408
00:30:19,530 --> 00:30:23,940
So it's kind of it kind of goes with the overall design of your code.

409
00:30:23,940 --> 00:30:29,190
So we're thinking about an abstract idea and trying to come up with an abstract data type.

410
00:30:30,520 --> 00:30:37,850
We need to think, well, you know, what is the relationship between employees and buildings?

411
00:30:37,860 --> 00:30:39,490
How should I turn this into code?

412
00:30:39,520 --> 00:30:44,590
Well, each building has, you know, a bunch of employees.

413
00:30:45,010 --> 00:30:47,420
Could I make a list of all those employees?

414
00:30:47,450 --> 00:30:48,730
OK, I probably could.

415
00:30:48,760 --> 00:30:50,680
What is a good thing to use for a list?

416
00:30:50,710 --> 00:30:52,480
Well, either an array or a vector.

417
00:30:52,690 --> 00:30:55,570
This is kind of just coming up with the idea for the code, you know?

418
00:30:56,530 --> 00:31:00,850
OK, so I can make a building struct right for an abstract data type.

419
00:31:00,880 --> 00:31:04,780
Let's have the information associated with it for each building.

420
00:31:05,320 --> 00:31:12,850
And since each building is going to have a list of employees, I should make in a vector of type employee.

421
00:31:13,280 --> 00:31:13,710
Right.

422
00:31:13,750 --> 00:31:16,870
So I have this variable there and it says vector employees.

423
00:31:17,260 --> 00:31:21,650
I'm also going to need an abstract data type to represent an employee, right?

424
00:31:21,670 --> 00:31:25,120
An employee has an idea, a name and a job title.

425
00:31:27,170 --> 00:31:31,340
So that's how you can kind of relate these to strikes in that way.

426
00:31:32,810 --> 00:31:36,480
OK, so we're going to be moving on from structs.

427
00:31:37,040 --> 00:31:42,170
I think you now know enough to use them as as abstract data types.

428
00:31:42,170 --> 00:31:46,670
You know that you can use them in an array in a vector, you can put them in there, have arrays of

429
00:31:46,670 --> 00:31:48,050
strikes and vectors and strikes.

430
00:31:48,440 --> 00:31:54,200
You know that you can have multiple strikes and they can be related in a way like this with like the

431
00:31:54,200 --> 00:31:59,900
composition way where you know, a building has employees.

432
00:32:00,320 --> 00:32:06,960
We also could say that a building has an employee, one employee that's a manager as well.

433
00:32:06,980 --> 00:32:11,450
You know, I didn't put that in here, but like I was talking about in the beginning, that is possible

434
00:32:11,450 --> 00:32:11,990
as well.

435
00:32:12,410 --> 00:32:17,420
You could say that a building has a single employee manager as well.

436
00:32:20,240 --> 00:32:26,840
And so what we're going to be moving on to is something that is kind of a new with a new paradigm in

437
00:32:26,840 --> 00:32:27,550
programming.

438
00:32:27,560 --> 00:32:30,770
We've been doing procedural programming up until now, right?

439
00:32:31,100 --> 00:32:32,360
Remember one of those lectures?

440
00:32:32,360 --> 00:32:38,210
I talked about the fact that we had been doing procedural programming and that we at some point we kind

441
00:32:38,210 --> 00:32:40,670
of added on to our procedural programming.

442
00:32:42,460 --> 00:32:46,450
Was kind of this modular programming where we were using more functions and stuff.

443
00:32:46,930 --> 00:32:49,540
I haven't been breaking everything into functions.

444
00:32:49,750 --> 00:32:53,980
It would be really good if you could break this into some functions.

445
00:32:53,980 --> 00:32:59,470
I'm hoping that you're using multiple functions in your program to organize things better.

446
00:32:59,980 --> 00:33:04,960
We're going to move on past that procedural programming thing now.

447
00:33:05,380 --> 00:33:07,240
And we've talked about stress.

448
00:33:07,420 --> 00:33:09,490
We talked about abstract data types.

449
00:33:09,760 --> 00:33:17,590
Strokes can still be part of that procedural programming or functional programming or modular programming

450
00:33:17,950 --> 00:33:22,930
because strokes were available with the C language before C++.

451
00:33:24,410 --> 00:33:31,370
But C++ kind of brought about the ability to do it, didn't bring it about, but I'm just saying that

452
00:33:31,370 --> 00:33:37,190
C++ has the ability to do something called object oriented programming.

453
00:33:37,670 --> 00:33:38,100
OK?

454
00:33:38,380 --> 00:33:45,860
Structures are kind of bringing us into the realm of objects and object oriented programming.

455
00:33:46,070 --> 00:33:48,880
You could think of this struct as an object.

456
00:33:49,160 --> 00:33:50,930
It's an abstract data type.

457
00:33:50,930 --> 00:33:58,430
We're going to continue on with the idea of abstract data types and trying to bring abstract ideas into

458
00:33:58,430 --> 00:33:59,690
code and represent them.

459
00:33:59,690 --> 00:34:03,770
You know, here we're representing something that's not in numbers.

460
00:34:03,770 --> 00:34:10,310
You know, it's an employee and employee is not something that's just baked into coding languages.

461
00:34:10,320 --> 00:34:16,310
You know, you have to come up with your own kind of structured data for this.

462
00:34:16,880 --> 00:34:24,230
So you say, OK, I'm going to associate some data with an employee, right when you use the name employee.

463
00:34:24,230 --> 00:34:30,080
And I'm going to associate the fact that employee has an Indian name and a job title to create this

464
00:34:30,080 --> 00:34:32,150
abstract data type in the code.

465
00:34:32,510 --> 00:34:33,590
Same thing with the building.

466
00:34:34,190 --> 00:34:39,500
What we're going to do is move on to something called object on your programming, where we're not going

467
00:34:39,500 --> 00:34:40,860
to use structures anymore.

468
00:34:40,880 --> 00:34:46,040
It's going to be very similar to structure, almost identical, but they're going to be called objects,

469
00:34:46,400 --> 00:34:51,410
and we're going to need to introduce this whole new idea of something called a class to be able to do

470
00:34:51,410 --> 00:34:51,620
that.

471
00:34:51,630 --> 00:34:59,210
So to take everything you know about structs and remember it because we're going to be continuing on

472
00:34:59,210 --> 00:35:06,920
with this idea of abstract data types, but we're going to be using a new thing besides a struct, and

473
00:35:06,920 --> 00:35:08,100
it's going to be called a class.

474
00:35:08,120 --> 00:35:14,390
So with that, I will see you in the next video or we will get started with object oriented programming.
