Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
What is going on, ladies and gentlemen, and welcome to this very, very important video in our programming
course as well as in your programming career.
So in this video, we are going to talk about a couple of things, but mostly we are going to talk about
how we can use relational operators such as smaller, bigger or smaller or equal, bigger or or equal,
not equal or totally equal using structs.
OK, so we know how to use relational operators with just some standard variable standard data types
such as integers, floats, doubles and so on.
But now what we are going to do is to take a look at how and if we can take advantage of these relational
operators and use them between different variables of certain struct.
OK.
And we will see that it's not so trivial, and it's not kind of very, very easy and intuitive, but
we will need to think of a way to find out how we can implement what we are looking for.
OK, so I think that the best way to start these explanation is just by giving you these little nice
examples that you can see on the screen.
So we are going to take a look at two different structs, and hopefully by the end of this video, everything
will be clearer to you.
OK, so that's something we will refer right away.
So let us, first of all, start with this typedef struct point.
So we have the structure of point.
Nothing can new so far.
And we are going to take a look at how we can create two variables of these struct.
OK?
The first variable will be B one.
And the second variable will be to one of them is going to be with the values of three and five in the
second one with the values of two and six for X and Y.
Respectively.
OK.
So we create two objects initialize them, and then what I want to ask you is a simple question if we
can or not compare between them.
I mean, I want to find out and write these kind of logical tests.
I want to see if P1 is greater than P2.
And that's something that is very important to understand.
We compare now not just between two integers.
OK, so we know how to find which which of doing the jurors is greater, which is the smaller and so
on.
We also know how to do it for floats and doubles and so on.
Now we tried to compare between two variables of a user defined type.
For example, point that we've just created.
So the question is, how should you compare between and B2, let's say you want to find out if B1 is
greater than B2, then to run some code lalala and then to print that point one is greater than point
two.
OK.
Basically, associate some code with with the answer to these condition.
But the question is how can you even think about comparing B1 B2 to variables of a point type?
I mean, what fields will be used to decide the result of these condition?
What fields would you like to test?
Would we like to know only if B1 is greater than B2 just by using its ICS field, just by comparing
the ICS data member?
Or maybe would like to know if it's decided by one by five by five by white.
So, I mean, if we take a look at P1 and P2 and we ask which one of them is greater than the other
in correspondence, do the X value.
So we can say definitely that P1 is greater, right?
Because P1 died three and P2 X is two.
So we can say that in correspondence do the X value P1 will be considered greater.
But if we will take a look by the Y value of these two variables, we can see that P2 has a y value
that is greater than the Y value in P1.
OK, so how can we say which one of them is greater than the other?
OK.
For that, we will need to specify, but exact by exact what fields we want to compare between these
two variables of struct point.
So in this case, that simply won't work because.
We do not specify exactly by what fields we are going to decide the result.
OK, so it may be by one of them, it may be by both of them, it may be by none of them.
I don't know.
It depends.
So up until now, just understand what you cannot do and you should not try to do.
OK, so that's the problem.
Number one, you cannot compare between them.
You cannot ask if one is greater than P2.
The second is also to demonstrate basically, what are you trying to compare?
Are you trying to compare both of these variables field by field?
If that's the case, maybe we can write something down, but not always.
That's the case, will not always.
We compare between two different variables of this same structure, and we want to know and to say that
they are totally equal only if all of their fields are totally equal with one another.
That's not always the case.
OK, I'm going to show you hopefully during these course, a couple of scenarios where this wouldn't
matter.
OK.
So error number two, we don't know what fields are we interested in.
Maybe we are interested in all of them.
Only if all of the fields are equal, then the result will be true.
Or maybe we are just interested in knowing if P1.6 equals to P2 italics, then we can say that for us,
that should be sufficient.
And we can say that both of these variables, B1 and P2 are equal just by saying that if the X members
are equal, then we can decide and we can conclude that both of the variables of struct point are equal.
So we didn't specify it explicitly.
So that's hard to decide.
OK.
So far, so good.
I'm just preparing you for a material that is even more important and not not more important, but also
very important.
So that's about the first example.
Now let's take a look at the second example to make sure that we understand the small details.
OK, so we have these struct struct employee, and this structure is basically it consists of three
fields.
The first field is an array of characters.
The second field is a float age some variable and the third field is end ID.
OK.
Three fields.
The first one is an array.
The second one is float.
The third one is entry I.D. So we want to ask a simple question.
OK, let's take a look at this code that I've added here we have created to object to two variables
of an employee struct.
So we created empty one.
It is a variable of a struct employee initialized with the next values.
OK, and the same we do four empty two.
So the first one is Jake.
He's 24 and a half years old and his ID is one two three.
And we also have the second employee MP to which is John, and his age is 30, and he's IDs three four
two.
OK, so far, so good.
Now what we wanted to know is if we are to compare between these two variables of this structure struct
employee.
Then basically, also this will not work.
OK, I.
Intentionally intentionally giving this emphasis on this topic, because a lot of students, they find
it hard to understand the next topics that you learn, like how to use basically in C- language, how
to use the functions that are related to it in C++ language, how we can and why we should use openly
operator overloading.
OK, so that's just the basics.
Make sure you understand it completely, not just memorizing it, but understanding every step that
we discuss here.
Why is this happening?
Why is it not working and so on?
So we cannot compare if MP one is greater than MP two?
Because by what fields do we exactly compare between them?
Do we compare if MMP one is greater than MP two just by comparing the field of the age?
Or maybe maybe we ask if MP one is is older than MP two.
That's one option, but maybe we want to ask you for MP.
One is greater than you do, then it simply means that we want to compare their IDs who appears before
who in the I don't know, in some book.
OK, and also the same goes for the name which name appears first or maybe will want to take into consideration
all of these fields?
OK, so that's why you cannot work with it.
OK.
And you basically don't know, are they equal by ID, by name or all of the fields?
OK, so that's the problem that we have in the solution to this problem.
I'm going to give you in the next video.
OK, so stay tuned.
Let's go.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.