Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,990 --> 00:00:02,860
Welcome back, ladies and gentlemen.
2
00:00:02,880 --> 00:00:09,690
And in this video, we are going to talk about how we can create structs, new structs which should
3
00:00:09,690 --> 00:00:15,420
hold members that are going to be objects of another glass.
4
00:00:16,170 --> 00:00:22,890
So sounds very, very intimidating, but I think that we are going to be hopefully just fine.
5
00:00:23,280 --> 00:00:25,470
OK, so let us start.
6
00:00:26,430 --> 00:00:32,400
So we had these previous example of one of the common examples that we've talked about, and this example
7
00:00:32,400 --> 00:00:39,840
creates a structure called point in these struct has two members X and Y.
8
00:00:40,110 --> 00:00:43,950
And in this case, both of them are of an integer type.
9
00:00:45,030 --> 00:00:52,950
So this structure is used to represent a simple point with X and Y coordinates.
10
00:00:54,410 --> 00:01:01,850
OK, so a simple point he's basically used to represent, basically that's all the structure is all
11
00:01:01,850 --> 00:01:06,620
about representing points that have X and Y coordinates.
12
00:01:08,820 --> 00:01:10,170
So that's the point.
13
00:01:11,580 --> 00:01:15,750
And now we want to create a new structure called Circle.
14
00:01:17,280 --> 00:01:21,690
And we want this circle to be able to represent a circle.
15
00:01:22,560 --> 00:01:27,300
So how should should it look like if we take a look at the simple circle?
16
00:01:27,720 --> 00:01:35,270
We know that there are a few things that are used to characterize a standard circle.
17
00:01:35,280 --> 00:01:39,390
First of first of all, there is the center point.
18
00:01:41,240 --> 00:01:44,360
And the central point is actually the center of the circle.
19
00:01:44,630 --> 00:01:54,950
It also has the X Y coordinates and also we have the radius that is used to represent the distance between
20
00:01:54,950 --> 00:01:59,660
the center and any of the points on the circle itself.
21
00:01:59,930 --> 00:02:02,450
OK, so do things are used to represent a circle?
22
00:02:04,320 --> 00:02:11,640
So now what we want to do is to create a structure that this structure is going to show us, and basically
23
00:02:11,640 --> 00:02:14,970
it's going to be used as a template kind of a template.
24
00:02:15,000 --> 00:02:21,210
Yeah, of course, template is another topic, but just generally speaking, we are going to use the
25
00:02:21,210 --> 00:02:22,410
circle template.
26
00:02:22,710 --> 00:02:31,350
And the circle structure is the basis for the creation of all of the future objects that we are going
27
00:02:31,350 --> 00:02:36,030
to make in this program or basically just by using these struct.
28
00:02:36,900 --> 00:02:38,640
So it will look like, oops, sorry.
29
00:02:38,670 --> 00:02:41,820
Now this one, the first one, so it will look like this.
30
00:02:42,090 --> 00:02:51,600
OK, well, we'll use index and the Y to coordinates to basically specify the X and Y coordinates of
31
00:02:51,600 --> 00:02:52,200
some point.
32
00:02:52,800 --> 00:02:55,380
And also we'll use double radius to specify.
33
00:02:56,330 --> 00:02:58,310
Their writing is itself of this circle.
34
00:02:58,970 --> 00:03:04,760
It now based on these class that we've just created, we will be able to create instances, right?
35
00:03:04,790 --> 00:03:08,690
We will be able to create variables of this circle structure.
36
00:03:08,690 --> 00:03:15,620
We will be able to create one which would be circle one, C2, C3 and basically access and modify each
37
00:03:15,620 --> 00:03:16,670
of these members.
38
00:03:16,820 --> 00:03:17,750
One by one.
39
00:03:17,780 --> 00:03:18,890
One after the other.
40
00:03:18,890 --> 00:03:19,400
And so on.
41
00:03:19,700 --> 00:03:20,090
OK.
42
00:03:20,180 --> 00:03:23,120
So that's basically what we are going to do, what we can do.
43
00:03:24,920 --> 00:03:25,330
Awesome.
44
00:03:26,600 --> 00:03:29,870
Now, the question is, should we do it this way?
45
00:03:29,900 --> 00:03:38,450
Or maybe there is more elegant way in organizing our project, so we know that X and Y, both of them
46
00:03:38,720 --> 00:03:41,810
are used to represent a point.
47
00:03:42,070 --> 00:03:42,380
Right.
48
00:03:42,380 --> 00:03:48,260
So basically, a circle can be represented as a radius and a center point.
49
00:03:49,070 --> 00:03:51,560
So why should we keep it in extending why?
50
00:03:51,560 --> 00:03:53,870
And basically kind of duplicating the code?
51
00:03:54,170 --> 00:03:58,850
We can make it much more elegant by using the following structure.
52
00:03:59,570 --> 00:04:03,080
So the structure is the same typedef struct circle.
53
00:04:03,140 --> 00:04:05,240
We are using a circle structure.
54
00:04:05,240 --> 00:04:11,900
We're creating this structure and now we are going to use what we are going to use.
55
00:04:12,410 --> 00:04:13,790
Point Center.
56
00:04:14,360 --> 00:04:15,140
What does it mean?
57
00:04:15,140 --> 00:04:16,970
Let's try to understand what it means.
58
00:04:17,450 --> 00:04:19,520
We create a variable.
59
00:04:20,420 --> 00:04:20,960
OK?
60
00:04:21,410 --> 00:04:28,310
We create a variable of type point, and this variable is a member.
61
00:04:28,790 --> 00:04:31,730
It is a field inside of the circle class.
62
00:04:33,280 --> 00:04:41,620
Once again, we create the circle glass inside of this circle, sorry struct, we create a circle struct.
63
00:04:41,920 --> 00:04:45,160
That's something that I teach in another, of course, so forget about it.
64
00:04:45,700 --> 00:04:54,580
We create a circle struct in this part of the struct we use a member of field that is basically a variable
65
00:04:54,580 --> 00:04:56,290
of another struct.
66
00:04:57,160 --> 00:04:57,670
OK.
67
00:04:58,240 --> 00:05:00,730
And we also have another field called radios.
68
00:05:01,120 --> 00:05:07,180
So if we take a closer look, basically the structure of Circle is going to look like this, OK?
69
00:05:07,570 --> 00:05:10,040
It will have main two fields, right?
70
00:05:10,060 --> 00:05:14,680
It is going to have the radius, which is of type double.
71
00:05:15,940 --> 00:05:18,580
And also, we are going to have the center.
72
00:05:19,830 --> 00:05:21,780
Which is of type point?
73
00:05:22,710 --> 00:05:25,330
OK, so that's basically we have these two.
74
00:05:25,350 --> 00:05:26,430
That's the first one.
75
00:05:26,730 --> 00:05:29,730
That's the center and that's the second one.
76
00:05:30,120 --> 00:05:31,160
That's their ideas.
77
00:05:32,190 --> 00:05:35,310
But what we also know is that these center.
78
00:05:36,490 --> 00:05:39,310
It is also of a point type.
79
00:05:40,060 --> 00:05:46,150
And we know that any variable of a poison type has two fields, intakes and entwine.
80
00:05:46,570 --> 00:05:50,680
So if we take a closer look at this one, we will see that it has two fields.
81
00:05:51,130 --> 00:05:58,330
It has intakes and it also has in white oak two fields.
82
00:05:59,450 --> 00:06:00,110
Are we clear?
83
00:06:00,650 --> 00:06:01,190
Awesome.
84
00:06:02,450 --> 00:06:08,900
So now what we can do is basically we can use it to create what can we create?
85
00:06:09,980 --> 00:06:17,180
It's I will simply remove it, you can copy it to your notebook that you will keep some record of it.
86
00:06:17,990 --> 00:06:25,100
Now we can use to see and basically how we can create variables of a circle type.
87
00:06:26,120 --> 00:06:31,400
So first of all, we have point B one and use some initialized zero initializing at this point.
88
00:06:32,000 --> 00:06:36,800
So point B one equals to one and two point B one equals to one and two.
89
00:06:37,820 --> 00:06:39,800
That's just the point that we created.
90
00:06:39,810 --> 00:06:40,430
Here it is.
91
00:06:41,360 --> 00:06:42,080
Here it is.
92
00:06:42,620 --> 00:06:47,690
This is one and it has the values of wanting to be one.
93
00:06:49,280 --> 00:06:51,080
Now we create a circle, see one.
94
00:06:52,160 --> 00:06:59,150
Currently, the center and the radios are not specified, but we are going to specify the sensor and
95
00:06:59,150 --> 00:07:05,840
the radios, so we specify the radius equals to three point three and the center equals to be one.
96
00:07:06,620 --> 00:07:08,900
So it's just going to copy this point.
97
00:07:08,930 --> 00:07:16,100
These members into the center are since both of these structures, both of these variables P one and
98
00:07:16,310 --> 00:07:19,490
C one, the center, both of them are of a point type.
99
00:07:19,820 --> 00:07:20,960
So there is no problem.
100
00:07:20,960 --> 00:07:23,900
There are going to copied one by one field by field.
101
00:07:24,860 --> 00:07:28,250
So let's take a look at it and it's going to look something like that.
102
00:07:28,910 --> 00:07:31,100
So that's going to be three point three.
103
00:07:31,340 --> 00:07:35,270
And this is the C one circle that we created.
104
00:07:36,650 --> 00:07:37,190
OK.
105
00:07:37,910 --> 00:07:38,690
Is it clear?
106
00:07:39,690 --> 00:07:41,850
So once again, we can access.
107
00:07:43,570 --> 00:07:51,280
Various things from an outer variable of type circle, we can access the radius in the center.
108
00:07:51,850 --> 00:07:55,480
And also what we can do is very important to clarify it.
109
00:07:55,930 --> 00:07:57,780
We can access and print.
110
00:07:57,790 --> 00:07:58,870
Let's go like this.
111
00:08:00,400 --> 00:08:01,840
Let's go simply.
112
00:08:03,310 --> 00:08:08,860
Let's simply say that we can access see one dot center.
113
00:08:09,400 --> 00:08:12,490
And we know that center is of a point type.
114
00:08:13,470 --> 00:08:15,660
And we will be able to access.
115
00:08:16,690 --> 00:08:25,420
What can we access the X and Y coordinates, OK, so you can see that we can access X and Y inside of
116
00:08:25,420 --> 00:08:31,510
this center point so we can access X, we can modify it, we can print it, we can read information,
117
00:08:31,510 --> 00:08:32,710
write information into it.
118
00:08:32,980 --> 00:08:34,300
We can also do it for white.
119
00:08:35,300 --> 00:08:35,560
OK.
120
00:08:35,600 --> 00:08:37,700
Because once again, we have see one.
121
00:08:37,820 --> 00:08:42,230
Here it is, see one is the bigger park than we have inside of see one.
122
00:08:42,230 --> 00:08:43,310
We have the center.
123
00:08:43,790 --> 00:08:44,520
Here it is.
124
00:08:44,810 --> 00:08:45,920
And we have the radius.
125
00:08:47,380 --> 00:08:50,350
And the center itself is a member inside of C one.
126
00:08:50,650 --> 00:08:51,030
OK.
127
00:08:51,190 --> 00:08:58,510
It is a field, but this field is also basically it also has some smaller fields inside of it because
128
00:08:58,510 --> 00:09:03,820
it's of type of point and it's a user defined structure that we created.
129
00:09:04,060 --> 00:09:10,480
So these sensor, it also has two fields index and in white, and we can access each in any one of them.
130
00:09:11,170 --> 00:09:14,140
So the way we do that, we can access C1 that center.
131
00:09:14,380 --> 00:09:16,470
So we access this center, remember?
132
00:09:16,870 --> 00:09:24,490
And inside of these member, we can access any of the fields that it contains, changed them, modify
133
00:09:24,490 --> 00:09:28,090
them, reading to them, bring them out and so on.
134
00:09:29,070 --> 00:09:33,750
OK, so yeah, that's very important for you to be familiar with.
135
00:09:33,780 --> 00:09:40,560
And to basically know that you can access this, you can modify, OK, also you can do it for X, let's
136
00:09:40,560 --> 00:09:50,130
say five that you can access and modify these fields and that you can create structures that basically
137
00:09:50,130 --> 00:10:00,540
contain variables of another of structures that you can create one struct that will basically be consist
138
00:10:00,540 --> 00:10:03,390
of another part of structures that you create.
139
00:10:03,420 --> 00:10:07,890
OK, so there are plenty of examples that can be used for it.
140
00:10:08,310 --> 00:10:10,530
For example, you can create, I don't know.
141
00:10:11,820 --> 00:10:19,290
You can create an employee structure, and these employee structures should have a couple of fields,
142
00:10:19,290 --> 00:10:19,710
right?
143
00:10:20,100 --> 00:10:27,120
And one of the fields that it can have is basically the date of the birth of the name of the employee,
144
00:10:27,720 --> 00:10:29,760
and date is also should be struct.
145
00:10:30,390 --> 00:10:34,500
We can also have a date when the employee started working.
146
00:10:35,430 --> 00:10:42,780
We can have something related to specifying, I don't know some information about some status of the
147
00:10:42,780 --> 00:10:45,180
employee by using another structure.
148
00:10:45,600 --> 00:10:52,620
Maybe I will also add some exercise about it that you will be able to work a little bit on this topic.
149
00:10:53,640 --> 00:10:58,440
OK, so but this is the general concept of using it very important.
150
00:10:58,890 --> 00:11:05,040
Make sure you watched this video from the start of the end, and maybe if it's not so clear, I will
151
00:11:05,040 --> 00:11:06,620
add additional exercise.
152
00:11:06,630 --> 00:11:08,070
Maybe I'm not promising.
153
00:11:08,160 --> 00:11:10,020
Hopefully, I will add additional exercise.
154
00:11:10,770 --> 00:11:13,230
But for now, make sure you understood every concept.
155
00:11:13,800 --> 00:11:15,290
Write down this code on your own.
156
00:11:15,300 --> 00:11:16,020
Try to run it.
157
00:11:16,020 --> 00:11:19,440
Try to make sure that you understand everything, how to access everywhere.
158
00:11:19,920 --> 00:11:21,090
And yeah.
159
00:11:22,040 --> 00:11:25,220
Thank you for watching, and I will see you in the next videos.
160
00:11:25,240 --> 00:11:27,320
My name is Vlad Lisa's Alfa tech.
161
00:11:27,350 --> 00:11:28,850
I'll see you in the next video by.
14759
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.