Transcripts
1. Introduction: Hello, my friend, welcoming the video calls Seacoast plots. This course is divided into over 50 lessons and is over 12 hours long and it's recommended for bagging us after discos who will become expert in the C plus plus language. You might be asking yourself Who is the altar off this coast? Well, my name is our catalogue Adopt trick and I really, really love teaching other people. I am the altar off 26 very popular video courses in Poland, and I also created a few courses about the C plus plus and Web development in English. I put all my heart integration of video courses and I want them to be understand able for everyone. All the subjects are shown to you the easiest possible way. OK, it's not about me discourses about the c++. So what you will know after discourse. Well, after this goes, you will be able to use the advanced compliments of the C plus plus language. You will know cementing of the c++ semantic means meaning of wars in the C plus plus, you will be fluent in the sea prospers language, and you will have solely basics, allowing you to create whatever you want. Off course, you will know the advanced components also, but sold it. Basics is the most important thing. If you want to become very good programmer. Okay. If you have basics, you can create whatever you want. You can read libraries, and then everything is gonna be easy here. I type things that you will exactly learn this course. So you know, basics like variables have toe insel i d. How to use it. What is a compiler and other things like that? Operators condition, actions, a raise, loops, functions, references, pointers. I deeply discussed pointers. After this goes, there is no chance you have problems with them anymore. Project creation structures and class is object oriented programming templates, exceptions and name spaces. So, you know, totally fully c++ syntax. Okay, Now you might be asking yourself Why should you choose Michael's right? Because I have enormous experience in teaching other people and I do a different way. I always explain things from scratch. I do not omit anything. If you don't believe me, you can watch for free a few first video so we can check if you like the way I teach other people. I even in this the world at least free videos before buying anything, I'm sure that you will be satisfied with my course after completing it. And, well, it's really cheap comparing to world you can achieve after these cars. After this course, you will have knowledge. And what is the most important ability that we lead? You read C plus plus language. If you know how to read c++ libraries, you can then create whatever you want. If you have any questions, feel free to ask them. You can send me a message. I will respond as fast as possible. Okay, you can ask me about programming, but take in mind that I am not making the homework's. But I would be happy to give you hands. Okay, thank you very much for watching the first video and have a good day.
2. What is programming, compiler. Installing IDE : Hello, everybody. Welcome
to the first lecture. In the upcoming videos, I will teach you the
C plus plus language. I will try to cover all the
subjects about the C plus plus from the beginner
to the expert level. So after you watch
all my videos, you should be able to
create your own programs. But before we start the school adventure
with programming, I want to explain you
what the programming is. Firstly, let's focus on the word language.
What is language? Have you ever wondered
what language means? Well, let's make a comparison. Right now I'm talking to
you and I am using what? What kind of language? I'm using English
language, right? So we are using some kind of code to communicate
with each other, right? And that thing is
called language. We understand each other. Only, only because we both know, we both understand this code, and this code in our situation
is made of what of words, and each of that word has
some kind of meaning, which we all understand. That's why we are able to
communicate with each other. But unfortunately there is
a problem with computers. When we look at our PC, at our personal computers, we can say to the PC to him, something like hello, PC. Bring me some beer. Well, if the computer
understood it. Probably if our
computer had some of legs that will
allow him to move, he would bring it. He doesn't understand
it, as you can see, because I am not drinking
a beer right now. We need to talk to
a computer with a language that he
can understand. What is that language? This language is called
programming language. Programming means creating
understandable instructions. Orders that will be followed by our computers.
They must be followed. The instructions that you give computer are followed.
That's how it works. If that instruction
must be understandable, we need to talk in the language that our PC is talking in. That language that
our computer know and understand is
created of numbers. It's like this 001 1100. Much much, much more
zero than ones. But why is it zero and one? That subject is connected
with electricity. Our computer can read
only two pulses, zero and one, and every
message, every word. Every instruction that is
sent to our computer uses different sets of
the zeros and ones. Whoa, that would be hard to talk to him using zeros and ones, as he might have probably
noticed already, it would be probably
impossible, right? Can you imagine writing a
code using zeros and ones? It would be hard for us
to use that language. And for sure, it
would take lots of time to create anything. And because of that, people
created something between the computers language and our language that
we use every day, like, for example, English. Well, to be honest, many line languages like
that have been created, but we will focus on
something what is called C plus plus
in this course. Now, using the C
plus plus language, we could write, for example, something I get characters, and what that instruction
could mean to our computer. Well, it could mean that
we want to get cha, get characters from
some kind of input. But as you can see, this
is still not working. We type instruction that could be understandable by our computer, but
it is not working. Why is that so? Because this is still not a language
that our computer uses. It is not a sequence
of zero and one. This is the language
that he uses. We need something
that will translate the C plus plus language. Instruction, like, for example, this one into the
zero and end ones. That thing that translates it is called a compiler, compiler. We have just learned
a new word and the process of translating
the languages, from the instructions
into zero and one, is called compilation and
we use it compilation, and we use it for it, a program that is
called compiler. To download compiler in
order to compile a code. When you compile the
code, a program, Using a compiler, you are doing many things in
behind the scene, like for example, also checking the syntex of our lang language. It's checking if we hadn't made a mistake, it's
linking libraries. It's optimizing our program,
and many other things, but I don't want to go into
these details right now. You just need to know
that compiler for now just translates the code, the instructions into the zeros and ones in order
to make them work. We need a compiler. Without it, we won't be able to program. So to start our adventure
with programming, we also need an
editor that will help us write programs in the
CplS plus language, right? Because we want
write our programs in Google Search engine, right? Do we want to write programs in the web browser your
entire life? No, right? So it would be great
if that editor also had many additional features that we have us write programs. Like, for example, showing
instantly where the error is, or it could also
colorize our programs. So it would be easier to read. That editor with
all the features and connected to a compiler. W compiler pre installed
is called IDE. It is a shot for integrated
development environment. IDE is some kind of set of programs
inside of that editor. There is a set of programs
that will help us write new programs and after
compiling these programs, we can run them on our PC. It's time to download IDE. And we'll download ID that
is called code blocks. It is a free one. It's
good for beginners, so we will be using it. You can use any other IDE. But keep in mind there might be a small difference set start, how to create the programs, so on, but do not worry, these differences are
pretty small and you will be surely able
to manage them. I highly recommend
Visual Studio code. This is also very good ID, for Mac, I also
recommend X code. But we'll focus on code blogs. So let's download it. In order to download
code blocks, we need to go on Cdlogs website, go to the Download Sap and click on the download
the binary release. If you do not install
something what is called compiler that I
talked about before, your programs won't be
able to be translator. Here is something what
is called Man GW. And this is a compiler, which is included in this setup, and we need to choose
this pin here. The one with Man GW. Choose the link with the
Man G W. And then we click on this in order to
download our code boox. So the code block box is
being downloaded right now, and now it's time to
install it, right? So let's click on
it. Next. We need to read license, of
course. I agree. And as you can see here, we have got MN GW compiler suit. We have got a compiler included. It's clicked care. Let's click Install. I have already the installed, so it ask if we want to
keep existing folder. I would just
overwrite everything. It will take some time
to install it, right. It depends on how fast
your computer is. Let's run our program. We have got now here the ID, integrated
development environment. And in this environment, we can develop using integrated tools our
own programs, right? We can develop our
own programs as code. And how to do it. Well, we need to first create
a file. So let's go here. File new empti fy. And now we can
write here a code. I will write it now
as fast as possible, so you won't lose
your precious time. I will explain all
the code later. Very simple program right now so we can just check
if it's working. So let's incle the library. Let's say that we are using
the proper name space, and now we have to use the main. Function, and let's
send something to the output so we can see
something let's welcome people, for example, hell
award, like that. And now we need to save the fi. In order to save the fi, I can go here five
and here save five or use the shortcut Control plus S. I'm missing the shortcut, and now it's very,
very important. Here, I have got
the name of my Pi. It's very important
to not save by default this as a C. Language, because we are not programming
in the C language, you're programming the
C plus plus language. If you buy mistake,
do not add here. C plus plus, you have
to manual type here. Remember about it. I'm
telling it five times because people make
mistake here most time. As you can see, now we have
got zed, and we can run it. Okay? We can write using the
built and run option here. Here, it means
that it's going to build and then run the program. It means it's going
to compile it because the compiler is hidden behind
this button right now. B. And as you can see here, we have got ward
and some kind of additional message that
is added by our compiler. But hey, we just compile our first program. We
can write it, right? Of course, I will explain everything that you see here better in future. Do
not worry for it. Now. I just want to show you in this lecture how to compile
things, how they work, okay? Normally, if you are
using either ID, you might have to stop
your program manually. Remember to add then at the end intraction
de system pause, and you have to probably, not always include a
library here that is called L D. Just do it and
this will work. If you cannot use the system, you might need to add
something like that, get character, and also
this program will stop. Sometimes you need to also add here and here, return zero. Okay? We do not
need to dit here, so I will not confuse
you anymore, okay? So let's just focus. This
is the simplest program, the most simple program
ever possible to create. I will explain every instruction
very very profoundly, very deeply right
in the next lesson, so do not worry. Her, I said something
about the compile, right? And this compiler
is hidden here, and it translates Cl plus
language into the 0111, right? Go into the computer language. And it also means that
if I make any mistake. Like for example,
that, well, this word, I don't know what
does it mean, well, it doesn't exist in my language. It doesn't exist in the
CPS plus language, right? So it will be probably
hard to translate it. When I click here,
as you can see, our program did not run.
We have got an error. And the cool thing
about this idea is that when I click here, I will be instantly shown
where this error is, and also, I can read
here the error message. That word work was not declared in this
scope in this place. You have to just delayed it and then run again the program. And it's going to work, right? I'm inviting you to
watch my other lectures. If you have any question, as
always, feel free to ask.
3. Basics of programming: How everybody on
the second lesson, today we are going to learn
basics of building programs. This lesson is really important in order to
understand programming. Let's hide our manager on the left side because we
don't need it right now. I click view and Manager. Now let's create a new file, counter sheet plus n, and stands here for Me. We have just created a file which is called the source code. Let's save it. L et's
just add here, dot CPP. Remember about
adding the CPP here because you might have
problems compiling your programs in the co blocks if you don't
add the CPP here, because the default option for saving is the C five,
not the C plus plus. Remember about adding
that extension here. Okay, we are saving it. And now I will say something
very, very important. We need to understand, we need to know and always remember that
when you write programs, we are doing it for our PC, for our compiler, which will interpret things that we wrote. We have to remember that our PC without us,
is very stupid. That's true. I'm not lying. PC won't be able to get
anything if we make an heroes. Computers are doing only de, what we want them to do. We are sending
them instructions, and they have to do them. If you make any heroes, when you are writing programs, remember that's only your
fault, not the computer. If you want to write
programs well, we have to feel and
f like a compiler. Since today, we are
going to be compilers. Okay. Almost every program
is going to be read by our compiler from
the top to the bottom. If I write here something live. Let's assume it's some kind of instructions, orders
for computers. We can read code from
any place we want. We can jump from one
line to another line. We don't need to
read line by line. It's up to us what we do. But that code would be
read by the compiler. From the top to the
bottom line by line. Okay. Why I'm saying this. Why is it so important? Because as I said earlier, we need to start thinking
like a compiler, not a human. It will later help
us avoiding misdem. Let's start doing
some serious stuff. If we want to write
anything out to the users of our programs or
respond to their actions, we need to use mostly something
what is called libraries. When we talk about
library in programming, we are thinking about many tools that we can use to
achieve our goals. We will explore many of the tools in the
upcoming lessons. That tools are some kind of
toys that we can play with. They will help us creating
our programs faster. Sure thing is that also
we can create libraries. But that topic is
a bit advanced. There are many libraries
that we can use for free. Some of them are
on that website, but how to use the library. If you want to use the library, we have to write has
and the world include, which means we are
adding library. Then add angle brackets, less than greater than signs. Between angle brackets, here, we can use the name
of our library. We will use I, stream, which stands for
input, output stream. Let's note that if we want to know something
in our program, well, in our source code, and we don't want it to be
interpreted by compiler, we can use the comment signs, which allow us to
comment our program. Slash slash, and I can now
write something like I O stream stands for
input output stream. This thing is one common. Everything behind
everything behind here, everything in next line, For example, here that line is again interpreted
by the compiler. There is one more way
of using comments. Slash Aster risk. Here we can write many
comments in many lines. Now if we want to
close that comment, we have to use the asterisk
and then Backslash. Now as we can see,
that text is not being colored by our IDE. Why do I need things like that? Well, comments are
really very useful. It's a good idea to comment
what our code is doing. Believe me, when you start
writing programs that will be over 200 lines
long or even longer, you won't be able to
memorize everything. You might also write programs and leave them for about one, three months or maybe longer
because you will have, for example,
holidays or you just want to need to look
into your code. When you come back to your code to upgrade it or maybe
extend it a bit, believe me, without
comments is like a nif ma. Okay. So in situations like
that, comments will help you. Remind what you had programmed. Also, remember that when you start programming with others, they won't be able to understand everything that you wrote. So it's good idea to make it easier for them because they will be your
teammates, not enemies. Let's go back to the library
that we have just included. Let's remove that
comment here also. And this is basic C
plus plus library, which allow us as it
says, as it says, two input, which means putting something into our
program and output, which means putting something
out of our program. Now I will create something
what is called a function. Here we have function. What is function? Function as the name suggests is something that is
created to function. This function as we can see
is called what, like main. This function goal
is to be invoked, executed, always as
first, always as main. This is a special function that needs to be created
in every program. Here, we have also parentheses, brackets, which are here
to declare parameters. But we'll talk about
it later or not now. After it, we have two brackets. First, the opening one, and it is the beginning
of our function, and the last car bracket, closing one, and it is
the end of our function. That thing between,
that car bracket is called the body
of the function. Our program will start invoking instructions
orders from this function, starting from the
opening card bracket, and it will finish on the
closing card bracket. I write instruction in
the body of function, S out less than sins. Quote, this is test
and the semicle. And that instruction
is ordered for RPC, and it, of course,
must be followed. Let's figure out what that
instruction is doing. As we can see here, we have got something
like C out. C out stands for console output. After it, we have
two angle brackets. Less than signs. As we can see that signs are pointing
to what direction, to the C out, to the council output. It means that everything after that angle brackets will be
sent to the council output. In our situation,
it will be what? It will be the text
inside quote signs. De signs are reserved
for sequence of characters which are
shortly called strings. Since now, every text will
be called by us strings. At the end of every instruction, we have to add semicons
why is that so? Well, we can write programs
also like t, for example. For example, that way, we
can write it another way. For example, we can do it, let's remove it the
white characters, we can do it dead way also. It can be almost in one line, but here we have a comment, so it's not working. For example, I will remove
that comment for a second. And as we can see, we can write everything
in one line. And if we had more
than one instruction, be hard for our compiler
to decide what to do, that sem colomns at the
end of instructions allows the compiler to interpret our programs
always right. As you have probably
already noticed, white characters like space, Dub, enters are not
interpreted by competitors. It means we should
write programs clearly, which means like that. Just look how do I
write programs during all lessons and try to
do it the same way. Your code will be easy to understand for you
and other people. Our program still won't
be able to run now, because that see out thing
is inside a namespace. What is name space? Well, name space
is a space where we can store functions and other things connected
with programming, and we can name this space. That's why it's
called namespace, because it's a space,
which has a name. Okay. Name spaces are used in order to avoid
situations where, for example, two
programmers are going to make two programming elements
with the same names. If you want to use
the C out element, you have to say from which
name space is that element. C t is from the STD namespace, which stands for standard. Now we have to add two colons. In order to use programming
elements from that space. Now, our program
will be compile. As we can see,
it's working well. However, using that STD
name space every second, for each element like
C from that space, might be a bit tiring. That's why we can say
after including O, something like a space, S D. Now, we don't need
to use D, thank you. Our program, as you can see, is still working well. If you have any questions, feel free to ask. Thank you
4. Variables: Everybody. Today, we
are going to talk about variables in the
C plus plus language. Let's start this topic not
from what is variable, but why do we need variables? For example, I want to send something to
the console album. Let's write C out two angle
brackets for semicus. It means that I want
to send a number four. To the counsel out. But hey, what if I wanted to
store this number somewhere? Because I would like to make some operations on that number
or even change the bit. Look, right now we have
the number four here. After that instruction
is invoked, we can't do anything with
that number and more. We can't do anything here
with that number here. This number disappears. We don't have any
reference to that number. That's why we need variables. Variable, as the name suggests is something that
is able to vary. It means that it is changeable. It can be changed
any time you want. Variables are some containers that can store
values like numbers. Imagine that this beans containers here
are our variables. Each of them has different
label name, A, B, and C. As you can see each of that container
is also a bit different. They have different shapes. It means the container variables can store different values, different type of values. Now we have discovered
a new thing, the type of variable. The type describes what can we put into our
containers variables. Let's create variable
in our program. Let's name it A. We have got on label now, name of our container variable. We have to also describe what can we put into
our container variable. We have to declare
the type of variable. Let's start from the int. Which stands for integer. Integer are numbers that
have no fractional part, so now we can assign to
our variable on integer. By assign, I'm meaning putting something
into that variable. Let's stop for a second and
think about memory in our PC. Is it unlimited? No. It is limited by our
hardware because we can only assign subset
of integer numbers. In our situation, we are allowed to assign to
our variable named A numbers that range from minus two billions to
about plus two billions? Let's do that. A equals,
for example, four. The equal sign allow us to
assign values to our variable. The process of assigning value to variable is called
initialization. I can do the process of
assigning also in one line. I could write
something like that. I will common that. But let's assume I want to
assign two variable A. So, for example, I can't do it because this value is greater
than two billions. It's really good idea
that we can do it because we would take too
much memory in our RPC. We don't need that number
for all the situations. Now, I will say something
very important. When you look at any book, what is the easiest way
to find something inside? If I give you, for example, one section of book or
even only one word, and I will tell you
to find this section inside a book that
has 1,000 pages. I'm sure it will take
you very long time to complete the task. What about the same situation? But now I'm giving you
the number of page. You will find it probably
almost instantly. In programming word, that
situation is almost the same. The section word in
our program is called Label or name of variable. The page number is
called address. By using variable address, we can get to values faster. But this is a bit advanced topic and it is connected
with pointers. We'll explain it
later very precisely. But now I want you
to know how to get address of variable. In order to do it, we have to write something
like percent percent, and now the name of variable. Let's send that things
to the consul output. Let's do something
like that now. C and C out percent A. Now let's build
it. As we can see, we have everything in one line. We will add here
something like end. L stands here for line. That fin here is indicating
the end of line and it's adding the der at the
end. Now when I build it. As you can see, we have
in two lines four. In the first line,
there is four. In the second line, we have
the address of that four. We have the address
of the variable. When we write, something like A, we are declaring variable. Declaring means that we are in compiler that there will
be somewhere in our program, named in our situation A. When we write
something like in A, in the C plus plus language, we are also defining variable. Defining means declaring,
and in addition to this, we are also reserving
allocating space in memory. In our situation, we are allocating space for the
variable that is integer. I allocates four
pytes of memory. One by these eight bits. We are allocating 32 of
bits in pieces and memory. Bits are zero or one signs. We are allocating
in one sequence, somewhere in our memory, 32 places that can be
filled with zero ones. That sequence of zero and
one can be translated to our language or our language can be translated
to the sequence, and as I said earlier, variable values can be changed. Any time. In the second lesson, I was talking a lot
about that compiler is reading everything from
the top to the bottom. If I write something like that, and I will copy that. T. What will our
compiler do now? Let's start from the
beginning because our compiler is doing
that way.per is, including the IO stream library. It will use the STD name space and then it will invoke
the main function. In that line A equals four, our compiler will
be informed about existence of variable named A. It will also allocate somewhere
four bytes of memory, and because of initialization
that equal sign, it will change sequence
of zero and one to represent number four
in our PC language. After compiler we print to the console output value and
address of r variable here. Here, A equals ten, R compiler will change
value of variable named A. I will change that
sequence of zero and one, but it won't change the address
of variable, of course. Let's compile it. As we can
see the number has changed, but the address is
still the same. Let's study how we should
name variables now. Let's do it in comment. The first thing is
that we can't have two variables that
have the same name. Variables can't
have the same name. If I want to declare
two variables, I have two different
names that way. We can run our program, but we can do
something like that. Zero, redeclaration of. We can do something like that. We can start the name of
variable from the number, but we can use numbers
in other places. Variables can start from the
number. Let's check it out. I'll try to create in and now
I'll do some, for example, that I'm trying to build
it, and I can't do it. But I can do it that way easy. We can use spaces, but we can use underscores. We can't use spaces. I can do something like int, and now I will do something
like prime number. I can do something like that. But we can use of
course underscores, so I can do it that way. Prime number. That's all right. We can execute r program. When we declare variables, we should try to make
them self descriptive. Self descriptive means
that we should be able to guess by looking at
the name of variable, what is that variable
created for? For example, we can
write in prime number, or maybe I can do it even
that way, in prime number. I can do it prime er. I can do it also that way. I prime number. The i prefix. Let us guess by just
looking at the name that the type of variable is
integer, because I in. This notation, that one
here is called tab it. Hungarian notation. Variables should be
self descriptive. We can use special keywords. Let's see what we can do. For example, I can do
something like int using because it's the
keyword, I can do that way. It's not working. I can use the special character like
has. It's not working. Let's know that variables can have special
characters keywords. And variables should be nouns. They shouldn't be adjectives or other things like that.
They should be just nouns.
5. Types of variables: How, everybody, today
we're going to talk about more types of variables in
the C plus plus language. Right now, we only
know how to create variables that can
store integer numbers. But we also need to know
how to store real numbers, character, sequence
of characters. If we want to define variable, we have to write what
type of variable, and then name of variable,
and then semicl. We can also define in one
line more than one variable. In order to do it, we should
write something like that. Name variable. One.
Name of V B two, name of V B three, and we
could just continue that. Let's check it out if
it's working in A, B and C. Build build and run. As you can see, our
program is working well. We can also assign one of that
variable in the same line. For example, I as that one, and I will as that one. Let's build it. And
it is working well. But let's see what values are stored in that
variable right now. C out A, and line. Now let's just do that thing to the P and C. Now
let's compile it. As you can see,
variable named A and C has got value that
we assign, 4020. But y variable B, as a number here. If you combine that
program on your computer, you might have even
different number there. Why is it happening?
It's because we haven't assigned any value
to the variable named B, but this might be
still a bit confusing. As I said in the
previous lesson, every variable has got
something like address. Let's send addresses of
variable to Csle output. Let's do something like that. Now, let's do it. That way. Let's C. As you can see, the address is some weird numbers connected with some letters like the F. The doation is called
hexadecimal code. We don't need to
understand it right now. But we should notice one thing. Each of that address
is different. Here I have for f and C,
they differ from each other. As I said in the
previous lesson, when we define variable, when we write
something like in A, we are then allocating reserving
memory in the same time. It also means that we are allocating address
for our variable. But allocating doesn't mean clearing the value that
is under that address. Allocating means
that we just want to reserve that space
for other value. If we write, for example, just P. We are just allocating memory that already might have
something as St.. But how is it
possible? Still how? Any programs that are running on our computer could use that space before for
a special reason. For example, for two
store actual ear, when we stop using program
that stored, for example, the actual ear, the space
in memory is again free. It can be then
again allocated by other programs like the one
that we have just written. But the value is still in there. The value under the address
is not being removed. That's why under
variable name B, we have some random value. To avoid complications
before using any variable, we should assign default
values or just anything. Now we are sure what value is
under the variable name B. Now we are sure that
it will be zero. Not some random number. Right now, we can
store in that one, numbers from about
minus two billions to about plus two billions. But in the same time, we have to allocate four bytes of memory. As you can probably guess, you don't need so large
numbers in every situation. If we don't need
large numbers and we want to save memory, we can use, for example,
something like that. Short in Tiger And let's name it t one. That type, let us assign
values that range from -32,768 to plus 32,007 67. Now we can assign
smaller values, but we need only two bytes
of memory, two bytes. We don't need to write d when
we define short integers. We can do it that way
like now, or we can just. We can just remove the d, and it's still the
short integer. Let's send some value to
that guy, for example, five. Let's send it to
the console output. As you can see, it's working
fine. Here we have five. Let's study something new now. What if I wanted to
use real numbers, numbers at a fractional part? Now when I write something like, for example, that
and I compile it. As you can see, you are losing
the value after the point? We lose that six. We have only five
on the consulat. The type that can
store real numbers are called in programming
floating point numbers. There are two of the types. Float. Let's say something
that and double. Let's to the consult point. Let's compile. As you can see, now we are not losing
the part after that. Now what's the difference
between float and double? Float allocates four
bytes of memory. Double allocates
eight bytes of memo. It's just doubling the float, and to the float variable, we can assign numbers
that are up to 38 zeros, and here we can assign
numbers that are up to 3080, it's a big difference, in addition to this, double
has got greater precision. Which means that it can save
more digits after the point. It means that it can
save more digits here. Because double variable can save more digits
after the point, we should use doubles when we are calculating
something important where the precision
is needed or we need to store very
large numbers. Now let's talk about
saving characters. Character car, T four. Car is an abbreviation
for character here, and let's send it to
the Counsel output. We can't do it that way
because the compier, we try to assign here, the variable named A. That guy here. If we want to assign
the character A, we should use something
like Eposrops, like that. Now, as you can see, everything is working fine. What if I wanted to store more than one character
in the variable? If we want to sort sequence of characters that are
called strings, we should use string. String, let's do something
like that, for example. As you can see, text should be inside the quote signs for
the sequence of characters. Let's send it to counsel output. Is working well. Let's learn how to combine two
different strings. I have for example, string
x, same value part one, string y p two, and now string combined
strings equals x plus y. C out combined strings
and. Let's see. As you can see, Part one
is now combined with Part two in that variable that
is called combined strings. We can add, for example, a space between
them now like that. To combine two strings, we should just use
the plus signs. Is working well. Let's talk about bing type now, buling. True or false. Bull is a type that can store only two values,
true or false. Maybe let's send it to the
console output and compile. As you can see, we don't have
here something like tru. We have one here, but here is true, why. Every number that is not zero is going to be true in
the C plus plus language. Zero is representing false, false is always zero. Every other number is true. Let's check it out. For
example, I will write false. As you can see, we
have zero here. Let's write something like that. As you can see,
we have one here. One is representing True, and let's say
the negative number. As you can see, it's one, and now zero, and it's zero. Everything is working
well, like I said. Now let's talk about
unsigned types of variables. When we look at that guy here, I told you that it
can have values from min hundred 6,767. But there are many situations where we don't need
negative numbers. Then we can remove the
minus signs, remove it. We are making them
unsigned types because it's without that sign. By removing negative
part of integer, we are increasing amount of positive numbers by amount
of negative numbers. For unsigned short int, we could assign a value that
range from let's do it for unsigned short int
zero to 65,535, that number here is a
sum of the numbers here. Let's send it to the
Council output that way. See out. As you can
see, it's working well. Let's talk about that we can also remove
that integer here. Unsigned short is
side short integer. It's working well. We can add unsigned to all
other types flow double, so it's working the same. Let's talk about
constant variables now. There might be situations where we're going to use
something in our program many times and we also want to make it unchanged able by mite. In order to do it, we
have to add type of i, a word, which is
abbreviation for constant. For example, we have string, we name it name of game. Conqueror of C plus
plus, for example, and I don't want this
name being changed. I will add cost here, and now let's send it
to counsel output. As you can see it
is working well. As you have noticed, I'm using uppercase for the name
of constant variable. You don't have to
do it that way, but it's good idea because when your
programs gets longer, you will know what
is constant variable just by looking at
name of variable. Is the uppercase. So it's the constant for sure, and we'll know that we can't change the value of this variable from the
other part of program. Let's read out, so we'll
see if I'm lying or not. Name of game, and now
something. L et's build it. As you can see, we
have a error here. We can't do it, so I didn't lie. Okay, that's all in this
lesson. Thank you very much.
6. Downloading data from input: Everybody. Today we are
going to talk about how to get something from
the cosle input. We're going to learn how to
get values from the users. In order to do it, we
are going to write something like C in, which is abbreviation
for console input. It's the entrance for the data that we
come from our users. When we wanted to put something
to the council output, we're writing
something like C out, and then we added two
angle brackets that we're pointing to the consul
output direction. For example, I will send something like
test, the consul out. But this time we are taking
something from that place, from the console input. We are going to write
two angle brackets, but they will point to the right to something
that can store values. We are going to use now variable name after
that two angle bracket. Let's create a
variable, for example, in A, and now. Here, I can direct
something from the console input to
the variable named A. That value is going to be
stored in the variable named A. Maybe let's change that guy
here variable named A equals, and now let's try to compile it. As you can see, now we didn't see that guy
here, that C out. We don't see anything
of the consular output, and we have got here
blinking underscore, which is waiting for us. Which is waiting for
us to do something, to give something to our variable named
A. I will give it, for example, ten, and
now as you can see variable name A is equal to ten. Now, As you can see, the type of that
variable is integer. What will happen if I try
to assign not a number, but for example, character. For example, key.
As you can see, that character got
converted to the number, but it also makes an
error in R program. If our program was
longer, it would stop. I will learn how to
fix situations like that in other
lessons, don't worry. Now, let's train maybe a bit. And I write the program
that the ask for name and Surname and you will welcome to the person program.
How to do it. Let's just create string
name and Surname. Now let's ask a
user of R program, enter your name. Sin name. Now let's ask him for the
Surname, enter your Surname. Let's do it the clean way. S Surname. Now let's welcome that guide
that visited our program. Welcome name,
space, and Surname. Let's see how it works. As you can see, our program
is asking us for our name, I'll type my name, and now I'll type my SR name, and as you can see,
it's greeting me. Welcome chi, that's
working fine. That's all in the lesson
and thank you very much.
7. Arithmetic and Assigment Operators: Hello, everybody. Today, we are going to talk about operators. First of all, let's
start this topic from what are operators? As the name suggests, operator is something
that can operate, it means that it can
perform, work on something. In programming world,
operators are used to work on, for example, variableus
expressions. In this lesson,
we'll learn about arithmetic and
assignment operators. Let's create two variables, and A equals ten, and B equals five. Now let's send to the
console output A plus B, and let's send line at the end, and this is called
addition operation. Now let's compile it. As we can see our result
is 15 operator operated, worked on two variables, and we have got now one result which we can send to the output or assigned to another variable. We have got other operators
like minus operator, which is substraction operation. We have something like
multiplication operator. And it is multiplication. Now, let's talk about
the division operator. And let's compile. As you can see, our
results are right. They are all good. But as you can see, when we divide ten by five, we have the result
two, which is right. But now let's change B to
four and you are probably expecting that the result
will be 2.5, 10/4. Let's see. As you can see, our
result is two, not 2.5. Why it's not 2.5? Because when we divide
two integer numbers, you see that variables
are integers. Our result will always
be integer, always. The part after the point which is in our situation
five is being removed. Math rounding is
not working here. So if you had, for example, 2.6, the result would
not be equal three, but it would be again two. But what if we want to have
a real number in the result? One of our variable must
be then double or flowed. It doesn't matter which one. So let's do it, for example, that
guy. Let's see. As you can see, we
have now 2.5 is Okay, now for example, that
guy make it double, and as you can
see, it's working. Of course, both can
be double and they do work, for example. Okay, let's back to the integer. Now let's talk about
modulo operation, which is later, really, very, very useful, but it might be
a bit confusing at start. When we use Modulo operation, which is pers and sign in the C plus plus
language on two numbers, for example, ten, modulo four. The result is two. Now why? Two, in our situation
is called reminder, and the reminder is amount left over after the division
of two integers. So when we look at
this operation, we should think like that. How many times can four
be located stored in ten? The answer is two, right, because two multiplicated
by four means eight. And now, what amount is left over after the
division of two integers? It is ten minus eight, which is two, right? Okay. Now, let's check
the next example. For example, one, modulo
five is one. Why? How many times can five
be stored located in one? The answer is zero because
five is greater than one. Okay, so zero multiplicated
by five equals what? Zero. Now what amount is left over after the
division of two integers? It is one minus zero, which is just one, right? And it works. Okay. You
should train it a bit. You can train it by just sending it to
the console output, for example, ten,
modulo four, right? Let's combine it.
As you can see, we have two there,
A, modulo, Okay. It works fine.
Training a bit because it's important to
understand it later. It's one of the operator
that is really used a lot. Fine. Now let's talk about incrementation,
decrementation, and assignment operations in
retation and decrementation. Incrementation means increasing
current value by one, increase by one, right? And decrementation
means decreasing current value by one,
decrease by one. Operations like that are
so frequent that they have special operators that
let us write them faster. And normally, if we want to increase current
value by one, so to increment something, we have to write something
like, for example, in C equals one, and now when we do something
like C equals C plus one, and then we will send it
to the console output. As you can see, we have now
the two at the end, right? We can get all the
things to cohan so it won't confuse us anymore, you can see is
here, how it works. That thing here means
something like that. Take the value that is stored in variable
C, which is one. Add to it one and then after summing that assign the result
to the variable name C. C will be too. Of course, that one can
be anything here like ten and it works. We can do that thing here a bit faster using assignment
operator like that. C plus equals one, which is the same. It is the same as C equals C plus one.
It's the same, okay? And of course, the
number here can be changed to another
number or maybe variable. And there are many more
operators like that. For example, division
equals minus equals, modular equals,
multiplication equals. Almost all operators have that shorter notation.
Let's compile it. Let's see if it's
working. You can see everything works fine. And now, finally,
let's talk about incrementation using
increment operator. Okay, let's come on
that thing here. Now in D equals one. Now
let's do something like that. See out the plus plus and line. And that plus plus here
is increment operation. Let's compile it.
As you can see, well, still, our D is
one, but is it true? Let's send D to the
console output again. Let's do it here.
Let's build around, and now we can see the dis too. It's another one. But why? It's because we have just
used something what is called, right, post
incrementation. And post means here that plus signs are after
the name of variable, and it also means that it
will begin the expression that thing here from sending
value to the output. I send to the output, and then it will
increase the value by one because of the
two plus sign. Okay. So now let's talk about pray incrementation.
Pray incrementation. The pray incrementation
is looking like that. Now, as you can see, we have two, two in both places. As you have probably
noticed, plus signs here. Are now before the
name of variable, which means that now variable will be first incremented by one and then value will
be sent to the output. And how to remember
what happens first. Just look at the notation
of incrementation. If the plus signs are
prefix for variable, right? Then incrementation is first. If the plus signs are
postfix for variable, then incrementation is going to happen after sending
value to the output. Now let's talk about pre decrementation and
post decrementation, post decrementation, and
prior decrementation. Prime. They work the
same way incrementation, but this time we are
decreasing value by one. So if I do something like that, and now we compile it,
what will happen first? That guy here will be
decremented by one first, and then the value will be
sent to the output. Let's see. So it will be zero. We
can see zero, zero. But if they do
something like that, it will send to
the output first. One, then it will decrease that value by one and then
it will send that one. Sorry, it will send just one, and here, the value
will be zero. Okay, as you can see,
everything is working fine, and that's all need a
lesson. Thank you very much.
8. Relational Operators: Hello, everybody.
Today we are going to talk about relational operators, what are relational operators? Well, as always, we
will concentrate on the name relational operator. It means that this
operator operate on variable expressions by checking what relation is
between them, right? So if I have two
variables, for example, and A equal stand
and B equals five, and I want to see how they
are related to each other. So for example, if
they are equal, I need to use
relational operators. When we want to check if
two variables are equal, we should do
something like that. See out, A, equal sine
equal sine B, headline. Two, equal sines are representing equality in
the C plus plus language. Remember that one equal sign is reserved for assigning
values to variables. Remember about the difference because you might make many
mistakes because of that. Now I will try to compile, but as you can see,
we have error here. That angle brackets
here are also operators and now our
compiler is confused. In the mathematic to
solve problems like that, we should use parenthesis. I will add parenthesis here. And now compiler will
know what to do, and I will compile it. As you can see, our
result is zero. Why. The result of relation operation is
always zero or one. One is representing
in variable two, zero is representing falls. We've just got informed by that zero in
the cancel output, the value of variable A is not equal to
value of variable B, because our result
was zero, right? Okay. So we can use the 01 information later by using something what is
called conditional statements, but we'll talk about
them later in lessons. Right now, let's talk about
all relation operators. This guy is true when both
variables have the same value. Now let's talk about that guy. I will copy that. Exclamation mark is just saying that it is
not equal, right? So it is true when
both variables do not have the same
value. Let's compile it. And as you can see,
it's true because ten is not equal to
B. So it's true. Okay. Now, let's
talk about that guy, and it's true when value of variable A is greater
than value of variable B. So in our situation, it
should be true, right? As you can see, we have one
here, so everything is. Okay. Now, next guy, so this is true when value of variable B is greater than
value of variable A, right? So this should be zero. And as you can see,
everything works fine. Now let's find out that guy when value A is greater than or
equal to value of variable B. Okay, so it's okay.
It should be true. If that variables were
equal, it will be true also. Okay. Now, that guy so B is greater than or equal
to value of variable A. So it should be in
our situation, false. We can also use
exclamation mark to change value from two to face, 1-0, zero to one. To do it, we should do something
like that, for example. I will add exclamation
mark here. And now I will say,
if that guy here, that result is zero,
change it to one. If it's one, change it to zero. So in our situation, A is not equal to B, so that guy will be true.
9. Logical Operators: Hello everybody.
Today we are going to talk about logical operators. Why are they called
logical operators? Because they work in
the math logic section. Don't worry if you don't know or do not
understand the subject, I will try to
explain in easy way. Please concentrate and if you do not understand
this topic, where this video again
because it's really important to know how
the operators work. Let's create multi
line commands. First operator
that we learn in C plus plus is called
end operator, which is called in
math conjunction. It is used to connect something and in the
programming language, it is hidden behind 2%
signs, that signs here. You can think about
conjunction like it was a connector of two expressions, and what do you think
by saying expression? I'm thinking about
things like that. Seven is greater than five, five is not equal ten. Mostly the things
that we learned in the last lesson that
expressions have results. As I said in previous lesson, the result is zero, which is representing false or one which is
representing true. When we connect two
expressions connect to expressions with end operator
like that, for example, we are saying that both
expressions have to be true if we want the full
sentence to be true, the sentence is the thing
what I have just highlighted. So this is the
sentence. So sentence is something like
expression connected with, for example, the
conjunction here, right? Okay, so let's note that. Conjunction is true only if both expressions are true. Okay? Let's chick it out, see out. Now I'll use the parentheses
and our sentence, right? And let's build our program. As you can see, the
result is one, why? Is seven greater than five? Yes. Is five not equal to ten? Yes. So here I have from
that expression one, here I have from that
expression one, right? And one and one, and is the thing here, one and one is also one because conjunction is true only if both expressions are true, okay? Well, for example, let's
change the numbers here. Now, you say that five
is greater than seven, which is, of course, not true. So here I have as a result zero, and here I have,
as a result one. So zero and one
should give us false, so it will be zero, right? And as you can see
everything is working fine. Let's make a table for that. So I have, for example, expression one, expression two, and the result is zero, zero, Result is zero, zero, one, result
is zero, one, zero, result is zero,
and conjunction is true only when both
expressions are true. Okay. Let's talk about
logical operator. And it is represented in C plus plus by two pipe
sines, that's sins. And in math, it is
called disjunction. Okay? Sometimes people
call it alternative. Disjunction is
working like that. Let's make a table. So as you can see, disjunction is false only when both expressions are false. In all other situations, disjunction is, of course, true. And how to memorize it. I think if you want
to memorize it, I would suggest thinking about disjunction
as alternative. In real life, when
we are deciding, we are trying to choose
right decisions, right? And which are in programming
language represented by one, two, so here we have only
false expressions to choose. So the result is zero, zero, zero, and I
have no choice. I have to choose zero and okay, the result will be zero. But in other situations, as you can see, we have always at least one right decision. I have got one decision
to choose zero or one. Oh, okay, I will choose one because it's better
for me, of course. I will feel better, okay? That's why the final
result is one, one, one in the places here. We are choosing always
alternative decision, which is good for us. Let's try it in
programming version. I would change the guy
here to alternative. As you can see, is five
greater than seven, no, I have here zero, is not equal to ten. Yes, here I have one, zero or one is what. The result is one, of course. I will choose the easiest
alternative for me, right decision is one for sure. Let's check it build and run, as you can see, I wasn't wrong. What if I have both
expression as false? As you can see, the
result is zero. Everything is working fine. Maybe let's know that. This junction is false, only when both
expressions are false. Now it is the last operator, which is called logical
negation operator, which is represented in plus plus language
by exclamation mark. It is changing zero to
one or one to zero. If I have, for
example, that thing, the result the result will be one if I have
something like that, the result will be zero. Here, our result is right now one if I use that
exclamation mark here, it should be as you
can see now zero. One was changed to zero. We can understand that
exclamation mark as our word no, no, no. It's not. Probably this topic
might be confusing for you and you might
be thinking like, how is it important
for programming? I'm assuring you that
in next lessons, you'll notice that this
thing is really important. You can create many
very important things by using the knowledge in this.
10. Bitwise Operators: Hello, everybody.
Today we are going to talk about bitwise operators. Before we start, I'd
like to mention that this topic is not easy for
most of the programmers, so don't worry if you
don't understand it. However, it's good
idea to watch it and know about existence or
something like that. What are bitwise operators? Bitwise operators are
created to work on bits. Bit is the smallest information that can be stored
in our computer, and it is represented by
let's know that zero and one, 01 can be connected. Eight signs of connected
bits is called bite. For example, sequence,
something like that. If you want to operate on
the zero and one signs, we have to use
bitwise operators. Look, every number is stored in computer by using
the zero and one signs. Computer notation is
surprisingly very similar to our notation which is called
decimal notation, 126. This number is really created
of something like that. One multiplied by ten raised to the pair
of two, plus two, multiply by ten raised to
the power of one plus six, multiply by ten raised
to the power of zero. As you can see, that win
here is equal to 100, that win here is equal to 20, that in here is equal to six because ten is
the p of zero is one, one multiplied by six is six. You might be now like,
why am I saying this? It's because if you want to
change computer notation, which is called binary notation, we must do the same thing. We need to understand the changes to understand
bitwise operators. For example, let's change
something like 10, one, zero. This thing is some finite, one multiplied by something, plus zero multiplied
by something, plus one multiplied
by something, plus zero multiplied
by something. As you can see,
I'm writing what? Just the numbers here, right? And if you look I was writing also that numbers
here, as you can see. And now we need to write what? We are using here ten, white ten because here
is a decimal numbers. So we are counting
to ten, zero, one, two, three, four, five, six, seven, eight, nine, nine. And there are ten
numbers already. We have ten fingers, and that's why here is ten. In computer, we have only
two numbers zero, one. So here we will multiply by two, multiply by two,
multiply by two, multiply by two,
multiplied by two. Now, as you can see, I was rising to
the power of what. Look, here is the
position number one. Here is the position number two, here is the position
number three. As you can see, that numbers
are decreasing, two, one, zero, three, two, one. This is the number of
position minus one, three minus one is two. Two minus one is one, one minus one is zero. Okay, so here how it should be. To raise to the power of
zero, one, two, three. Okay, so to the power of 30, multiply by two to
the power of two, raise to the power of one, zero multiplied by two, raise to the power of zero. Now, that thing here
is decimal number. So one multiplied by two to raise the power
of three is eight. Plus, that thing here
is going to be four, but four multiplied
by zero is just zero. Zero plus two multiplied by one. So it's two plus
zero, one, zero, one, zero is really in our
word in decimal notation ten. You should also notice
now that when you see zero in binary notation, you can pass it because anything multiplied
by zero is just zero. So why do so many things. You can just remove it, right? And now it's a bit shorter. And again, you should
also notice that anything multiplied by one
is still the same number. So we should focus
on which place is the number and raise two to the power of
position minus one. So we should just do
something like that. And now it's very short, let's use the thing that we have just learned about, for example, I have one, zero,
one, one, zero, zero, and you should
think like that now. Here I have zero, so I
don't need to think about that situation because anything multiplied by zero is zero. But normally here is
hidden number one. I zero was one, right? And now again, number zero. I just pass it, but I
remember that if it was one, there will be number two
in the simal notation. Now I have here one, and now I know that
I should raise two to the power of
position minus one. What position is it? One, two, three, three minus one is two. Two raised to the power of two. I have four, and I memorize
it somewhere just writing it here now plus two to the power of three goals
I have got here one. Now I have zero, so I know that here would be to raise
to the par of four, here is to raise to
the par of five, plus two raise the par of five. So is what four
plus eight plus 32. So it is 44. Can use something like
binary calculator, and now when I write
here 44, as you can see, we have got here one, zero, one, one, zero, zero,
so I was right. 44 is in our computer, say it as 101100. But as you can see, also before that one are
many, many, many zeros. Now we can learn about
the bitwise operators. Before we start, I'd like to mention that I'm assuming that you understand lesson about relational operators very well. Okay, let's start from making multiline comments and
let's start from bit wise, operated, which is 1%. It works like relational
operator end, but remember, this time we are
operating on bits, not on the results
of expressions. Okay, we have got also
bitwise R which is one pipe, and it works like
relational operator. But this time again, we
are operating on bits, not on the results
of expressions. We have got also bitwise
operator note, which is Tilda. And it works like relational
operator negation, which is exclamation mark there. But this time again, remember that we are operating on bits, not on the result
of expressions. And there are three more
operators here this time. Bitwise, exclusive
or, which is cart, exclusive or because it
looks like that, right? It's abbreviation
for exclusive or. This thing is also called
exclusive disjunction. Exclusive means here that we cannot have more than one
alternative to choose. So table for R is zero, zero, which gives us zero because we don't have any right
alternative to choose, right, because we
have only zero, zero, so what to choose here. Zero and one will give us one because we can choose the
right alternative here. For example, that guy. And 10, which gives us one because we can choose the right alternative
here too, for example, that guy and one, which gives us zero because we cannot choose more than one
alternative in exclusive. There can be only one
right alternative at once, it must be exclusive. It's a bit different
from that guy here. We have got also
something what is called bitwise left shift operator which is two angle brackets
pointing to the left. They are used as the name suggests to move
bits to the left, but we'll explain it
more clearly later. We have got also bitwise
right shift operation, which is two angle brackets
pointing to the right, as you can see, and
they are also used as the name suggests to
move bits to the right, and also we'll explain
it more clearly later. Okay, now it's time
to do some exercises. For example, see out
and ten and and two. And we want to see
what will be the out. Okay, let's do
something like that. Look, normally, zero, zero, zero is just zero, right? If I want to change
that thing to ten, let's do something like that. Here normality is hitting one. Here normally is hitting two. Here normal is hidden four, here normal is hidden eight. So eight plus two
will give us ten. I change this G to one, this get to one, and this
thing is ten, right? Now, I think about
that two here, so it will be zero,
zero, one, zero. Now we have got
here ten in decimal and here two in
decimal notation. When I change it from
binary notation, of course. Now we have just
used something here, what is called a
bitwise end operator. It's working relational
operator, as I said, when conjunction is true, only when both
arguments are true. So zero, zero, and this thing is one because we have got here, true, true, and zero. So what is going to be
here, it should be two. As you can see,
the result is two. Now let's try the or
bitwise operator. So operator or is working like it is false only when
both arguments are false. So here is true,
false, true, false. So the result is,
as you can see, ten. It's working well. Okay. Now let's try the alternative or exclusive or, I wanted to say, sorry. And now, how it works,
we can see here. So here is one, here is zero, here is also zero. So the result is what? Zero plus zero plus
zero plus eight. Can see it is eight. Cool. Now let's
check the negation, the node bitwise
operator, for example, let's do ten and
something like that, and now 1010 should change
to zero, one, zero, one. You might be thinking
that the result is what? One plus four is five, but the result is -11. Why? As you have noticed probably when I was running
that calculator here, look how many zeros
we have here. So here is so many zeros, and that many zeros are
changed to one, also. And in programming,
if you want to achieve the minus number, the first guy must be one. The first number here is
indicating that the number will be as you can
see, negative. And now we are
decreasing it, right? Okay. Well, maybe I should say increasing because when
we are negative side, it's working different
way. Well, never mind. Now you can see why we have
got here the negative result. Okay, now let's talk about out and shifting guys
guys here, right? So for example, I do
something like that, then shifted one time
to the left side. And what the hell is that? Look, for example, I
have that guy here, and I am saying, Hey, move to the left side. So this guy here will be
moved to that ply tone. The guy will be zero, but the guy that was
here is moving here, one, zero and one. So right now, what happened? We increase the number
for sure, right? But by how much did they
increase the number? We are all the time doing something like raising
number to the power of two, two to the power of zero, one, to the power of one is two, two to the power of two
is four and 16, right? So 16 plus four is 20. So the result will be
20 in decimal notation. And if I did
something like that, I would have one more time that bits shifted
to the left side, and we would have four to here because we would multiply
it by again two. So this thing means that we are multiplying by two raised to
the power of that fin here. So this thing means
that we are multiplying ten by two raised to the power of Two. This time, it's two. Let's write maybe three to the
power of three. So ten multiplied by two to the rays of the
power of three is what? Ten multiplied by eight. So I should have 80 here. Let's see if I'm right, if I'm not lying, and then you can see everything
is working fine. Okay. So if I'm doing
it another way, so that way, that we are dividing ten by two
raised by something. So let's divide by two, raise to the power of one. So I'm dividing by ten, so the result should be five. This time we are
moving it another way. So this thing will be changed to what zero, one, zero, one. So it will be one plus four, five, right? Let's check it out. Sorry, of course, we should
change that guy to the right, and now it works fine. Okay, it's five. Everything is okay. That's on the lesson.
11. Contidtional Statements: Hello everybody. Today
we are going to talk about conditional
statements, instructions. Conditional instructions
are used to condition, check if something happen. Conditional instruction
let us execute, perform some block
of instructions, only if some
requirements are met. If the condition is met, which means condition is true, which also means that it
is not equal to zero, some block of code
will be executed. Otherwise, the code will
be omitted, skipped. In programming language,
it looks like that. For example, let's write
following code and A, B, and now let's ask our
user for the arable, A, now let's ask
for variable Bam. Now let's take it
from the input. And now I want to execute some
code only if, for example, value of variable A is greater
than value of variable B. We don't know what
values will be stored in the variables because the values will be assigned by user
of our program, right? So that's why it would
be nice if we could, for example, check
this situation. Okay, so I will use
conditional statement, which looks like that. If parenthesis and
inside parenthesis, I will write condition, and condition is just anything that can be a final result
zero or any other number. So for example, any expression. So if I write A is greater
than, and after it, I will write any instruction that will be executed on
if that condition is met. For example, C out A
is greater than B. We are sure that we can tell our user that A is greater than B because that condition must be met in order to
run the instruction here. Now I can compile that guy. And I will enter A, for example, as ten
and enter B as seven. And as you can see,
that instruction is now here on our output. So ten is greater than B. Okay? So so everything was okay. But what When I run in the game, and now I will type, for example, four, and now I
will type, for example, 25. As you can see, that instruction was omitted or skipped, right? Because A is not greater than B. Well, wasn't greater than B. Now we'll test a few more things and that thing would
slow us a bit. So let's just comment this. Let's comment that thing here. Let's do something like that. If seven is greater than
four, see out something. Now let's see out here test. What do I want to tell you now? Look, what if I wanted to execute more than
one line of code? Only if that guy here, if that expression, if
the condition is met. Now, as you can see, both of the instruction got
executed and it's okay. But what if I do
something like that? Four is greater than seven. Only that guy will be executed. It might be a bit confusing
when I write it that way. Still, on that guy
will be executed. Test. But what if I want to execute that guy on when
this condition is met? I need to use something
like brackets. Brackets are used to
group many instructions. As you can see, we have
got here brackets, opening one and closing
one that brackets are used to group that
instructions here. That brackets here, opening and closing one are hit to
group that instruction here. Because of that brackets, that two instructions here are treated like the
one instruction. That's why now when I
build this program, as you can see, both
instructions weren't shown. As I said, earlier,
anything, right? That is not equal
to zero is true. So condition above is
surely not equal to zero. As you can see this thing that
instruction got executed. We can use also not only
relational operators, but we can use the
logical operators. I can do something like that. If, for example,
seven is lower than four or zero is lower than ten. So let's show that thing here. For example, tell me
about that instruction. Will it be executed? Yes, because it's
zero lower than ten. Yes, it's lower than ten, and this is alternative. This is disjunction. So we don't need to think
about that guy even. Even if it is false, the result of that operation
will be one and away. If you don't understand
it, please repeat the subject about the
logical operators. As you can see, everything
is working fine. Now let's maybe make it
a bit more confusing. Now I would add,
for example, here, conjunction, and I would say, and ten is equal to nine. That, as a result
will give us zero. That thing as a result
will give us one. Conjunction is true only if both expressions are
true or one, right? So as you can see, the final result is zero
and now when we build it, we cannot see that guy here. That some exercises. Now I want to tell you about
something very important. Come on that thing here now, and let's back to that guy here. We'll assign values
by ourselves, for example, like that. And what would happen what
would happen if I want to, for example, do something else when the
condition is not met, then I can do
something like that, else, at here se and say, the condition A is
greater than B, surely wasn't met, right? And now is 100 greater than ten. Of course, it's
greater than ten. So this instruction is executed. But when I do, for
example, that thing, as you can see, the condition A is greater than B
surely wasn't met. But we can do other things. For example, I can do
something like that, else, if A is lower than B, C out, A is lower than B. Now I should change this
condition A is greater than surely wasn't met and the condition A lower
than surely wasn't met. That instruction is executed only if all of the
conditions were rent met. Right now, as you can see, minus four is lower
than smaller than ten, and that insection was executed. But if I want to
execute that guy, that condition cannot be met and that condition
cannot be met. So when will it happen when the two variables
are equal, right? So that dsuction is executed only if all of the
conditions weren't met. Maybe I should
change this thing. That insection will be executed, only if all of the
conditions weren't met. So as you have probably noticed, we don't need to use
that s if or se thing. We can use as many
s if here as we want to check many
other things, right? And that instruction
after will be executed on when all of the
conditions aren't met. We should also know
that we can nest. So we can have many
conditional statements when we use brackets. We can have nested
conditional instructions, for example, that way. Now, I can, for example, check if A is lower than, for example, ten, A is,
I'm sorry, smaller. A is smaller than ten. Now, when we build it, as you can see that
variables are equal, but I can do, for example, something like that, and now we will execute
that guy here. Ten is smaller than 20, but this thing wasn't executed
because A is equal to ten. It is not smaller than ten. Now when I do
something like that, as you can see, everything
is working fine. We can nest our
conditional statement. Since today, we can decide
what we want to execute. That's all in this lesson.
Thank you very much.
12. Switch: Hello everybody. Today we are
going to talk about switch. Switch is used as the
name suggests to switch between cases due to
the value of variable. Let's create a variable. Let's name it X, and let's
say value to the variable 15, now let's create a
conditional statement switch, which looks like that. Switch. Two parenthesis,
and now inside parenthesis, we can plates variable, which value will be
switched between cases that we will soon create. Let's type here, X, and now let's open body of switch
by using curly brackets, opening and closing one, and now we can create
cases that might happen, for example, case zero. So for example, this is
place for the instructions that will be executed when switched value is equal to zero. Now, let's make another case, for example, as 25. This is the place when it's 25, now case, 50, 50. Now I will type default
here, not case sign. And this is a place for the instructions that
will be executed, that will be executed
when value of switched variable is
not equal to any case. So that instructions
here will be executed in our situation when
variable X is not equal to zero, 25 or 50. Now let's compile it. Our X is 50 now, so what will be executed? That fin, right, for sure. And as you can see,
instructions after case is zero and 25, so that guy and that
guy, wasn't executed. But case 50 was executed, so it's good. But Hm. What's wrong here? That's weird. Instructions after default
also got executed, so that guy here got executed. Hm. Why? Because switch
works like that. Oh, here, I have variable X. Let's switch it between cases. It's variable X
equal to zero, no. Let's skip that guy here
and let's check next case. Is variable equal to 25? No, it's not so Let's skip that guy and let's
go to the next case. And it's very equal to 50. Yes, it is. Let's execute every instruction to the
closing curly bracket. It will execute that guy and
it will execute everything below until it meets
with the curly bracket. But it will also stop the execution if our
compiler meet something, what is called
break instruction? What is break instruction?
It looks like that. Now, as you can see, on that instruction here
got executed as we wanted. What will happen
when I assign to the variable, for example, zero? As you can see, that guy
and get guy go executed. That thing sometimes is useful. Sometimes you want
something like that because for example, the instructions are good
for all of the values, but in our situation,
it's not good and in most of the
situation it's not good, and then we should add something
like break every time. Now as you can see
everything works fine. When we type something what is not in that case, for example, four on default, only instruction after
default got executed, right? So everything works fine. Now I'd like to also
add that we can use only integer and
character variable types here for the switch. Why? Well, let's think about it. If we could use, for example, the double type I told you that double has got
something like precision. So for example, I
have two variables, double like that, and that one. And now I'll do
something like that, and here I will do
something like that. And probably that variable is still equal to that variable. But in reality, it's not true. But well, that's how it works. There is precision and we are losing precision
after some digits. That's why it would be hard to compare double digits, right? We can use here character, but why? Well, look. We have got something
like SK table. In reality, every character
is not a character. It is number, number
assigned to character. As you can see,
for example, here, A is assagt to 97. B is assigned to 98. D is ascaged to 100. So when I do something
like character X, and I assign value 100 here, and now I'll do something like, for example, that thing. That instruction
should be executed. Let's see. And at the end,
we have zero here, right? So that instruction will be
executed. Let's check it out. As you can see, that
instruction got executed well because D is really 100. Okay. But when I do, for example, here, A, 97. As you can see, on a default
option got executed. Well, instructions after the
default got executed, right? Okay, what about when I
do something like that? That guy should be
executed, right? And we can't use string here. Strings cannot be used
in switch statement because it's a bit
connected with pointers. I don't want to go into
details right now, but believe me, we
can use strings. So we can use only
integer and character because characters are really integers that are
assign to characters, and that's how it works. Okay, that's all.
Thank you very much.
13. Conditional Operator: Hello everybody.
Today we are going to talk about conditional operator. Imagine situation like that. We have two variables and A, and I will send the
variable value ten and B, 20, and now I want
to have string, which we call message. That message will
have value that will depend on values
of that variables. For example, I want
to say here, Hey, A is greater than B, so I have to change
that variable to tart that thing is true. Now I can, for example, send it to the output, right, and everything
is right now, fine. But of course, that
variables can come here, not from us, but
they can come here, for example, from our user
of our program, right? And then, for example, that might change to ten, and now that thing is not true. So we could try
something like that. If A is greater than B, then as to message A
is greater than B, otherwise, do something
like that. Mm hm. But we could also try to use
because it's good idea here, something what is called
conditional operator. It looks like that. Let's
do it in the comment. First, we are making condition and then
after question mark, we are going to write
something what will happen? What will be sag to that guy, for example, here, if
that condition is true. Instruction that will be
executed if condition is true. And after the sklon if
condition is not true. So when I do
something like that, for example, if A
is greater than B, then please assign to message
the thing that is here. A is greater than B, else, A is greater or lower equals P. As you can see
now when we build it, A is lower or it is equal to B. When I do something like that, as you can see, now everything
is working fine, right? And that variables, of course, can come from our users. But we can do also
something like that. For example, when seven
is greater than four, please, I want to
have here seven. If not, then please, I want to have here four. And I want to add
to that thing here. For example, ten plus ten. Now, seven is of course,
greater than four, then I will have here
seven from that fin and seven plus ten is 17. But of course, it is more useful when we
do something like that. For example, I want to
create a program that will add to the higher number ten. I'm here checking
which one is higher, which one is bigger and the one that is bigger will be
used in that operation. Now it's 60 50 plus ten when
I do something like that. 20 is now greater
than this number. I build it, you can
see 20 plus ten is 30.
14. Calculator - EXERCISE: Hello, everybody.
Today we are going to train what we have
already learned. We are going to create a
calculator, very simple one. It will be able to add
to subtract to multiply, and divide two numbers. Let's create two variables
that will store our numbers, double variable number one
and variable number two. Now let's ask for
variable number one, user of our program. Enter first number. Let's ask for the
second number also, and let's take it from
the input like that. Now we can run and
as you can see, we cant first and second numb. Let's ask our user
of our program, what does he want to do now? For example, what do you
want to do with the numbers? For example, you can add them, you can substract them. You can also multiply
them and divide. Let's make line up
to each guy here, so it will be easier
for us to read. Now, as you can see,
it looks like that. Five, for example, ten, and now what do you
want to do with the numbers he's asking
for one of that character. We need to store a
character somewhere. Let's create character,
let's call it decision, and let's switch that decision. Let's create
something like that, and in case our
decision is plus, let's send to the output that
variable number one plus variable number two is equal to variable number one
plus variable number two. So we are using the
arithmetic operator here and let's make break. Of course, we need to
also a default operation. So if somebody here
something wrong, so let's say to him, you type wrong character. Let's check if it's working. Of course, we have to
add here a column. For example, ten and five. And of course, I mean to
take the decisions for it. Now that everything
will be fine. Ten, five, and he's asking
what we want to do with that. I add two numbers and you can see everything is
working fine. Cool. So let's you know, other cases. Minus multiplying, dividing, and let's change here all
the things and divide. Of course, we can't
divide by zero. So when we do
something like that, then now zero, and I will
say I want to divide, as you can see, we can do it. So we should do
something like that here if number two that
we are sending here. So if variable number two
is not equal to zero. Then we can easily
divide the numbers. But otherwise, we will say
that you can't divide by zero. So now, as you can see
when we do something like, for example, ten and zero, and now I don't divide, you can divide by
zero, it's wrong. And we can also do something
like that, variable to. I value in art is
not equal to zero, that instruction
will be executed. You should notice that I told
you that condition is true, always true if the
number here, right? If the number here is
anything but zero, I can't be zero only. Now when somebody type here, for example, t two, ten, if 1010 is true, so we can divide that thing. But if variable two is, of course, zero, we can do that. But let's strange for
example, something like that. And you can see everything
is working fine. So that's co and that,
it's the same, right? That notation is the
same as that one. Okay. Now I will teach you
something like that. System, clear screen. That thing is going to
clear our console output. Let's check it out. Now when I, for
example, type here ten, then five and I will
substract that things, as you can see,
everything got cleared. But of course, everything
after the clear screen, so that things here.
Aren't cleared. They are going to be
outputted a bit later. Maybe we should also do
something like that. Hey, guy here, do you want
to continue that program? Yes or no? We should ask
something like that because maybe that guy don't want to run every time that
program again. Let's create character decision to here or we can use
that guy here also. But let's create another one. And let's take him here, see the decision two. And if our decision
is equal to, yes, or or it is equal to
yes, the capital, yes, right, because somebody can type Y in lower case or somebody
can do it in upper case. So we have to check both cases. If yes, we will use
something what is called GT and don't use it. I'm using it only because we don't know
something like loops. We'll discover them in other
lessons, so don't worry. I'm just going to show you defin now because
we have to use it. Otherwise, we wouldn't
be able to do it. So go to beginning, for example. Now when I do
something like that, I can create beginning,
for example, here. And now when somebody type
Y or Y in upper case, our program will
start again from that place because of that thing because we are
saying go to beginning. Okay, so let's check it out. So, of course, we are
having here a character, so we should do that
thing like that, compare now let's try it. Enter ten and five, and now, for example,
multiply the things. And do you want to
continue that program? I would say, Yes,
I want to do it. And now, as you can
see, we again asked, enter the first number, enter the second number and
other things like that. So ten, five, and divide now. And no, I don't want to
continue that program. And you can see execution
of the program is stopped when I type
no or anything else. We can also clear
the screen here. So it will be easier to read. Maybe also well at the endline
here. Let's check it out. Ten, five, and substract. Yes, I want to try
that thing again, five, ten, and multiply. Okay, that's all Okay, now let's check what is
really happening here? What is our compiler doing from the total
beginning, everything. It will be good training for us. Let's remind everything. Compiler is like, Hey, I have to include the
IOStream library here. Because of that, I'm going to be able to use many things like CO, see in, and some other things that we don't know right now. Let's use the names from SD so I don't need to every time
type something like that. Okay. Now, I know that I have to run our program
from the main function. Here I have to reserve the space in memory
for two variables, variable, one variable two. And here I know, oh, I have got the label here, so it might be used, doesn't need to but
it might be used. Here I have to clear
screen instantly. Well, there was
nothing on screen, so I don't have anything to
clear right now, but okay. Now I'm going to send
the output to enter the first number and
add at the end enter, and I'm going to
wait for the number. From the input from
our user, right? And he's waiting for that. Now our user is doing something, so he's typing something wrong the keyboard, for example, five. He's asking for another number. Our user is typing it, and now he's sending
you the output, all the things here, and we are waiting for
decision of our user, and we are also clearing
the screen again. And now we are switching
the value of our decision. And in case it is the plus, we are sending to the
output variable number one is equal to plus variable two is equal to
variable one plus variable two, and in case it's minus, we're doing that, in case it's multiplying, we're
doing that thing. In case it is dividing, we have to also check
if the variable if the second variable is not equal to zero because
we can't divide by zero, so we are checking
that thing here, and if somebody types
here something wrong, other characters, we are going to type Ty
wrong character. And he again asking, do you want to
continue that program, and our user have to decide. And if he decides
to to continue, our program is going to
again run from that place. And please, again,
don't use that finger. I know that you are like, now, wow, it's so good. Go to Wow. Please don't use it because when your programs will be longer, for example, 500 lines, and you will use more
than five of the guys. Is almost impossible to
read code like that. There are other better
ways to do that things, but we are just
right now training. We don't know everything
about the CIPA sps language. Don't worry, we'll
know better things. So that's all in this
lesson. Thank you very much.
15. Arrays: Hello, everybody. Today we're going to talk about a raise. Let's write something like that. And normally when we define a single variable like that, our compiler locates memo and the situation. It is for bites because we have intelligent vory boot and we can get value from the located memory by Jozic Identify their and in our situation I didn't fire. It's called a And what if I wanted more than one variable for example? 10 off them. I could do some things I debt for and ABC The e f g h i j and I could just constant right s o e I could do something. Maybe. Ah, easier. Something like that. Inver Juan Vertu. For free for four or five on. Just continue. Right. But as you have probably noticed, it takes a lot of time and all of the values have different identify IRS so I can use them so easily because I have to memorize all of the names. And what would happen if I wanted not 10 variables but 100 or even 1000 of the rebels? Well, it will take too much time to create something like that. And even if he did it. It will be knife murder, using something like that in the game. What will happen if I change amount of variables that I need? You could have the king guess it would be very time consuming. And that's why we have something. Will this cold in the area? This is harm a moral looks like for typical variables. And Paris Here we have. They're typical variables. As you can see, here we are defining in a big And as you can see, there are many other things. Start in memory between variable and and very will be their mind be. But it doesn't need to be like that, but there might be so we don't know exactly where that variable are. A or very will be with Putin. Another memo. We don't know that. We just know that did it. He will be four bites and it is called it would be We can access the variable by using the identify a right. Okay, but here we have an area in order to create an area we have to right after the identified over. So in our situation this x the square brackets and in the square brackets inside. We should put the size of our area. And it means right now that for here that we will create an area off 4/11 as you can see here. And Harry is a serious off 11 serious means that they are next to each other, right? They don't have other things start in member between them, there next to it, each other and off the same time. It means that we can create Iris. All know of the same type. So I know that all of the guys here have worked four bytes, for example, because the dive isn't teacher here right now. So we know that if we jump four bites far further, we're for sure meat. An alignment from that area. Right? Okay, Now let's go back to our coat and let's create on area. So let's create something like that, for example, in our way. And let's create Honore that will pay that we'll be able to store free a Lammens, right? So how to create an area type next name and in square might we should say how many of them Harmon over lemons? We will have so size number off limits, right something like that. And right now we know that we created free alignments that are next to each other. They are the same time, okay? And how to access, maybe how to get values from from the elements how to the same value. So that guys, well, we can use something like index. Um so in order to do it, we should do something like that. For example, lets the same values that right now I type are at array. Maybe that's changes just beat. All right. And in the square, Brockett, we are telling which element we want to take from here. We'll take a lemon. That index is zero. The element with index zero is the first element. OK, so I'm a sink even for example, 10 now live to the same thing toe other lemons, for example. That way something like that ST different values and I just the same to all possible elements something 10. 15 256. Because we have free a lemons. Right size of the dairy is free. And as you have probably Nolte's ah, we have to count a lemons from 0012 There is no there is no such being like All right free right now. I can't do something like that. I can't. Same thinks here. If I do it, of course. Fingered come pyre. But look, what is very wrong in that thing. Ah, let's get that. Maybe for let's make it for, like, here. So it would be easier for us to understand it. And now it's of course, Cool. Think, But we can do something. Like dead, for example, that zvehr wrong. Wrong thing. Why? Because, um when you create something like that, we have something like that here. And as you can see, we don't have anything after that Black, right? We don't know exactly what it's after. That place dir might the other things start in memory after and before. So right now we're trying to assign value to something. What is here? We don't know. What is it? We are trying to do it. So probably we've just destroyed something. We just a saint to something very important to tell you like that. So Ah, this is really, really bad thing. Okay? So you can do something like that because you could destroy our program. We called um saying toe other program something eso remember that we have to count from 001234 That think it doesn't exists? Well, we can do it because, uh, it exists more existed there. But we can't we shouldn't we? Ah, Matson dis having like that. Okay, now let's see how to get the values from the self. Example Airway on Let's do something like zero. It cools, for example, Dead way 012 and free 012 and three. They are all four lemons, right, That area size of the l A. All right, so number of a lemons is full. Let's build it. And as you can see now we can see the values from that guy's because we use the index here , that finger, skull and X. Now let's like to maybe see what address have that era of alignments how to get address off a lemons into area. We are using also M persons here, but three dead way at the rest. And this time we are doing these deadweight away. And of course, we have to add the index. So let's copy that. 12 free, 12 free. And now we can see the address off the guy soon. I don't think here is cool. Hexi Decimal. It means that we have 16 numbers in the notation in our notation it is. We have 10 numbers in notation. Bye bye. Not in addition that I talked about in the lesson about the bid wise operators we have to the numbers to use right two digits off here we have 16. Well, we can't have 16 numbers because we have on the 0123456789 And we only know dead guys, right? So if you want to have notation that have 16 numbers where you think a we just stand right bay, which is 11 c, which is 12. The weirdest tempting E, which is 14 and F, which is 15. And now we have total It's 60 numbers here. I told you how to change notations from for for for example, bar Nery to there decimal notation from the hex inserts email to the same politicians are the notation. It looks like it looks the same. So, for example, let's change want to a and so I should just while multiplied by something plots to multiply by something plus free plus a multiplied by something. And now we are in world notation. We are in 16 notation in the Hexi Decimal notation. Right, So we will do something like 16 Race to multiplied by 16 race A multiplied by 16 rights too . And now the position 01 into two. So zero when and of course do. And I watch we have 16 too. Uh, the race through the part of to which is 256 glass 32 plus plus a multiplied by one A is 10 . So what? Stand right. And we have, what, 298. If you don't understand it, please go back to the bid wise operator lesson. And now when I bet it you notice about that at the end that things are moved four bite zero at the end. Now full No eight. So a minus eight minus four is zero. Right? See? Which is 12 12 minus eight it's for So we are moving four bites by four bite. And this is why I told you here. So they are next to each other. You might be like, Hey, why I'm focusing on things like that that they are next to each other. Really? Believe me, it will be very, very useful thing. Yeah, because it took about pointers soon, and you would be like, Wow, Okay, I liked. Also add that the address off first a lemon in a right. So that guy here can be also achieved that way. So the name of our A is address of the guy here. Let's get out. Let's see if it's true. We don't like, as you can see the other that is equal together. So everything is fine. So if I do something like that eighth address off, airy zero equals that's true. That thing should be, of course, executed. Let's check it out. As you concede through, I am not like like Okay, so that's all about the areas. And now, as you can see, for example, I told you I want to have 500 off Elevens, anti germ, X 500 instantly. I have 500 of the lemons and they are next to each other, right? So the vehicle And now I can check, for example, the toe 300 change it to 1000. So kill. But place. Remember that this number here must be here before compilation. We can't have, for example, a dead way seeing a and, for example, that we can get the size off. All right, when we after we ran the program, it has to be here before running program. So it could be something like that constant, which means that these variable will not change for sure. And yes, that way I can do it. But I can't take it from the user and say hello. I want for example, 5 500 a lemon it we can do it. We have to use dynamic operations to do that. We'll talk about them later. But right now we can do it because we have to know how many off that guy's here. You see, we will have next to each other before compilations. So are completely later. We'd be able t o do something like that because he won't be ableto do something like that after running program. Ah, if we don't use the special operators to do it, So ah, with dead guys here. Ah, If the construction we can on Lee say, Hey, I want 100 of lemons and this. Okay. We can't change it after running the program. Okay? There's only listen. Thank you so much.
16. Multidimensional Arrays: Hello, everybody, that they were going to talk about multi dimensional area. Let's start this topic from two dimensional array, which is sometimes called bi dimensional areas. You can imagine two dimensional area as the area off area. We took imprisons lesson about one dimensional, all right, and now we know that the airway like that. It's some kind of country, right for vory both of the same time. Let's look at this came and I would like to remind, of course, that a rise in C plus plus remembered from CEO and look when we Kuwait, they become one dimensional. Alright, for example, in X, which sizes for we are seeing something like that. Let's create a container. Right? So this thing a countertenor one container that with store what for variables were ever able second for able, tired of a radical for the right, right? So Ah, we have a cult inner that can start former rebels off the same type there next to each other. And each of lemon in one dimensional area, of course, is called variable. So we're creating a container. The constant element and elements here are called variables. Okay, When the created a two dimensional array. You're doing it, Dad will end. Why? Which is, of course, right. Indeed. Your name, Why? And after eat, You're saying that we want to create free containers Airways, right? And each off that container will be able to start an airway again, off for a Lammens variables. So, as you can see, that is the first container that God created second container that could committed third container that God created right. And inside the containers, we have an airy one. Alright, Second there, right surgery. And each of the area can store one to free four for Ebel's. 12341234 Right. So I dro hear something like that, that arrow. And if you want to get to dead value here, you have to write something. Like why 11 when I write on Lee, Why one in brackets? It needs that I want to choose the container number two. So that got here, right? Why 11 means that I want to get from container number two. So I'm choosing the country and number two and are a so just in the area that 1234 worry both right. And I want to find second variable. I want to find valued at the start in a variable number two. So that guy here. Okay, so in two dimensional areas, we start inside Inari. Just another area. Okay, Okay, That's create two dimensional area here. So, for example, that let it be Inti Jer. And let's call it by, Harry. And let's make size of that. The same is here. So free containers that can start a raise that we have size for. Okay. And now let's check for example. World is inside something like that, For example here, of course, there are random numbers because we are just locating memory, right? The same as the Aziz were doing with the variables. So though he has toe Assane a default values here, we can do it very far that way. Now I've just saying to all the variables right here, zero As you can see now we know that everywhere there is zero if you wanted to have different values in elements, we would have to use something with this cold look, We will learn them in next lesson. So right now we way we could only do it dead way. Onda. We could Assane on things like that. But in next lesson we'll learn about Lopes and we'll be able to do it very, very far, almost instantly. Okay? And I like those. So tell you now, how are working addresses? Now? Let's shake others of dead guy here. Others of that guy here I want to free and now zero. Okay, you just can't eat right on its compliance. As you can see, address off by a ray Index zero is the same as address of by air A 00 and next addresses are moved by thought, right Zero for a C on the game zero on. Then it would be for As you can see, this is also a spacing memory which is continues. We can create multi dimensional areas, which means that we can create manage dimensions. I could do something like by a write off, but for example, to free to that's okay, I can gain more, more more dimensions. Most time you will use on the one dimensional raising two dimensional all right, rarely three dimensional rise. But it needs the same thing in we have got right now, too. Containers that will be able to a star free containers and that free continents will be able to start a container that will be able to have two values. Right? So this area of array of early Okay, that is all in his lesson. Thank you so much.
17. for : Hello, everybody. Today, we are going to talk about loops. Loop is something that will let us repeat a single instruction, blog of instruction as
many times as we want to. Okay, let's start from creating a multiline element and see
how does four loop work? Four parenthesis,
and we can place a few things in that
like initialization, condition, increment
decrement statement, and after it, we can place
the instruction to repeat. And of course, we can place more than one
instruction to repeat, but we have to use then
the curly brackets, so we can group them. So it's the same like when we use the conditional
statements, for example, if, let's
go back version of that. And please remember about
the semicolons here. Let's start from initialization. This is a place
where we can fast, define a temporary variable
and assign a value to it. So let's create a look for, and let's define a
variable c for example, I, and let's assign a value
to it, for example, zero. And then, of course, I have to remember about the
semicolon here. I can create here more
than one variable. I will use homer here and
for example, G equals five. But I don't need right
now two variables, so let's just delete this. I'm just telling you about
that so you know that. This is that initialization. Remember, this is
the first thing that will be executed
when our PC meets loop. This is the first thing and that thing won't
be repeated again. So RPC will define that
variable and that's all. After it, RPC will
check condition, that place here, condition is working like other
conditional statements. Condition is true when
it is not equal to zero. So for example, I
is lower than five. If that condition here, that's that same column, if that condition here is not met, instruction to repeat that
guy here, for example, that guy here won't
be executed at all. If condition is met, Instruction to
repeat, so that guy here will be executed one time. So right now is zero,
lower than five. That's true. That guy will
be executed at least once. After that, execution of the instruction
here or of course, block of instruction because you can use the block
of instructions, the field increment
decrement will be executed. This is the place where we can, for example, increment
that guy here. Or decrement. Do
something like that. We can lower it by one
or increase by one. Right now, we should
increase that guide, finally someday that
condition will be met. This field is the most used to increase
variables that are in initialization field
and variables from initialization field from here are used the most time
in condition field. It means that expression from condition will
finally change. Right now, that thing
should be run five times. Now let's the end line here. One, two, three, four, five, let's check how
does it work exactly. I'm right now the PC. Wow, here is the loop. I have to define the integer and so I have to allocate the memory for it and assign
a value to that place, and that value must be zero. Okay. After it, I'm checking
if that condition is true. Is zero lower than three? Yes. Okay, so I will send
this thing to the output. Let's change it to, for
example, I right now. I will send to the output zero. After it, I will
increase that I. So right now, I is one. And then again, I will
check the condition, is one, lower the free? Yes. So I will execute that thing here again and I
will send to the output one. Again, I will execute
that guy here and I is right now equal to two. Is still lower than three. Yes, I will send
to the output two. Cool. I will have
zero, one and two. Now again, I will
execute that guy here, increase it by one, and I is
right now equal to three. Is free lower than three? No, because three is
not lower than three, the condition is not met
and because of that, that instruction won't
be executed at all. So if I were PC, I will just move to
another instruction. For example, to that guy here, that is sing and
let's check it out. As you can see, we
have zero, one, two, and a. I wasn't lying too. And now you might be like, Hey, where can I use it? It's a good idea to
use something like that to assign values of fis. So do that. Let's create, for example, an array that is
that size is four. They want to assign values to that array to all
elements of the arrays, and how to do that? Let's create an loop, create defined integer number, and if I is lower than four, then I plus plus. Now we can, for example, assign I here or zero, maybe five or maybe ten. Well, anything. Let's
do something like that. This thing means what? That if I were the PC, I would define that variable, and then I would check if
zero is lower than four, yes, I would assign to array
index of index zero, so to the first element zero. And I will increase, check, and then I will ascend to the second element of array one, and repeat, repeat,
repeat repeat until that guy here is true. So when the I is four, that condition is not met because four is not
lower than four. And right now we can
also, for example, send this guy to the output
values of the array. Let's check if it's
working, right? That guy here will be commented. Se as you can see, we have zero, one,
two, and three. Everything is working fine. But look, we can do,
for example, like that, so I can assign 100
values almost instantly. Look. Wow. This was
really, really fast. Okay, we can, of course, also group that thing
with the curly bracket. That's the dead way right now. So I'm assigning value to
the arrow and after it, I am sending the
output instantly. What would happen if I
did something like that? As you can see, all the values in the arrays are random, right? We don't know exactly
what is in memory. Because we ascaent after
outputting, not before. Okay. So when I do something like that, everything
works fine. Now I like to tell you
about the infinite loop, which means that this
loop will never end. I don't need to put anything
in the fields here. Initialization, condition
increment decrementation, I don't need to. When I don't do that, our loop will be infinite. So, for example, Lala
let's see what's going on. Our program is going
to execute forever. I will use now the contro
plus C to stop it. Okay. And now, when
it's good to use. It's good to use when
we know something, it is called break statements, but we'll talk about the letter. I just wanted you to know that there are something
like infinite loops, and there is a problem with them because you can make sometimes
by mistake infinite loop, and you can do the
dead, for example, integer I equals five, and then if I is
lower than five, then I plus plus. But what if I did
something like that? So I'm not giving that guy here that field here,
I'm not using it. Of course, this is
infinite loop because that statement here
is always true again. Is zero lower than five. It will be lower
than five always. The same I would do
something like that. It's always true. You must be careful not to
make something like that, like condition that
is always true. That's all this lesson.
Thank you very much.
18. while and do while : Hello, everybody. Today we're going to talk about another two times off loops. About why? And do I Look, let's start this topic from the while. It looks like why poor antis is in parent disease. There is a place for the condition. And after it, Of course we have. We can set the instruction to repeat cell for Trump Example. See out le. Okay. And let's create a condition here. So, for example, when I is lower than 10 But of course, we have to create this indeed your number before that Loeb. So, for example, I was saying number zero here and look and we can't set here. Um, our variable inside the lob we can't in cream int that variable insight. That parent is is we can do that here. We have to do that always in the body off our look. Okay, so we have to create a block of instruction. So it's a bit different from the ah, while loop. But it works almost the same, right? Let's see. Right now, I will just run it. And as you can see, our condition is right now, always through because zero is lower, always lower than 10 right? There are is no change, but change the I, for example, I will do something like that. Then this being will be around 10 times. Right? So, um well, let's may be sent to the output I and do something like that. Right. Let's see. As you can see, we have 10 numbers here. Okay? So is working, like for whom? Blew up. And now you might be like So why do I need to know how that guy works? How the that Luke is working because one person will use the wild second person. We'll use the for loop and in to understand how they work. Ah, you. We also have to decide what live you like more for me. The wild. OK, and let's train a bit. Let's see. How does it work? For example, when we do something like like that, let's go back to the position. Ah, uh for example, I will increase the forever I hear what's going on. Can I do something like that off course. If you don't remember how Post Implementation works, please go back to the arithmetic a lesson I was explaining the very Cleary, as you can see We have 10 numbers here and they are begin from one and it's ending at them . We've had do something like that as you can see now, numbers and at night. And why is it happening? Because Aziz said, the the price increment operation works like that. For example, let's assume that we are already at the number nine, So prank imitation works like that that we have to first incriminate the eye. So it will be 10 and then we have to send it to the output. So it will be like if 10 is lower than 10. No, that's why 10 is not sent to the output here. But when I do something like that, is I lower? Ah is I want it's nine lower Dunton. Yes, and after checking if the diamonds lower than 10 that night is increased by one. So that's why here we have also 10. Okay, that's how is working. And look what we can achieve. Your very cool, For example, we could also count to zero. We could do something like debt and what we happen. Let's see. As you can see, we're counting from 9 to 0 when I do dead way. We're counting from 9 to 1. And why is this happening? That's focus for a second when condition is to when it is not equal to zero. So when I it's finally zero dead loop will stop executing that instruction. Right? So if we have 10 here right now So we are just decreasing. We have we are sending to the up 10. Then we are decreasing by 19 and at the end we have something like one sending one to the output were decreasing it. So we have zero. So are standing that zero here, right? And then what's happening? We have decreased that with the day increment operation right by one and you have zero already so we can repeat it again. When I do something like that when I is one, then we have to decrease it by one so zero and we are checking as an eighth contention is true. Zero is ah ISF Also the condition is false and we won't send zero to the up. That's how it works. Ah, let's train may be a bit on saying values to help to the Airways. So, for example, let's something like that and now if I was lower than 10 and I created Airway, that size is Stan. I could do also something that constant sighs size of our A on of course, in teacher Andi, I will say thank you. Really? For example 10. So the easier change anything right? Waken now change on here That value ended will be changing every place in our program. And now let's the same values. So all right, off I equals. For example, Let's just saying every value off really element Overy 10 for yourself. We can of course, we did way, but we want to do it it Hardaway right now. But we can, of course, for example, multiply it by I in addition. And now let's see what will happen. Ah, of course. Increase that I And let's send the output what you have to the dead way game. As you can see now, everything works fine. We could also increase the value here. Let's save. It's working the same as you can see. The output is the same. Ah, because ah, the proposed incrimination works like that that we have toe first sent to the output. So what started have zero. So area off zero and then we have to increase the so I will be increased in the next round of look. Right. Okay. This is the why. Look, we have also something with this called do I And this is very it is a bit different. Look from other lips because look Ah, we can do something. Like for example, do while and I will send your I Let's Kilman that guys here. So they want the Serb us. And right now I is what? Zero. So the condition is not too. But let's see if that instruction here will execute it. As you can see, it got executed once. So this loop is it is not checking the condition at begging. It is checking the condition after execution off every instruction between the Carol banging Brockett and current closing bark in the why and four loop. The condition is checked at the beginning. So when I do something like why I and then see out? Ah, Then as you can see, this guy wasn't executed it all So the conditions Check it The beginning There's a difference between do I look on and wire and four look Ok, okay, That's all One does lesson think
19. exercises, nested loops: Hello, everybody that they were going to train lobes and we'll talk about the nested lives. Okay, let's start from training them. Let's make a program that will tell us how many digits are in, for example, into journey number. So when I create a number, example like that and I were saying it very 1234 I would like to see that our program tell us that these guy Yes, for deeds, right. And when I increased the number on our program to tell us that it is five, OK, and how to do something like that. Look, when I do something like 1234 divided by 10 What will be the album out of debt operation? Let's see. As you can see, it's 130 free. So when we divide to into your numbers, we are losing the very after the boned. If I divided dubbed way, I would have the the right reason. Right. But right now will use that dividing two inches. Your numbers give us the number that is one digital s Okay, So it will be something like death. No, let's imagine situations like that and let's see what's going now. As you could see, the last guy is zero so one divided by 10 0 and now we can think like hey zero full. The condition and lips means false. So if I divide in condition dead number finally, it will be zero. So hour loop will add. And as you can see, that thing got how many times divided four times How many digits We have four digits. Great, so we can create next variable, for example, Number off digits and it is still the number of digits. Let's start from one. And I would do something like that while we can divide number by 10. Increase number off digits, right? And after it, we can sent to the art the number and are Hess digits. But look that think here, like I told you it in the arithmetic lesson he calls something like death. So it means that the number after that lope will be worth zeros. Right now, that's building the run. As you can see, the number zero has four did, so we have to create temporary, very able to restart a number here and now we'll divide the temporary of Arabia girls off that we will not lose the value that isn't that number in that the rebel and now the number 1234 plus four digits. As you can see, everything works fine. Now when I increase that number. So it has six digits. Now Ed will tell us right result. So everything works. Fine. Now let's see. How does it work? So, um, why Loop is working like that? When the condition is zero, it will stop execution. Right? So at the beginning, the temporary for Rabel s what is Let's spect That is the easier version 1034 then we are dividing it by 10. So well, eso it will be 132 is 132 not equal to zero. Of course, it's not equal to zero. So we are going to increase number of digits arrived now number of digits. There's equal to to and we will again check the condition, but first will divide and is 12 equal to zero? No. So let's increased number of digits. 8th 1 equal to zero. No! So let's increased number of digits And now we have zero. So a zero equal to zero, of course, is equals because off that condition is false and will not increase number of digits. Panama. So that's how it works. Okay, dentals some training. Now let's talk about the nested loops where we can use in world honest looks where nest, it means that we can have one loving another. Look, Look, we might want to, for example, right program that will be sending to the output the multiplication table. So how old us multiplication table Looks like we have not plan. 23456789 10. And then we shield multiply two by all the guys. Here's one, then toe 14 16 18 12. Right. And now we can a bit former thing here. So it would be in more read able and as you can see Ah, it is the multiplication table to intent. But most time I would like to have something guy Faneuil. Ethan. So I have to work. No multiply. Multiply free by a cane deadline. Here. Remember again deadline here. Okay, So free. Um 69 Twas 15 and written. And now for some five and just repeated. Right? Right So all the time we're doing What? Multiplying that guy here by the line here. How toe create deadline Here we can created by using, for example, a look for four and let's define in teacher number I, for example, lots started. That's saying very one to it. And if one is lower or equal to 10 keep doing that. Instructions that are after did look and what increased after each Ron's that very now we can send to the art boot I ending at the space at the end and let's see our results. As you can see, we have he want to free for 567 89 10 cell. You've just achieved that first language. Let's get the guys into the multi that lying common because we don't need to see them now. So we have deadline. And right now you like to multiply, for example, to buy that free by that for by that guy again. So you want toe multiply, for example like that And then we have what? The second line. If I multiplied by that guy, I will have the tear line. Right. Okay, so we need something that will change here like that. Okay, so Ah, how to achieve that? We can use the nasty envelopes, so I will have a little been site a loop. Now I create another looping side, Another va Rabel on other condition and I will multiply. I buy a G and now I at here. Um the end line like that. Let's see how yours. As you can see, we have got right now all the lines, everything works fine.
20. break and continue: Hello, everybody. Today we're going to talk about bragging counter new instructions in lips. Well, as you can see, we have got here. I called from the previous lesson and I reminded that call descending to the our boot. The multiplication table. Now I'd like to tell you what is re spend responsible for their outer the external loop and what is responsible the Inderal. Let's check it out. Ah, I would increase, for example, that guy to 50. And we noticed that we have got now five more rose. It means that the external loop is responsible for the amount off rose when I decreased that guy here do five. Well, not is that we have five last column. So it means that this guy is responsible for the amount of cones. Will also notice that when we are increasing, number of rows were also increasing world the land of column. Right? Look, when we decrease that guy to, for example, seven note is that the column is short, right? So this guy is responsible also for the Land column and this guy is responsible for the land off road. Okay, so this how it works. And now I'd like to tell you about the breaking counting you statement That's making situation like death. I want to show Ali Rose all 10 rows but row five So I don't want dead guy here, Right When I bid it, I want to have all those but numbers 5 10 15 toe under 25. I don't want to see that guy. What to do? In order to do it, we have to use the instruction counting eso if dead row is if that loop with debt. The Rabel here is responsible for the roads and we don't want to see the drove. We have to check if I is equal to five and then use that Continue Continue instruction Right now you'll see that we I don't see any more dead guy here. The road five So we have achieved what we wanted to achieve. But how does it work? What is that guy doing here? Well, continue is working like that Everything after county New instruction won't be executed. So everything after So dead guys here won't be executed. But loop want I will note. And because of it it means that we are skipping the coat after the continue. And after it were increasing, I buy one. So we're increasing I by one and we are checking again. A. I is not its lower or equal to 10 because it is too. We are again going to execute instructions. We are checking if I is equal to five. No, because six is not equal to five. And because of that, that instruction won't be run again to continue because I will be increased right and everything after it is going to run like it was before. So it's good. Okay, so this is the counting construction. It works like that. Now I like totally about that breaking strict action What we happen when I do something like death break else you can see we can see right now anything after the fifth grow. So Break is working like that that everything after break won't be executed and we are living death actual. It is very important that work here actual actual lip. So our actual rube is right now Dead guy here, the external one. And because we're living it, it means that we're on instructions here. They would be wrong there. But what would happen if I did something like debt. If J is equal to, for example, five and I was do break you. As you can see, we lost all columns here because Jay is responsible for the columns but older oath to then were executed. Fine. So when that Ah, when our PC meets with the break, it's leaving that lope, and it's going to execute that. And there, here and after it it was Go to that incrimination here. Huge condition and again, again, again. So it is living the actual look. Okay. And what if I do? The counting you here will not is that we don't have only the fifth column. This how it works. And I would like to ah, trained a bit. Um let's imagine station like that I want to have right now. One. Yup. That will do the same as the tulips. Wow, how to do that? Um, let's common. The guys here can do that because oh, have Komen's here. That's that. Then the wing. And now I was sent to the output the first line like before. So all right, applause. And now see out, weaved and see out I and let's create J here also because we have only one loop. Why? And as you can see em well, it's because of the night national that is here. We have got on the one Arrgh killed. And if I wanted to have modern one row, I should increase their jay. Right? So let's is it I'm going to increase J No. And what's going to happen? As you can see, we achieved wrong numbers here, right? Ah, because right now we're increasing the Jae Ahn. Do you are increasing the I in the same time? Um, because of that Ah, we have got multiplication. Did toe by two free by free four by 45.56 by six then by seven by a nine by nine and 10 by 10. Okay, so we should increase that guy only when when our I is equal to 10. We can do that. But before that No, no, it's not good. So right now we have only aguado and everything works like we wouldn't have it at all here , right? Why? Because condition here when I stand is not mad. And of course Ah, that implementation won't happen at all. Okay, so we should also a saying zero to Isil. It will keep running right on and right now let's see how it's going. A Z can see it will run almost forever, so because they are conditioned, will have. Ah, the right now falls because we always saying zero toe I when the condition is almost to be falls. So we have to also check Ah, we have to break. We have to live from that lope When j it's equal to town plus one. I would tell you why the plus one is here soon. Break. We should also add enter after each off role. And this is good scene We have got right now multiplication table by using only one look. Of course, that is a bit more confusing for me than that. I think here the nested loops. So it is a rather training off break and let's see how it's working. So right now we are multiplication ing I So at the beginning, one by J, which is one and after it. We are just skipping dead guys here because the conditions are not to therefore and there are increasing I tricking condition and wearing multiplication to buy one free by 1456789 10. And finally I wanted to stand They're checking that condition is finally to and we're increasing J where a singing toe I zero creating there ound line So we're creating And, uh and we're tracking the condition which is not to on again again. We are multiplication ing now this time ah, one by g which is no do so good No. 22 by two free by 24 by two And again, when I stand we can increase that guy in. But when finally g is thin, we're skipping some rolls. Of course, when g e stan way, we should also run that coat that the multiplication here because you want toe see this 10th role If I did the dead way, you'll not his death We are not seeing now the 10th row because ah, we must remember that when our PC meets with the break instruction, we are living right because we have to adhere the plus one because we want the 10th wrote to be also executed, right be also sent to the up. Okay, that's all learned is lesson. Thank you very much.
21. pre-function Scope of Variables : Hello, everybody. Today we're going to talk about scope, wrench of varietals. Look, we can create variable Daddy's between opening and closing brackets and dead variables are cold. Local variables. Variables that are outside the main function are cold global variety. They're called global the rebels, because they can be activist everywhere. We can use them everywhere. Variables that are created here between the Carol of rockets can be used only between the current Brooke. Well, you might be. Hey, but we have only here Carol Bucket. Don't worry, It will soon explain. So I recreate now a global Vrabel, for example, Like death and global for Rabel. And what ISS different from that guy from dead guy? Well, when we try to, for example, sent to the output value of that variable so value off global vory able IHS and local the right and you a lot is that in the first situation global variables zero and luck of a Rabel is random number. So globe over Ables are getting the default values at the beginning here. We don't know world Will Mitt. Okay, Um uh I would like to add that we off course can use variables before they are declared so when invited something like that. End number five And I would like to Same here That number from here. We can do that because in that place Ah, come, partner is like, Hey, I have never met that guy before. He doesn't know what is after what is in the next lying Okay, eso like I told you in the first lesson, we should become partners. And ah, we should know about things like that. So when I mean that variable is global, I meant that it is. It can be accessed everywhere but after the declaration. Okay, so let's go back to that Think. And now let's talk a bit more about the local varietals. Look, let's create something like that indigent, a thick walls. And now if a Colston which is to I want to do between the Caroline brackets here, something like and result equals a multiplied by 10. And now I want to send to the output the reason so understanding results up. Let's build this program. As you can see, our compartment is saying us that who have arrow here. The result is undeclared. First used this function as I told you the local variables. Can the access only between the closest Carrie Brock? It's so for Dead guy here for Did very well for did local variable. It is between that carry bark. It's after it. After the closing Carolyn rocket, their results is being destroyed. We can't access the animal. The memory that these variable located is now free. Okay, so I can do it dead way. But I can do it dad way. Remember about Of course, we can also do something like debt. We don't need to use carb rockets. That variable is still still cannot be active because, ah, it got destroyed in the same line. Right? Um okay, so let's get the think the comment and you can get that thing to become and also into the comment. And now I would tell you about the common mistake made by begging ours. It's in program. Let's great. For example. Indeed your number into Q two results. And now I want to take free numbers from the input from the user. So let's do it deadly. So that would be faster. Of course, we don't need to repeat now, and they're number Wonder number to enter number few, but we'll do it farces with this I'm like and ah, I was I Plus Swan song. It was start counting from zero last ones from one right I plus one number and line and they get in a number and then add these number two day value off result. And now let's send to the upper out good results. Of course, our real result is going to be. Output is here because it is local variable for that carol bracket. So it's not being good destroying. But let's type have few numbers like free to free. And will the result be eight? Think about I'm telling you that it's not true. If you know why I it's a very good Well, of course. That way our that way. Sorry. And now B Then run. And as you can see here we have enter number and the first number and I will type free do in the game free and with the result is 68. As far as I know, free pass to prosper is not 60 act. Something is wrong. I would try it again That Did I do something wrong? No, but here is very very bad. Our as you can see that line, it's equal toe result equals result. Last number. So what is result at the beginning? We don't know office it because it is local Va Rabel. And this is the random number we have to as saying zero here. So now Well, in the type something like that, the result will be right. Okay, we have to as saying zero to the result. Of course. Ah, we had toe a ST zero to the result because we're making the adding operation for the multiplication. We would need to as saying one here. We have to give you the natural value for operations. Okay, Now let's see. Let's talk about that guy here. I would like to say how many numbers we had it. So we add it. I numbers. So in our situation, we I should say free here. Right on what was going on? We can do it. Why? Because debt place if we define here something these like doing something like that. Okay. Ah, inside the Carol bracket. So is the lock Alvare able for that carry the brackets so dead were able is destroyed after execution off all instructions when the condition is false. When the tradition is false than variable, I is being destroyed. Okay, so how to get the help and the numbers we had? We should just remove the guy here and do it that way. No one yet. We added for numbers, Everything works fine. Ah, As I told you, we don't need to give anything here, right? We don't put the condition. We don't need to put here on in cream and equipment statement. Don't war. We don't need to. So, in situation when we need debt Va Rabel From here in outside this scope. So outside that the council Brockett, we need to remember that we should food that guy here before the loop. Okay, that's all in the lesson. Thank you very much.
22. Functions: Hello, everybody. Today we're going to talk about functions. Functions, as the name suggests, is something that is created toe to function. Functions are sometimes killed methods because you can imagine them as methods that help us solve problems. If I want to achieve a goal, I need a good solution. And this solution can be achieved by using, for example, met. Okay, so function is something that is created to solve a problem in the program. Function is constructed off many instructions. Maine is a function right. This created of many interactions that are between the curly brackets, opening and closing one. So is like a mini program inside. Our program can create many functions like that one here, but this is the main function that is invoking other functions, for example. And now let's imagine a situation we want to write a killed that will check if the data coming from the input it's number bring vacation like that might happen in our program a few times. Both functions. In order to check all the numbers coming from the input, you'll need to repeat the same coat. Mana ties. So let's do something like that. Mm. Let's great of a Rabel strength temporary. And let's ask for the name number. Enter the number blind and like that. No, my You might be like, Hey, you're asking for the number. Why did you use the string here? What the hell is going on? Look, if we ask for integer No, let's do it Deadly. What's going to help when I type something wrong? So I'm typing key. As you can see, he didn't asking for the second number. Why? Because we have a narrow. So when I type something ride, everything goes fine. But when I type something grow Mm, you haven't? No, that's all. So that's why we're going to take this shrink you Because string our characters and look, we have the asking table. We can check what characters are in string. Forte for 10 9 for 50 51 52 2 57 right. They are represented by the characters. So how to check characters? I can do that Dead way temporary off zero And I'm type, for example because it can see I have the first character I want. For example, second character. I will do it that way. So, as you can see I got the second character. It's one they can check that is that guy by using the conditional statement or cool. Okay, so let's create and loop that. We'll check all day characters inside the streak so full in teacher I that equals zero. If I is lower, then temporary dot length And what set de think is called invoking off function function is called left and that think here will be replaced by the length off string. So here we have, for example, for maybe five, maybe 10. Okay, so this is the function that was written by some. We can use it in order to use it. We're saying name off function. And then the parent is, um that those here is a bit complicated right now, but it means that we are using the function that is connected with the string. OK, let's remember about either right now and we'll increments that I hear. Okay, now let's check all the car or characters. How to do that? If temporary, No. Zero, but all characters. We have to check every character. It's lower. Greater then for 28 and lower. Then in the same time, 57 that guy here saying that Mars being that must happen in the same time, right? Because it is the conjunction I talked to you about conjuction that logical operator blossom. If you don't understand it, please scale back there. So right now we are checking that set off off numbers here from 48 to 57. So Ah, if that think happened, it means that we have a number as a character Know something like that, Dad or something else. So we should indicates some worm so creative variable that would indicate the true or false boule the type of the variable b bull right? Because it can take on the to values through or false. And we could just saying he is number two false, true. And then we can check if it's number, then so it through then we can send a doubtful number entered properly. Otherwise it means it's not true. Number wasn't entered. Probably. Okay, but hey, how we don't have the first statement. So maybe we'll do dead would change that guy to fall. But to make it right, we can use something all this cult, the negation. So we're changing 0 to 1120 And now let's see if it's working right. I'm typing, for example right? Number number under properly. Great. Now I am taking something like that. As you can see, number wasn't under properly but our program is a bit slow Right now we can a bit make it a bit faster. Look, why Shourd Wing check all characters temporary off I Let's send oh characters out that we type, right? I'm talking here something wrong. And as you can see even if we meet the wrong character we're still checking characters. Why? We already know that this is wrong. That is no number when we meet one wrong character, right? So after it we could just do something that break. And now look, one corrected from that You can see right now we didn't get to around this loop Dead monetize. Cool. We're just improved on your program is a bit faster. Okay, that was just a pit of training. But hey, we are talking about functions today, so let's imagine situation. We need that thing to work three times, so I have to off course Copy that on And look, that thing won't work because we can't define two times the same variety of the same name. So I have to delete that guy here we are changing value. He ran away so we don't need toe change the emperor to anything This guy must be Change must be changed. The default Very old. So we are doing it that way here on Broadway. Okay. Okay. And now, Now, now let's build. And he's asking First number second and the and tear it number. Everything works. Fine. Cool. But hey, now what's changed? Something. For example. Want to drink? If the first number isn't zero. So I have to check here. For example, if the first character so temporary als zero IHS a call to zero Oh, I can, of course, use their for 2 80 s So I can also use here Zero. Of course. If you don't want to live into the ask it a book Here we can use characters. Everything we work finals you can use did well that would. So if the Emperor of zero is zero I filled, Say that Hey, no, no, no, no. This is no number. Okay, so I have to also add it. Be he for all the guys here. So here, here. And well, if we have falsely, why should we check the characters after it? We are seeing the time, right? So let's do a dead way. Conjuction It's number. So both expressions must be doing the same time because we used the conjuction here and now we have to again Waas Oh my God! We have to change and gain again But everything will work Finally do it that way. Okay, everything looks fine about thing Many situation where you used it called about 500 times And now we have to change something. Hey, exactly be very time consuming and for should know enter thing Think that And that's why I also we have something with this cult function They can be within one's and reused as many times since we want Wah girl That thing must be cool but we still don't know how to create it. Okay, lets think you because I can look at it that on let's get hate uneasily faction first. So we trained a bit how to create a bunch First we have to say, um what will be rattled by our function if I function is not returning anything. We are going to say something like vote because void its emptiness. Write something. It is nothing. So we're not returning anything right now? Um bye bye. Saying returning I'm meaning that we want to return the value to the place from where the function is invoked. So that lan thing is involved, right? And ah, we are. And And he we had what we had the length off string so that land function was returning. Seemed so for sure. The declaration off that function is starting from individual, right? Oh ah, and the anything would ease in t German. I don't know. Maybe on site into the You know exactly which one is there. But it must be in teacher number because it is land, right? Okay. And after eight for sure. Very something like length. So it's the name off function. So let's create a function which we would call Well, welcome. Afterward, we will create a parenthesis between the parentheses. We can play something. What is called parameters. Ah, Ram at Okay. We can place here something that but we'll talk about it. Letter where I am right now, making easy function. And then cynical. This thing is gold declaration off function. And this thing is informing our compiler that some or in thesis program, our compiler will meet that function That is called welcome. Great. And he knows also that somewhere in this fight, he would meet the body. Oh, that guy and bother. It means description off our function, and it is just definition of our function to do it. You just have to copy that guy here and open curly brackets. And this thing is called a building funds. And here we can say something. Hello? Welcoming our in my program plays on plate that and now we can involved it function in other functions of, for example, for you. Welcome. And to invoke function, we have toe use. The parent is is. And now building rounded Guy is going to see Hello Will come in my program in terms of the number. I'm not answering Damper because I'm not really sick. Uh, okay. So, ah, how it's working when the PC meets that guy here. It's like, Hey, I have the name. Welcome here. I have to look forward and welcome function now a program because it's involved that varieties are saying the debt function is involved. Andi, I am jumping to death cult here, and I'm sending to doubt with think here. Great. And but that function is not returning anything, right? Because it's for is not retaining that guy here. It's just Santa Cruz up something that is doing something. This finger is really not called the findings, right? It's rather something that called, like procedure Ryan's. Ah. So how to maybe create something useful so something Will we have had bouts with that cold feel? Right? Okay, let's great function that will be killed. His number is number. So what will our function return? It will return bull. It will just indicate if something is number or not. I am returning door right now, but we have to know what will be checked in that function. So we are going to take parameters here. Parameters are just the rebels that are function can take. So I write something like and Sprink temporary, for example, Street gonna think. And now I'm need to create the body of father function, and I just copy that guy here, so I'm not going to repeats everything now. We don't need that guy here at all. We can just something like that. Return fell false, and I can also hear return falls. And then I returned to here. Andi, I don't where I will explain it. Some on Ah, we have to invoke that function and send that very bull right to here because he's the local va Rabel. It is only seen between the curry brackets. So we have to send that the right bowl toe that place now it will be checking. Very fine. Let's check his work and explained very soon, Huh? Working as you can see em on the heft, of course, to delete that think here and now we can build it in around and everything works. Fine. Number wasn't prepare, Lee. OK, a number on the proper. Okay, So what is that return here? What held is that Look how it's working. We are entering. The number leads assuming to like something like that and our PC's like here you have to invoke the function that is called is number. They have to send to eat the value from here. So 124 and key at the end. So I'm doing right now that think you and I'm checking in the first character easier. Far number Waas like that he will return the force, which means that he's not going to do anything after it. When the function returns, the value is the end off execution of the function. Okay, so it's going back to that place here, and that place here is being changed the false. So it falls. And because it's false, it's going. That guy here will be executed, all right, in our situation with something like that. So So we'll go here on We'll check if the first characters between that numbers right for the 7 57 Because first character is not so well, check gain the condition rinds on. We will check again again. And when we finally meet the key, it will return the father. And But that doesn't That's why we don't need toe in in situation like that. The breaking because after returning. But that's all. We are not going to execute the for loop anymore. Okay? So we don't need to use the break okay? In situation like that. So whenever finger is fine, we're going to return through Onley when Ah, when That instructions before didn't return the father. Okay, that's that's how it's working. So money to returns the true. Here we are just going to send it out. Number under properly. Great. Okay, now we improve it. But a breed Morse. So I will create another function that will be called like debt. Enter the name and it will be not returning can think. And I will just copied it. Him and no, As you can see, I am you sinking debt function that function from Hugh, right? We can do it. No, I just do something like that. And number two prepare a number of the preparing number Wasn't enter properly. Great. Now I want to change something. I've well, zero at the beginning. He's good idea. So number under properly. Now he's working you. Ah, well, I'm going back to that. Ah, These, as you can see, is working like I wanted to work. Great. I change it in one sec. Wow. That's why functions are very cool. Okay, now I like to add that you don't need to do say the name in declaration function for perimeters here. We have to, but here we don't need to say the night. We have to say the type. So there were more right, more parliamentary as I would do something like that. But we don't need, though at the name, because it is not needed. These declarations did. That thing is just here. So our compiler will know that very somewhere. Function like that, Basil. Okay, now let's talk about something. What is called in line functions in line. It means that we have declared declaration little and defi definition of function in the same line. How to do that example like that double Ah, adding two numbers Double a double bay. And I am returning a plus B in the same line. Of course we can do it not in the same line, because we can just had enters here. But the name is from that. We can do that in the same night. And for operations like that, it's OK. But please don't consented to the output. For example, a that ah steak that guys comments on Let's beat it. Um, also, that's chemicals for here. And as you can see, we have nine so five plus for his night. And as I said that in line function should be only for small operation. The police don't Dios it for something like that. Okay, Now I like to tell you about something very important. What if I wanted to change the value of variable from, for example, that ah, place from main method in another function. So I would create something void change value to and I would take the integer, for example. And let's what could do it in one line. It's fast. Think to do so. Something like that makes changed. The function must change the value off anything sent it to 10. So now I am going to the something like that that I'm sending a And now I am sending to the output a here. So we would be five or will we be 10? Ah, maybe Let's take it to the common. As you can see, it's five note town. Why whites think well, when we are sending anything to the function like that, we're complying the value. What does it mean? We're doing something like that in X A. And now we are making operation off on copy off dead variable. We're not changing value under the address off a but under the address off eggs and in addition to these dead variable here right is going to be destroyed after that Carol bracket. So we change very here. I had woken up. We'll see that it's 10 but there's all it will send here and only for the x variety. Okay, Even if I change names, for example, that let's make it the same names like a still we want to change. Of course, the value from the places and you might be Hey, but there might be situation like that when I needed the Yes, there might be situation. I would like that. And when you need that, we will use something with a skull pointers referenced types. Don't worry. We'll talk about them later. Right now, we can't do that. Okay, Now, I would like to also add something about the main functions you can say, Hey, this function by I don't see avoidable, hear anything by the function. Normally, we should do something like that at here. Something like ain't and se something like the return zero, which means that our program ended What this currency processor turn zero hour idea is doing it by default. As you can see that it's returning the zero, but is recall because sometimes your program might not end well. And then you might, for example, do something like that. Return five here, written one here and even notice that that guy's here won't be executed at all. As you can see, process returned one and the guys didn't get executed. Adult. I could do something like that. If, for example, let's create character. Let's say that character. Let's ask for the care of actor ive you want. Do you want to end the program? Example. Though you want to end the program Yes or no? And now did you will be put into that Got here, right? And if character East Oh, character is equal to that guy, Then return and we can end our program a bit far. Suffix um, I'm asked. Do we want to end the program? No. So the five was here sent to the airport. But if I do something like that, Yes, As you can see, our program ended a bit faster. Okay, so you might be like also when the other status ah can be used. It issues when we are using our program from the outside. When I say outside, I mean using its from plays like that so I can use my program. From here on, we'll talk about it later, and then our program can be used by other programs. And then that started might be useful right now. They're not eso useful, right? You can also send to our program some part of some arguments. Eso we can declare parameters here like arguments, car, character like that. We can do that. But right now we don't need it. Okay, We talk about it later. Right now we know the basic of functions, and we're starting the two adventuring program. Okay, that's all. Thank you very much.
23. Overloading functions: and over body. Today we're going to talk about overloading functions and well trained A bit functions. First, let's imagine situation like that. I want to ride the program that will be able to race toe the power off some kind of the number. Let's write something like that too. Race to the power off free is equal to Well, the thing is gold base. The thing is called exponent and when we want to raise to power free, we have to multiplication that guy here the base three times by itself. So I have to modification still toe by toe. I have to do it three times and I have to multiplication that guy here And why Don't say these because we want to write function that we'll be able to Rice to the power off something. Think OK, and no. So what will return our foot function? I think it can return the anti jer number and we call it power, and it will take to integer numbers, the base and of course, the expert. Okay, we have the declaration of function now will create the definition of function. So, um, let's called it guy back be from base And that guy a a from expert. OK, And how did it? Well, we have to Multiplication did monetize that guy here. Right? So let's do it in love, Of course, Goes So it's very good idea. Two years Look here and we're going to use the wild of this time. So while, for example, a s greater than one, we are going to multiplication. What be equals be multiplied by what you want to multiply it by the base. Right now we have based here, but, um well, right now, saying something to debate. So we are over writing. That guy writes that won't be the base. And because when we moved, applies, do something like that Ah, we would have, For example, he Ford and we were like four by four. And then it would be 16 here and 16 multiplied by 16. So we have to have the base somewhere. Sorts of what's great. A temporary of array belonged a saint be here and does something like that. All right, Okay. And now that condition, we always be true. Have toe dri crimen that guy. And as you can see, exponents is telling us how many times we have toe, do something right, so it's very good idea to use it. That's a condition. Okay, so let's seem well. We had to return the very radiant on. Let's use the guy, see out power and, for example, to free. So the results should be What a right. As you can see, the result is eight. So everything is working fine. Well, we can ride it a bit more confusing. Hot. Ah, it will be having less instructions. We can do it that way because this is there. Post discrimination, right? And we can off course use here something like that operator, which means the same like that, of course. So it's good idea to do something like that. Let's see, it's working. Fine, I think works fine. Maybe let's trying a bit before we talk about our lighting functions. Other things I get. Um let's imagine what would happen if I will proceed right now. So my MPC hello? I have to in club the ill streaming to use the name space. Hey, I have the declaration few here, so it means that I would have somewhere in our program the label power, and it will take to into your numbers and it will returned in Teacher. Okay, so I know that there will be something like that. Then I am going into the main function and hey, I have to sent it out by output. The result off the function that got involved here and it got involved with two arguments two and three. They were sent here s o it was they were complied to the variable and being variable in a and he were making the temporary variable. Well, let's maybe do it in the comments with the easier to fall. Temporary is right now. What? Maybe this temple Ferrari is right now. Two wife and what's going on? We are checking day condition if a which is right now free is greater than one. Yes, and after checking the condition, I am decreasing this guy back. Okay, Now we have to as saying to B B, which is right now to to multiplied by temporary wedges to so right now this is for great And what I have to check condition again. It's to greater than one. Yes. So I'm going toe invoked that in section after it. But he has to first decrease eso right now. It would be one, and I am multiple applying there Be so right now. Bees for for multiplied by temporary, which is still so right now be with the A Were checking the condition if a, which is one is one greater than one No. So we're not going to involve the instruction more, and we're going to return B two death play. So right now he there is something like that. Okay, we're returning the zero. The finger looks fine. Right. Okay, so we just trained a bit and hey, I would like to send for example, something like that. And but we can't right now. Rice, the power. The double number, right? The the real number with adult. Right? So we need another function that could take the double. You know, we can't have to functions with the same name when they looks like that. When they have the same parameters the same times. Okay, we But we can have to functions that are the same name with different types in perimeter. So right now we can easily do something like that. And now, as you can see Ah, sorry. Here I have to, of course, be end I now, as you can see, everything works fine. We can easily around the program and this thing it's called overloading functions because we're overloading the name right. We have to same names and our PC knows which guy to execute because he's like, Hey, I have the double here. So I have to take debt function. Know that function. He knows which one he must invoke. Okay, well, let's make a bit different. That function, so we will not is that he's invoking the right function. For example, let's do in that function something like that we will send to the our bolt every time. Well, do something for, for example, that to race the part off recent like to race the power of one is to to race the power off to its four to race the power of free. It's eight. So we're going to send it out all these steps right on and how to do that. That's great. For example, temporize Vrabel, I, which will take which I was saying to zero and ah, right now I will do something like that when I is lower than exponent and I will increase I right now. So I'm going to have the additional number because we can use the exponents right now because if you want toe start from the low, lowest excellence and was the something like that see, out on bond. So we are raising the base and are temporary basis Q. Right. So we're going to write something like a temporary raised the power off and our actual power is here. So that is a called Teoh. And the result is here and now. Ah, If I do something like, for example, dead, you'll notice that eso something is wrong because who writes the power of one is not for a brochure. We should first the dead way. And now you'll notice that that the results are fine, but that the result is not good, because to race to the power off signals not 108. So because off that we are going to also do something like that if I is not tickle toe a, we can multiplication, but otherwise So when is the last run just not even do it? And now the result is also fine here. Okay, so but the most important thing is that you should not Is that when you are doing something like that, they're invoking that guy, right? Because our casinos Hey, there is indeed you're losing teachers, so we're going to use dead function. But when I use something like that, I have double first. So hey, are we will use that function. So I didn't send this types up. And you might be now like, Hey, buddy, you could do it, dad way because double is wider than integer and everything will work fine. Go to something like that. Andi. Hey, look, we have the results to you. Why did you tell me about that? Because we were operating on integer. And why send in teacher to double? Why take more more memory? And maybe sometimes there were some operations on integer that we will be faster. So that's why that's why overloading is good ideas going back to that place now. Everything works fine, right? Do something like that. RPC knows which guy we want. The truth. Okay, does all Thank you very much.
24. Loops and functions - exercises : Hello, everybody. Today we're going to train loops and functions. We're going to ride program that will be able to calculate the area of a circle of square off re tingling triangle. So first, let's create, for example, manner. So we're going to send the output some messages like enter the option and you can choose from the calculation off satirical. And that's right. So this great a function that will initiated things. So vote any inish manner right now. I would copy that because we need a definition function also, and he will just send the outputs of like, enter option Oh, on now I could stuff like Syria coal, for example, to free four on and square the Rick Tango and the triangle right. And now we can just involved it function here. And as you can see now, we build and rounded program and we are being asked for the guy. So let's take him. So I'm going to create a, for example, a variable like and choice right, And we will take that guy here so seeing choice on and we'll use the choice to show something like that guy, that guy, that guy, or that guy. The calculation of the guys, right? We'll ask for another numbers. So let's grew eight a function that we re present a decision that we our user choose. Right? So, for example, I would create next function that we return void and are we call it manner, menu decision. And I'll copy that guy. And here we'll have the definition of the function, right. And I think that we should take here the choice so choices in teacher. So I need to does something like that here on Dhere and you can call it also choice here, and we'll switch the choice. So we're going to do something like that. Switch choice. And here we can do the cases, right? Case one case do. And of course, we have to use the brake statement here also. So, like that on, we have two more cases. Case free in case for and the default. So we're going toe send. Ah, you didn't shoes and off the option from above, right? For example, like that. And OK, now we should create a program. Um that, for example, calculate their reality circle. So, for example, like that, see out, Enter the read use, right, Because we need the red use of the circle too calculated. Now, let's create you double our favorable and let's ah create function that will count the area off circle. So let's call it, for example, area Sirico on and we'll take the radios here. So one double of arrival, and now what? We'll do something like that area of circle so seen Ah, uh, and area of circle will be sent here. You can dio self night that Ah, double result. It calls Ah, pee by the number pi And to race to the power of to I mean, our races apart of two, right? Right. He was raised to the power of two or so, Um, we should also notice that the pie is constant so we can create it here, for example, like that constant p a constant double pie on and do something like that are we can do it. Also dead way hash. Define by free 0.14. Okay, we can do it a little dead way. And now we can use it like that. You consent, for example, to the output. Something like the area off a cereal, um, off a circle it quotes results. You can anti like that. Radios is, um oops, like that. And here, the equal sign, for example. You can return the result also. So now that's right out. Ah! Oh, sorry. Do it. Of course, That way. And we are trusting to circle entered the radius. So I'm going to enter here, for example. Ah, to And as you can see, the reality sickle that the readies is still is Ah, as you can see, tohave adult 56 when we type for example one in the game one, it is 3.47. Everything works financed can see. Great. So we can now create other areas. We'll need the variable for site for square eso, for example A for rectangle two sides so and bay. And for triangle we will need also the height of try and go. So going into the rape was like that. No, we can just go peeing. That guy's here like that and we just ask Entered ah, side off square. And like that area off square area of Rick Tango area off triangle entered, uh, with Andi height of Rick single. So seeing a and we can do something here look like that bay so we can get from the input to variables like that entered? Ah, height of try and go on. Here. We condemn that. What? Right. Okay. And now we should create a little functions. Correa's square, you know? So maybe that's do it that way. We need four functions. 12 for on. Uh, it would be faster when they just copy. Did right? They look almost the same. So it will be faster to do dead way. And now area up school is right. He will need to double other things. Okay, now, let's copy. Did guys here? Let's create a definition of the function. So like that? No, very off the square ease, Jess. A multiplied by a said area off square. That site is a equals. The result. Right? And now area off rectangle. So a multiplied by Bay area Rick Dingle. That's first side. He's a on. And the second site base you been equals the result. And now the try on go. So it is the one divided by to But remember that went did the dead way multiplied by, uh A and multiply by age also, of course, the base of our triangles. So we need to the dead lice. Ah, you and, uh, base on hide of a triangle. No, everything should be fine. As she could out can We didn't run it. Um, we need to send here off course to the rebels. And as you can see now, I'm confused. For example, the square and the type that too. So it's forum. Think works fine. Now I will choose the rectangle. Andi, I do like something like two multiplied by six. So it is 12 of the thing works fine now the triangle. So, for example, to multiplied by four on it is said by a about eight multiplied by one divided by two is four. So everything works fine. OK, Andi, you might be like, Hey, but our user has to around this program again and again and again if he wants to. For example, calculate more than one time, right needs very, very time confused, consuming and is not. That's why I will use here lips. We can do something like that. For example, ask after the decision. If you want to continue the program, so see out. Do you want to continue the program? Yes. Oh, no. Like that. And then we'll taking here the decision. So character, for example. Like that on. Let's stay that guy here. And we will use the low Pierre like that. Do everything in the lip. So at this one's why the county news IHS equal to yes. Oh, continue equals Teoh. Yes, in the optical using the upper case. Right, So right now. Well, not is that when I take for example square and that for here, I can no type. Yes, As you can see again, we can choose from the man who Something by type No or anything goes, For example, key the execution. Will this stub of our program right? Great. But mm, it wasn't read able after a time so we could do something like that. He system clear screen. And now we'll notice something like, um sorry. No, I did, for example, the triangle. And now I want I type. Yes, but you can see that everything is being cleared on our screen and again after the system clear skin. We have the initiate realization of man. So that's good, right? And I don't know, American type of game example that guy and nine type. No, and execution stops. Great. But what will happen when we do something like that? For example, Now I've typed something like that is you can see the program has stopped. Ah, but if I had something like here, for example, like that So we are being asked for something after the guy? No, like that. We weren't asked for the choice. He rides on the gain when we do something like, for example, death. As you can see, we are being Gaza gained. Two going to continue the program. And that's good because the default option here was executed. But look at that. When we do something like that, we weren't us at all. We want to continue the program or number, whereas, but we didn't have a chance to choose anything. Right? And now way will, um, in the next lesson, know how to validate things like that. Right now, you can see it's not good, but don't worry. Ah, we could also add dry programs, something like that, that it's training for example, when I type something like that and night type. Now that your key, I like to be asked again Do you want to continue the program? Because the only option that you should choose here is the yes or known right. So we could do something like this, for example again. Here do Why. And here we can stuff like that. Why count? It's not equal to Yes. And in the same time, counting it is not equal to yes, in upper case. And in the same time, Continis isnot equal to know and in the same time is not equal to no the lower case. Please keep doing that to alliance you. Okay, so online. And I'll do something like that in the light type key. As you can see, I'm going to be asked gain again again when I type. Yes, everything is being repeated. Okay? And I type no execution stops. But what will happen when I do something, for example, like that More correctives here, as you can see. Ah, all Kalak characters were being put to the counting. You variable many times and each time they were No there. Why are en now? I would do something like that. As you can see. The last character Waas. Yes, and I reckon our program was counting it. But look at that. When I do something like that, you'll notice that our program has stopped. But the last character was and and we'll talk about it in the next lesson, will use the thing and we'll try to validate our program. Okay, that's only lesson. Thank you very much.
25. Data Validation - exercise: Hello, everybody. Today we're going to talk how to validate the data coming from the input. So we're going to learn how to react when somebody give us something wrong and our input. Right? So in some other type, wrong type off the value in the input, Right. So, for example, and I build a program. Now we're being asked for 123 or four. And now I take something like that. And as you can see who you think is wrong, right? Oh, are when we do something like that, Right, guys, here and now we are being got I want to continue the program. And I do something like that while I have got I'm being us a few times here for the right and how to make it without arrows like that. So how to do that? Well, first, let's focus on the guy here. So do we want to continue the program? Right? When they typed more characters, for example, 12345 world would What happened that seem 12345 As you can see, we have 12 free for five messages. Do you want to continue the program And why is that? So when I tied four, we'll have far right? Mm hmm. Why? It's because it's working like that when we put anything and input. Right? So in that place, you when it when we create the enter on the keeper ball, right when corrected that we have something in our memory. Temporary memory. Something good is called bar for this a temporary area. Right? And when we type something in input, everything is going to be inside the temporary area. Okay, in the temporary thing and after it one by one, it will be sent to the guy here. So we have only one variable here because it's one were able. Ah, we will take on the one value of that awry, right? And send it to that. Ah, that's labor right to the variable. So in the continue will take, for example, a And then we have got here, a condition that is checking if that if the character is not an egg y or n right, because it's not, we are again being asked. Do you want to continue the program? But this time, we didn't have a chance to take to give another option, right? Ah, well, we're again being God's going to continue the program. They're going to continue the program. We're going to contribute. Knew the program. Why? Because when very something in the buffer, it must be totally cleared. Okay. Everything from the buffer must be a saint somewhere. So I guess so. It was something. It was done instantly there. Value s waas put into continues in again. The condition was check it waas True. So again. And we didn't have a chance to put anything hearing input anything new, right? So the buffaloes the data after G And if we had anything like, for example, the right characters example here that why you'll notice that he's trying to end the program. But he's not doing that this time. Why? Let's see, I'll let's see when I do something like that is the last character. Okay, it kinda worked. But when I do something like that that it is in the middle, right? Well, not is the room. Something is wrong that I think it's blinking here, at least on my computer, and I won't be able to dive anything here. You should test it on your own computer and look, why is that so? Because when we left that lope, because there was why some or write the letter here and we where checked. Ah, I mean, ah, the that's value from here went into the choice here into that guy here. Wow. Okay, but let's focus on Dedicated that. But I think here, let's fix that guy first. How to do that? We can use something. What is called the ignore function and that function by default ignores one character. So what? What will happen when I do when I run the program now and I will type something like two characters is against now when I type two characters on the one message so skin that good. But when I type free character, something's wrong for whom the more characters they type the the more messages I have, right? So we should change the default argument, which is for the signal function. By sending it here, we can type something very big here, like, for example, 1024. So probably nobody would type more characters like that. But sometimes there might be, Ah, we might take the date are not from from our user from the keyboard, but we might take them from the, for example, a fire. Then we should ignore more characters, like all of them. Oh, possible one. And then we can use something. World is called in na Marieke limits. And this is a class. You don't need to understand it right now. I'm just telling you that this thing will return. Very big number. The maximum number, right? Ah, that might be in the heard. That might ah, is it a size of Ira Bopha? Right, So that is the maximum size. Good on. And here we can add also, the next argument this thing is representing enter and the right. And if he meets enter before taking golden characters, that's okay then the we can also just Ah, go on. We've our program. So let's shake it out now when I type something like that, as you can see. Great. Uh, okay. Now I have to type. Always the right guy, Right? Even the vital. Why no, Somewhere I want you to type. Why are no tonight? Why? Who Everything works. Fine. Great. But now when I type here the right things for the Regis's off circle for example, everything is OK. But what? When I type here? Kerak, They're selected. Something is wrong. And here it's not enough to do just that. Think it's nothing not. Let's copy that. Let's see. Is it enough? No, it's nothing up knowledge. Three dead weight. But it's not enough. What? Because when we type a value, which is not the same type as a variable. So Ah, I will stop Inc. Your characters and I was trying toe the same characters to indeed, right? Something is wrong. I can do something like that while I can't say more than one, right? I can't do that. That's wrong. So how tow Avoid situation like that? Well, we can do something like that. Why that think, Ace? Not right. Think so? It is not the same type as we have. Invariable. Right? So why things coming from the input? So the choice. I'm not the same types here. We will do something like that seen clear. So we'll use the method that we clear the state off our import because look what happens here. We have methods state before and like that Read state. So Air Rd States stands for reach State right reach state and it is reading the state of our impossible. It will return if it's right. Or maybe it's not the right. Okay, so stays before in state after. And now let's check it out when I type. For example, Um, it didn't go well, but it's because I typed the value for that scene. I should start from that guy here. OK, we we have toe fix that. That guy's here also, but let's start from here. So I should talk the wrong characters, for example, here, atop the wrong characters. I'm expecting the the 12 or free and in the choice. Right. But I am typing right now, many characters. And now, as you can see, we got here something stayed before for after the clearing, we have the state after zero. If I didn't do it, I didn't clear what we would happen. As you can see, we have to clear the state in situations like that because, ah, when the state is not cleared, we can't put anything anymore into the input. Okay, so remember about clearing input in situation like that. We don't need to clear an input, because look, we have we are taking characters here like eso. We're taking characters, so anything is a character. We just need to ignore the everything every other character. And this is this and we have every single right now. But when we once the ah when we are expecting the integer Vela's and we're sending the characters very always Dan, we showed clear he was the clear. Okay, the thinking go to comment and let's do something like that here. Clear the screen that's sent to the output mental again. And let's inform our user you have just type the wrong they talked to the import repeat and or something like that the your decision, How toe informal Use them and do as you could see you thought you had just like the wrong date out being no and can type for example, the right one. And now he right. But everything is bought or everything is wrong. So how to change it? Well, let's create a function that will help us. Do is it will be faster for us goes a so you have not their money. Ah, instructions can sent here. So why to repeat them many times So we'll make a function of written bowl and will our name It is valid. It OK and it will take streak. It's apartment and now into function. We will check at the beginning if that seeing wreath state So if the state is wrong so state is wrong is wrong when it is not equal to zero. So if the state is wrong, we have to clear the state right and everything is fine, then we have to also ignore like that. Okay, you have to also ignore and then we should clear the screen So it would be easier to read for our user later our program and initiate menu again. And we can send here something like, for example, are a mess. Stated that we will decide later how we do local looks like the her message and written falls Falls will mean that it's not valued right. It's not very because we were taken to that guy here toe that instructions. Otherwise just return to true won't be returns. Um will never be returned if that guy is written right? Because I told you that when in function, our PC meets the return statement, he is leaving the function instantly the the place where it was involved. Okay, And now we can you do something like that, for example? Um do why do why? Right? And as the condition where will do something like why is valid? Why it's no developed late. Please take the radius and when it's not valid, please also tell our user something like that. Read. Use is wrong Place type. It's a gang. So it is the arrow message, right? Let's see how it works. Circle Now I'm taking something wrong. The regis's wrong. Please type it again. Gay. I'm not going good. You go to that. You have to type the right now you can get your free. Okay, so everything works fine that we have to also do the same thing for other guys. So but string the bid song Oh, let's go Deadly Do. And here we had. And then let's just like the data is wrong. Please died with the game. Um, now seen a B and now hopes, uh, they go a and h that that is rock now Will not. Is that when I type anything grow anything, then we I'm not going to go through anything like so our program is now almost okay. What is the situation when I don't want to send a message? I could do it. Dad Way, for example. Let's overloaded function here and we don't want message. Okay, so do it. We've all message them was just three dead way, right? Ah, no, we don't want message. No, we don't need to type on a message here, but well, when I do it that way, let's see how it working, um, into the reddest and taking grown radios. Um, didn't comply it, sir. I didn't use the right function. Of course, our PC. It's Finke. And he knows which one we should use. And now, as you can see, um, maybe it will be good Invited. Something like that goes. It didn't inform us enough after making a New York. So no. And just being God's answer, the radio centered reds into the readies. Until I make it's the right Reddy's right. And don't. Okay, So how is it working again? We are being asked him for the radios and we are taking in from the input to the R variable . And then we are checking if the condition is void So we are invoking the function here. We are checking if the state is wrong or no. Well, if, ah, if we typed the right guy. So if you type in teacher, we are passing that guy returning to And if I return the truth through here, it will be negated by the exclamation mark 20 Well Ah, calculate the area off, Sicko. Otherwise the state is wrong. We're hearing the state so we can again use it input. Right. So we can again later take the value to that variable here. Then you are ignoring characters that might be after, um in the that might be in our bathroom. Okay, so we have to clear the bathroom, and then we are doing good assistant clear screen and initiating off my nose so it would be easier to read for our using your returning false. So we're changing false with the negation exclamation mark to through and because condition issue your again, sending out of the things here and until we get the right values right, it goes final. Now we are secure. Okay, That's all in good lesson. Thank you so much.
26. Enum Type: Hello, everybody. Today we're going to talk about enumeration. Type in admiration type is a type that can define its own time. I know it might be confusing, but don't were assumed he would be explained with a new stands for enumeration. Right? And it it means counter. Right? So it means counting from 012345 Okay. And now you might be why, it's names like that. Don't worry. It will be soon explained. So in order to create and, um vory able. So we have to do something like that type. And, um then the name off our for Rabel. So, for example, day off week. And then there is something different here. We have to open curly brackets and after it at this cynical and now look did the name the rebel Hell is really know the va Rabel? It is a time Does it type? No. And we have to define in that curly brackets What can be a saint to the variable off type day of week Someone great now something day of week Now, for example, name are very well, d we want to define in that Carol brackets here inside here. What can we thank you? So, for example, I want to be able to saying here something like M which we re present Monday. Right? So I will type your m. And now look, when I compiled the thing, you'll not is dead. Everything is working now. I can sane today I m right goes d type is they of weak And we define the type. Right? And I can This ain't here, for example. Key. Because it does smell to you about the night. Create your key. Everything works fine. So we're creating where speed specifying the set. Ah, that can be ST too. They're variable. That will be talked at the time will be day of week. Okay, so for example what? Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday, for example. Like that? Of course we could do something like that. Pond day tours and things like that. But they do the dead weight. And now I can, as you have noticed I can thank you. For example, Monday and I can send it is late to the up like debt. But what will be sent it out? As you can see, it is zero when I changed this guy to Tuesday. So is the second guy here. As you can see, I have one. So it means and well, this thing is called enumeration because it is enumerating is counting way have to count you like that. 0123456 So Sunday, when I changed guy too as, um, you'll note is that six, Right? Great. Okay, So we created our own time on and we know how to send it out some values. But let's see if I can do something like that seeing on Let's take value from the out from the input. Can I do it? No, I can't do it because our that operator is not specified for our type. We can do it. Okay. We can also do something like for example, debt. I can't the same here. Zero as you can see invalid conversion from in today of week Because that variable the type , is what is They have weak. So I can't the same here in teachers. I know that when we send it to the output, it looks like in teacher, but he can't. Ah, he our compiler must do something must send something to the output. And he doesn't understand the things that are here like that's And what the hell is that, Right? So he has to do it that way that he's enumerating the guys and sending to the output the value, like, specified by the position of the guys here. Okay. And and now I like to tell you about something like that. We can use the day of week like a function that they have weak. And then in the parent disease, we can do something like a example Tuesday and we will know what place it is specified in that sense, right? As you can see, it was one. Now it might be like, Hey, how to use that thing. And you have also noticed that we are counting my Monday from zero. It might be not good. Let's change it. We can change the new and admiration like that now, as you can see, Tuesday Ah, Tuesday is two. And Sunday it was seven. Right now we'll see two times one. So now we changed the enumeration. Now he's 1234567 Okay, you off course could do it like that. That would start from five. But I think that from one it will be good idea. You can also change not for example, that guy five and then a day off week you for Tuesday would be five for Monday. It would be one. So now was 15 Onda Ah, Wednesday would be now seeks 56 Shake it out. As you can see, everything works fine. But we want to do it that now young behave how to use this, OK, but we can ride for example function that we will call get day get today would return the string and it will It will have a para matter. The type is our type that we created so day off So we have a declaration Now we need to create a definition of our function and to you we can, for example, name that guy and switch Now that the and now we can do something like, for example, went in case in case it is Monday Please return there value Luigi's what in our situation, Mondo, right? We don't need to add to brag because when we return the value, we are living the function in function instantly right. So we don't need to have the break. Your statement. Well, now we have to just certify that, guys. Teoh. Ah, possibilities. 123456 Thing is OK, so Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. And now he returned the seeing her stay When's Today? Thursday, Friday, Saturday and Sunday. And on the fault case, we will return. You typed something wrong. Okay, Something like that. And now we can use it, for example, like that gets see out, get day. And you I have to send, for example, and let's get that guy's into the comment. And you'll not is dead now. When I sent you m itwas month. Well ah, we can't send here, for example, zero o r. One. We can't do it because, ah, we can't convert into day of week, right? And because of that will use that. Think you here in that function, we can use Easley 01 or two or free here. We can do it. Look, when I do this, do it that way. Um, you'll not is that we will get the one so everything works. Fine. Right. One for ah, this thing of course is representing then and terrorist, right? So that things returned the terroristic, something like that and bottom the output. We have to see the four on other things like that. So we'll take now, for example, the I, and we'll send the eye here. Here, we can ask all entered a day of a week and line and we can create a man in menu. So, for example, one. It's Monday dio iss Monday to use they and just a lot of days right, It's easy to do it. So, uh, just you can do it is really and I'll Let's see now when I typed gives ah two. We go the terrorist coast because I don't know how to name names in English. Okay, How would I do it feels day, OK? And when I type for example seven sand right eso we can even do it without dead and enter the day of Wigan's somebody. When somebody type seven, we get this sounding, you know? Hey, this seven day in a week east called soundly. Great. Okay, there's only two this and thank you so much
27. Reference Variables : Hello, everybody do. They were going to talk about referenced variable. First, let's focus on the world reference. What is a reference preference is just something that can heil bus, identify somebody so we can do something like a guy with a reference number seeks come to me. And if there is person with for example, the paper and the paper has six, he knows that it made We're calling that guy, right? But he also has name. He might have a name, for example, Skull or something like that, Right? So Ah, he has a name. And he is also a reference number. So about both that thinks the reference number and a name when we call him by that he will understand that it means that we're calling that guy right? You'll understand it. He will know that we mean him. Okay, So what is the re ference variables in in the programming? Well, we can create something like, for example, string on name a name your name and ah, let's the same here, Agnes. Right? The name eggs. Now we consent to the output. Did name for example valley off variable this name. And let's also send the output, the address off that guy, Something like that. And let's compile it and you'll notice that everything is working fine. Or now. And we notice also that the address off the variable is zero at the end, right? The end of the arteries. And now we'll create a referendum variable. It was like that type. And then we have to use the m percent here and then the name for a reference re ference variable. So it is the label for it, right? I'm doing label. That will be number six, for example. And now I have to a saying here, another variable that will be s aided with dead variable. And now this is just a re ference for that variable. It means like I told you, that it is like a big name for that guy, right? We can call the value that it's under that address here with that libel, all that label now. So let's check it out. If it's true, that's saying others of a rebel is. And as you can see, the Velo of Barbara labels is the same. And also the address of Bovary, Bos is the same. So we created just another name for variable here, Right? Okay. Now, what would happen if I change value using that guy here sample like that? And then I was sent to the output. The values again you're not is that we change in both cases. The very right. Great. Okay, now let's talk about the re ference a bit more and I will give you some rules about them Re Ference. Variables must be initialized when created. As you can see, we can do something like that Beans and run. As you can see, our compiler wants us is compiling a program onto our re Ference is not initialized. So we have to initialize the guy have to do something like that also please notice that here is an percent and here is in person. This n percent means different thing that this guy here remember that n percent that is preceded. So if there is something before it and this thing is type type of a Rabel, it means that we are creating a referenced arabe. But these and percent here means that I want to get the address of the variable. Remember about it. Okay, so also we can do something like that. Re ference Var Rabel can't change as sensations. So by s sensations, I mean connection. So Ah, I've just related to reefer rants aside, I mean, diet is a skated one reference for variable name, right? And now did the re Ference will always be eso sated with didn thank you. I can't change his later. For example, I can do something like that string name to La Jolla and I can't do something like that because I like to something like that. I am trying here because there is no type before I'm trying to a sane ah value to the I'll address, right? I'm trying to say to the address value la la la lots of what is wrong And when I do something like that, you're just changing the value. I am not created every four ends. As you can see, I'm just changing the value. Okay, so this thing, this line is like that lying here, right? Okay, we can change the value but we can't change the associations And we also should know that it's because a to the beginning here is a world constant. That ward here is saying that we can't change associations. Dead Ward can also be here counts in sync. When I do something like that, you'll notice that I won't be able to do something like that here. So right now by we can use the re ference variable too Get value from here. So it is just another big name. Another Ah Ali s another thing that we can call name here. But we can't change a value using it right now. Off course, we can still change the value using the name here right that we work is And in both cases both will be changed. But right now that the re Ference is just think that we can call somebody by it would be just in evening. You also should know that referenced variables must be the same type as a sous ated variable. So off course can do something like, for example, dead right here I have an end trying trying. Teoh does something like that here. We can do that. If both are ain't. It works fine. But here I have to also get it into the common. Now he's okay. But when they are different, we can't create a reference and now you might be. Hey, why do we need something like that? I will talk about it in Lex lesson. I will explain eight. Over. Cleary. Okay, that's all. Thank you very much.
28. Reference Variables in functions : Hello, everybody that they were going to talk where referendum array books can be used goes in Peru's. Listen, you might have been like, um Well, great. There is something like a referenced variable that is grating. Just another variable that will help me call other variables. We've just another name. So why the hell trying to do something like that? Don't war. Assume it will be explained. Imagine a situation like that. I have to arrives, for example, in a and in big. And now I have to swap Replace Ah, that values. So I want to have in 81 thing I want to haven't be 10 right now. How to do it really create a temporary variable that will start for a 2nd 1 of them. And because of that, we would be able to change it. So I will allude something like that. Do temporarily a saint A So I have right now a start summer So I can Same toe may be easy. Now I can the same Toby t. And because of that, we change values Anti. We have what we have 10 in a Now we have 20 and it be were saying t So we're saying then we swapped there values, right? So everything works Fine. Let's send it out. Good values. And now the big and does he consume? Values are swapped, right? They're replaced. Now we can create a function. Teoh, do it. Ah, because normal. Oh, you know. Ah, I would like to, for example, do it, man. It ties in our coat on. And it would be like, Hey, we have to do all the instructions again again and gain. So it's better to create a function, right? So void Because we want return anything and let's go to place or swap. Right? And, um, here when you do, the rebels did that. Teachers and I'm just 30 p did think you, Ryan. So something like that's and the thing is used this pope to varietals. Now, I could do just something like that. So no sent a them and let's see if it's war kink. Uh, okay. Of course, we are using eight x and y. So let's use the right guys. Thanks. Thanks. Why do why? As you can see, the values were not changed. They were not changed here, but here, check it out. Um But here they were trenched, as you can see, X 20. Why Weston? And why is it so? As I told you, when we're doing something like functions and we're sending, we were able to function. We are just complying value. So we're doing so like X equals now a And now when I change X, I am not changing gay interest in Drink X So everything he worked Fine. But after the color of the bracket, X and Y disappeared from the program right and deals. So we've changed something. An adult. You change it and we don't have a good result here in our main function. But, hey, we noticed in previous lesson than that when we did something like, for example, like dead when I change re Ference, for example 50. I also changed that guy here. Wow. So Hey, I could does something like that. I killed have references, Hugh. No. When I building runny I will not is that they swapped right? Needs working down because right now I've created a referendum. So this time I'm calling the same person. I'd we just Another name is like a nickname. Eggs like a nickname for dead guy. We're changing the same value under the same address. So now everything is working Fine. And now you might be Hey, that's refrigerators are really you Give, he has exactly Well, I I could end this here, but I like to also tell you about retiring reference so I could do something. Like, for example, that into your hero. Indeed, You're here on return now, for example, the first guy pull the X. Now, I could saying that value from here for two, for example, seem. And now I could send the output little scenes and you'll notice that is 20. Right? So C is 20. And it's true because ah, x was changed here, So ah, to 2 20 right eggs at the end is 20. But what about that? Now I like to change that. See, for example, to 100 here. And as you can see, we change. See? Because it is the copy, right? That is a copy right now. Ah, off the value is just a very under new address. It is no the same of a Rabel like here, right? It's not the X, But I could do something like that. Adhered Temper sand here in person. I'm saying that I'm retiring there Re Ference and no one I change everything is working also the same. Because here we've just the same just the value of aches. Even though that I'm returning the re ference, I have to also at here. I have to at that I'm creating a re Ference were able and now look when I change See? I changed also a so ah with debt Right now we're able to change the value off a returned excuse. Ah, we've for able here, right? So it's really, really killed. Okay, so now you know how is re friends? Very believes. Now you won't look at them like Why the hell did I need them? Ok, that's long. The lesson. Thank you very much.
29. What are pointers? : hello over about it. They were going to take about pointers. This topic is really very important. And it might be the beginning. Very confusing. I'm like, Hey, why do I need pointers? Don't worry. Next lessons, we show the usage off pointers. Look, right now we can create variables that construct number straying starting point numbers. But we still have one more value that we don't know how to. Still, this fellow is called address off of Arabe. So when I have, for example, Rabel and Var and it equals five delivery because an address that we can get by using the m person, the N percent, and after it, the label off variable will give us. As a result, the threw us off the rape, right? Okay. And that we need have a rabel that could star addresses. It is really very important thing to know how to do that. You'll notice the user just that something like that next isn't so. Don't worry. But right now we do learn how to create something like that and to create something like that, we are using the type that we want to points to And then the asterisk, then the name of our va Rabel. We call it P from Pointer. And then this cynical despair able here can point. It means that it can start as a value the address of variable that the type is intelligent . Okay, so for example, we can start that address You, right? We can do something like the equals. Address off. Vory able I can comply it. And as you can see, everything worked. Fine. Now we consent to the output, for example P and you will know this death both All the things the same, right, but results of the same. So now we know how to start as a value address. So pointers are ordinary varietals. Death can star address off variable at the rest of variables. Right? Okay, No, let's see how to get a value. But ah, just by having the address. So here we have an address. And here we have an address, right? If I want to get the value under the address, I can use something like death. The s the risk. Sign this, sir. Start right here. I can do the same. And now you'll notice that we got in both cases the same value. And now you might be a bit confused, because here is s the risk. And here is histories. The S series that is preceded by a type is used to just inform that as serious kill. He's just used to inform about that discovery. Able is a pointer. So it is a variable that can point to address off another va Rabel. Right. Okay. This asterisk here, that s serious. Kill is used to retrieve, get value from indicated pointed area in our memory. So address. All right, This guy here is not preceded by a type. Okay, remember about the differences, because they're really, really important. Okay, imagine that this think he'll is some kind of area of our memory of our program. And right now it's free. When I do something like debt they compile on my program. I am reserving four bytes of memory because I need for buys for indeed, right? Okay. And then when I do something like that, I am reserving memory for a pointer somewhere. So, for example, that applies here. And then when I do something like that, So I I'm a sane to pee the address. I am doing something like debt. So that guy here is pointing here. Okay, We can also Assane the address in one line right like that so we can just come under guy here and it will work also. Fine. As you can see, everything works fine. Okay. So as you can see that thing that notation is giving the same result is that notation right ? Okay, so it means that we can change the value that is under the address just by using the point of like that for example ill Same here now to end it. And now he's sent to the output the value of far. And then I was sent to the output value by using the as the risk and the pointer. Let's do something like that so it would be easier to it and you will notice after compiling death value changed here, right? And we used pointed to change it right. We can also change the value by using, for example, still that guy. And you will notice that both both cases both values were changed because we're changing every time very under the same address. Remember about okay now you should not is that we can change where our pointer is pointing to. So for example, I can create another variable. For example, they and our saint of it, for example 20. And now I will do, for example, here in the place you I will do something like P. Now we're equal to dress off a So now that got here is pointing to the address of furry ball. A note to the address. Variable there. So now when I use Q s series, I would get the value to this under the duress available A. You'll notice that we have 20 now, here. Okay. And the game. Now I can change the fighter here and the value we would change. And that instruction will change the value off dead guy here so I can send the output. See, it's working. Does he can see the value changed like I told you side in life. Okay, But sometimes we don't want to alot to change. Where are points are responding to? It is indicating right when we don't want to love something like that we should create something will discover that constant pointer No need to create a constant pointer Wishes at hell that place the war to Constant. No, we have to a sane the address when they're creating a pointer when you're defining it and we won't be able to do something like that. He now when I bought build it, you can see where we're going to read you an arrow assignment off on leave a rebel. It means that we can change you something like that. But when the constant is here, way Steel can do something like changing value that the pointer is pointing to. Okay, But we can't, of course, do something like that. No. Okay, let's Maybe the something like that's so you can read that later Example and P constant. No. But also here that counts stand no examples, and a now commented, This is a pointer that has to be initialized when defined because it cannot change after defining it after defining the thing that it is pointing to. So address right? Can't change the address. It's Ponting. Okay, We can also create something like that constant, uh, end and, for example, P to And this time I can, for example, again, same thing. For example, address A. And this time we won't be able to change the value. Because when we did it that way, you probably noticed that when we did the dead way, we still could change the value here. Right? You see, good. Go do something like that. But when I do something like that, I won't be able to change the value by using point and sometimes through the use. Okay, so this is a pointer that cannot change the value that it is pointing to while the value that this under address it is pointing to right. But when we do something like that, off course can change. The address is we also can do something like that constant and mm under again. You, for example, Constant. And this time, this is a pointer that cannot change the value that this under address a disappointing toe . And also, it can't change the dress. Okay, but don't worry that things are not used very often if you don't understand either. Right now, the most important part of this lesson is dead thinking. OK, remember about it. And now we talk about something. Ah, what? They might confuse you a bit more, but don't worry. Well, look, that's see here now a situation is our pointer right? And as you can see, it is also some wearing our memory. Live means that we also need a variable that could start address of all her pointer. Yes, the Pointer also has an address. Exactly. Wow! Now it's getting a bit more confusing, right? Don't war, we don't run. And now let's do something like that. Integer, ordinary, very able right? And I will say to it, for example, Now I create an ordinary pointer that well, take the address off that guy you right! And now I was sent to the output they ordinarily var Rabel And now I will send to the output there point. So this thing is addressed fine as a result, that's Finke's in teacher value and also can send something like that. And this think is what this thing is integer value from pointed place. So in our situation this or deny ver very bold. So it will be the same value, sq And now some think you will take we'll send to the output address off pointer itself because it also has an address. Right? Remember. But oh, and you can also scented output the dress off ordinary variable. And as you can see, ordinary, very bullies Then the s series of denarii goingto this 10. So as I told you, everything is working fine. The address off ordinary variable is the same as the rest of ordinary reporter because they have pointing to the same place right now. All right. And now, as you can see, the address of ordinary pointer is different because it is also address. It's OK, so it means that we can create something that could start also raise often point Yes. And this thing looks like that a teacher. And now we're creating now here to as the risk. And now we can call it, for example, at Pointer pointing to address no going to. Yes, I know it might get confusing and now I can do stuff like that. Ordinary p. And when I do something like upset, let's send it out. Put and let's see if that thing he'll is the same of debts as that. Thank you. Let's see as you can see it. So now we can still that the rise of the guy here and if I wanted to start the address off that guy here because it also hasn't addressed. I would do something like that. Don't worry. Situations like that is are very, very, very rare. Okay, so okay, that's all in the lesson in existence. We'll talk about uses of the guys here, and I know it's confusing. Thank you very much.
30. Name of array - Pointer : however body. Did you know that the name often area is Ponta? Well, look no, my lamp. When we create, for example, Mary, that size is free and, for example, short end set them. And no, if you're looking to our memorial, it would look probably her like that. Of course, it could be in another place on it would be, of course, bigger. But somewhere in our program there would be free times reserved for bite for integer because interior is reserving four bites. And as you can see after it, we have the that I am the shorting because it's serving, reserving to buy. It doesn't need to be next to each other the that m and the the Eric, but they can be. And the most important thing here is that you should notice that airway is always continues dead men, that they are next to each other. OK, so it means that if we could point to that guy here that zero Mikel jam for bites later and you'll need there second dilemma. And then again, I could jump to more four bites later and I would meet there third the limit, right? Okay, now let's see how he's working. For example, I will send to the output right now a hue. And then I was sent to the house. Good there. Address. Oh, first lemons in an era. And as you can see, both addresses are the same. It means that this guy here is a point of right, Because I did something I got and going there. Now, I would say you address for his appointment. You would notice that by sending something like that out. But we still have the same other rescue, right? So the name off the area is a point of in addition to this, this pointer is also here, Kellison. It means that we can change. For example, the the address issues. I had some example something like, Ah, And now I like to something like that. No, we can do that. We can do something like that because it's going okay. We can't change the address. Okay, Now let's send to the output. Oh, addresses off. Did the area here it will not is that they are moving by four bites. So they're next to each other, right? Zero for a the And if you had, for example, double you Shannxi rows of double time. They're moving by eight bucks, right? Zero a and then 23 in that position. Okay, let's go back to the into your tie. No, I like to show you something. Let's make the landlines here. So to be easier to read. And the I was sent it out with a and then I was sent to the out with some tonight a plus one and then a plus two. And as you can see, that values here are the same 32 free for there to a and here are the same, right, so we can move. I feel by using the pointer by using the signed plus right the plus one and the plus one here doesn't mean that I want to move by one by, but I want to move by one position of the size of the ah pointing variable be pointed right now. Right? So in into for the integer it means that we want to jump by four jump by eight. So it is like to multiplied by or something that okay, because ah, pointers are intelligent, right? Date day We they know what they are. Um pointing to because it states here. So they know that they meet something like plus one. They have to jump by four bites when it's integer. Okay? And now would a school We could do something also like death because it is address. We can get value from the debtors by using the s Aries cried like I told you in last lesson . Second to something like that is the And now we have here some random values because we didn't think anything who was the same? A few values. Example 20 and 40. And as you can see 0 2040 So we can do a dead way we can do you eat? Ah Dad away. So this notation is going to give the same result this season. You can see everything works fine. Okay. I told you we can do something like that. Why? Because a post blast is going to do the same thing like a equals a plus one. So it means they won't change the address of first a lemon of the point of view And the pointer here is a told is what comes but the scene hesitant if you see it's not working but we can do is limb. And now they're pointer example anti German. Let's call it example P to a saint here, address first elements here in the all right. And now we won't just I p constant we just removed at which is that something like that. And now we can easily sent to the out something like that. And then we can also do something. For example, that or like that Oh, like debt. Okay. And all that Ploce issue in different positions means different things. If you don't understand the prank commendation Posing Commendation. Please go put the arithmetic lesson because it will be very important ones and send it here and now. What should win say in as a result here? So here we are getting the value were retrieving the value that is under the address that this pointed here. So it will be what? Zero. Right? Okay. And then what we are doing You are first incriminating the value that this under that address. So it means it's here we will increase What the value that is he right? So it will be changed to one so t really zero he'll be one and Hugh, we are doing. We want to get the value from and he'll we're doing something like, Let's move by one air a later. So we were moving four bite by four bites here because Pointer is intelligent, right? Like I told, now we are moving by four. But so here moved by four bites and show me. Now hear the address of next next guy because we were pointing here the first a lemon. After that instruction here, we're going to point at second the lemon. So they've got here and we'll have here 20. Okay, what about that guy here? Here. I want the value from the current pointed address. Right. So right now it is to win, too. So we sent the album 20 but after it were also increasing again, would the address by four. But because you're seeing it rose by four bites in next line that got here will be pointing to the address of debt. A lemon ovary. So we'll get here developed for Let's see if I'm not playing lying As you can see, everything is working like I told 01 2020 40. My baby confusing at the beginning. But train a bit on It should be Ah should be fine. Don't worry about it. So Ah, right now we're pointing to the last guy right here. Ah, we're pointing Teoh to the last guy oven early But steel we can jump, for example. We can do something like that later and should as because, you know, I have here too on we can jump again. Dead values here after it a random We don't know exactly what will be there. We are right now pointing onto the memory that might be using our program. Oh, it might be so also something from another program. That's why we should be careful with pointers. Because when we try to change something with this outside of our program that we're able to disease by other program are a programmer will stop running because ah, it's not secure operation and it will be stopped. Okay, There's owned a lesson I will talk about ah, cooler things. Next lesson and that will use the information is in the head lessons. Okay, that's all. Thank you very much.
31. Dynamic allocation of memory : Hello, everybody. Today we're going to talk about dynamic allocation, off memory, But first of that stock, how it is done normally. Well, you know what? Do you write something like that in a row? And I will create an area of 100 eleven's, right? So 100 multiplied by four is 400 by it means that we like Lake Building drown. Our compiler is reserving until our program ends 400 bytes of memory just for our program. Okay? And this is reserved for us. It cannot be used by other programs. Okay. And it means also that we can't by typical defying like that reserve more memory. We can reserve, for example, after dead after compiling after clicking that thing when I our program is running more memory. But situations like that might happen a lot of times. You might be like when? Hey, imagine situation like that. See out? How many numbers would you like to star in an area? So I'm asking our user and I will say the amount he want to start example like debt student of are able and now we problem will try to do something like that. Would this valve. Very wrong thing. Uh, so eight amount. It's wrong thing very wrong. When I do something like that example, I want to have 500 of the guys here. It means that I'm trying to right now get the value or change the value from the place which is free. Or maybe it's not free because normally I told you when we did a dead way this thing happened when, before compiled and reserving the more like that, it's easy. Uh, by doing it that way, we are trying to reserve something with this outside off our program space. And then we need special operators that can do that because right now, when I do, for example, like that is a comply, I can even send it to the album later the K, everything is working box. As you can see, everything works. But these thing that I, as ST here that value could be a saint to the place to the variable that is used in another program. And then I program would crash. Okay, because that type off defining vory able is not enduring us is not making us sure about that. Did memory will be free okay, but I computer memory looks like that. For example, the red guys reserved guys a reserved space of more. Okay, the blue ones are no the reserve and now might like when we need that amount here multiplied by four. We need that spacing memory in a row. They must be one next toe. Another one. They must be next to each other. Right? Because that's how calendar is working. I like I told you. We when I do something like that that a off zero and I won't really something like that on . And I want a off Ah one. I need something like that, right? The area is really a pointer, right? The name of the name, the I didn't fire over is a pointer. Okay, so we might be now, like so how to do that. Okay, so this thing is wrong. Of course I'm just really disgusts you. And how to do that. We have something. What is called Knew that Think IHS Stelling to rpc that we meet a free space in our memory after compiling, Remember? After combined. No different. Whoa. Okay, so we need it. And we want to be sure that it is free. Were just telling to eat to RPC just by using dead guy here. Not there It. We also need to tell our PC How many bites that more mori we need We can say, for example, I want for Weitz of the memory Oh, I can say Hey, I want, for example, advice of memory. Right? Okay, so right now I'm telling, Hey, I need four bytes of memory and that's ive is really an address. That guy him. Let's see that. Send it to the up as you can. Maybe let's come on guys here first because you just take our time. Let's do it on. As you can see, it's just an address is good. But look, isn't it at these others every time different? Oh, so I just didn't didn't around this guy, as you can see every time, the other is just different because we are locating he dynamic Ali. Okay. And can I get value from the place? Yes, of course, you can get the value, but this might be a random really right. Well, this is a random well, because we just got a free spacing memory that could be used before by another program, but mountains, hours only hours. It cannot be used by other programs. Okay, great. But now, hey, we haven't address here and what we can send to the output, the value that is under the dead rest, or we consider the Androids itself. But okay, I can also change the value here, but that's all. I'm changing the value. But the value here is getting a new new address that was just here result. Right now, we don't have an identity fire that we could refer to. So now you might like Hey, but isn't address. It's an address. So I can so addresses the conservative new pointers like that. I can do just something like that. And hey, I can start an address here, and I'm will be happy. Okay, Now I'm storing at rest in a pointer so I can send to the out of the value that is there. I can also change the value, for example, toe 50. Great. Okay. And now I would like to tell you about something very important when I do something like a local variable. So local variables, I am reminding you are being destroyed After meeting the Carol closing Brockett that think here is called static local space. Something like that. We could do just something like that. A 50 then his that. Ah, that think we work, we've out even checking the condition. So these variable after that curly bracket is not going to be anymore in our program, right? As you can see, our compiler is telling us that is undeclared because after the curly bracket, we can't get anything from that point of him. So it also means that we reserved here a memory and thes memory like I told you, belongs only to who toe our program. Tow us right. And because of that, it's not free anymore. It will be always belonging to us. Okay, so we have to do something with that. We have to free that guy that space. We have to release that space in memory. In order to do it, we can use award deal it and then we have to give an address off a place. Ah, that wants to be released by us. So we want to release the place that is pointed by that point of view. And now we are sure happy Disney more is free and it can be used by other guys later. But remember that this deal it here doesn't mean that I am deleting the pointer. It is just really think that other address here. So it means that I can send after it the pointer, his employees that the output and there's you can see every time that address is the same. The dresses are the same seat because he still pointing to the place. But this place is not belonging to us, animal. It's not belonging to us because it's not belonging to us. We shouldn't change that value there because it's wrong. So when I do something like that here, of course you hate with it. We happen. I would change the value. But right now I am changing value off a place that I shouldn't change. So hold IDs. That's bad thinking. As you can see, it's random value. After deleting all right again, it's gonna be used by other programs. So when we deliver the space, we should always also a saying here. New No, he's just the empty is basing our more something like zero. OK, and now when I do something like for example, if he exists. So if there is no equal to know, then I can do, for example, things like that. I can do that. Then everything is fine. But otherwise please just don't do that things okay? So if I do a dead way, everything would work fine. And he's okay, but I should do it that way when I delete the point of Okay, we should also know that after deleting that pointer here can star another others of another variable. So, for example, that guy here I was saying another Will you hear? Uh, I can do something like Hey, Okay, now I want to start the address of variable, you know? And now I can build and rounded program. As you can see, I change the value here also. Okay. Considered to be helpful to you, it's changed. Okay? Everything is working. Fine. Great. But remember debt. Ah, this operation here it's not dynamical reserving government more, so I don't need to delete that guy here again, right? I don't need toe Freedom Member. I enter free only memory that this reserve dynamical. This is just typical. A cessation. Okay, okay, Now let's go back to our problem at the beginning of our program. So let's come And that guy See you. And now it's the program that he wanted to do it the beginning. So Haman Numbers would like to stirring. Inari I would like to start for example, 500 up, lemon so ain't. And now I list the pointer equals new end. And here I can also in the square bracket tell our PC how magnetize multiplied by the type I want to have bites, Right? So, for example, I mean, type five so five multiplied by four means 20. So I want 20 biting memory and the new here operator will, ah, return the begging off that space that was just here reserved. So it will return the address. He was started addressed. We consider to the out book so concede that so for example, five as you can see here we haven't in the rest is start as you can see that the dresses are different, right? They're different every time. Okay, um so let's also remember about that I have to deal it. The space is reserved, reserved by that point at the end of the program. Remember? Always about that. And now we can do, for example, or in I eyes lowered amount I Plus plus and that's sent to the output. See out and heard. Ah, and that's sent out. With which guy? So I plus one because you re 010 pause on his one and number, then cologne and line. And let's take that guy here because, you know, we can use that that think you're easy. Because as I told you the point, the when I did something that example. All right, It's really a pointer, right? So Eric last won the same, like all right off one. And here I have just a pointer. The first element of weather. So everything is working fine. And then I consent to the output that village that we just typed here so I can just send the output The p off i a cools payoff, I No, it's compile it. And I would like, for example, five numbers stand. 40 5500. And as you can see, everything is working. Fine. Great. Okay, but what do you happen when I do something like that? I want to reserve there at March. Memo this dedication has requested the runtime terminated in an unusual way. And because, well, we can't get so much member. Right? So a week old, he tried to catch that error. But we'll talk about right catching girls. In other lessons, we can do something like that. No troll. So it means that we're not going to catch anything because we don't know how to do that on . If we don't have enough space here to the pointer will be a saint, a new. So we can do something that if it is not equal to new, then please, just doof that thinks here. Right? But otherwise say our user that we don't have enough memory. So I know there's something like that because you can see our program is at least working properly. Okay, we could do after eight other other A search is right. Okay. And now I'd like to tell you something very interesting. That's killing two guys. Him it is raining. Let's go back to that. Go for you on the look at death. Oh, it's just come in disguise here. Okay, Um, let's do something like that. We are now reserving it for buys, right? And you are sending to the Al pulled. Ah, just I were address that has been just reserved. And you can see he's like example 68 at the end, right? And what if I do something like that? Deal it, then P and I will do something like that. And then again there, As you can see, both times reserve the same spacing memo because I have program, Remember that we can storing that place free four bytes for But I did something like that. It would be different, as you can see from the guy here. But look, now is the same. But when I don't do it, that guy here, as you can see, they are different. Why? They are different, because thes thing it was reserved for our program only for our program is not free. We haven't released that guy, so we can't take that spacing. The more animal I'm just telling you dead. So you no, he's dead. That we have to remember about them releasing off memory at the beginning. It might be for a bit confusing right of doing. Uh, really It can make so many errors. Remember about it in McKeel your program in my bagging. She's if you have men arose. Well, okay. That's only the lesson. Thank you very much.
32. Strings and a pointer on a char type : Hello, everybody. Today I want to tell you about strength and characters. Well, exactly. I want to focus on the point. Ah, that points own the character type. Um Ah, Before we do something like that, let's remind world are strings and other things like that with I want to create a string survive type string. Then name was our strength. So for example, texts. And then I can insane here some car actives. So, for example Trela, right? So I'm singing. Okay. And now how to get the that characters here? Well, we can do it, for example loop like that when I is lower than text dot length that left will return. Here is a function to return the land of of that guy here. So it is. Make it a bit shorter. Ah, 12345 Well, the truth is that it is six character long. There is one more character. I would talk about it later, but right now you should know that the land function will return here. How many characters are in this string? 12345 Common Invisible Okay, of course, is there is one more character and we talk about it later. Now the i class, because they have to increase the ice of the condition will be finally note to someday. And then let's send it out. Put the text I and then and line. And as you can see, we can send each letter to the out. So it means that the string is really an area off characters. Right? One corrector second, correct, Ted for fifth car, right? Okay, of course. Because that our characters we can a saint single character to ever able the diabetes car rights of character and, for example, something like that. We can do that easy, and you can send it to the out that's been around it. And as you can see, everything is working. Finder is a t at the end here. Okay, Okay. Let's come int That guy's here because we don't We won't need them. I told you that this guy is 12 free for five six letter. Ah, letters off land. Right? Um And why? Because this is safe like that. The r a l a. And then there's something good skill the backslash zero. Because when we want to send the output as strings of the seconds of character. We are sending everything the output. Until we meet that guy here the secret that backslash 00 kerak, right? And then it's just stop sending the upward thing. So it is really important to have something like that. Okay. No. How to, you know, we are right now. Programming in C plus. Plus, before when there wasn't c++. So there wasn't something like a swing. There were only characters. Then we had to start characters, pain, the all right of characters. Well, this is an area of characters, right? As you have Not this year. So, um, but it is hidden inside the screen. A beat. Well, that's how it is the hidden. But first I can do something like that, for example, characters. And then I'm give you size of five. And now I can insane here. Five characters, for example. 12345 Right. What? No, this is five cards goes going to remember that the fifth guy need to be the Baxter zero. Right? Okay, so now we consented. Output characters. Um, sorry. That is, You can see everything works fine. So that's how people start streaks, But There are many problems that will be soon shown. You What if I want to change now? That guide, for example, something like that. This is it did longer then these right? And I want to send it to the out. As you can see here, we're being said that I want O Assane 25 characters Teoh the place where we can sit on the five of them. We can do that here. I can do it easy. Let's see. Is it against the everything works fine, because behind there is, ah, program that is doing eight by art. Well, we're programming suppose Plus so we shouldn't worry about the characters here and doing things like that. But, you know, you might be want to look into libraries from C, and then you would not understand what is in there. So that's why we have to now focus focus on how to do that. How did the things like that? We've just characters like Well, first thing we don't need Teoh here. Dive the fire. Our compiler is so intelligent that when he see that I want to say in here something like that. The sequence of character he will give here the right size for that area. Okay, so that's that's okay. And now, you know, from lessons from the previous lessons that this guy here characters is really a pointer. Right? The pointer characters. So it means that this guy he's really pointing at the beginning. That guy here the first left. Okay, So we can send the output, that thing, that way, the first character. Or we can send into the our food that way. Is everything okay? It is Inconceivable times got 11 And if I want to have the next letter, like in Jaws, do it, for example deadweight. It also means that I can do something like that character. And now let's create a pointer that will point to the address this pointed by that guy here . So too, the first letter here. And then I can do something like that again, for example. But now I can do that. We've p and everything should work. Fine. As you can see, 112 to 1 wanted to. So the guy will the same things like that, you know, maybe like how to transfer that guy here from strength to characters have to do that. Is it possible? Let's see. Can I do something like that? Occur characters Thanks to equals that way. That text you Can I do that? As you can see ng, we can do something like that goes Hugh. We have a narrow that saves us initialize though. So the guy you face So he is not able to do that to determine size of text to So he doesn't know how much of that. Thank you. But here, right. And when I put something here, it says it is invalid initialized. It's because the text the three and we want toe Assane three ng so different type two characters well toe area of card and we can do something like that Well but let's try to it this time Dead way. And what would happen now in Urban said that we cannot convert the string So the character s a So to the pointer the car but a string There is a method that allow us to do something like change the string You do that type you so this thing will return us They're pointer to the first letter here that seem as you can see it's still we can't do that because it is returning the constant. So is returning during that way that we can't change later letters in By using that point, let's check it out. If we can at least send the output valleys. Well, let's go into the guy's him because we don't need them down. So I want to send it out that this is a test, something that if you consider these attacks and everything, works fine. So now we know how toe change. Drink too. Come on. Okay. How to do that the other way. So I have, For example, um the A Write off some lemons and theories Here is text. Now, can I do something like string tests and can I sinking area and now sent it out? Test as you can see these way, everything works Fine. So very there are some of the programs like to the live are of scene. You want to do something like that? Okay. No, I like to tell you about something. What might be be weird for you? Because we can way we can do something like character. And then, for example, a equals. This is ah test So let's think different. That has. So now we consent, ese the album A Because it is a dozen, this big number here. But we can't change values. You can do something like that. It's a symbol war because program with stopped working and why it's happening like that. Because these guy here is being created when we're compiling the program as aesthetic sing , it means that it has award constant. Right? So it means that we can't change values. Okay? And he we have just and in that a point point where we have an address. So the first letter here but this that there cannot be changed so we can send the output folded values easy, but we can't change the values. Okay, So in order to prevent errors, we should that here constant we don't need to. But we shoot at heres something like that and then we won't do something like by mistake goes, our compiler will tell us. Hey, you can do that. Okay? But ah, it's very confusing because you know, we can do something like that. Easy. This is a test and then Oh, sorry. The brackets are here. Break Andi, I can send it out with being. But I also can do something like being and then change the value. For example, the 1st 2 day G. I can do that and you might be no like But why? You know, our compiler is thinking like that when he sees that guy here is reserving the space for a pointer and then is saying to the Valley Off the Pointer is a saying the first address off that sequence of characters. When he says something like that, he's reserving space in memory for so many letters like you. So he's counting them. And then he's a saying to Oh, off that reserved spacing memory, dead letters. So there's a big difference, right? This is some were in our space. We don't know exactly where where everybody disappointed by that guy and the dis constant. But this guy is not a constant. Okay, we can also do something like that car actor, and then we can, for example, create Mills is the dynamic Alright, for example, like then and now here equals and new character. And we need, for example, 50 of characters. Now I will deal. It's at the end of the program reserved base, just in case. I don't know the Remember about it right there. So now it's done simply, okay? And I can ease these a saying here. Isn't it toppled? First, let's see what's there. So we're sending it the output. As you can see, he he are random characters because, of course, that guys here ah, reserved dynamic Carly. Right? So we have to saying here something. We can do it that way, for example, Alarm and everything will work fine. But we should not is one thing after saying that guy here that starting value here cause it's a static guy it's constant, this constant value. We can't change values inside like that animal. As you can see, it's not working the look before that we can do it easy. These working, but it's because we changed. It's here, and we also ah made a big arrow by doing the line here because way after dead, we're not able. Teoh delayed that spice him. That was just dynamic Kelly reserve. So be careful doing something like that. We can do things like that. We should adhere. Also award constant So by me steak, we do not change here. The address that you are pointing to. Okay, so now everything works fine. We should also somewhere. And these, for example, with the blacks are zero. Well, as you can see in the sea, that was a bit harder to create characters you can just use string, so don't war. I thought Italian that when you created area of three ng self example string array, off strings. And now, for example, five of them and Seiken saying toe all the strings ALS The sequence here, some text is is a text that we'll be in all of the elements of strings. And now I consented. All boot, something like that. As you can see now, all strings are like that off course. I can change here easing that guy's other guy. And we don't have to worry about memory like I told you before. But I was I told you all about the things here because really it might happen in your in the future that you I want to read something from the sea library because steel, some people need to use them. Ah, are you need to write something insane then that information's here should be really, really useful for you. Okay, Does own the lesson. Thank you very much.
33. Functions and pointers: Hello, everybody. They were going to train pointers. They were going to see how useful pointers are. Okay, so we will start this lesson from example like debt When I have a variable, for example in a And I will say to that variable value 10 and I want to change value under the address here. So eso in this variable In another function, I have to use the re ference or pointers. Let's remind the of the version with the reference I had to do something like void multiplied, multiplied by then. Ah, what are humans and our function? So the first argument is the re ference and the second argument is by what amount we want to multiply by then after creating the prototype functions. So after declaration of function, we should create a definition of functions. So the body of and now here we have the variable that we want to multiply by something. And here is the amount that you want to multiply by that guy because this is a re ference. It is. It looks like Ah, the definition and initialization looks like that and equals here the ed And now the river is just the nickname for a right and because of dead. Now, when I, for example, do something like that, I am changing the value also here. Right still. Now, when I sent it out a after, of course, changing it by debt function here, for example. Let's multiply 10 by five. We should see here as a result, ribs. Ah, of course, A, which actually has There is up 50. Okay, everything works fine. What about if I wanted to do that thing by using the point, it will live like that here. I'm taking a pointer right now. Of course. Here. I'm changing it also. And now I should use here that Esther is right. Because the pointer is worth. Pointer is a varietal that can start an address off type that it disappointing to so that under here can start an address off. Um, the variable that is in teacher. Right? So right now we are sending a here. Well, we shouldn't send an air here as a value, because we should send here what an address? Because we want to start an address. So I'm sending here right now and address off, right? And Hugh, it would looks like like that, Something like that. And now we have in that dressing that guy and with the asterisk you we can get the Valley Room death address by. Well, let's maybe do a dead way. Good. Look a bit easier, right? And now let's see, it's working. As you can see, the value is again 50. So everything works fine. So I'm reminding you that we have to send an address here when you are taking their when we are declaring Here is a perimeter at that point. Right. Okay. Now I liked also tell you how to return pointers. Well, if I do something like that and now I return here something like that. I am retiring on value. So if I do here ain't being. And then I was sent. Beat it out with you. I should have 50 and 50. All right? Everything is okay. But this guy here right now is total of different for able Now, when I thank you for example 999 we'll notice that we changed the value of B. But we didn't change the value of I. If I want to return the pointer, I have to adhere also as the risk. Of course it can hear it can hear it can be here. Don't worry. This is just white space. They're not interpreted. But well, I prefer the notation like that. And now look, I won't be able to compile it, because here we should return. What a pointer! So eso We are returning, appointed, and you're trying to say no to the guy that cancer pointers right now when I change it to s Terry Scare, I can start with easily. And of course, no. We should change the village dad way. And we should also return the pointer. So we're not returning value, but there address right now. Let's see, as you can see. Ah, of course you like that. As you can see now I change the value here and also here. Okay. So Ah, that's how you can return. Okay, that think, um if we could only do that things with pointers, you will be. You wouldn't be happy now because you would be like, Hey, I last lots of time. I could do that. Things almost with referring right. Was everything like that? Yes, but look right now, because of pointers, we can send to functions a raise before we couldn't did it. Because a raise always are in our memorial start that way there are next to each other, right, and because of pointers because they are starting gathers the first letters of first Lemon in an area we can jump one by one enlightment, right, because they're next to each other and we can just send the first guy in them can jump to the next. And I'm sure that this will be no. My value ins and Harry some right? Okay, so let's create an array. So in a way, and let's make size you 10. That's saying he reserved the beginning. Or maybe we don't need to do that. Well, let's just say value to all off the guys, Hume. So let's do something like debt. Eric. I it calls, unless the same just him. And let's send to the album so you can see How does it look like right now? And let's compile it doesn't concede. So we have 01229 We can send it that way so it would be easier to do it later and de bark our program right? So check it. There are in the box. As you can see now everything is working fine. Okay. And well, let's create a function that will be able to change well with will multiply our right by some kind of values. So multiply by Ah, multiply area by And here, for example, I would take it I'll create two parameters ain't And now it will be Pointer, he right will send a right here because name of a wrestle did you awry is really a point, right? So we can send it here like that. And then we have to also send Of course, the amount of want to multiply that guys by ups I didn't copy death. Now I think it's ok, so let's name the guys alright? And here I will type amount. Okay, so Ah, well, we want to multiply that guys, how I would like those that you consent arises that way Also that way it's ok to so you can send every dead way. Well, let's do that example Multiply All right. Bye. That's an area. And then, for example, by five Fine. As you can see, everything is working a on We can of course that both ways. Okay, Okay. And now how to change Philistines off? For example, a skating lib on I is Lord, and then than I plots Plus, and then we should just air a I equals all right. I multiplied by amount, right? And now we can send it. Did the our food that's going that got here. And we should just see everything multiplied by five today. So everything works fine. As you can see now we can send easily arise to functions. But, hey, you might like Oh, why are you typing the 10 here? Isn't it too easy? Yes, it's It's three too easy right now and and it is very bad idea to do that way. Um, because I can change it right now here to, for example, six cents. But they will have to change here and here. The demo and well, I could do it as a council. This is a good idea, but is not still the best light here because, ah, for example, what about situations when we when we are dynamically creating a rise, then we should check the size of various, for example, how to check the size of that era here. Let's send to the Albert something like See out size off, then name off. Very. Let's make a few more. Just just comment. That's him. And what will see Ups building? As you can see, it's 240. Why is it so well? Let's make it a bit lower value for 10 in this fort because 10 multiplied by four is 40. So this function is returning us how maney bites are stolen memory for an error like that. When I do something like size off in teacher, you'll notice that now here is for So this is giving us the size of integer. When I do something like that, it would give us the size of one off lemon in the current. I think this version is the best, because might also change this guy to double later. And then I'm here also, it will change. Ah, other things. You have to come, singer. It's a function. But well, you know what? Okay s So this is really a better idea to use something like that here and now we can off course. This is also something like that, Sighs. Oh, our air a divided by the size of type that is right now. Here. Well, just give us the size of very So it is 10. Right now. We can just use it now. We can just change it here on. It will work. Fine, as you can see. But there is a problem when I do something. I like it here. So when I change, check the size off the pointer. No, ordinary. Here is a pointer here. We have an area. Ah, that was created by as and here we can check the size like that that way. But here, look what will be what value. See this far as you can see, so is wrong because of that unlikely in C plus. Plus we have to send the size off airway to the function. So we'll have to sent it here dead way. And now, of course, it's changed it here. We can off course. It may make it dead way also. And now let's see if it's working. Um oh, that's changed the prototype also. So the declaration function. And now, as you can see, everything works. Fine. Now let's trying to be itself example exchanged it law to something like Why the size Airway Minus minus. So until we see here, the zero please execute the instruction below size of for Ray. Emma, let's saves working. As you can see, it works too. Okay? And now how it works. Well, we're something the size of worry here. So 10. So we have, ah, insights of a right 10. And then here is ah, post the decriminalization. So we are discriminating it after checking there conditions. So if then it is still Then we are decreasing it now. And you are changing there. Value that this under the area off nine. And we are just multiplying it by that amount. So that's how it works, right? Until this guy here is just zero. Okay, I would like to also add now that you should notice that this guy here, right, that area is being said that way. Known that way that we are sending the address here because remember, if I did it that were here, I would send the address off a pointer. No value that this start in a pointer. I know that the point of his also storing the address, but it is address off something else right. It is snow address off pointer. But it is address off. Ah, off something that under it weakens. Find value, right? Present like that came value that these double that this fall or something, for example. Okay. And so it means that we can sent here a dead way that we're sending it here. The first lemon, everything will still works. Fine. Ah, I'm telling you now, that area off zero, it calls the name off our era, right? Because it is really boned. Okay, there's all learned it Lesson. Thank you very much.
34. Lottery - pseudo-random numbers generator: Hello, everybody. Today we're going to learn how to create a pseudo Rendon numbers generator. So we're going to learn how to draw numbers from some kind of set. Okay, so how to do that? But we can create, for example, ever able that we started random numbers off example in teacher number. And then I will Assane here their results from the function that is killed rent. Then I will send this pink to the out and let's see what that I'll put this. It is 41. OK, so let's combine again. And as you can see, it's a game 41 that's complained again. As you can see it, this 41 What's so great? It is really random number, right? No, this thing is called pseudo Ron, remember? Well, you know what is the difference between the Suda Rambo around the number and the random number? Imagine, Right now I'm having me a cube in my hand and I am throwing it. I might throw it. We've a bigger, strange or lower strange right on every time. Ah, that cube can meet different off cycles on the way. Right? And then this is a random number they'll tell a random because we don't know how exactly it will react with the environment around, okay? And but the pseudo random. So the pseudo random number, it's going always. It is following some rules. Okay, He's following girls because it is computer. Right now he cantrow Cuban Teoh even know. Meet this. Ah, obstacles. The random off cycle suit. And he doesn't have strange in other things like that. Okay, so he is following some rules. Always. Okay, So this is Sid Iran's and even And we can send the rules for debt function here by using the function that is called the S Rent here in that here we can send their roll. How debt function will be working day. This thesis s is here stands here for seat Ah, seats. This just a set off values that we will ah get a random values from right. So I type You're not 400 you'll notice the disease ramble. This number is new. No. Right. And now I would be to the game. As you can see, it is still the same. But this is no now the 41. So it means that for 41. He was different number. Now we change it to different number. Okay, let's see what do happen when we do something like that. As you can see now we have three different numbers. So every time we have different number in school. But hey, every time around the program that number is the same. But when I changed that think you to something girls did. Numbers are being changed in right. There are different then skill. So it means that we need something here that will change every time I execute the program. Tell me what think in our world is changing every second who I just told you It is time. Look, we can send to the output something. Ah, what? The result of the function that is called time. And here we consent as an argument. No, because thes function is taking is a perimeter. Ah, pointer. I don't want to go into the details of the function, but well, remember, the dysfunction is giving us as a result, the how many seconds are gone from 1090 70 or something like that? We'll never It doesn't matter. It's the most important thing about that function is that the seconds every time will be different is considered the end. We have 26 now, a few seconds later, we have now here 32 right? So it is changing is the most important part in debt. Now, when I do it that way, you'll notice that every time I run the program dead numbers, um, will be different. Great kill. So now we know how to I have always pseudo random numbers this. OK, so now let's greet the function that well, repressing the lottery. Okay. Debt function will be called lottery and it will not return anything right now. And we will take two parameters here. Eight to in teachers. The 1st 1 Let's specify dysfunction. Here will be how maney in numbers we will drove from, right? Some of the numbers we'll have in our set. So for example, 49 a second we will have What Maybe you can do that. We, for example, total balls. And here I call it Bulls to dro are both two allowed that are the same wars. Okay, uh and now Ah, we can create that function is like Quicken. We'll use it later. Like that. And we'll send here, for example, for tonight. Here seeks. And I want to have ah sent to the ALP a doctor debt invoking of the function. Six numbers from 49 they want them to be all random sued around the way. And the first thing we should check what we should check if the total balls is lower than bulls to dro. Why? Well, because we can do something like that. All right. You can get 1235 numbers from 49 day and to make them all different, right, they get that can't happen. That's impossible. So we should check it. And then if the total balls is lower than balls to draw, we should just return. When I told you that we can return on the finger into here, we are returning devoid because it is the empty. As you can see, we're retiring. Nothing. We don't have anything after the returnable. And this thing means that we're just leaving that function. So every instruction after dad here will won't be executed a dull Okay, so now we should also also create a seat right like that. Okay. And Now we will create Dynamic Alley because that think you can be changed every second area. So we will now create a pointer that we call balls. And we'll a saying here by using the new operator eso, the new operator will return here the address for In teacher and the first address in teacher Array that size will be balls to do it right. So we'll start here The balls that will be drone in that function. And so and I shall delete that balls at the end of the function. Right? Well, I should delete bye bye bye. Saying deleting I mean that I am releasing I am freeing the memory That was dynamic alley reserving right, Remember about it is very important to do it here. Okay, so now we should just get the trend of numbers four and I equals zero and I is lower than bowls to dro I lost plus and now issued just a saint Balls off i something, for example, random number. And now well, when he drew numbers that are between that are in range from 1 to 49 Soon I will tell you how to do that Things and Let's send that think to the Albertson. It seems the result. Well, let's just needed is against the we have now numbers. We have no six numbers that are random, but we need them off cars to be from that range here. Okay? And he will lose something while this called them more. The law operator. Right. We're coming back to the first lesson. And here, when I do something like that, look what would happen. As a result, we have now numbers from zero to 4 to 8. Well, maybe let's train this finger bid, he'll in number random model, for example free and now then sent to the output, The number and did way. Those of the sink. And then And that's sending. As you can see this think Waas one now is too and I would be a game and then it zero and then it is one and then it is too. And again it will be zero because that's how the model operator is working right is given as the reminder off that value here. If you don't remember how this operator works, please go back to the six last knifing Derek meant ah, lesson and you will see how the operator works is really important to understand. So now, by doing something I get we have the set of numbers, like death. But I won't do Have 2 49 49 of the guys, right? So by doing something like that ups the comment. I would have numbers from 0 to 48 Right? Dead way. If I want to have from 1 49 I should just add after it just one, right? And then I have numbers from want to fortune that Okay, so let's use the information Didn't just seen here. Um, let's just to it that way. Here, as on and off course, that's really deadly. And as you can see now, we have pseudo random numbers. Hey, but this guy's repeated here. They're the same. We can't do something like that we want to have while the most time in the lottery. You want all numbers to be different when I do something like that. Six from six, as you can see. Well, of course, here is not 49 but we should change the guy. Total balls, as you can see, did numbers. Sometimes we'd be repeated and we don't know. So we don't want situations like that. I want all numbers to be different. And now the true Ah, hard fingers stop. Okay, so how to do that? We should just check all the numbers that have already. Bean don't right. And if there is ah, bull like that and it's set, it means that we should a gang repeat the drawing of numbers. Right. OK, so let's create an inner function here. Dead the wheel. Be that will be invoking the instruction. How many times when ah g is lower than I? Because I will represent common tables. We have already drone right then g plus Blas and we can now check all both one by one. Okay, so how to do that? We can do something like that. Eighth balls off. I equals bowls off G, right? It means that we showed just dechaume in the eye. And because of that, we were just repeat Ah, the drawing off number to that area. And we can break after that easily because we know that the if one guy is repeated, which you don't need to check other balls, right, but also should notice that the G my B here, once equal to I find because they might be equal here. We he will check the equality off to the same balls you're Jackson like is balls off zero ah, equal stir both off zero It might happen. Something like that happened and of course, is true. And then this love would start being at the infinitely right. So we should check you by using the conjunction If the eye is not equal in the same time to G. So if they are equal here, which we won't just check a check the check The equality of values in the earth. Okay, now and well and otherwise we'd just send to the output Well, us if the G is equals I So if we end that look you it means that the ball he'll that was wrong for sure wasn't ah repeated value. So we can send it to the output easy. For example here both off. I right and life. And now what would happen as you can see Nothing. That's because these being here needs also hear something like I plus one now all the values you will be always different. So I'm changing 49 on. And now I have six numbers from 49 their old different. But why do I need the plus one here? Because I told you once that the condition in four look is checked at the start at the beginning. OK, so it's check at the beginning. We have to remember that the I at the beginning here was zero and we're checking it. Zero waas lower than zero on. And then the condition was just falls right? And that love wasn't executed. A dollar and we couldn't send that. Thank you to the up. Right. And now everything works fine aids. Okay, right. Kill. Okay, that's all in the lesson. Thank you very much.
35. Type Casting : Hello, everybody. Today we're going to talk about typecasting. Typecasting means that we can convert one very able off one type to another type. Okay, so it means that, for example, I have double value 5.5, right? And now, in sending into the, uh, as you can see, the output is right. But what if I wanted to change the double toe in? I would use the type casting here. The expect one. Okay, so it means that we have to tell about it. I will use the parentheses and in parentheses, our type, the time that I want to castillo the variable after. So I want to cast fire to the anti Jew. And as you can see, we lost their value after the dot, Right? Okay, But, hey, these was bad thing, right? Ah, because where we lost their value after the adult, right? But sometimes something like that. This use of example, I have very big like that and variable like that. And I want to divide a by B. Now, as you can see, the result is zero. Because Bob variables here are what ah, integers. Right. And now I can change one of them to, for example, Double. And because of that, the results will be right. Because if that guy is double that they're able is being converted is being costed implicit . Okay. So we can cost the expert Guay. So the XP great is like, for example, that is that explicate way? Oh, we can do something like that. For example a I want toe create two variables takes and short Why that will take x You as you can see, we can build the program. Everything works fine. But you know that X can start a bit bigger values right than the short one. And we can walls here that some digits. As you can see, we are allowed to a saying that they're able to hear, but the result is wrong. Okay, so we should be careful. Ah, debt think can happen easily. This is the implicit way off casting. So we don't have toe specify headway in parentheses. But be careful because you can lose precision, right? Or we can lose even old number by doing things like that. Okay, so I want to tell you about all XP quays. No, the extra grey can look also like that so we can use it like a function if you work fine. Also, you could see five at the end and we can use something like that static cast and then in the in the angle brackets the time that I want to Castell Extra great in C plus plus in the past. Plus, this is the sea version. And this is also see version. Um, sorry aesthetic, of course. And as you could see, it works also fine and where maybe it would be more useful, you know later will know something like class and other things like that. And then things like that would be more useful for sure. But for now, for example, we can check what value in the escape table character eats, for example, character. And now I can type your key and I can sent to the output a dead way. But I can also change it to the integer type. Does you can see it's 107. That's check if it's true. As you can see, the K is at 107 so we can easily check the value. The true Valley off character, for example. You know it might be useful because sometimes you have characters that are on Lee in your council. For example, In my contract with a character like that, I can see that this character is the same toe minus 19 1 And because of that, I will know how to check the characters, right? They are not in the escape table. Because here I have values from 0 to 127. Ah, that character was minus side. Okay, that's all in the lesson. Thank you very much.
36. Creating project, external execution of program : Hello, everybody that they were going to lend How? Toe execute the program from the external place in the same time, I will tell you how to create project Okay, in order to create the project. So something that can starman if eyes so something that can help us. Organized Feiss, we have to create here, file new and then find the project. We want to find in the council application here because we are creating consulate vacations right now. I think we go next. She was the language they want to write in off course. We're choosing the c++. Then we should name our project, for example, first project. And then we should choose the folder. We want to save it right now. We will save it here in our lesson. 35. Ok, and then I click next here. We can change the compiler, but we'll just use the one that this year and I would click Finch. Now I've just created project. When a Keegan view we can hear show the manager off our project. As you can see, here is the folder sources And here we can create new fighters Father knew and then five countries world type of five want to create Here it Ah, it can be the heather, which is the library. If I and other things like that about dead will talk in next lesson right now, I want to show you how to execute our program from the external place. What do I mean by saying external place? Well, you know, our programs can be used by other programs or they can be use from the place like that in order to show the thing here. We have to type C m d. When we click on the start button right in the windows. And here we can change the director t d then go to the path off our project. So here, um maybe that's compliant first when we compiled it and build it. As you can see, we have here now. Two folders Been an object. We will go to the being bean. And here is the exit five that we want. Teoh Youth, I recall, pleaded pef here. Then I will creek right button here and then use the clay which mean past and well we have to also say something like CD change directory. Of course, on then we are in that folder here. We can use something like dear, which were se us. What files are in the folder you can see Here is our the first project. And we can run the thing. As you can see here, we got on on the output hell award. So everything we do here's off example something like that. We'll see after building the program here when we were on a dead one. As you can see, everything works fine. And maybe, you know, you did not know you, can you? You might have noticed that you can run programs here by anything, something present like that, the darshan than age which should show, for example, help off our program. Oh, are we can run many programs by adding other letters that will change the meaning. The I think that the program is doing right the way it is doing. And we can also do things like that here. Remember also that our programs might be run by other programs, of course. And how to do that? Well, we can create to poorer matters in the main function. The first parameter we can call for example, arguments. See from arguments counter that guy here was store How maney things like that here we'll be sent to our programs in our situation is 12 free for five? Well, we can send it to the output so we can be then Rhonda, And then do something like that is you can see we have five, right? Okay, because ah, here we have four. And that thing is just count on this one. Always. Okay. And after it, we can create something like that character. Then the s a risk, then called. It's like, for example, arguments, values and then two square brackets. So arguments values on here will be solved. The values is are sent to our program. So now we explain How does it work? Well, maybe that sent all to the output so we can use the arguments counter noted to send all that guy's to the upper right? So it is very helpful. Now we can build it and then here and I said it toppled issue can see we have one toe free for five things like him. And you can use the things right. So, for example, we could check one of them is for example, Dash H and then send the help of our program how to use it, for example, something like that on how to do that? Well, first, let's talk about that declaration Here, look, we can create characters dead way a B see de, and we could just counting. Then you consented Teoh up, for example. When I build it and run it, as you can see. Oh, as you can see, we are sending to the Al. Put that a B C D. Here, right? And some other random values because we need to also end that guy here with the backstory. Zero. Now everything works fine. And this is one off version that we can you create. Eric's right, So it's like, Hello, that something like that. So this is an area off correct single characters and we can also do something like that. And this thing is just like a saying the address of the first character to the point, right? So on, by sending beat the album, you just get all that sequence of characters, right? Okay. And we can just combine the two things to achieve something like debt. Now I can just create an area off sequence of characters so I can do something like, um ah, on and something That's right. So we can we have no air, a off sequence of characters. So now we can send it out, for example, See off zero. And you can see it is being sent the output. All right, all right. It works. Fine. Kill. So this thing is like that because we want toe I have all that sequence of characters are so you can start your sequence off characters in area. Okay, great. Now I want to show you one more problem. The problem is, we have something when I create something like that and then create something like that. And when I comported things, so when I do something like if x is equal toe, why what? Verily I will see him as you can see it. Zero. So is the case. But what if those values are the same as you can see? It's still zero. This operator is not working like you probably think home something like that because we should know that the name off is what name off area is a pointer, remember about So this is a pointer. Disappointed what? Its start in pointers and address. Okay, so in pointers we are storing address that think here and that think here is start in different place in memory because they are start in different placing memory that things cannot be to right, because this is really something like that. We're changing. We're checking the address. We're checking if the addresses are equal off that varietals. All right. Okay, so that's being with zero. So how to compare characters like that? You know, normally, when your foot you when you have strength. So you have seen a law on and drink. Let's go. If they want to do, you can easily use that operator like that. As you can see, everything works fine, because string is really close. We talk about class, laters, and it is overloading. So it means that it is changing the functionality off that operator. So that's why we can compare things like that when they are strings. But, hey, we are getting here really argument value that are not safe, like strength. Right? So we have to know how to compare it. We could write our own function to function, to do it, but there is one function that can do it already. It looks like that three Inc come per so as the R C M P sense for string camper reason and then in the parentheses were just sent arguments that want to compare so X and y, and then we can send it to the out. You'll know this, that the result is zero, and it's OK because, ah, it's the air company. Reasons of string comparison returned. Zero ah, when it returns there. Zero. It means that the that variables are the same. They're equal. In the end, it is one. It means that the first string is greater when minus one. It means that the first three Inc is lower. So when I changed that guy to be, you'll see that we have minus one right, because it is greater than be in the SG table. A has higher number, right? Then be okay when I do something, for example, like that those little checks He's right and then changed that guy. That guy, as you consider they will have the different value here, and it it's used. It is good to you, something like that when they want Teoh sort strength arrive. OK, so we know how to compare now that thinks so. We can create. Well, we can use that think here and let's do something like that. Lisk get the things go in and well, there might be times when we want to check if, as their company reason. Oh, argument Volume five and then eighties, for example Dash age. I want to run function, for example. So help Leslie Claret function here. And now let's find it function here. And that function here called Do Something. Many sanctions where we can send to that it is. This is so her full did. You cannot stand it. Rise something like that. And now we can desire program. We can run it now from here. We've Dutch age here, and as you can see now we have in our output these so couple that you cannot send it. Of course, he would be some messages that hell. But how to use that then? As you can see, um, well isn't working fine. Still, because the Esther camp a reason is returning zero when it is true. So we shall do hear something like that if it equals 20 then it's okay for us now. As you can see with the dash key, it's not working bod with dash age. It's working fine. If anything here else, it's not working. Fine. I give here Dust age. It is working fine. You can place that think in and the position when we want to make sure that, for example, age dash ages on the first pushes position, then I should also check the eye right? And in the same time I equals one. Then show help. Otherwise don't do so now. Why not do something like that? It won't work. But when I do something like that, it works fine because it's on the position that I want it to be. Okay, that's on the lesson. Thank you very much.
37. Preprocessor directives, Multi-file project : Hello, everybody. Today we're going to talk about purposes of directives and 45 product. Well, first, let's talk. Why should we create Morton 15? Imagine situation like that. Your program is a bit longer, Longer, longer and again long magnetized in these guys. So your program is about, for example, 1000 lines right there is. There is much coded. And then you are decided. Hey, I have to change something here that I'm making the change change. And then I have to work. I have to all compile the program, right? And the compilation will take those of time because your programs longer now, right? So it is taking time off toe, compile something like that and imagine our institution like that. We have magnifies. So now I am dividing the 1000 line of code into, for example, 55 And then when I change something in one of the fire, we have to combine Onley one off that fire. That five that has changed. So we don't need to compile all the cold again. So our program we run well, we compile faster, right? So we are saving time because of that that the one of the reasons. And the second reason is that ah, well, our program will be organized because of creating man. If I write, it would organize. And because of that, it would be easier to find something in, ah, our program. Okay, so now how to create and you fire created mortify products. So now I have to create a target. That source here, then five, then new, then the five and then the heather five. Here. The heather file is something that is used to create libraries. Okay, so I am creating, like, nah, right now the heather file, and we can go next. And please always remember about clicking here because later he might have problems. We've compiling. So remember about that. And now we have to name our file so I can name it. For example, our first libra. Then zap the shootings safe, and I would click finish. As you can see, our I d has created already here some line off skull that I will explain you later. And now we should know how to how the US that hash things works. We have already been using something like the proposals, some directors, but we didn't tell about them. So Marjorie goes, I think that it was too hard topic. Then we just say that it is the library that these just included here and we can use lighter because of did it, for example, something like that. But now I would show you that we can go to difficult. For example, I can go here. And as you can see here is some cult. And in that cult, we also does something like that that includes something and that could include something and other things like that. Okay. And how does exactly this thing war? Well, it looks like that the pre protester directives works like that that they are executed before compilation because they are pre processor dire. It's OK, so it means that before the compilation, everything here that is looking, for example, like that is being replaced by, for example, something like that. You'll notice it now on the building around this program, everything was still work fine. So I could also go into that thing here into that in Kenya and just copy and paste. But of course it that think would be bad, because every time we change something in our program. Everything from the beginning would need to be compiled Will take time. Now, we don't need to compile the thing that these that right. Okay. The next example is, for example, something like defined. Find something that can define so Concrete's Something, for example, can say that I want to in every plies on our program change by two free 20.40. Now I can just something like that and before copulation that by here would be changed something like that. So now when I didn't around the programs, you can see with three point hard. Okay, so now we know. How does people's this a directive? War and, well, let's, for example, use our first library, right? I will deal it this cult for a second. And I will do something like end a equals stand here, and I want to include our first library. In order to do it, we're going to use the quotes. No, the angle bracket, our first library that age. And now you notice that I can use Is Lee that thing here? Because it's really that think he'll is being replaced by that, right? So let's see, when I didn't run program. As you can see, everything is working fine. What is the difference between that quote science and think of Barket saying, Well, this thing here is really the library that is said in our compiler cities. Okay, it is set in our compiler city and the path to it is just absolutely right It But if he's known and we can use something like that when we want to include five, that is next to that fight here. So it looks like that that are first libra. At that age, it's next to the main see PP. We should deals the quote signs. Okay, and now you have not. Did I remove this? Some culture that code is re gold, that it is created by our i d. Because we normally would need to create it by hand. And as you can see here, there is very similar code. There is something that gave no defined defined. How does it work? Well, you're not is that I can do now. Here's something like that and something like that might happen by me steak. Sometimes sometimes it's needed. And as you can see, well, it's working. Still has so We could just copy the cow out in Iowa Stream many times. And the thing is working, how is it even possible when I coping that guy him and they build ungrounded program, you'll notice that it's not working because it's telling us that has already been defined. Well, it's true because it really looks like that we can define So reserve Memoria for the same. A variety of the same name, right? So we come to something like that. So ah, how how it happened, It an hour streaming work? Well, it looks like that I'm just back to that. Place him on. Let's you see how does it work? That is the process of eyes on directly. So it's working before compilation. If something good is called like that is not defined, please define that thing and then just do everything after that until meeting the anti that anti visa like the closing Carol Brockett. So we are defining it. They're able here, and that's all. But when I do it about, for example, three times and I've been around this program, it works now because in the first time, when we, when their purposes Aries doing the directive. Hey is checking that is not defined. Defining it on second situation. He's checking. Give it ill defined. Well, it is defined them. So everything from to go to the and if it is not going to be executed. All right, so that's why that goat here is really good. I know that the situation like that probably won't happen, But you might include a lot of men and libraries in other libraries and things like that on that mistake might happen. And because of that, everything will work fine. So that, I think, is really, really good to do something like that. Okay, No, I like to tell you about something. Like the x turn Rabel Several able is bere able that should be should be in other place and define So this thing it's external outside. It means that here we do know reserve memory memory for were able a so four bites are no the reserve at all. We should have the that variable defined somewhere else. And there's something Well, this called multiple functions right and then can create any library. So, for example, functions show help, and I can just have you declaration which is automatically external. We don't need to adhere External X turn and we can create it outside off the library here on. And it's always being down there the way and in programming. So that is well organized code. Now we can create, for example, a source code again new five. And now I would choose the c++ Sourcefire girl next C plus plus language course. And please remember about doing that. Think you take the Deep Bargain Realty's. Then we can call that thing we call. It s the same, like like our our first library, and we'll click safe things. And here we should just create definition off that things and a 50. And now the function This is help, right? For example, like that on, of course, the quotes. And now we'll need to also use your name spaces to the and include the ill stream so we can use the C out easy. And as you can see, everything works fine. We can now use the function from our first library. So, for example, show hub, he'll that everything would work fine. And you might be now asking yourself, Why do we do something like that? the two Farsi Notice that later your cold might be be longer and then you just go to the but fire that is ended. We don't dot h to look what you can do, You know? So here would be just a declaration off function declaration off variables and they would be also for example describes So there would be something like this is going toe hell view . Right? So everything is going to be described here and you can read about that. But if you need to change something Oh, are you need to know how code works? You would just go to the file that it's ending the CPP and just go in. Look e there is there Is that function right? Change of view if you need. So it's really now organized, Zairi. Good. Ah, you should now notice that we also can, for example, includes Io stream sheen You could use for example nine space here, right way wouldn't need including that thing here. Everything showed work fine, but well, maybe is more read able when they do it that way this time. Okay, there's only the lesson. Thank you very much
38. Data Structures and Pointers : allow everybody that they were going to talk about day tots Directors structure defines how we build something. It defines what something is constructed. Right? So data structure is a group off date Lemons there somehow connected with each other. Everything. Well, every object is built off some elements and data structures. Let us define that Lemmens structure. Little skate, a new type consisted off other type. So it let us organize our coated. So how to create its structure? We should type a world structure. Well, instruct. And then we should name our structure, for example, will name our structure personal data. So it means that it will be structure that will be consisted off a lemons that are connected with personal data. Right at the end. Here I will add the semi color. And here inside its structure, I can now define variables I cannot declare them so something that is defining the personal data. We're going to create attributes, right? So, for example, string name, string SAR name. What else? Doing where, For example, String, telephone number and for examples. Short age. Why? Something like that? So now we have a structure personal data. It is new type this hour type that we just defined before Normally that thing was written dead way So we were the type definition were defying our own type. Now, in the simplest floods we don't need to add that toward him And we can use the type how to use. For example, we can create Alvare able. The type is our personal data and I will call the variable person right like that And now I can use that person how to use it We should just use that variable did just create it and then use the dot sign So this is the operator that let us go inside variables that are inside the structure right? And now I can change something, for example name to, for example my name sar name to, for example my sorry name on and tell Eiffel number to note my number and person hate Ah, 22 for example. So now we have just learned how to the same values inside the vory able type Is that our type? Where is the structure? And now we learned how to send things like that awful so we can do it for example, like that Nice urn toe level number. Just copy that things here and building on our program. As you can see, everything is working fine. So now we can start a few of arrivals that are connected to each other in one variable right in one variable here. Because we just created a new type. And it's very good, because look, now it's organized a bit. Now we know that there are connected to each other. Okay, this variable here is working like all other were able. So it means that I can create a rise off people, right? So I can now create person on now. I want five of them now. I should also do something like that. So I am now changing value first person, right? We can now, if I did that way, for example, here that first guy here, the zero I didn't have any value but that one value because he's just a saint himself. Okay on. And now I like to tell you about point or something. Something special about pointers when we talk about structures. Well, now I like to tell you that the name of all right is appointed, right? Like always. So we can use Barson Pointer Also dead weight. I won't get you. You that is under the address. So it's like the same like here than that name. I want you to know all the where you can get to the value there because some people might go into the place to be a different way, so we don't know them. So now, as you can see, I also go to the name here. Let's say the name to the second persons off example here. Like, for example, dead name. And now I will try to get to the place I can get there, for example, died away. As you can see, everything works fine. So these one off the version, their friend, the next version is, for example, that way, right? Because this is a pointer. Really? So there is an address start first of lemon. It's another thing Would work also fine on now something very new. And this is very cool Operator. We can get there by using something like that. That arrow here. So it means that this point are it's pointing toe that think you right. And as you can see, everything works fine. If I want to do? Get to the next limit. I would do just something like that, and I would I will get on the output. Oh, the right there. Also, you should know that you can create the variables off type personal data here So I can do something like that, for example here and then, as you can see now I can get a judge and I consented to out, for example, like that. Let's see what's working. It works fine. So you can create here that I get fast declaration of variables into center. We can, of course, create, for example, personal date Ah ah, pointer, for example Like that. And it can point the first address a fear Then I can send the output is really just by does that way. So let's coming that thinks here because they won't notice which fingers which. And now, as you can see it, everything works fine, right? We can Also saying here a dead way is a everything works fine. So this thing is really cool because, you know, on a great for example, testing, um, function on it will take your that personal data So personal daytime know for example. I recall it. Person here also, I can send here, for example address right So I can send to test P. Oh, I could send here test person, for example, like that because that our address is really right. And now, um, I could do something killed, for example person. And I can change the name to, for example, Agnes. And let's see if it really happened here. Um, whips. I should also at here in declaration. Sorry. And now, as you can see, the name has changed here, right? And that everything works fine and not is one thing we're sending here on the address off a structural on the one address, right? And three Cool, because we don't need to send here h alignment. Want to free four variables, but I need to send only one guy. It's faster to write something like that. And it's possible suffering for computer to send us an address. And then by using the address we can get to the values. Okay, That's only listen, thank you very much.
39. Classes : Hello, everybody. Today we're going to talk about classes. In the previous lesson, we're talking about structures and structures called defined, something to specify something exactly. It could specify attributes of something. So, for example, when I have an apple, I could say that this Empoli's first green is red. I could ah se type of apple is that? But I couldn't do anything with it, so I couldn't use it, For example, for anything. I couldn't eat it. I couldn't, for example, Salad. I couldn't buy it right. There might be many things done to the apple. An instructor we can't specify. What can we do with something with functions we can do? It sounds great. And in classes at this possible So class is just extended structure and ah, it can also specify the functions of something. And it has also lots of other toys that structures did not have and we will try to lower them in next list. Okay, so I'll create first structure and I will call a personal data, writes personal data, and then at the end, I will end this with semi comb. Then I would create just one attributes the age and now here I will create variable the targets, personal data, for example. I would call it person and now I will set age to, for example 50. And then I was sent this link to the out. So they're things should be easy to understand because we did it in previous less okay. And now I will change the structure to something Woody's called class so close is also our own time. Right? And let's see the difference that between class and structure s legacy. Now we have an arrow here that says short in personal data ate. Is priv ate? What does it mean? Well, everything is modification by something like that. By default. Here there is something like that modification or provide and by default, everything after it is just previous. So it means that it can be used only within so inside the class so it can be used anywhere else. If we want to use ah variable outside Our class went to allow doing something like that. We should just change this think here to the public. So we now say that everything after that I think will they public now you'll notice the differing is working. Fine. Okay, So we have to modify Qatar's now, you know, to motive cutters. Now, the prevailing public. If I do here something like that, it means that age is prevail. And when I adhere, for example name, it means the name is public, but age still previous. Okay. So prove it means that something can be used on Lee within the class. Public means that it can be used anywhere. Of course, if we create the object, recreate the instance off class. Okay. In our like to tell you, uh, what is that instance? Off class is just a single object is a copy off an object, and classes are used to define objects to describe them. Right. Um, everything around us is an object. I can. I'm looking right now at the monitor and is an object. It has got some bottles and that can be used it. It is created by its some kind of company, and all the things can be described, right? So everything is an object. I am an object. Okay, So and this is called also on instance off class, This is this is the instance of course, means that it is a copy. And by saying that it needs that when I create second person right? This person doesn't know anything about this person so that objects did not know about each other. So when I change age in that guy to, for example 20 I'm changing the age of other guy, right? Um, of course, H two public and then And now? Well, sorry. And now, as you can see, we have got now to compass off personal data mine they did not know about each other. Okay, And now when I tell you that all variables should really bay in previous sections that attributes should be in Priv ate section here. Why? Because we don't did not want people from the outside. Some like here. Oh, any hackers? Ah, and a people that don't know how to use it. Exactly. Our variables to use them. I want them to use our variables only by using special functions that we create for using rape. And the most common functions are killed like that set age. So this is the function that it will set age right? That allows setting age from here and this think she'll return the void and then it should take the integer, the age they want to set it right. So, for example, these value that is going toe saying age and then we can make the in line function here, right? We can, for example, saying toe age value that will be sent. And, of course, the semicolon here on Well, we are not able to change the think here now. So we have to use the function person and now set age. And now we consent here, for example, 50 right on. And where we consent also to the output here. So we need to create a function that will let us get the age from our class. So we need to return the short and we call it get age and then in line will return the age . So now with the person, get H in person to get age, you'll notice that in the first situations 50 likely set the second stations off course. Random, right? Because we've been set in a finger when you can do it. Concert the age here again and you are probably like now hey, she's had to ah create so many functions jobs to do then that Waas just But, um really this think it's important to do things like that? Why? Because notice now we can, for example, do hear something like that. If the value is lower than, for example, zero, then we turn. So don't do anything otherwise, that's saying the value u right. If l A is lower than zero as ST to 80 we can now decide we can now decide here how something will be said if somebody do it Wrong way Right. So now we somebody do something like that here. So he will try to sink u minus 55. Um, course, we need to do the else statement here. Otherwise did that, as you can see now, will have zero here. But no Marie, If the age was here that way and I would do something like that, I could ST easily. Ah, I could say easily as you can see minus 50 feet. And there were no function that could check the value here. Right? So now we can check easily what is coming here, for example, like him. Okay, so that's why it's good idea to make it in functions. Well, everybody notice that we have now The definition off functions in the same place where we have a prototype of functions with declaration. And this thing is also not well organized. Killed goes later. Your classes might be longer, longer, longer and it would be hard to read something like that. That's why we should create new farts new. And now, for example, I want to create five that we would have had her go next. Remember about taking that thing. See you. Then You have to choose where we want to say the and name our fight. So our first class, for example, right? Of course you can name it. You should be self descriptive name. But right now our well we could call it may be like, for example, people something like that. So that well being Heather with the classes that are connected with people right now I'm quick to finish. And now I had header here. I can now just card the think here and coupled to here then of course, I have to the include the people on that. You can see everything looks fine Now I should create the new five. The CPP version, right? So, girl next c++ create the deeper country light years than the people see PP finish And now here I should create definition off things here, Right? So, for example, that thing is now the prototype, right? And I should go Teoh the personal data You I will use something that personal data and then the operator that is called the Scope Operator. And this operator let us, as you can see, go inside the class declaration and take for example, that said, H function right on. And now I can do something like that here. Well, ain't value okay? And let's see if it's working. Um, of course we until so at him. What time we were returning So returning to avoid time Ondas, you can see we still have arrows. That's live. That's because we didn't include the head of you. Now everything You work fine. So now the setting wars. We can do also that Think we've get age, but well is one in line function. And here we do not do it one right now, anything as just the get age. So this is really good idea tojust leave that think here. But if we did something here it if we had more instructions and get h here. We should also just take that function here. Okay? So if you want to get if you want to stiff define the function to the seaside, the class we need to first. What? Say what Dived? It functions returning. Then we should use the name of our class than the operator off skull. So trying to get to the function that is called set age, then we should just, um, tell Walt parameters that function. It has just fine the inner function, Right? Of course, that being key here is the predictable functions. So we don't need Teoh. Specify the name. Fire of a ripple here. It needs to be only specified here. Right? Okay. What about situation like that? I don't want to create this partial name for the of Arabia. He right. Very liked it to something like that. Um then will not this one problem. We're trying to send a judge in Well, so I have to also always create new variety like age, too, and then do something like that when I slower also tonight. There. That will be time consuming, right? No, we can do something goes, we can use something like that. This, um this age. And now, as you can see, everything works fine. How does the days is work? That thing is Justin address to the sexual instance off class that we're working. Come. Okay, So, um, we are trying to Assane the value do there property to the at redo built to the value from that class that we're working on right now. And the age here is the age that this sent here from outside. So So for example, the finals 50 feet five he sent here. And here we have minus 55 but here we're trying to saying the value to the age to this here , this questo dead instance. Of course. Right. Okay. Not like to tell you about something very new in classes. Well, something will makes Chris is different from structural. So about something that is called the contractors and destructive cause sector. As the names subjects is used, Teoh construct our objects so it can define values like age when we create an object. So, for example, here So how to create something go. This called construct constructor, is like all other methods, but it is not returning anything and it is called like our class. No, it looks like that we can of course, define it here. But we won't define it here because way are writing the well organized called right. So these a contractor and I was something like that. Personal data. And here we can, for example, saying toe every edge 50 oh, every age 10 by default. So when it's not specified, do something like that. The age by default will be. As you can see, 10 We consent here Something to the apple, for example. See out this constructor has bean just invoked. Right? We need to first use a nice big here also and include the ill stream because you're sending yourself to the board right now when I build and rounded program, as you can see Ah, way we have on the output that the constructor has been invoked two times, right? Well, we've created two objects, so it had to be invoked two times. We could create a variable like that, for example, and sent it out. Put something like that that scene as you can see discourse structure has been vogue 00 when I do the implementation. You like that? Well, not the disconcerted has been vogue one one time. How toe may be creative array able that will be the same for every object. Right? So I don't want that variable. It will be different in each up. I don't want it to be. Every time the constructor is invoked, Toby zero right. We can create aesthetic Marie aesthetic variable. It's just created Wiles. Need me? Is that now on this program? Constructor has been invoked. First time consequences invoked. Second time, right? You can see this thing is right now. Static for rebel. So it is shared between all the classes that variable. Okay, now let's talk about that thesis tractors. So if constructors were used to create something to initialize something distracters are used to distract our open. And it looks like that before the personal died the data we have to aid the sign, Tell them and let's define that guy here. Well, let's just scented Al put something like these. Tractor has been invoked. Now here, another variable home on the times, right? No one I build and rounded program. You'll notice the destructor has been invoked. 12 times where when they'd met these place here when the creative function, for example, void test. And here I created something like that. For example, in there, the type that this personal data on, you'll notice what's coming. The things you let's involved, it function that this think, um is making ground the constructor function five times and destructive five times. So every time our object meet with the Carol abroad closing block it, it's being destroyed. Well, we don't have any more re ference to that place, right? So we can we can get active our access to the place. So why do we need just to remove the place Freedom member that's killed? And we should remember that when creates something dynamic alley here. So, for example, I'm doing something like that end. And then the pointer that we point to the variable the Taiba zine, for example, here I will do something like pay new and five. So I'm just created a narrow A off five guys like him when I building around this program Right now, Destructor here is not making the memory free. We should remember about doing something like that. The late be okay from now, everything works fine. So distracter It's a place where we should free memory that is dynamically reserved inside our cloth Because, well, people that will use our classes won't know what is happening inside of our class. They just want two years it. So it is our duty to make something like that. You should also know. Now you notice something vertical when I create em pointing to our, uh, uh, class that we just created the our type. And I would just like new personal data. Five. You'll notice something very cool. Onley Constructors has been invoked, right? So like I told you that the new operator here is just returning as the address. The first alignment here I and that's all. That memorial is result for us. And did you always be reserved for us? So we should remember about making more free here. You will notice that when something like that the destructor will be involved, right? Okay, so we always need to remember about the thinks you because our programs will work very bad . We don't I titles tell you that you can overload that constructor here is Lee because they told you the constructor is what? It's just a matter so we can override it. For example, I can now take here the short Meribel. Now I can define you Mind. Um I consign to this age from that Glad that I'm working right now on age that will be sent here. And now we can do something like that When I building around it program, you'll notice that the constructor that was involved with the default constructive So that had one here on and who I want toe. He was that constructor. This is different constructors. So you will just notice that that one was involved. Now, as you can see, face constructive Still working on that one, I would have toe just send Hugh example Ken. And here, for example 15 2015. And as you can see now everything goes fine. The destructor be that were being bob. Is that one right? The construct Aries that taste how to remember that? I think you will notice that when you're creating objects of personal data. So it's like that right for some all day down per soon and we're sending to debt function that went to here, right? And then We are invoking that function here right now. As you can see dead think Here is a very well organized co Now when I want toe for example , See, how is that class constructed? Just looking at this. Well, her here I have two rivals there provide. And here I have two constructors destructor. Two methods right now And I can see it is Lee. And now I will be like, How is that? Think here defined right? Oh, so I have to just go to the five that is called the same like that thing. But the CPP version non looking here and and I can see how is constructed. Otherwise they don't need to know that we can create here now, for example, comments. What can they'll say? That these function is setting age. If age is lower than zero? Then age recalls. Look then. So as you can see, we can now make Commons here a easily they can be read Israel. We don't need to know how. It's something working. Just know that it is working and doing. I think that this discard him. I know there's right now when you're not experienced programmer, that might be confusing for you. And the psychology is I had to read, write so many things to do something like that. But really later things like that are just basics. And you notice that they would save you a lot of time. So please try to do things like I told you and try tools The right things, Like you see in the video noted that I'm, for example, writing the first later off the class end up. Okay, goes later. When we were creating, for example here. Ah, variable, far type. We know that this is our type and they know that it is a class just by looking at it because it has got there first. Netto in upper case, right? And here, for example, in functions, the first letter is in lower crime. But when you're creating two words, the second World is in uppercase. All the things are really important because then our variables are settled of script is they're easy to read. They're easy to, um, use. Okay, that's all in the lesson. Thank you very much.
40. Static variables and functions : Hello, everybody. Today we're going to talk about static properties in static Met. So about static variables and aesthetic functions. Right? And what? That word static that modifier will do when we use it before the property or the matter? Well, it they met it, or the property will be Schardt between all the instances off glasses. So it means that all the objects will have the same value. Okay. The same value, for example, on property. And if it means about method, it means that this is ah, the method that can be used by all the instances of classes. Ah, and even we don't need toe have because Well, it will be shown since, um don't worried. That are just words. Soon we will be explained very clearly. Okay, let's imagine the problem. Ah, here We have already two fires the use of that agent user that CPP created and mention the problem like that. I want to create a user right and I want toe identify the user some quality from another user. How can I identify somebody from another guy? How they are? How can I distinguish them from each other? Right? How is it possible well, in order to do it, we need something some property that that could distinguish them. Right? So, for example, world name. Well, names are not good guy there because there are many people with the same names, but certainly well, here people. I don't have the same seldom Ah, all the time, But it can be repeated well, so maybe let's adds the name and serving well, that would be roughing when both for people have the same name and surname. But still it can happen that they would have the same name in several. So we can just create something like, for example, mm, new variable. That would be, for example, integer, and it would be called idee. And this thing would be always different for other people because every person would have different number, associate it to the guy. So the best thing is to just create something what is called ideas. So it will be the key to somebody, right? For example, they use their number one these their number to the user number free and, ah, that think cannot be repeated in another user again. Right? So that's how we'll do it. And let's create a class that we called the user and now here in the public section will create first the ah, uh, constructor and destructor. And now here I will create the definition off constructor and I will create Ah, definition off destructor. Okay, now here. When I create the use of a and then use or being and I create something like that, I ain't I d here. I like to tell you also that this guy here right is really improve eight section. This prevents section here is added here automatically, so we don't need to add that Prove it here. So it means that I can't do something like dead right now. It won't work because this thing is provided right, and it won't work. And of course, here, please remember about it that we should add the semi column here always after the class definition. Now here we are being said that error. Ah, that end user id's previous so we can get that value. And as I d should be, for example, like here and we'll get because we don't want anyone to change this thing by mystic, right? We don't know. Want that Somebody changed the idea of user from 5 to 2 because there would be, ah, by mistake to people with ideas that are equal to two. Right? So we should just create a function that will return the I. D. Right. We can make this function in line. Just return the I d. And we can say something to that. I d, for example here, for example, like that. And now here we can easily send its to the output like that. There's a great see everything works fine. But hey, I want to have ah different idea for each user. All right? It's about that. But these were able is different for each user now, so it can't be like one for all of them. We could create a global va Rabel Butthead. That thing will be bad idea because everyone who you would like to use our clothes with me to use the Globe armory because we need to know how our classes working and remember that will arrive Classes. You want classes to be used by other people easily, not only by us. So we should now create something like static property. That will be, ah, the same for each guy. So we created the static and and call it counter. So this guy will be counting on the East Variable would be no sharp between all the all the incenses of classes so that their guy here and they got here. We'll have the same value here. First we have to initialize our counter in order to do it. It will do it that way and then the name of our class. So the user, then we go to the counter and then saying here, zero So these the initialization of our static for web. Okay, then each time they construct a reason we just increase the counter, right? And then just the same toe I d the counter because each i d must be different. Counter should be shirt. Okay. And now let's see. How does it work? As you can see Now get the get I d function is returning us one than two. It was great. It something like, for example, that And then I will do something Like, for example, that you'll notice that Stan Automatic Kelly we have the i d 10 here and he's right, because remember that Arise arc counted from zero right. So the So this is the 10th a lemon. We got the idea. 10 him. So now whatever number we we put here well, we with automatic away as saying right ideas to each user they all will be different. But the country shirt. And remember Because that thing is Schardt, we can get the value always. It means that we even don't need to have the user created. We can do something like that. A well user. The name of our claws, then two columns. And then we can go to the counter. But right now that things won't work because this thing is what it is privy, right? These there is a modifier to medically added that it's privet here. When we do it that way, everything will work Fighting. As you can see, the council re zero right now because we didn't create on the user will need to. Something like that you will not. Is that the counter is 50 right? Go. But there is a problem. When we did it that way Now the country can be really changed. It can be changed. For example 60 here by somebody buy me circle. Maybe not me safe on and something might go wrong, right? So while that's bad idea to have the counter here, it's better when it's here. So we should create in ah function and that will return the counter right and get the counter and then return the counter right. And now we can do it. But we can do it only that way. When we have the instance of our class, so and and then can't get counter. Ah, that way we can do it. Right, Bob, Hey, we need any sense of the class to use that that bad idea because static things should be ableto be access without having the instance of our class. So we should create something. What is called this had take method that will allow us doing something like that. The user and then get the counter now can get counter always right. Scarcity 50 And we don't need also the instance of our our colossus. Everything works fine. So by having static Ah, we are making the variable metal shared between all instances of classes and also this thing is ah even created before the ah instance off our class. So it is always somewhere created. Okay, that zone did Listen thank you so much
41. Constant classes and methods: I have, however, body They were going to talk about constant instances of crosses and about the council met it. We'll see what will happen when we proceed that things with the World Council. Let's imagine a situation like that. We want to create a class that worry present a position off on object, whatever object it can be. Adult. Can the hum house, right? Uh, it can be anything. Eso will create a class and we call it position. And I can't click this base him because Kump, our i d will use the hint here. Okay, so class position, remember about semi colon him. And now when you two star position Summer. So let's start it into priv ate variables X and y. Then we're creating the public section by using the public modifier to constant request, constructive and destructive. So constructor position and this constructor will take to a para matters So ain't and because we in the contract that position here, right and of course, will create the distracter. And now let's create a definition for the thinks you so position and they are taking the position. Ain't eggs, ain't why and now will use that these address, right? That we help us get to the extent we are working on right now and we'll send your ex. So now we don't need to think about new name for X and Y are declining to hear types of K and V. Ah, I I can use the same names for the rebels because we can use the days, think. And of course, we create them definition off destructor. And now let's create objects. So position and we call it dark. And I think your position the beginning, for example 10. 15. Now you recognize that we had functioned? Who could let us care The X and y So let's returned. Avoid so nothing and now get position. I called it things like that, and, uh, here we will in notes, stick and the perimeters. And let's define that guy here. Void position, get position and let's send to the out of the information about So include the ill stream. There is also the name spaces today, and now he was sent to the Albert C out the X and Y position. You could of course, do. It would be different way about right now. I just want to make it. Is this possible? And now you just get duck, get position and that's been rounded Program as you can see, the position you, Stan and 50. So now Ah, lots. Maybe creative function that we change the position. So set position on Did you take two arguments? Void position, set position. And now I will say to x six and two. Why? Why that it's coming from here. And though dog is an animal, right? So he can move, isn't it? Oh, I can moving, for example toe the place like that and then to get position and everything should work fine for a dark right and everything works. But what about institution like that? I am creating it position for the house. Ah, the beginning. Recreating the foundations of our house, for example 102 100 and is the position for our house And of course we could create the wave. And if he's like that But the most important thing about the houses that how to move a house right when we create the foundations way we would have to destroy the house to move it right, So house is not move able and but I want to keep that guy move able within the same class. Right? How to do that? Because now, when they do something like that, somewhat strangely, think to the house. So I'm working. Get for example, toe place like that. It can happen, but it's not right. We should be able to say, Hey, I am going to make a constant here. So I know making the constant variable off our type. But there is a problem. When we do something like that, everything within the class is being made instantly constant. It means that we can't use any functional. So now we can't even to get position. Look, get position is not working. Also, if we want to let a function Toby used when there is constant before the type off our ah, of our class, we should at hell something like constant. The world after the declaration, okay, and also, of course, here and then to get position will work. So it's OK because we should be able to get his position right field, but we shouldn't be able to set position because set position is wrong. So set position. He's not work. And as you can see when Ah dog is working. Fine. We get positioning set position, but the house is working on the world. We get position. So everything is working fine. Like we wanted to. Okay, So the user of our well, the programmer of our Ah, the programmer and that will use the class our class we'll be able to decide on his own. Hey, I would just create this guy x constant. And now I know that I could get position because here is a war constant. But I won't be able to set position So everything works fine. Like I want. Okay. This alone did Listen, thank you so much.
42. Friend functions : Hello, everybody, That they were going to talk about the French? Yes. We're going to talk how to make function friend off some kind of class. Okay, first, imagine situation night. We're creating a function. But here in that place, the main CPP. Well, as you can see, we have the code from the previous lessons. And we're creating a function, for example, that we not return anything. And it was set X. Okay. And here that thing will set x 02 some kind off object types, British position. And it was set the X value that will be sent, right. And here I would create a definition of the function. And of course, I need to name that Rabel somehow. And no, I will go to the object dot x and I will Assane here. Well, right. I'm trying to get the dead place here. The ex exist. Oh, um, in the lower and as you can see well, we have an arrow because that boy's here is prove it. And that function here won't be able to change the X. You we would need to make a function inside public section, but sometimes it is useful to have the function here because, well, we can, for example, added something the class or ah, the creator of the class. Well, hello. Other functions to do things like that. So, um, how to do how to let that function here created here to added the x two x here because it's previous right, How to light it. Well, we have to just copy that. Think You okay? And we just may We need to make it the friend, so we'll just adhere, friend. And now we say that this function is a friend of this class, so this thing should work. Fine. Because you know Hey, I'm friend now. I can use your pre very things. Okay, I believe you, right. Ah, I believe you still have anything. You want to change anything? Ah, wrong way. And as you can see now it works. And let's change, For example, the position off eggs in for the door. So I was set X for dog to for example, 500 0 let's Let's go. It's 100 1000 and four for 500. So that think here should change the dead value here. Let's check it out as you can see that value hasn't changed. Ah, even toe. We can change the X here. Why is it so? I would like to remind you that this think here Looks like really like that So And we are singing here. Just dog has a value. So it is a copy of the object. So if you want to check this dog that is here, right? I wish the world we should, for example, use the referring. So let's change everywhere the declarations and no, this finger look like that and everything will work finding right now, is it? Concede? Develop is changing. Very well. Okay, that's all needed lesson. Thank you very much.
43. Friend classes : Hello, everybody do. They were going to talk about the French. She both in the classes will make a simple example off that things. Well, let's great to classes. And I recall the first class class A and I would create a second class and I would call it class big. And now I will have, for example, within the class being the in the private section that is default off course ever able like that, for example, into and here something like, for example, secret volume. That's call it like and no, I was creating the public section. They met it that will let us take these secret value. Right. So let's create something like that. We return the end right and gets secret value. And let's make it in life function Return the secret volley. So now when I create be here like that. So object being I can sent to the output value that this inside there is, I liked it. Of course, there are some random value because we didn't Essent anything care right. And now we'll focus on the class A because, um, I won't dio sec thes value from day schools and this thing is what? Well, this is the privet property, so I shouldn't be able to do it from that place. So normally, when we do something like that public, then the function that it's voided, Then it was set secret value. And I will, for example, take here the closet e right. It's a re ference and it will change the value that we will be sent here. Now we create you that that in the test that see pp definition of the functions void A secret secret value Here are we call that think subject to you we'll have to value. So I won't do setting the object the secret value to the value that will be sent here. So when I do something like that a object, a andan object a set secret value to for example 600 I want to see here 600. Let's see how it's good. What? We have arrows. The first arrow is, uh LA is about that. We'll see he was a type B and the type B is defined after type A right. This glass is before debt class. So within that class, we do not know about existence of clause B so we'll create something. What is called the Declaration of Declarations. Looks like that. Just say here, Class B. And now we're telling our compiler believe us, that will be somewhere. Ah, the definition off. Well, the initial declaration of the grass. Now we have the second arrow that is telling us. Hey, you can't do something like that here. Right? In that function, you can't get to the previous section off off the class. You can do that. That's wrong. Eso Ah, they are like enemies to each other. But we can make that class because a friend for disc rest as we that was just that friend. And now I will just do something like that. And now well, the invoking off this for function is wrong. So we have to also, of course, sent him which objected want change on and well, it's my fault, my fault, because B is the name of glass. So we're sending cure an object after so should be done that that's a concede. Now we can change the value from death class by using the functions from that class because that class belief classed a okay so we can easily change the value from that place. Bob, remember, we are saying inside the clothes be that the class A is a friend about class A dozens talk about the class B at all here. So if I had here and second secret value or something, that was second temporary. Well, anything that class, the functions we conduct class cannot change it of value here. Okay? Because have I think there's a clause B, but Chris is my friend bought close A Doesn't think so. And I get in real life. Of course. Um, we can be friends for somebody, but that's the guy that doesn't to be our friend. Right? Okay, That's very thank you for martyrs during the lesson.
44. Copy constructor: Hello, everybody. They were going to talk about the copy constructor. But before we start talking about the thing, I would like to show you the problem. Well, look, when I create a variable in a and I will sing here, Lieutenant, then I create and be in the same here. A And then I'm saying to A for example, 16. And then I was sent it out. A and I was sent to the output value of day will notice death the first value 60 and the second valueless then right, Because everything is going to be executed from the top to both on right. And in addition to these, Well, when we are assigning here something right, we're saying 10. Here we are, a singing just value. So we're not saying address, Rather were. Just think of that. Okay. And regional situation like that. We're creating class class that we call just test because I don't want to create anything useful right now. And I have a great in the public section, so we want those time for Ebel's. Well, I don't want to create cared and setters and other things like that, so I just do it that is, We've been the public section this time. And well, of course we knew that there, constructor, that will set the two things and we'll need also destructive. Okay, so? Well, that's defined that things in the typified. So going to test. And now X and y No, I would do something like this. X equals X. And this Why it calls Why, right? So this is the typical constructor who did get here? No, I create the thing. Well, I create two objects. It will be the time will be test object one and it will be. And what do you have values coming from here from the constructor and second object that we'll get value dead. Now it's sent to the output. The value that this under X and value that this under why? And of course, the same thing to the object. The second object here I will make humor lines. The thing can go to comment now. I've been in run. Of course. We need to at the cynical on here with them about that senate calls on what now? Oh, yeah. You also create definition of our distracter. Um, no. Everything works fine. And as you can see, the values Hugh Co part Well, because they were compiled by the simplicity Constructor Copy constructed in police it that constructor is cope eyeing. Ah, when we use the same operator, the values inside. I thought, you know, that values can pick a pied easily on and on and everything We worked fine later because they are like that values here. All right. Ah, when we change something now, for example, object to to, for example, 200 right? The peaks of the second guy. As you can see, I'm changing only value under that guy, right? Because they are Two different instances of the class are to different things, right? Two different objects now steel. Okay, but so so what's the problem? Well, the problem happens when we create something like that. When you create a pointer. Well, when we do something like, for example, here this p I was a saint. New end, that value will be, for example, 50. You know, when we use that things like things like that we're creating, we're reserving free spaces in memory, right? Free spaces for integers. Right? So we're reserving free, multiplied by four bites when we do it? Something like that. We just were just reserving one and time for bites, for just value off 40. Okay. And no. Well, ah, what happens? Well, maybe that's been upgraded. Think here. So another ain't here. We can stuff like, for example, value. It comes from here also. So I'm saying here, for example. 60 line. Okay. Now sent it out. Boot value that this reserved That's phase of memory. Well, let's do it. So these things should be that way. Well, that thing will re present what the think will re present the address, right? And I do it that way. It is an address how to get very from address. We have to use the asterisk. Write a story sign so will do it that way. Candice copied it that way, that way. So they think we give us them values. And as you can see, the values cut compiled. Everything was working. Five. Are you sure? Well, what was compiled here by the in Place it constructor. Ah, Cut copy. Constructive. The address was complied in both cases, right? So it means that now, when I do something like, Well, let's use that guy I'm changing these two 700 and you notice that in both cases that value has changed because who are trying to change the value under the same address? So right now that two objects have got they are sharing the same on Verugal, right? Well, the same address. So it's not good. They are not too different instances of classes. Fine. We should somehow change the implicit copy constructor. And also, we should remember that when we well, um, locate dynamic other memory We shall do. Deal it the p right. You should remember about it that we should free our memory. And this time, memory is being created two times because two objects Andi freeing two times more under the same address. So it's also wrong thing. And that's why we have to create that copy constructor. How does it look like? Well, it looks like that, like normal constructor, but this time way are taking here the constant name or free Ferentz. It looks like debt. And now we should also do We should defined thing so fast here called it somehow. And now it looks like that when I do thes and I, for example, go into the P here I am trying to get to the value that this is the left side. So to the object to when I do something like object dot p I am trying to get do that guy here. Okay, so now we can as sane through the new vory bull, The value dead is here under new address so I can do something like new ain't and I want value. That was under that There were us off the object before. Now, in my burden rounded program, you will notice dead this things for for focus on the object one that being object to that day as you can see the value even till we change him. Mm. Didn't change in object one right? The object one is 60. Well, sir, we changing the object one. We didn't changing the objective. So and object to its 16 object want its 700 but And the other values are were wrong Because when we create our own copy constructor, we need to remember that the implicit one is not working now. So we need to on our own also do something like that. We have to change that to become a values ALS right like that. And now, as you can see, everything works fine. Great. Now we have two different instances of classes even though we're using the dynamic location of memory inside the vocalist. Okay. Doesn't the lesson. Thank you very much.
45. Convert constructor and overloading operators: allow everybody that they were going to talk about the Culver constructor and we took how to overload operators. Okay, First, imagine the problem like we have two integers, for example, a equals stand and in bated equals, for example, twin. Now, when I do something like a plus being, the result is start right, and that being it is very easy, right? We know that something like that would happen. But when both types are different like that, this thing is a bit confusing. It should get list because, hey, this is different time, and this is different type. But when we do something like that, there are different times. Why? What? Which type? I should choose here into general. Maybe double. I don't think it's somewhere specified. Okay. And you know, there might be a problem when we create the class and we want to, for example, at two classes to different classes. Oh, that would be problem, right? And it will. It could be a problem when we if we wanted to, for example, checked it. Quality of to they have equals equal elements. Right? The properties, Yes. It will be problems because, you know, for example, when we create the strings, for example, text warm. And then I created a second string like that and oh, plastics one and I was sent to the optics. Dude, you will not. Is that that's drinks are no connected, right? They're connected because off using that plus sign. But hey, Plus was really usedto Edward to add a tent last 20. So it was easy to add numbers. So because the string is really a class all right, golden here the example you we can read about that. We don't know about templates that yet, but we'll know about that soon. We know that it is the class and it means that some order there is specified the plus operator for just strings because notice that how the strings will Well, you're reading one character. 2nd 3rd 4th 5th character and the six character. It's no is that zero right? I told you that it's like something like Baxter zero. And this thing is telling that he should start braiding right this hour street. So in order to at one street to another, we should just change that Think here. So the address of the think here, right, making them together. Well, the situation did. I just told me about it like that. Were making them together. So we are changing that. No sign that bex zero that sign here, right to the address of the guy. And he's reading anti. He needs that Texas, and they think it's somewhere done. There was a function that is overloading at Plaza Parade. Okay. And, ah, when we were talking about the situation like, Let's go back like that we should not. Is that days? Isn't is double on. The result is what is doubles. It means that some are here. There is something like that. The implicit way off changing that die to that type, right is the casting so can create our own time. We should know how to do things like that. Okay, So for example, I want to create request these terroristic example Cliffs and we call it in Teacher. And now I want in our class the previous section to have the property number so ain't number. And now, in the public section, we need what we need. A default contractor. That won't do anything now, So we just There's something I did, and we need and something that you a sane he value. So we'll create something like that in Teacher into your in value. So we are going to this'll number. We're going to sing him Well, no, now we can create our teacher. So in teacher, A saint of 50 and I can be then run program and what we need Also the get function. So ain't get number return number like that Let's send to the our book value because you can see we have faith to hear right now and look normally we can't do also something like that are compiled. Won't know that we won't hear sent to the up the value 50 right? But if I had something like that, the value would be sent easily to the out because the in teacher from the C plus plus nose about that operate right there, that to anchor bracket. We also can specify that, but we won't talk about it right now. I want to focus on other face. Look, for example, when I create in being and I want to sing a to B and then sent it out to be, let's seem as you can see, I can do it about debt to the A. I want to sing 100. Sorry. Come into a single. So as you can see this, I can do. But why can I say here? 100 How our compiler knew that I want to do that. Because there really that can kill. It's called the Convert constructed Comfort constructor. Looks like that that creating here that mattered with the name like our clise. And then we're, um, creating the perimeter here that will be here on that side on the right, sir. Right. And then the finger, these on the right side. So here. So the interior, that object that I want to say to our objects somehow will be a saint here. So I did it for things that, for example, something like that. You look this 56? No. Even though I around Royalty 100. So 100 was sent here, but well heh missing here. 56. Okay, civil. We can specified. So now we can do it. We had more properties. Hear what? We could also do it in that matter. But without situation like that, I want to also be able example like that. It's also called toe to be able to do something like that, right? How could do that? Well, notice that this thing should be really converted like that. We should be able to convert there A which is in teacher to end. Right? So this thing is really that casting is really up. Operator. So does something like that operator then name of our operator. And then we'll specified that Think here. So we should go to the hour in teacher Then we should go into operate on and then light it . And now here I would just return this number. So let's see if it's working, as you can see were able to sane here value A to B But we we can now do the XP Equate are we can do it The implicit way like that never fingered work. Fine, as you can see. So we're specifying the integer operator right in this place we're returning value. It should be returned when somebody used that integer upper right? Or so The casting like him Body No, we can do it. Expect great, but can also you do it the implicit with okay. And now what about situations like that I want to do something like a plus b This thing, we work fine because he is now translating. Well, we have the both the convert constructor and we have also overload the operator in. And because of that, he knows that he has to now change these guy, for example, toe into germ, right? Well, for example, this guy to the integer and he will know how to do the rest Think is doing the implicit way The problem is, where if we wanted to do something like that Hey, um, is for example plus what a plus equals B This thing is really what a equals a plus b right on the night scented output. A good number. Can I do it? But that the Inca think as you can see, you can do it because here we have a narrow know much for operator plus equals I have to just tell about the operators. Operator and that operator were returned in teacher plus equals And here is the time that we are Hey, son, I would explain it so don't worry. So ain't in teacher operator and then plus equals integer. And here we can call it. The integer here will tell us what will be returned by that thing here. Okay, so we should, when we return him, for example. 15. Let's see. Well, with the result, as you can see, it's 100 seats. Because this is just the return. We didn't change anything here. Well, we wouldn't change anything in our quest. So we should do what? This number. And if you did that way, everything will walk fast. Bazookas. We change the thing that is here. IHS really here, this place here. So we can now do something like, Oh, that. And now then we'll get get number function. All right, And then we'll add to ease Did this number and then we can return to this Now. Now, as you can see, the value is right. Because here is 15. We use 101 100 plus 5150. So everything works fine. Okay, that sounded lesson. Thank you very much.
46. Inheritance between classes : Hello, everybody. Today we're going to talk about the inheritance between classes. But first, I would give you an example from the rial life. Look, I have got blue eyes, the color blue, right? And I have got them because also, my father has blue eyes. I inherited that blue eyes from my father. Probably so the color get inherited disease. This could be in the programming situation. A pro party. It's gonna be variable, right? That color that blue fink, it could be inherited from, for example, other class. Right? So inheritance means that we are taking after some kind of properties from other classes right here. We can use properties from other classes, for example. Okay, so we'll make an example that will be connected with points. Let's create a class that lyrical point, just simple point in one dimension and in one termination appoint has good only one coordinate. So, for example, and fix this thing, of course, is provide right and now in the public section will create they're constructor that will take one parameter, and we create the destructor and we'll create the function that will be able to get that X so in ain't get X and we can return it. That can be a lot lying functions return X and void Set X that will be sent here right now we've got here and creates Oh, that Things that we've just declared. So we start from the constructor, then we will create a destructor. Then we will focus on the I think you so voids. Point set, X like Okay, what's the right to begin around it also Everything works fine. No, What's create Hugh? The global function has created a declaration on it for its operation on points, then definition of it and we'll use it inside our main function. Now we can create the says of the class so point we call it the one no center. The output value, the days in X that seems working. As you can see, it's not working. Why it's not working because no tease that we didn't send anything here. Now it's working Fine notice that we have got now only the constructor. That is what that is not default constructor. Right? Some people construct Aries. It is taking one permit One argument right from here. So we should create also something like that or now I would like to tell you about something like that. We can he'll types of, like equals zero. And it means that when we do not send anything here like that, the default value will be a saint from here. So we can also, for example, like 66. As you can see now it's 66. So this thing is the value that this eegs when X is not sent. Okay, this a bit foster, right? We need only one concert and we don't need to create second Constructive. Okay, now let's do something like that. Let's entered output from the constructor. The constructor from the point class. Les has just being involved. They did. And no here. The destructor from the point. Pasqua's just being invoked. As you can see, the construct on this sector has bean. Everything works fine. We'll need that. Think to explain if you think so. Okay. So now we have a point and they re making situation like that. I want to create a class that we re present that point in two dimensions. So right now way we'll have to coordinate, right? We have to coordinate X. And why so it means that I should know right the function. Caddick's and said It's a game. So I would need to repeat that cold here again, right? That here and there and sticking time on. Do you know if I had if I have to have to change something did functions I would again to change it in two places Well again will take Mort. It will take more time. So this is the time where we should use the inheritance. Because inheritance means that we are going to use that methods or properties from other classes, right? We can use them well, we're inherited them in other glasses, right? And in order to do it, we should write something like that. They're killing you and then we say, How do we inherit? We're inheriting the public way. So I will tell you how it's done. And then we are saying what clients want to inherit from. So I would just say that I want to inherit from that part. This thing means that I am doing something like that. Let's do it that way. This will be in the public section. It means that constructor and destructor is not occupied him and thinks that are prevail. Hell, hey, you know, there is a previous modifier. These things prevail. This thing belongs only to that guy. It's not going to be complied here also. So when he does something like that, we did exactly something complied Declarations. And we also. But by the definition, right, we can now use them by creating that type of cost. Okay, let's go. Thank to a place like that. And now we should think about that ex. Well, we need that X right in that points two dimensional. Also. So, uh, how to do this? To let it be hell. But still, I don't want to allow people from, for example, here to get axis so that that that things without using their set eggs and getting right have to do that. Then we should use a multi for a fire that this gold protected. The protective means that it will be priv ate for people like that here for people, for her, the coat like here. But we won't be able to access it directly. We'll need to use the get ICS and statics, but eat with the ableto be inherited in dick Less that we are inheriting things like in the 0.2 dimensional. Now, I would like to also tell you how article a class called de Skull s is called baseless. All right. Sometimes people call it the parent class because it's part of, like my father. I told you, right? I inherited from him my eyes and sometimes called also the super class because it separates . It's, uh, first class, right? That glass here is called No, the baseball do rights. Glad 0.2 dimensional is a class derived from the point. Right? Okay. It can also be called shy or the subclass. Great. Now we know how that classes are called, so that would be easier to target quality. And what now we it to define the new things in the two dimensional? Um, that's right. So what do we need? We need the second Corden. We don't need to think about that. Things here, right? They are already defined in that class, so we don't need to lose our time. Notice that, of course, here aren't many properties. And this thing wouldn't take us much time but imagines classes that help, For example, 500 of cold. Then he has. We are saving time. Okay, Now I would say protected. And of course, we need to create the court. And why? Why? We will plating the product exception because noticed that later we can clear to create a class that we call the point free D. And it will what inherit? From that point to dimensional. Right? And this thing, I would like Toa I tell you, you should do as an exercise later. Okay, so we have No that. Why then we'll creating the public section our own constructors. So point to dimension. And here I was something like that because to think specified, he will also created there have point to the distracter Right on. Now let's go here and we'll go into 0.2 d then And that applies here and why? And now Maltese one We can do it. Headway and everything will work fine when this create, uh, destructor. So everything should work. Fine. But there is a problem. No notice that when we change something in that constructor here, it means we should change also something here. All right, so we have to change it in two places. The first the second thing is that imagine situation that this constructor has got here like 500 lines. It means we'll have to repeat them here now, because on the don't lies. Right. But imagine situation like because of that in the constructors in the derive closing try. Because in the subclass, we showed on that do something and like initialization off things that are new in the class . Right? So we have only why cording that new here and use if that constructor from here we can use it dead with We are, I think here that column Then do that use using here the name of the constructor that we that is. The base goes for us and we'll just send here the x two this year. Right x descend here and now let's see if it works fine. Everything is working. Fine. Okay, Now let's create it. 0.2 dimensional. And now let's be the rounded program. As you can see, everything worked fine. We could use the get X easy, right? I like to show you now also, how are constructors working? Let's to something like that. The constructor from the point to the national has bean just being broke. And now that this tractor from the two point And now I've been in Rampal them No, look. The constructors were invoked in the order that from the base cuts and then from the derives close All right, the destructor, where invoked in the different way. First it was revoked from the they deride girls from the child caressed and in this, then the destructor from the parent class was involved. And now why it happened that way? Because notice. Well, how can we construct something here when we don't know anything about thinks here, Right. So that's why first we need to use the constructor from that place. And then we can use the constructor from that. Okay? And no. Why? The order off Distracters are like that, because how can we? He struck first something with these. That ball loss when we have toe first destruct things that are in the right, right? You need to distract things that are inside first, right? We can't start from the glass here. This kindle logical. Okay? It means also that the constructor from here Mars being so even if I do it that way. All right, I am not going to send the peaks there. The constructor from point Chris has just being invoked. So always the based parent constructor will be involved. It has to be involved. Always. Okay, Because we need to know in the class that he's shy. How to create things got above us, right? Okay. Now I liked about the public world view that's doing in the common look. When we do something like class on to the and then public point, it means that everything what is in sight? Point two d mention lol no, including excluding the constructor and distracter will be in point to the mentioned Well, everything would is inside point, right? Because you are trying to get things from here right to you. Everything good is inside point. Excluding constructor and destructor will be in point to the like that. When something was prevail in the class point, it will be changed to cannot access. It means that we can't use the variable X in the point duty. If we had he proven right, okay, the protected will be still protected. The public well, they said public if we did eat dead way the previous year, won't be ableto activist protected would be protected. But public will be changed to the project. And if we did it that way, if we inherit Priv ate way, this will be prevailed. And this will be privy. What provides? Still cannot be activist. Okay, so in how to remember the thing. Well, just remember that something is public. Nothing is being changed in every situation. The privet things are just things that we cannot act. It's right in the protect six situation. Just protecting the body. She's protected in priv ate way. The protecting in public exchanged the previous. So what does it mean? Well, if we did it dead way the privet thing, it means that older functions will be in the previous section of them. And because they would be in the previous section, I wouldn't be able to use them from place. Like you. Off course situations like that might be useful. They are big wear. I just want you to know how does it work? Will change to the public way because we need it to be inherited. Dead, right? We wanted to work that way. Everything looks fine. No, I like to tell you about two more things well. We need to also create him. Get why? Return line. Andi, Let's create the set. Why Function 0.2 dimensional set. Why? So this Why it quotes a line. And now that seat works p to set. Why? Let's change. For example 50 Get Why here before? Let's go. Something like that. So it means that why here should be 15 off course. We need Teoh. Change the declaration. And as you can see, it works fine. And now imagine situation like that. I want to create a function that we change. Bothered things at the same time so I can create something except X and y. And it'll take two mentors. And now I will defined that. Think he'll And now what should I do? Should I do a dead way this X and then this? Why should I do dead weight? No, never do it. That because Remember going when I change something in here. And then I change something in here. I wouldn't do also changing here, so I would need to remember that. Go. All right, Does the first. It's a good thing if I had to, like 1000 lines of code have need to competent thinking, right? That's why we should use the function from a boat. But for my boat from Frankie. And we can use it. That would. So now we can do, for example, I that and you'll notice that everything is working fine. Five and 50 right? When I don't change it, it would be turned 60. Well, 0 60 said what happened? Bubble. I did Then to use their, um point you right? I removed it before and I didn't added again, so Yeah, no, Now it will work. Fine. Okay. It's not done in 67. Because what is that? When we don't use it like that? The constructor from the point has been invoked like setting. But because we didn't send any think you didn't send any thinking, right? The default value will be a saying here, so it will be easier. So I changed these things toe. Something like that. You will notice that this value will be Show me. You can see the default value was used. But now everything. We work Fine. Okay. Now the last Hey, I would like to have no changed a bit. The function void said I want to change it a bit, I wonder. Differ, I don't want it to be like that. So I'll to do that. What? Normally, we just do something like that Corn to D on now. And, um, X and I was let go. Ex speaks, and here I would do something like I am from point A to D And here I was sent. I am from Of course, this is just different things that functions. I don't have good example here, right, But there might be many, many, many different instructions, so I just want to show you the problem. And now let's use the function for example, that set X right and what happens? As you can see, I am from point A to D. So when we do something like that, the function that is going to be used will be the one that type that they have type here. Okay, But there is one thing we should remember. It doesn't mean that we removed that function. That ah we can still act is the place by using something like that. Beato then dot point then too. Colon's now, as you can see. Okay, we have the message I am from point. So if you want to use still dad function with dead function, we can use the construction like this sometimes, of course, something like that. These very useful because we want to have Ah, we want to add something to the class. The to the function that this year. And we don't have access to debt glass directly because we are making the child class from the class that somebody wrote right? We can and get access to it is just saved. You can remove on the characters here. We can just use it. Okay, so then something that these reviews Okay, that's all in the lesson. Thank you for much.
47. Polymorphism, virtual functions, abstract classes : Hello, everybody that they were going to talk about the holy more fees, little functions and Absa classes will try to explain the topic by creating a firm. Right? Do They were going to create a firm with animal. So let's create a less class that will be called animal. Okay, so here we have a close animal and public section will create a function that returned the string and it will be called Get voice. It will return the voice off an animal, right, and we'll make it in life. Functions are here. We should return the string. Of course you were using string. We should include here. I'll scream and use the name Space s the the in the protecting section because it won't Harry later from the glass animal work rate Very able. That will be cold voice. Right? And this voice will be a saint inside our contractor. And of course, we need also destruct so here will return the voice in line function. We also need to saying that value to the blaze. So let's find our constructors. So to the voice, we should saying What? This is the question, right? Ask yourself what should weigh a sane to the voice off a mom that we can specify. We don't know if it's a caddy. It's a dog with that cow. We don't know what any monies that. So what voice it has. And here's a problem, because it is some kind of abstract thing, right? It's abstract A bit. We'll talk about the light right now to know the Magi hard. Just if you default Valley. Okay? Something like that, like that will change it a bit because I want to show you the problem. Very clear. Okay? No, I've been rounded program because everything works fine. So so far, I have written everything. Fine. No. Let's create that animal anymore, right? And let's send the up and mold. Get voice, Let's walks. And as you can see, everything works. Fine. OK, now I want to collect, create classes that will be representing animals like, for example, Doc and this thing will inherit the public way from animal. Right? So right now I have just killed by everything from here because we don't have prepaid section here. All right, We don't have anything provide section because private sections here by default here is something that prevail. But we have just inherited everything dot Okay, we create desk phone to make more examples. Um, duck cats and, for example, co right with free animals. And now we can Spotify them a bit. So we've just been created that Meribel Who here? So we don't need to repeat it. Him, right? You don't need to repeat it. We should create our own construct or see as they should be created. So public section and duck on way need the destructor of dark. We also need the same thing for the cat and for Deco. Okay, so for the dog and for their cats or the Dugway Needles instructor on the what? Um, that's saying the voice you right? So duck is doing good. Dog is doing, for example, how how How Right. Um let's create Couldn't co a bit faster. Copy this. Be faster. Ket Co Okay, so we have now cokehead and dog. And will this kid doing cat is saying you know All right, a hand cow saying move. Okay, so we have free animals right now. Different have voices, right? Well into Of course, the things public section. Okay. And now we inherited that function, right? So when I create, no, for example, are dug kids and to co. And I do something like then ever think it's working Fine. Default value. How so? Ah, we were just needed. Create the constructively certain we're using because of the inheritance. So it's fast. We can use the property and the function from here. Okay, But now imagine a problem like it. I won't do changed its function would be to you. For example Here, here I was here. I want to change it a bit because I want to create Have a Rabel that will be called sign in the private section like, for example, dead. So well Ah, I want to change something right in our classes and I will. There's something like sign for doggies Day sign for cat C Sign ful co is C C O. Okay, so they have no signs. It is a bit different. And now I want to return. Hear the voice Plus that same gets over changing a bit How this function is working right now, changing the one I'm building surrounded program. Everything works fine. We added that science here. Easy, right? Didn't really the way, So it works. Fine. But it's because we are using the right time here. But now imagine a situation like that I would like to de function function that won't return anything that will be called voice off animal. And I will take here as argument animal. Exactly. I thank you the pointer to animal and I just want to send the output the pain Get voice. I want to do it that way I think is compiling. So I know the right way. So I want to use voice off and mom and I want to send They're an address. So I want to send their example like something like that. These things should be easy to understand now. Um well, silvery, of course he's voice. No, As you can see, we have default value. No, this king dies. It isn't because what? Here we have a mammal. The type is anymore. All right, we have got now here function good voice. And I am returning to voicing because pointer ah pointer can point to the sky. Then you will hear. And we can, by using the pointer easily access the function right. That's okay. But I told you that normal and create example pointed like that. For example, I create here value like that. I won't be able to do something like that, right? Of course we can't the same the address off the Obel to the pointer that can start. What an address off in teacher, that's impossible to do him right, Bought in classes. It's a bit different in classes. When we are inheriting from animal, you can see you're inheriting from animal. That class go cat and dog 10 at the addresses of it. Types can be a saint to the pointer off animal, so we can easily do something like that anymore. The point. Remember about this pointer and we can saying Here, duck against the everything works fine, even though the types are differ. But it's only because the talk is what the derives class from animal. Right? So we can do it, isn't it? Of course. Let's change. Check. If I could do something like that dog, I want to ascend address all, for example, cold tonight something they did. As you can see, I can do that. Well, oh, maybe that's great. First pointer pointer and I want to Ted As you can see, we can't the same The address kids to the point of that is pointing to the type off dog that kind of done. But this thank you can be easily done. But now what would happen when I do something like that being and said to the output the get voice As you can see now we have what we have on our boat with how Right. So the dog voice on is it really the fingers we wanted toe See him? Hey, Well, we have here a sign also. Why did I get here? Only the voice We're getting voice but I want to see here also What I want to see here. Also the sign. So by using the point of that way we're getting we're using the function from class here, not here, even toe We are, ah pointing to the address off the dog. Because when we do something like that, the compiler exactly doesn't know if we recreate classes later that well, um inherit from animal compiler doesn't know where we could just be dead. Way right? Doesn't know about two classes and because they he doesn't know about it. We should inform him by using something like virtual war. And now, because we use the digital world were saying, Hey, when something like that saying happen like that, you please check if there isn't a matted in the inherited class in the derives closing the sub causing tried cliffs That is like that one Because, you know, I want to use that function. Note that function here. Okay, so no one like giving around. As you can see, I have got to sign. We've all the fear 12 or two on the that function is working. Kill. Okay. So that if you double or is working like I say told you that now and now notice what is very cool about it. I can use the voice of thing, Mal function easily and I consent you. I just don't. I can use huge address, call everything works fine school and now notice that it's paid. It is very fast to do things like that now, But later you can have, for example, a raise off cat dogs and cows. And you can use on Lee one function to operate on them. Easy. That's the cool thing about a mutual thing and notice. Now. Well, we know what is the veritable function, but we don't know what is the following? More fees? Well, nothing's that we have got here. A few morphs because the farm, because the dog cat and co is just free, different morphs rights on the second part of the the second father that Wharton right more and, ah, they are poorly. So they are a few. My poem is a few more than one. Um, I were come pie there because off saying that worked here nos which function he should invoke, all right, which function he should involved from here. And this thing is called polymorphous the thing that our compiler knows. Which of the more that few Moore's he showed. Invoke. Okay, that get voices. So this is the pulling more fees and it's really, really good. I know that right now, my ah, but later everything. When you program a video notice that these things are just very ever killed. A light also show you that you can, for example, overloaded Think here and you can take a re ference like then and everything worked Fine also. So now, uh, having a re ference here, Onda. We can send Hugh No co right on. It works also. Fine. So we can use the reference No, uh, Pointers the living rework final. So but it's easier to send re Ference he right, Because we don't need to remember about that Addresses, However, sending another dressed like that, I think a bit faster. So the thing should work will be used the most time. Okay, so now let's see. What is that? Napster class. I told you at the beginning that default value that bit absurd. That voice for any mild that doesn't exist. What shoot I saying, Hugh, knowing exactly right and we can do something like that? No. We made that class the abstract by doing something like that. And But when we have an obstacle s, we can t create an instance of the clients. However, that you can see we can easily inherit from close like it. But now we don't need to specify things. That doesn't matter, right? That I think that's butter. Well, we've just we lost timeto saying something to the blood, that voice because that that will never be used. Right? Nobody will create in any month off just nothing, right? That glasses really will be used only by programmer to create other classes that will inherit from the West. Right. So this is just abstracts is an absurd class. So this thing here is telling our compiler this class is no, Absolutely. We can no easily inherit from the cliffs. Okay, that's all in the lesson. Thank you very much.
48. Virtual destructor : Hello, everybody. They were going to talk about the view to all distracter. As you can see, we have got here the cult from the previous lesson. Let's come on the thing. So they don't interrupt us. And let's change something in the distracters from our classes. So let's send to the album stuff like I am from the class. Ah, from the base, Chris my something like that. So it will have us the box off. I am from the sub colas Something like that on Dhere. Something like that. And here's something like that. So when the constructor will get invoked, this fink should getting go. Right? So when I create, for example, duck right on and then I will just compile it thing. And Ron, the destructor is from is invoked from the suppers and basis. Right? Okay, But what will happen when I do something like deck equals new duck? As you can see, the sectors where an in vogue is because we didn't deal it. We didn't free that Spect right. So we have to use the delete now. As you can see, we have got both distracters evil. So everything is working fine. The suckers and day in basic. But there will be a problem in situations like that when I Assane here the address off duck to the pointer That should 0.2 annual What will happen as you can see on the destructive from the base place Go involved. So if we did something here, the destructive we had here, for example of a few instructions that would free memory we would have problems because that memorial wouldn't be now free. So how to make dysfunction well toe these destructor to be involved We should create a view too well, destructive So in a gloss that will be used to ah inherit for others right? We should create a here to all distract now. As you can see, we have both his distracters invoke I am from the sockless and I am from the basic above Distracters get invoked. Everything is working Fine. Okay, so please remember that when you create a collapse like that you should always create a virtual destructor Because later, when somebody use your place he should delayed the our the objects is will be created. We've all done the problems right, they should That way we won't make any errors. Creative you to all the circle we needed. That way it would make a big problem, right? We didn't free a memo. Remember? About it. Okay. Does nothing to lessen. Thank you so much.
49. Function templates: Hello, everybody. Today we're going to talk about the function template. As you can see, we have got here the count from the lesson 45 about the inheritance. So we have got here a class point and point to the create. Right now, I would like to show you it's always the problem. The program that will be resolved later by the function templates. Right? So we know. Why should we use something like that? We won't use a military. We need those practice. Right? Okay. So look, we can have situation like that. I want to add two numbers, right? Let's make it as simple as possible. Let's add two numbers that arming teachers so we have to return. The in teacher were called the function at and we'll take to indigent very blond ever able to. And now we make this in lying function. We just returned the variable one plus were ableto So right now we can easily to something like at and then sent here to and five to the out. Then you can just building run program and at you too. And as you can see, the numbers were added well. But what will happen when I do something night. As you can see right now, the result is also five. Even though I sent here double right because, well, we had only that function to choose. And our compiler just, um changed 5.5 to the indigenous rights. He changed that. I have double toe painted. So it means that well, if you want to have the right result should also create something like that. Double, double, double, right? Something like that. As you can see right now, he doesn't know which function he should run because, well, I have got here. Want variable indigent? The second doubles here. Ah, here I am taking to indigency. I'm taking to double. So which one actually choose? I don't know. He doesn't know. So we have to choose one of them by doing something like that? Well, something or something like that will not change the result, right? Oh, we have to just the dead way, right? Or we can just do something like that. You can use the casting right and everything would work fine. But when we are using function, we shouldn't think about things like that, right? That would be horrible. if I had to remember about things like that. So we have to create another functions of example. I create function like that's first will be double second will be, for example, a teacher. Andi. I have to create another. For example, did that I would be integer and this guy was the double right. And right now I can easily building around it program and everything. We work fine. But as you can see, we had to write four functions to achieve the feat. And now well, you know, the double that integer is a big firm apple varieties taking memory. So it is taking four bites and murder. These guys taking a bite of my more. Sometimes we don't need so big numbers, right way we could use the shorting teacher or something like that. That would be enough for us. And then, Ah, these guys here would be a bit slower. So we should create another. And now I would like to show you something, will discover that function templates. And there's something like generalize generalization off functions, right, generalization of function. So we can just remove that think here and now we can say the walk template. So we are creating a plan plate. Then in the break, it's like that in the angle. Break it. We can define our own die. This type is called genera of type, so we can do something like type name. And then we can, for example, do something like that. The shortcut from the type we can type your anything this our time, our name off time Well and well, I just do something like tea here, okay? And then I can use the type that I've just created him. It is that it is any type that will be sent to our function so I could do something like that t at than the for one, the for two, and then returned the device plot one plaza bar to So right now I want to do work. I want to add to variables that our world this same type, right? They're both the same type. So when I do something like that, it will work. When I do the double way, it would also work. But we can right now send something like that because here we just declared on one type. Right? So how is it working when he it can see the to double variables, he's changing that t two double right instantly. So it's very kill. We just written on the one function and it really works for also, for example, shorting teachers and other things like that both when both types of this thing. But hey, we can create more than one type. It can take something like dive name T two. And now I would just changed it guy to teach to And now I can easily at the double and end Or I can add that ain't and double. But as you can see now, we had the wrong result because first we use what it was the integer Then we use the double . So the first think you is the integer. The second thing here is the doubles of Tito is double t want tea is dainty job so but I would like toa have the double as a reason always how to do it. But first, I would like to show you something normal. Um, when you use something like steady cast, there is something like that angle bracket. Never seen larger debt thing, the guarantee and you were sending for example, integer then in the bright guest we are sending for example 6.5 And this think here will be changed the world to the integer numbers. So step because it's really a function that is having something like that you Now, as you can see, the result, it's 16. So this is really at template, right? Said the case is really function template here. We can also specify what with the Inti and will be B 92 from above, right? We can say it so we can just doesn't like Hey, I want it to be, for example, the first guy with must be double and the sinking guy must be also doubled Right are the double right. And as you can see, the result now is okay. So we can make it always working probably like that. Okay, um so is against the We've just by creating Guan function template, we saved our time, right? That's the first thing. Um, but is the is the situation on? Well, I didn't, uh Andi, I used the couch here. That point Not by mistake, because I'd like to show ism. What about doing something like Ed right but like may make it coming right now and operation on points. I like to, for example, create two points. The second guy would be 50 and free. They want to add the two points of 10 plus 50 and 67 plus free. So the results should be, Ah, 60 and 70 right? So that should be our reason. And now I am doing I am using our function here right at function and he won't be too. As you can see, we can't do it even though that both guys here are the same type. So here we have the 0.2 day. Here we have the point. Today we're retired in the point today, but it's not working. Why? Because we didn't create the operator function that we talked about before we created. But firstly, I want to show you another problem. Imagine now that we can't act is the place you we can add that another function toe operated function. So how to deal with the problem? We can make something like, um, templates, privatization for functions and he decided template. And then we're just creating the two Unger Brackens and we are not specifying its things here, right? And then point to Dean den at my the name of our function. Then we're just beautifying cigar, saying this guy will be point to the force. You sure? Vory Balon, point to the were able to And then we must read to return the 0.2 d with the with new values. Right? So what? Well, that's create 0.2 D that will be temporarily for us and will use the function Temporary set Eakes for able one Quips point to Dean dimensional vory below one. Get Eakes class variable too. Get X! So we are getting eggs from Burrito one over e book to and now we just need to do the same thing. But right now, to the why that and you can just returned a temporary here. So no, we can do something like that and sent to the put some dot Get X and get Why? So the results should be 16 7 Um sorry, I That's my music. I didn't use the the operator that allow us to invoke functions of course, to their functions that are not property. So now we do work Fine. As you can see, we have here there without 16. 70. And of course, we have got their messages from the distracters and contractors, so we don't need to worry about them. The most important thing is that all right, A working girl? But we had to specify that because, remember, only we didn't have. We are paging situation. We didn't have the way to get access to that place. You okay? That situation might have been because, for example, there's the sense lie. The dozen law has changed in other things like that. But But you know what? I wanted to show you. No, it isn't. It's an exercise that's just created operator Hugh. Eso what? We should return. We should return to point to Dean. This guy needs the operator functions operator then plus then we're saying, What? There's what? What things will be. Added it. This will be the point today, right? This is the declaration. Now we have to define it here, right? And we can do it by saying what will be returned. Then we go inside the point. Do the then we're specifying the operator plus point to deal. We call that guy object and here also to create the temperature. Our guy and this time will set X that way. Thes. But let's use the think from here because we don't need to write so much done. Set this object that extra all actual guy, right? The same thing should be done here, plus the guy that will be sent to us by the operator function. So right now we can easily Ron. It's that way as you concede the result. Um, we didn't return the temperature half court. We need to return that the result is 60 and 70. Because now Ed is working fine with just one function. Great doesn't go around one function, and it's working very well with manner after types. One functions for thousands of crisis. That's good. This is that function temple. Okay, there's only lesson. Thank you very much.
50. Class templates : Hello, everybody. In the previous lesson, we learned about their function templates. Today we're going to learn about the class Stump place? Yes, exactly. We have the same thing in class. Isn't is really needed. Manage her arm. So let's see. How does it work? As you can see here we have the Cardozo from the previous lesson and will create now the template of class. How to do that? Well, each diaper here template so is the same like the function templates. Then we are typing here something like type name, then name of our type. So something like that we can just di peel tea. And now we just created a A class stamp. But of course, we need to specify all that taste. So I want to change of the integers here to see right now somebody create point guys. Ah, every t will be changed to the type that he will choose. Right? So we will be able to create at class of doubles or class off. Ain't teachers and other types. OK, but now I would like to tell you that unlikely will need to do use the nights pacing that place. Also we need to include the I'll string here and we also into copy all the functions from here to hear. So definitions must be in one fire because that I the won't be ableto refer the things from that fight here so well that things here we're getting to the comment that think you also will be commended for a moment because we focus on one class first and let's now define the functions How to define what we need to in every time. Repeat the template and type name T before each of the function. Right. Then we need to remember that we need to add something like that. H time. And of course, we need to change the integers to t remember that we can create here Easy now. For example, the character be something like that. Everything will work fine. So it means that the dese variable will be in each object that we can't create By using the template, the class will be character. So it won't be changed, right? If we did it that way, it will be changed. But that way it won't be changed though. Okay, So we will right now, can just Okay now Let's go back to the place here and that's created point A. That this equal five. What's they eat? Everything. We work fine. As you can see, it's not compartment. It's because when creating a template went to specify that day here. We have to specify that. So I'm going to create the point of pain teachers, for example. Now I can build ungrounded program. As you can see, everything is working fine. Consent The output, for example. The value that is in X easily. Let's see if it works. As you can see, everything works fine. And I like to remind you you have toe just specify the city in places like that. Okay, but you don't need to do it in places like that. For example, here where I am returning. But where is getting X? Here is the getting's right. We can return always indigent, for example. Right on every finger Work fine always returned the double and it worked fine. We are deciding what will Bay. No tie will be here. But of course, right now we wanted to be the T because we want to change. It never played, but sometimes there might happen that you will need your own type. You must. You We want to be like that. You don't want it to be changed from place. Thank you. Okay. So as you can see, he's working Fine. Now eso Let's maybe ah, talk about something good is called the type definition. You see, we can do something lie that we can they think type definition. Then we can se point ain't And now place. Just think about is the point in now we can declare we can define We're Abel's dead way. So right now this thing means the same thing like this. I know that it is not very, very time saving or something that but maybe you will notice something like that in cold. And I want you to know What does it mean? Okay, so now everything like that. We've changed to something like that. We can do something that well, something I did, and it would work. Fine. Okay, so this is the part type definition. Um, well, I liked it so surely that you can still create double things. So right now that being could be double. I see. If it works, everything is working fine as you can see. OK, so now let's define maybe that things here, right? We need also the class 0.2 dimensional. You will do as an exercise that you can do you took. But it's good idea. You can do it next 6.3 day on. Now let's just create a template off its of template and now type name and we call it the And now we remember that we need to send that t to at place here because we need to know Ah , in the subclass how to create the ah supper. The parent class, right? The strikers went to know how to create the parents concerned. Ah, we need to send what type should be off that thing. See him? Okay then of course we should change that. Things we don't need to bother. We showed because wanting to look like that it's against the Here we have the point to the returned and we are not changing. That t is the do we wanted to be here, right? Okay. And now, of course, we need to copy that things from him. Let's cut it and that's cope with it. Now let's something like that You know, it's time consuming right now. But remember later if you want to use it in many situations, like like in point. Because points might be double my being teacher. That would be easier for us, right? And you know that a point of doubles. Ah, the class point of doubles is taking more, more more than point off integers. Right? Okay, Andi. So now let's change where we shoot where we can That team Let's changing oops like that. And now we also need to remember about adding that t here like that. Oh, okay. And I liked also add that you need at the point t here because you know you need to Ah, we are using the constructor here from play from the class here on that They didn't mean it means that we need to know. What is that thinking? Right. Okay. And we also need to say about it here. The girls were returning something on. We need to know what type is it? We can add it also here and here. But it is not needed because our compiler is intelligent. He will somehow manage out by that lying here. What is that him now I could be the rounded program. As you can see, a compartment, let's maybe now create the 0.2 dimensional. And now, for example, like that, that the English common things number is building around it program as you can see the result these 10.57 works fine on everything compiled. So now we you should create the point for Diaz and exercise. There might happen situations maybe not with that class. But I will show you on this class. Do you want this specialized template place? So it means Hey, I want Teoh make a point class that will behave a big difference when somebody is sent here . Ah, type that I choose. So how to do that? Let's do it. For example, here and now you're doing a deadly template template And then, like in the functions, were not specifying anything in the angle bark. It's then we are saying name of glass that want to specialize a bit And then here were saying, Hey, I want it to be character. And now we can, for example, creating the public section the constructor, my and that's sent to the output, something this is from once or not at that point. And this is from point on character. Let's see if I can compile it as a consumer think is working. Fine. Now we can created point Something like that. Corrector? No. Here, I guess. Um for example, 40 nine, uh, character. Let's call it somehow a on by default a saying he was zero. So now let's just be the rounded program. As you can see, it is working from these from point characters. So now when our compiler see something like the character sent you No. Ah discuss is not being created, but the specialized These one is being created, right? Because we want to behave with a bit different notice one thing right now can we get something like we get X as you can see that the dead class do not have that function. So right now we need to define everything in that class is just special case and we need to define everything from the begging special case for the character. Okay. Must behave different way. Okay, So this is the specialized off the class part. We could also do something like specifically specialization off Just one method for example , I won't. I waas gone good x get X to behave a bit different. This guy, right? I want to tiu. I wanted to behave a bit different, so in some kind of situation. So I'm going to do some tonight that think template done. Of course, I'm not specifying anything in the angle brackets. Then I am, um, just creating that get X. So, for example, for the double point, double get takes. So right now we can return this eggs here, right, But, ah, it will work only in for double stations. When I sent something like that, these function will be executed on one point double is being created, right? So these dispersal case when people create it dead way, um, I think it's not working because we have got here and in line function. Let's change this thing to note in line function. So let's create before it to get eggs. Good. Thanks. Their return, the tea, return these eggs. So this is the default function, right? And this thing is the specialized function for template. No, it should work fine. Mm. You know, I stopped the program for a second because I was a bit confused. Why that air Awas him on And then I just remove the point see pp from the broad like when you're creating temperature, you can you have the CPP five because he's compiling sometimes two times something when there are templates, Will templates are making some problems when there is a point that agent point that CPP. So let's just remove the CPP from the project. And now it's concede, Uh, this is running well, right? It's goats. Our program is wrong because you can see this function would be executed only one point double. So, um, dysfunction, Good executed, right, So good. 90 dead way so and I don't want the specialized verse shin of the functions you can see Ah , we, um, involved that function right, that function getting book So now I can specify only the function, So it's, I think, a bit better than this thinker. These thing is very rare to use, but specializing the function Ah, I think who might be used many times when you're doing something like that not like to tell you about the half class specialization Onda when it is a good idea to use something like this is big advance topic. Look, we can do something like that. So the template and now type name and here type that we want to create a want tohave here so we can name it us. We want we can a girl named Tiki, anything like that. I would now call it King, so it would be different. Just so you know that you can pay for rent. And now here. Okay, the class point that will take that key here. Right? And in addition to this, I wanted to be the point mas Evita point. So this thing means that when somebody will use here something like that, I want compiler to create that class here. Note that class here. Okay? And when it's good idea to use, because right now we can say something like, Hey, you just did it. Um, so we'll send to the output. Something like that. You can use pointers here. This is right now. Um well, to specify something Q. No, there is a key. I equals zero. Ah, sorry. Should the point, sir, I heard the point in our link in my language. Okay. On here, right now. Of course we can't get inks because it's impossible, right? We conduce pointers here. So now we're informed that can do it here. That glass is running all right, that God's good creation. Of course, we couldn't use it function here because that function to get X is not doesn't exist. Right? Um, that's how it works. These very advanced up again. It's very rare to use. Um, don't worry about it. I think the most important thing is to remember about the specialization of function from a class like that. Get X that we created here another than that we didn't change much here, but e c a useful thing. Okay, that's all in the lesson. Thank you very much.
51. Exceptions : Hello, everybody to They were going to talk about the exceptions and about how to handle exceptions. Okay, So, first, would these exception exception is jazz? Ah, situation that can happen in our program that will stop our program. So it is bad. Ah, when exceptions a que well, look, when I do something like that, folks up Can I divide by zero? No. As you can see, this program has been stopped here. We getting only close the program now, and that's all. So everything after read like that, if you had more instructions here, wouldn't be executed. You can see the program has stopped working. It's very, very bad. Of course, there are many, many other situations when something like, ah, when I program can stop, for example, we can locate memory right with the New World and, for example, we want have enough off. There's no more when we try to use the new one, and then the exception might a cure. And then our program we stopped working and other things like that, and we should be able tow handle that exceptions. Okay, Now I will try to show you very easy example. Look, I will create a varietal, for example A. And I was saying it here value five. Then I show you how to handle exceptions. Look, we can try to do something that construction is studying us. That we should try to do everything between the opening Carol bracket and closing curly brackets. Okay, we should try to do it right. And here I would, for example, multiply a by, for example, 10. So a will be equal to 50 right now. And let's assume that a shouldn't be 50. Let's assume it is an exception that will stop our program. Then I can do something like that if a equals 50 please tro exception. So tro, for example, dead a here. So we, um, through there object a somewhere and Well, when we threw something right, we should catch it. Because when we don't catch something like that, our program will stop working because it doesn't compile even here. Um well, we have to catch it because otherwise will make big hole in the air right when something was falling. It is making a whole Okay, so we have to catch it with the world to catch here in the Perak between the parent disease . We should say what we want to catch right now. You want to catch world? You want to catch something with this ain't teacher, right? Because that object here that we are throwing is what is indeed you. So let's colleagues here, for example E. And here we can catch that arrow So I can say something like that. A cannot be equal to a for example, like that. And now when I bathe ungrounded project. As you can see, that thing has been written to the out. But it would be like, Hey, why? I just didn't do it that way right here. And everything will be OK. Um but look, now I the instructions after, So for example, here here are other instructions, right? That instructions won't be involved. As you can see, if I did it dead way, the instruction after also got involved That's the first thing. Second thing is that ah, that are special. The things that catch and try constructions and they can catch errors that cannot be catched by the instruction. Okay. Like for example, memorable occasion. Okay, we are making here an example. That is as is this possible So if I changed for example, that guy here now to double what will happen? As you can see, this application has requested the runtime toe. Terminate it an unusual way. Please contact the application supporting for more information and our programs stopped running. Why? Because we trio here A which is double. And we could catch on Lee things that were what in teachers. So we threw something into the space. We didn't catch it. It made a hole in our program, right? We have to catch everything always so we can do it. That way we can make another catch Instruction, for example, that we before integer and will be for the double I det now everything will work fine. Oh, of course. Everything after the catch is working Le you can see That's why Kadji school, huh? On and all You can do it that way we can just catch everything possible. So now here I can write something like this is going to the ah, just leave ignited. Um, as aggressive is going tobe a. This is a message that will be shown when other catches. So other things like that Other catch, other catch instructions won't be involved. These like out Statement in Ah ah, If insurrection right. And now we can catch every think here. Easy, double when the character right, We can do it easy. Okay? No, um I like to tell you about the true years of something in it. Look, we can make a function that will call division as first bottom. Aitor will take the number that we're de vie is the second number will take a number that divided now the number A right. And now we can just return the a divided by being. And here I would just run division Oh, for example 50 So I want to divide five by zero. And let's a saying some were the result of that. And the result is the result is here will send reason not one night business, Ron. Oh Ah! I cannot be equal. Teoh. Ah ah Business Run! As you can see, the result is infinitive. What? Ah, our problem program. Our programs somehow managed to defy 50 but is because the double types and you some brother divide 50 Then the result is like that. But we shouldn't allow a situation like that right? So how toe manage something like that. We should check here. If B is equal to zero before and if it is equal to zero, we should throw for example, be so this catch instruction will be involved now, right? As you can see, dense. This instruction got involved so we could say he rare or la la on other things like that. And these extraction didn't getting broke, right? So after the ear, everything. So the closing curly bracket here wasn't involved. So it's good, but in But it should be written a bit more professional way we should create. Now hear a class that we called SA that should be self descriptive. And we call it division by zero exception. Okay, We just created the class the same fire. Why won't the I don't want to create the other fights so it won't take our time right now in the public section will create a function that we get the error message and we will just make it in lying function. Do not divide by zero and are something like that. And now we can throw here object like that. You can do it that way. or we can just do it dad way. The second version is better because well, when the error want or cures, the one is not equal to zero. We don't need to create ah division by zero exception. Right. So this is better version. And it means now that we have that type off our to Trone somewhere here, if the zero right so we can catch, we can do it, for example. Well, when I do that surrounded program these catch, he got involved, right? But we can, for example, specify it so division by zero exception here and now because e is really that object now, right? So it means that you can get that get at our message to King goes something like Okay, and then get error message Didn't rounded program. As you can see, Arrow do know divide by zero place. It works fine. And these the professional away and it should be done deadweight. And we also showed inform other programmers about world is being thrown in our function. So here I think hate. Remember that summer here in our function Ah, there might be true that arrow. So you should remember about that that you should catch it. Because if you did not catch that thing, it will cause problems. Right? Because easy. Now we can do it for example like that. I'm not catching it now. And our program has been terminated, right? It stopped working, so Ah Mm. Matching that. Our function is like 100 lines long and ah, it's hard to notice. Where is something thrown? If I do something like that, I am saying, Hey, remember, there is something like that. And in using, for example, he can The programmer can click on something like that and he would notice where something is being thrown and he will know that he has to catch the terror later. So these used like that. And you can also leave that thing empty when you defeat Empty. It means that there is no Ah Not that there is nothing wrong in that function. Right? And you are informing you don't You don't need to worry. You don't need to use the try. Catch state So these like that. Think here is used as an information OK, that examples are really easy. No matter that things are used to be in different places like in the more location. But, you know, we'll target probably a in other courses when me right of harder programs. Right? Right now it's Ah, it will be Just, um those of time. Okay, There's only lesson. Thank you very much.
52. Namespaces: Hello, everybody. They were going to talk about the name spaces. Look at this name. What is the name? Nice. Because the space where we can create names, Okay. So we can create classes, variables with some names, right? We can create label for them and the world. The school about the name spaces is that we can create in one space, for example, of a Rabel. We've name. Okay. And in the second name space, which is different, we can create a for able with the same name. And both did very labels. One know about each other and we can use above of them is Lee in our program. So when something like that is used, you know, for example, I am a programmer. And right now I will use, um, some kind. We create the class that will be called, for example, person, right. And, you know, there might be another programmer that we create the project and he would call and other objects like that. We call it a person. We call that class of person, right? And then there will be a problem. Because we don't We can't have too the same names like that And then we will need to rename all in all the places that it was used the names but with the help of name space, we don't need to worry about. Look, even now we are having some nice base here. These is the locals pace. And when I create here, ever able a and I sank your 50 and and then I will create in the global space variable A. And I was saying here, 20 this program will comply because here is a local space and this is the global space. And look right now when I do something like that, we will get on the output the 50 because a will be coming from the local space. But we still can't get access to the value here. We can just use the scope operator, which is still cold now, and I built in the program. As you can see here we have the 20 Valley so we can get still access to the global. Very, however we can do something like that, right, Because that's do guys are now the same so we can create a nice piece how to create a name in order to create nations. We type nine space. Then we are naming our nicest example. Are we call it Big A. And here I will have our A And then I would create another in any space. Be. And here we'll have dead variable. Now when I come pie it. Ah, as you can see whether he's trying to get something from here. Ah, but if we work because that guy here is now in other nine space for than this and we can get access to the to the Geiser because we can do something like that. Okay, scope. Hey, so I'm getting the value from the story. I am getting the value from here, right? So, 20 if I want the value from here out to something like that, As you can see, it is working fine. Well, that's called it guys bit different now. And for example, I would like to use everything. What? This is the nice place. A Then I will just use something like that. You think Name space A. And now I would have access to that guys here without even using the scope operator. As you can see here, we have to and to know but they can still get toe the place here, for example, like that. As you can see, it is working fine. So when you're creating a project, it's good idea to create your project in a space. So when somebody will use your and your programs, your classes, he will just use your nice base, and it would not call it with his names in his program. If I know them would repeat right because he can then choose which guy he wants dio using his program. You want to use the variable from his program Auriol program. Okay, this all in the lesson. But I would like Toa trying a bit in this lesson because it's the last lesson. Let's imagine situation like that. Here's the end line, right, and it is used in the nice place STD. If I don't use the nice necessity, you'll notice that this program won't around. We have to use the STD here, name space like that and like that. So it means that we can't create an object that we be called and line. But hey, I would like to create an object. It will be called end line and this and lined would do, for example, free enters, not want. I want my own and line it will be here. So how to do that? How to do something like that? Well, for example, we can create our own name space, like that Name space, and then my space. I would call it right now. And here are clearly ate a class quests that I can come, for example, my new a light and I would create an object that I would call my new line and line. So I want to use here right now something like that, My spice. So I'm getting here and then end line from my space here. All right? I don't want to use the end line from the STD, but from my space, I have to also make it work right now. When I didn't around, the program is not working. Of course. Well, here this is next something they did. As you can see, it's not working because we didn't ever law that operator here and whether I like to tell you how to overload things like that. So let's create, um, string in the provide section that we would call, for example, next and the public section will create A. When this may be topping that way will create a construct. Er my new line. Let's do it in line Constructor, we have to say something to our text. But let's just say something would will be coming from here. So string text like that we can an a saying here also the default value. Let's a saying here, free enters. So by the fault, the think here will achieve free enters the vaccination is representing Enter sign and now Ah, we want to just Ah, When somebody used the end line here, we want to show the text here. Right? So right now we can do something like that text because it is in the previous section We have to create a function that's called dysfunction to string and it will return the string and well written, just the text. So right now we should be able to do something like that. Um, as you can see, we can do string here because spring is you. It was from STD. So we would need to add everywhere STD! Or we can just use the nice place STD inside that name space As you can see, we have now here. Free enters, right. You can add some text, Hume. It will not this that it is working. Fine. So we can easily send to the output world is inside here. But hey, that's nothing new. I want to achieve something like that. I want to do something like that when I see end line. I want to see on the output the thing from here. How to do something like that. Well, we have toe overloaded operator here because it's concede saying has no matter for operator too. Angle brackets, lower one, right. How to do that? Well, you know, in the aisle stream there is an object. All stream and I sing ice cream is input stream also Miss Output stream. Right now, Here we are, using the output stream here. Everywhere where we were we going something like that. You are returning the output stream. So if I want to send it to the output that think here we need to use we need to return the output stream. So we call here something like our put stream and then return the references it out through . Okay, Then we'll create a function that you overload the operator like that. Right? These one on then in the in the between the parent is is we will create where we'll take as an energon argument. Two guys Well, on the left side we have walked. We have the see out here, right? This thing is really it's what is it on all stream, right. So we call it something like that on the rights hand, we have what we have. We want to send these things, for example dissing right. This thing is our object that we want to send out. So we call it what we call it. Just my new line and we call get the reference of the object you And now we'll just return . We need to return the oil stream. Right, So we'll return out Object to seeing So we are just doing the same thing. Like we did it here. But we are just returning. You are returning that thing right? We're returning that thing here. That thing with the sea out is being returned here and then because of that. Well, because of that, as you can see, we can write it faster. So right Now you can write with the function like that. We can write something to the apple very easily just by using the name of your object, right? You don't need to use the function like to string. Um, you don't need to use the function that gets, for example, text. You can just send name of your the off your object and everything will work Fine. Well, we can also make it a bit shorter. We can say something like you sing name space, my space. Right. And now we won't need even to do something like that as you can seem. Um, well, it looks like it's not working because we are using the nice with this TD Herein he's trying to get in line from here and he's starting to get it from the city So we could just do something like that to repair. Just used before age off guy from STD Something like that. And now, as you can see, it is working fine. We can, of course, still get to the end line from the STD place. That way we have just one and line that way. If I free end lines because we specify it like it feel we can, of course, change the bid. Now, for example, I want more off them and there will be more of them. Everything works from okay, that's all in the lesson. Thank you very much.
53. Streams - what is input and output: Hello, everybody. Today we're going to talk about streams. About the input about output. We would like to be more firm. Millar with Ted reports. Otherwise, we have just problems. Will have to memorize everything by heart. So we won't understand. It will just write some kind of coded won't understand. Let's understand the stopping from the scotch from the begging. Okay, So what is the same? Well, let's look at the pictures. Look, here is the stream, But what? They'll held its stream. You see Europe above the right now a disease just Walter, let's talk about programming, right? Of course. We talk about programming, but look, he was the stream. You can see the the water is moving. There it is flowing from one place to another from something Go. This called input to something with these output. Look, from the top to bottom stream. Is there some kind of object in programming that allows us doing these operations behind the scene? Right. And they could stream just because of it, because they're allowing us to do this things right. Okay. And now Okay. So what is in the programming, for example, input. What is the water in the program. Well, look at the programming and situation in the programming language. The water is information, but right by that they're moving from one place from something. Body sculpt and put to another price. So, for example, variable Or, for example, something good is called output. For example, toe the monitors. We can sit right. Ah, So to sum up we can move, for example, bites represented by characters from the user keyboard, which is in put in that situation to the file. We just output in that situation so we can think about input. Ah, as an entrance to something right. It is a source late for we can put something in, for example, characters. They are waiting there, and we can extract them. So the input is like the source. We can extract things from the embassy and we can think about output as the place where you want to put something out. Look, how emphasized that Think output put out something right? We can also example hearing the Coleman the synthetic, put in from a ski boat, put art to the fire. So, as you can see in boot out food, right, so out to be some kind of destination and put input is some kind of source and fronts exit something. Here we have a very simple program which right now that's nothing. But, well, we called here for a large library with this input output stream. So it has got an object stream which allows us flowing, moving the information from input to output. Right now, the input is represented by the object weeks. We just called c in. So it is like you can, for example, remember it is CPP in Booth, we can put things there, do that thing and you can take things from that input. Exactly. We can boot their characters from the key boat and we can put them later. For example, Tova Rabel A which we have to also declare here defining and when around this program. And right now I am typing numbers and the numbers are being popped put here and then they are moved to a so on the input. Things are waiting and when we type here and then they are moved to the very book. But we can also move that things toe other place. We could also move them to the outward right so we could do something, for example, See out. Let's send something to the output. So with that arrow and something like that, we are moving it outside so everybody can see so we can run it. And as you can see now we can see also that 55 that we put here. That the import and look right now we are not talking about five. Somebody say no. Look, it is very, very similar because right now we can, for example, take things from this source from, for example, input and put them inside the fight. Or we can say that the file will be the input. It will be the source this time and we'll take things from there. And we'll put it outside toe, for example, User, so he can see it on the mind. So you see, the fight can be wants the source and once it can be the destination, I want to sometimes, right? Do it. But you can. I also want to We can also take things from the fire, right? It also it all depends on the situation and we will talk about the situations. We also talk about other library that we exactly do thinks five it is very similar in next lesson. Thank you very much.
54. How to open and close files: Hello, everybody. Today we're going to talk how to open close and right to fire. But remember, we'll do it the simple way So we would just know how to opening, how to write to it and how to close. Well, no talk about the advanced topics. Like, for example, a pending to the fire opinion. Is that the Binali fire and other things like that? We just want to simplify that so we can learn it step by step. Okay, so we want to learn about the library. We discovered five stream so extreme stands for five string. So it is operating on five. And it is really, really similar to the art input output stream. This time we will treat the file as an input or as an output. Well, we'll decide how we want toe treat that fire. Firstly, we need toe create an object object that will, ah have inside the fire that we want to treat. That won't operate him. So let's create the object. So we will talk extreme and my five handle. So this is the place where we will save where we will, um, help our fine. And because we are you think you hear the extreme class. These objects has got lots off methods with functions that we can use here right now. And we can operate on that fire that will be opened here. Right? So let's open it. My fight hander and as you can guess, varies a method that can open the fire. He we can type the name off. I So, for example, test and the extinct. And right now we should be able to open the fight, test the test fire. And there is a problem because heroes you can see there is no fire lighted. And because of it, we won't be able to open it because it's not here. Right, So we should create it on here way are doing it. It's grated right now so that here is a pole Iverson inversion off this windows. But well, you know how to create the five for sure. So we're creating the fine. Okay, So it's not that we are open, you get the fighting is already created, and now we can do some things with it. Well, look, that fire right now that it's happened here, um is really at the output, right? It is the destination off the things that we can put the right or we can, for example, get something from inside example. We could get some things here, and we will drive toe, retrieve it, Extracted right now in this. Listen, let's just put something inside there, so let's make it as an out look when you have something like see out. So the character output were moving something there. Right? And here it is no different. Right now we're moving something. Toe the my five handler and, for example, this ISS saying a simple text. Right. So we're moving it here. We could also do something like that that's here. It is really very similar thing. Okay, so we're moving these desks here and now we should also calls the fight. Why should we close the fire? Well, you know, firstly, you could use the my 500 toe open. Other fights. Secondly, now we are for making, um our resources, more resources and other things like that. Free. We are not operating on the fire and more so we are making it free. We can work on other things like that. So it is good for her program for the health of our program for health of our competent that things like that eso we're freeing here our memory and we are allowing us to use them , my friend 100 more than once, right? So we're closing the fire, and right now we can compile it and run. And as you can see, when they opened if I Here we have this. This is this is some sample text, right? So we just We've just written that think in fact. So it works perfectly. We can also, for example, check it. If I has been open, probably some present my 500 And here is a function is open. So if then you can don't this insight and you can close the fight. Otherwise don't do it right? Said something like that, Andi, as we can see, for example, when we do something like that on the fight has bean open for a poor really that now it's not working. But when we use the name, find that that we create it. As you can see, the fight has been open properly on Of course, it's working fine. We can also notice that we can Could something God is simple text, for example. So we're at a here which was missing. And when I run it, you can see that it this added. But look, we are creating the fight from the beginning because you can see we're not adding on and to make things like that to add new text, not removing everything. We need to open the fire in some kind of mode and we'll talk about this bolts. In other lesson, we also talk upto extracting from that right now in business. And as you can see, we treated how where if I as what as, uh, output, right as the place where we can put thinks inside. Okay, thank you very much.
55. File opening modes: Hello, everybody. Today we're going to talk about the ways we can open the files because you see we can open the fights on and make them being on the read able on the right table. Or maybe we want to upend something at the end of the fire or maybe want toe open. And if I as a binary file so we can add it, for example, an image. So let's let about the flocks. Flaks are most for opening the file, so we can said, if I toe only be able to, oh, fright to them to read from them and other things like that, As I said, area. So let's get the comments so later you can read it easier. Um, as you can see would have got here. It called from the last lesson we have got only created a five which is tied this F stream and you are paying here a fire with the sample text Fi and we're checking. Give the fights open. If not, we are sending a proper message. And if not, if it is open, and then we will do something, keep right. So when we around, this program is you can see we have got here a matter. The fire hasn't been preparing opened, so Ah, as you can see, it is not cool that I would tow every time created five that way. Right. Using the windows of something that, um, we have to make sure that if I can be easy, is a curated through the C plus plus language, right? So how to do it? Why it's not being created in this place. It's because that file right now here has got some kind off flocks. Right now it is in some kind of moat and f stream default mode. Let's let's some 95 vote flacks. Ah, is input output stream input. And it has got also the flag, which is out. So it has got the to flacks like that. And let's talk about the flax here. So these guy IHS from input I in stands for input and it allows us to read from the file. So it is for reading, all right, reading from the fire and here we have good out and it allows us toe right to find. And when we have Teoh that two months up in the center in the same time when he opened the fire. We can write to it and read from If we had on Lee this think then we would allow only for writing to fight. And it is pretty easy to understand that when we have Onley, that flag on the five will create automatic Ari. Why is it so? Because look, when we can when we love somebody to write to something then, um we need a five which he exists, right? We can't have who can write to the to nowhere. So when you have the output Ah, flock, we can write it. If there is no five, then create it. And also, if there is a fire, then tragic aid it so remove remove for every remove content on Lis It's a course with IOS in flak. So when we have a default mold the right like now because it has also these flak we are not creating the file automatic car But if he was only this flag and we can change this behavior by simply using the second parameter here. As you can see, the default mode is set here that it is in and out and this could see we can study to only out no and when we comply it it's a conceit would have no error. And as you can see here, we have new fire. What is a sample text? So it's working very nicely. Ah, we can create a fire. But if we used as I said area, something like that is so the default mold on that's changed. For example, this name here. As you can see, the fight hasn't been open properly because it's not here. Of course, if we have the five there already, it is working pretty good. Okay, so we can change it here. We can also open defy by using the constructor here so we could say do something like that . It's good idea to know that it's possible to do also that way that you can see it's working Fine, but we'll use these syntax. Okay, so here we have the import. So it is for reading on them. There are more flags like let's see them throwing Kate, which he's from truncating and it is truncating the fight, cutting everything inside right Onda, we have got also something like eight, which sends for at D and and it is setting pointer at the end off five. So when they open fire, we've, for example, something like that. We have got the ah, the pointer at the end of fight and we were right at the end of fight. But the problem is that this flag is also truncating the fire. So we wanted to add something at the end. We would need to also ah, at that flock here, the input output stream in flak. Okay, so maybe let's check how it works out. And let's add to the fight, for example, Um simple, simple text. And for example, let's at another text him, that's at the end. The enter line. Now when we open the fires, you can see we have got here a sample text two times, and when you run the other game, we can notice that it's the same. Why? Because that output flak is cutting everything from inside. So when we met input Apple Stream in Epsom, then when we're on it, as you can see this ad Inc this think at the end. But we also need to remember that the pointer is at the end of the fight not only for righting here. It is also for reading. Here. We can read, write to this place. We can change the point where things are being put, so it is really important to know it. So Pointer can be changed. Maybe the place of pointer can be changed in that moment. It it's possible to read and write in that moat. It is very important. Why is it important? Because you have got also something like a pound mold the flock and the content is added at the end off fire, always at the end of five. And it is not possible to remove content nor adding something in other place than the end. Well, fine. So you see, the difference between these two months is that in the happened, we we have way have on the possibility two at things at the end. It's not possible to change afterwards. On to, for example, it's something the middle off off the open fire. It might be important in some situations when we try to do something so but it is also very , very important to notice that we will not need Teoh at that. I always in flux this time with the output Flak. Why? Because, as you can see, it is not possible to remove content them. So when you have got this toes together, when you're on it, as you can see, um, the sample texts has been added at the end and we didn't remove the counter, right? So it's pretty cool, too, because we don't need to add that flack him with it on. There is one more mold, which is binary, and it opens the fight as a buying narrow. Fine. Okay, so let's I think a second about what is binary file. And finally, fine is fine, he said. It is. It is just a typical fight every fiza binal If I So why did they even create something like text by byline? If I and other things like that? Because you see here in that program it is a note, but it is automatically changing that Binali form to the text form. So every 0111 is changed to, for example, as a MP, I called angry, right, so the text file is a binary ified. But when we use a note but we can interpret, isn't US attacks And here we have got a binary moat and not a Binah. Ramon, Another bine animals is a text mode. And the difference between the stows is on Lee that in the text mode, the default mode Ah, there is an enter adit, which is a bit would just always they gonna be interpreted the same way. Under any operation system, we use the binary. We might have problems if we, for example, change from the windows. Some kind of lean nox or other are other place we will change between binary and the text mode frequently or something like that. No, I have a problem with the enters. Right. And that's on the difference between here right now. So maybe you will need in the future. Maybe not. Maybe you don't need to even ah, be confused, writer. But you need to remember that if you want to open an image off some kind of archive like a zip, you would need to use the beina remote. So here is the very important difference than right. A Z can see a few. We have the F stream library. We have also the I F string library, which has the default mode input and 00 F Stream Library. Which default is out? The extreme has got inside because it in carats from if stream and off saying so, It has got all things from the stools guy. So maybe it is the best idea just to use it all the time, this thing. But you know, if you especially want to say that you want to just great just this thing don't especial say that they want to just put something inside the file, use the offspring. That's the way you shoot used that. The library's okay, that's all the lesson. Thank you very much.
56. Stream's error flags: Hello, everybody. Today we're going to talk about the streams Arrow flats Because, you know, sometimes when they open defies their my happen some kind of arrows you see, for example, might try to by mistake, a sign ever able. Which type is string toe the variable, which is in Teacher. We can try to retrieve something from fight. And by mistake, we we could do something that right, And then there will be some kind off earlier. And you can react on the errors because when some kind off off errors happen every time there is a state which we can read and we can react to it. So there are functions. Functions which returns through or falls depends depending on the situation. For example, we have got to function, which is called BET and, as you can guess, hisses, bad, bad situation. And these function returns to if there is an error like, for example, writing to fight, which was opened on Lee for reading. So it had the flock IOS a boat. We have to remember that this function returns the true because there exists a flag, a state we just called bad. But okay, so let's check it out on the practical example. As you can see, we're opening here a sample text which you would have got here and here. We have a simple text inside off. Okay, so let's open that fight right now on Lee for reading. And let's try to answer something inside. So for example Ah, sample texts about some singles. So we're trying to insert thesis sentence inside, but we cannot do it, right? So what happens when around it? As you can see, nothing happens. But when they opened, if I also nothing happens So what happens? You see? No. Right now we have got the state bad bit and we can read that state. For example. We can do it that way. Five bet, and we can send it to death output. And as you can see, we have got to you one. If we don't answer than the thing inside, then as you can see, we have got to your zero. OK, but well, why do we need something? I did look, when something like that happen, what would happen if I try to, for example, write something to the temporary five from the fire? So it's like that. Um, Violet sanded up. As you can see, nothing happens. Why? Because right now we have a big old bet. Um, bend it estate which say's we cannot do anymore anything on the fire. So, you know, right now, if you wanted to do anything on the fight, we would have to rest it. We have to clear the state. So we will need toe use the function which is called clear on it's clear the state. So we will need to use heres something like five. Clear and yes, right now when we were on this program, As you can see, we have got here a sample. So we have to clear we if something bad happens so we can check if I but 10 we can say that something happened and we can clear the state than do something as for example. Ah, OK, So what else flax do we have? We have got a function. We just called fail. And it is indicated by the favorite and the function fake returns through if we try to assign string toe in teacher while wide reading from five. So the the very boots are not the same type or when bad beats situation happens. So the Fae bit includes bad beats. But it is also indicating situation when we try to science string to intern, teacher Another wrong type, right? So let's check it out right now. We also learned how to take something from the fine. So we can, For example, let's create here a string which will call the buffer. So is buffering is some kind of temporary place where you can store the things and here right now we are directing things from the fire. Do the buffer and as you can see now we can send it to the output. Let's do it. As you can see, we have example here. But what happens when we have got here? And teacher, As you can see, we have got here zero because the stocks are wrong on. We have got their some kind off, um, casting, which is hidden from us. That's why we have got a zero. But you know, right now we have got a five. It we can also we can check it So as you can see again something like see out ah, five fail and line And as you can see we have got to you one which indicates that something faith So we can check if five failed, then say that it failed and we can rest it. Them, uh, the car on state. Right. Okay. We have got also a good fleck which indicates that everything is good. So it returns through. If everything, it's fine him Well, if any of the both flaks are false, right? So when we do something like, see out far good, we should enter here. So exactly that what is coming From what Ondas You can see we have got here zero so not everything is good But when we change it back to the string As you can see, everything is fine. Okay, Now let's imagine situation. I would like to read everything from the fight, but we have got here lots of more texts, right? Something like that on Want to read all text at once how to do it? It would be stupid. E we did it for example. Like that fight the buffer c out buffer And again and again. Of course, the thing would work But it is not a good idea to repeat things when we can use what loops . So we have to use the look. But when will the loop end? When we reach the end of the file. And that is the most important fact. Flock here with this end off fire E O f. Which sends for end five. And it is e o f bit. And it returns to, um if the file opened to read, reaches the end, both five. Okay, so let's try to use it. So we'll try to do something. So try to read something all the time and let's send it to the output. Why and why? We will not reach the end off five. So something that fired dot and the fight and when it on it. As you can see, we have got here all texts and at the end, we have got zero. Why is that zero here? That's the question. Good question, because you might think, Hey, everything is fine. We where? I didn't think so. We shouldn't worry about it anymore, but as you can see, I said, it threatens through if everything is fine. If any of the above flags are false, the problem is that and the five is true after reading everything from the fire and we have got no situation where we can do in the more anything with the fire. What if I wanted to do something now with the file, I will need to reset the state. But firstly, I would need to check if the state were just here. Waas end of file. Or maybe it was bad. Better, maybe five. Or maybe it was some off end of bidden fibers, right? Because these things can sum up also how it happens because you see the good bit. Zero. The end of it is for the favorite IHS. Um so the favorite is for the end of fight is still and the bad bit is one. And let's see how it is represented by bites. One is represented by 001 to the zoo, presented bar 010 and for is represented by 1000 Because we have got one in different places, we can some the these things together, and we can say exactly which one is happening at once together, for example, because of what? Because offbeat wise operators, for example, the contruction, the some and exclusive or operator. These operators are very well. Ah, Talk about in the first c++ language course we're just use it, Hugh, in the very practical place. Because you seem right now, for example, I'd like to check if that state here was really end of fire. I could check off course Eve the firewalls. And if I and ive bad fight, then if five. But how to give the stuff where at once, That I wouldn't to make lots off conditions. So it will be then long how to do it once and very well. Well, we can go. For example, something like that. We can use the read state function greet state, which is reading the site. Ah, that r and D is from breathe. It stands from re it right so we can wait the state, for example. Let's check it out. What happens when we do something like that right now? So five read state As you can see, we have got here too. So it means that right now we have got the end of fiber dio If you had the Fabi well care for If we had faded and end of Bill, we would have six. Okay, so when situation off something off, the beats happen Well, for example, now where did here and enter and that enter end of lying cannot be added to the string when you're on it. As you can see, we have got six here. So we have got in the same time favorite and under five. So something wrong happened. And because something wrong happened, we wouldn't like to continue our program the same way. Like if only we read the five properly on and we have to only red reset, the state went and the five big status on we can use the exclusive or here. Why? Because when you have got to Sikhs, for example, 110 and we do the exclusive are here. So, for example, on 010 the result off that think would be 100 So it will be four, which means that there happened more than just end of bit. If you cut situation like 010010 then we've had 000 from the exclusive or because exclusive war or works like that, that it is only true when only one off the bit is true and we can use it here, for example, like that if five read state, soar exclusive or we've And here we can use the i f stream and used the flags, which I talked about so badly. Favorite end of bid right now on that think end of bit indicates to So if something like that happens, um and it equals zero, then it means that it is for sure, and on and off bit on the end of it and we can reset the state. So we can, for example, say something The fire has been reading proper. Read properly, Andi. Now we can create the state easy. And as you can see now, we around this program we have got six year. Why? Because the state wasn't cleared. Why it wasn't clear because when, for example, we do something like that. As you can see, we have got here now for why is it for because, as I said here, it's for here, right? Six and two is giving us for But when we have good really a situation which is just end of five, we about the fate bit ah, well arrested the state and we can use again. This five toe do something goes okay? Of course. When we just cleared the state, it doesn't mean that we can read that fight again without in the problem, because there is some kind of indicator at all, which is indicating that it isn't the end of the at the moment we have to change these things. We have to move it to the beginning of the fight or something like that. But we'll talk about things like that later. So here you can just clear said indicator off place in fight some other place, Uh, and some other operations on fire. Otherwise, we could check if it was, for example, just Fabi. And he could just to a condition here and everything would be fine. Okay, There's only this lesson. Thank you very much.
57. Reading position pointer - seekg and tellg: Hello, everybody. In thes lesson, we will talk about the reading position pointer about the indicator off the place inside the fire. Look in the last lesson, we created a program where we retrieved all possible information from the fire. And when we did it, we cleared the state and that I know, unlikely. We just cleaned the state and we didn't do anything with their reading position point. Because of that, when we do something like and we try to send it, it output will not is that we have got to times important work here because it is the last world and it's because the pointer is right now at the end off the fire and we have to change that. The pointer and this pointer is called reading pointer and we have got to functions that we can use on the reading pointer and these functions are inside the F Stream library or inside input esteem library. It is not possible to use it inside out would have seemed library because it's easy to remember. It is just for reading like the input have seemed. Library FC Library has got both library so we can use it there and these functions, Kim tell. Where is the reading Porter off, said the reading pointer at the specific fight position. So let's start from getting the pointer. Let's see where it is right now so we can do something like see out and five and used the function tell get. And when you were on the program, we can see that the position of the pointer is 40 free. This position is and is the binder is the binary ah position. It means that it is 43 bites far away from the bagging of the fire. We should use the IOS binary flock here because sometimes the text mold, which is set by default, might have sometimes problem. We've interpreting free things, right? So it is more safe to use the Beinart here. Okay, so we know now how toe tell where is the reading pointer? And now let's learn how to set the pointer Summer. And maybe, let's ask ourselves, why would we even need something like that? Well, for example, you would like to read from the middle of the fire. Or maybe you would like toe back in the middle of the fight to the beginning. Or maybe you would like Toa. Just see how big is the fine? Oh, let's do something like that. Let's check. How big is the fire? So right now when we opened the fire in that line we are at the beginning of the Faisal. The ah tell get functions should return zero and how to get to the end of the fire. Look that see, get function has got a second overload function which you can use here. We can put the how many bites from the flag place we want to move our pro pointer and flag can take the begging And in current options, the begging is set by default. When we do something like far seek, get And when we put here, for example 40 it means that we are setting the point It at 40 bite from the begging So it means that we are doing something like that. But well, we want to set it at the end. So it might be hard be when we don't know how many characters are inside. We could read all characters, but it will be a big too long, but because takes time on the fight is very big, but we have got here flag would you can use. So let's use it. We have got the and flak and how many characters we want to move from the end and flak from the end of the fight. What come when they bite? When we type minus five, we'll move five five bites to the left when we type in five with the move five bites to derive. So when he type zero, we will be at the end of the fire. We are just not moving from the end of the fire. We're setting it at the end of the fire and because of it Now, when we use there five the get function here. Ah, we have got here inside the size of the fire. This size we can save to the stream position. Type off variable so size off. Fine, because tell, get function returns variable which tied the stream position. You can use the anti jer also, because it has got a converter which will which should do fine. But well, it's more professional when we know exactly whom the type when we look at the vory right. So let's send to the output this size off the five is sighs, fine bites stands. And when around the program. As you can see, we have got here. Now the size of the fire is 43 bites. But as you can see also well, nothing else happened afterwards. Why? Because look, we set the pointer at the end. And when we do something I do. Why? Fight is not at the end. Ah, why The end of five. Flack doesn't say we are at the end. Do that. Things that are inside here. Well, but we're at the end. So we're not doing anything right now here. And because of that, we should arrest. Set again the pointer. So how to do it? Well, we just need to go again. Said the five seek get and studied at the beginning of the fight. So just type here zero or type here. IOS bag inning. So we're sitting from the from the play from the begging to zero. Okay. Lets around the program. And as you can see, it is everything is working fine. We now know the size of the fire is 43. If you wanted to use the current flag it would work like when we, for example, would read 10 bites. And where if we use something like that and we did something like minus five. So our position he's 10 by 15 bites from the from the begging in from the begging. And after using this, our position is it's then. If you used that way, it will be 20. It's pretty easy and obvious how it works. OK, that's let's go back to the or gene away version off this program. Let's run it. As you can see, everything is working fine. That's all he does. Listen, thank you very much.
58. Writing position pointer - seekp and tellp: Hello, everybody. Today we're going to talk about the writing position pointer and about the functions that can check out Where is the point in? Oh, that again. Things the place off the point. So these functions are called Tell, put and seek boot. The difference between the last functions that we got to know in the last lesson is that there is a world boot, right? So is the only difference. And this function tell tells where is the voting pointer and seek boat set writing, putting pointed at the specified position by us. Okay, so here is also the overloaded function the sick put which takes harmony bites from the flag place. We want to put the putting point in writing position pointer in. So a This is the functions and not with how to use them. Well, first day we have to use the FISA or outward five string. So only did these libraries because these library doesn't have these functions right. And also we should open the fight for the out putting because, well, we're going to write some thinking to the fine. Okay, someone's right. Something to defy. So, for example, let's create a temporary variable. Which Diaby string? And let's say it's here since, like this is text about nothing. So something that let's put it into the five. So just something like that are with around the fire. And here I have got opened. That's fine. And as you can see, we have got to your message. This is text about nothing, so everything works fine. And now let's check out what this Pointer is saying here. So see out. And now let's say five tell where it's the pointer off boutique and now let's around the program. As you can see, the he would have 26 if we can't it here. So 1234567 This is the 26 position here at the end, so it means that we are at the end of the fight. And right now, if I wanted to, for example, change something in the video, I would need to close the fire and open the game. But with their sick, sick put function, we can change this behavior. You can change all the time. We're want to put something right, so let's do it. Let's do something like seek put to the beginning of the fight we can use here. A flag, which is by default, said So we can do it that way. Are we can not use it like that. But that's do it that way. So it look a bit harder. At least we know exactly how it works. Mm. And now let's put something into the fight against So what? For example, change this letter. So it is in upper case, not in lower case. So let's just sender at T It means that right now we are said at the beginning of the fun and you want to change the first letter 30 on and OK, that's all. Let's around the program. Um, something's not working. Oh, I'm so of course we are using the IOS here and we'll bomb. We have to reload the fight. And as you can see, we changed the first letter to the upper case One. Okay, everything is working fine. Dazzling Did lesson. Thank you very much.
59. Extracting characters from files: Hello, everybody. Today we're going to talk about free functions. Get line, Get on. Diego. These functions are used to extract characters from stream not only five, but also from string. For example. We have good their function, get line. This function takes free arguments. Well, it can also take one argument to argument because you we can all meet them. We can keep them. But, well, Muslim. We're using this function with free arguments. The first argument say's where we like to store the variable the content off the extracted , I think from the fight. So, for example, let's try to write something like five dot get line and now we need As you can see here we have got a tip we should send here the place. We would like to start our count from the fight. So let's create it as ah, as you notice, it should be the pointer. So it should be something like at that and ah, but well, we can use the FARC that the name off the area it's really a point, right? So we can do it that way or weaken you created Don dynamic Curry memo mori. But we can also do it that way. So five get line. And here now we're sending the buffer. And now we should say, how many would we would like to get her bites from the fire? So if we types and tonight 50 then we'll get 50 bites in tow. The buffer. Okay, So when you got this program, we got it into the buffer. Now we should send it to the out. As you can see, here we have on the output my name and surname because you know, if I would have good know my name and Sodom and some random two names and some things So it means that we are getting 50 characters from here. But look is my name and Southern 50 characters. 123456789 10 11 12 13 14 15 16 17 18 1920. So it's on the 20 characters Why we didn't get the more characters Because function get line by default has got here something like death. This thing says that it should get 50 characters unless it meets that character which is representing the end off line. It's pretty easy to understand because well, get line means Hey, please get a line from from the fire. You see that five get line is really cool thing. Because normally when we're using the stream, if we did something like that, we would get on Lee. What? One world we wouldn't get two words is one right now. Using the get line function we can do something like that for is pretty easy. So okay, here how good line function looks. The first argument is saying where to store, where to start there extracted contractors. Then Haman characters should be taken unless and here we can say, What is the separator? What is deadly Meter? What is the deal? A meter? Well, it is right now there, beck slash End. But you've used, for example, character a. Then it would stop here because here we have a So when you're not spoken, as you can see, we have got on a key. Okay, so it is just a deli Meter is the separator. It means where it should stop reading the Lyell. Something like that. We can also, for example, say well well, let's get from divine on the 10 characters when you know this program is you can see first in characters. He's just my name. Okay, so this function is a deadline function. What is the get function? Well, this function is pretty the same but there is a small difference difference in that. These think extracts it extracts the buffer. Well, the deli meter the separator and delete it. This think doesn't extracts separating. So what's the problem? Well, should be that way When we run the program. For example, if you wanted to take all characters from the fire, we could write with that function something like doh wide Ah wide Uh and the fire is not in that are we could also do something like that. Why this thing is possible. What can send to the output buffer if you work because get line Ah is true until we something going home is not happening So we have a rarer Then it will return the false. So when we not this program Onda we also know something like that. As you can see, we have got all names and soundings. Do it easy to understand We could all things from the from the fight But if you use these function we would get on Lee first name and sign suddenly. Why is it happening? It is because the get function doesn't extract the separator and look the get function. We'll take as many characters as it is stated in thes place, unless separate Aries meant so each time this function, it's meeting the separator, which is not extracted at all. That's why every time it's not going farther. So if you wanted to, for example, delayed this thing from the end, we could extract it with the ignore function. Ignore function, extracts character. Ah, well, extracts characters. Come on here. We should state how common characters two extra right and to ignore them. And at the end, we have good also as separate. Okay, so right now we should after each time we get something from the PFI, we should ignore Gig No. One character on. As you can see now we can get all of them. So you might be thinking, When should we use these potential? Do we use this the most time you will be using this function, but there might be sometimes situations like, for example, let's exercise these functions that we should we have just learned Let's create a program where we will get from the fire where our names and some names only first letter off the name and only first letter off the seven So Onley initials the name and sound how to do it . It would be wrong to use the guideline them We'll use the get function. Okay, so how to do it? We will get well, Let's get first coup tempering variables first corrector and last character. Well, for the first initial in for the second initial, right, call it second. And now this function the get function also has good one overloaded function that when you use it that way it gets only one character and it returns its character. Good line doesn't have something they did so we can write stuff like first equals five gets And now here. Get here first character can check it out. Let's set the output. Okay. And as you can see, we have good the first character. So it is thes character here and now how to get the second character? How could these character here we should What? We should ignore all these characters on Let's women book as space because we don't know exactly how many characters are here. So we should ignore all possible characters until we meet a space. So we should write something like five that signal and weaken ride big number here. I'm 40 characters until the media space and then we can get second car reactor and so seconds cools. Fight, Get on. No, we are where we are Here and now. We should What? Ignore all possible characters here almost will meet what the end off line conduct. So should again five that you know, for example, that many characters illness will meet and the Blanco and we can send it also through that are put second And now, as you can see, we have good both Carter's here, But we don't need that. You could send it out. Put that away. Okay, It walks. Now let's take all possible character. So we can, for example, well, for all possible initials Dio why fire is not end it. So fire hasn't been on it. And now when we run this program, as you can see, we have got all first initials A W h s and and see. Everything works fine. What if I want it for example, get full name on. Then on the initial it could be possible that somebody who liked into something like that Well, then we would use the cat also Buckley. But for and we'll get how many characters, too to the buffer Onda we would like to take, for example, 50 the characters homeless who meets the and write something that no you have bought for here. Example with at the DOT here. So now we are getting 1st 50 characters on this with me, the space. You know, I don't need to ignore anything. And now, uh, we're getting the first character. How weird work. As you can see, it's working dead wear, um, and why it's not working properly because the kid function is what doesn't. Extracting the separate of the Delhi meter, we need to use the guideline which we extract the separator and they hate it dead way. As you can see now, everything works fine. We have got the name on the any shot off the sound critical. We need to remember that the Gatlin function can be used on industry. No, don't known five. We could also say something like seeing and now that get line. And, for example, I would like to get characters to the puffer on. And I would like to get 50 characters now willing on this program will be asked for something. So when folks are sent to the airport, we'll see. So we need something that now we type something, Um, these type things can be seen him. Well, is schooling about it Is that Look, we can't take more than one world at once. Normally, if you will use something like, for example, dead way, we weren't able to do something like that. We could take on the one or two at once with a deadline. Everything like that is possible. Okay, that's only did listen, thank you very much.
60. Comparing content of two files: Hello, everybody. Today we're going to talk about the Rete function and as you can get it is what it is reading from the fire. But world, these different from the functions that we learned about in the last lesson. Well, this function is reading whatever it ISS plays there and it is not omitting skipping anything. It is not going toe end reading when admit something it just reading the thing like it ISS So it is especially function that is created to read bine Aref ice and there is only one function like that. I mean, there is no overloaded function off the function, so we can only send here as the first argument where to it where we want to safe think that were read and how many bites we want toe read from the file Okay at the beginning will just try to trained this function. But after it will arrive the program which will compare accountant of two fires we'll know if two fights are two different And in addition to this, we can also check if ah, fights are different not only tax fight, but also image fights and other things. Other fights like that What other by notifies So other fights. Okay, so let's try, for example, read everything from the fire and let's send it out. So how to do it by using the Red Faction? Well, firstly, when we use the rate So when we do it like that, we need to. But we need the place to save the things that we all right. So we should create a buffer, a place where we can sort so something like that and well, well, dynamical a located it this time. So new character. And we like to know how in the characters we want to create you. Ah, well, let's not forget also going to deal it and that because otherwise we might have a leak from our program. Let's train again. Something would this cult at the end flak? Because, you know, when the up on the end, at the end of the flock right now we can't exactly say how big is the file, and we can create buffer which will be as big as the fire so we could read it. Wow, at once will tell me so file size. And now we can just type something like five tell Where is they? Get indicator and we cannot create it. The buffer Here we can send the buffer here and now we need to grate on Lee Food Fire and then we consent it the continent do the out now Is it consume? Oh, cups the type of it variables integer Ah, we have some kind of problems. And why is it so? Well, it's a good question because while we are at the end of the fire and you are sea trying to reach something exactly, we're trying to eat 50 character. It's good that I made that mistake by staying because right now we can see that we can repair quit easing just by setting the pointer off the reading at the beginning of five. As you can see now, we read everything properly. But at the end, we have a small problem and why these problem happened. Look, right now we opened if I as a Binah refined, um but we created it as a text file and because of it, it created problems. So if we want to read this it that way by not if I, we should have inserted the names inside Mm. We've by now think firstly, so what? We can do it first. So example can do something pretty fast. Let's open it for out floating. Go. So So just create a new fight which will by not fine. And let's send the input something that on something like that now, as you can see, we have got it cited by nullifying. Now we can. Openness is final. If I also and should walk, you can see now it's working. Fine. Uh, in the game, that's a cute here. So this here. And as you can see now it's everything is working Fine because, well, looks like me in the last less lessons or well, I just inserted things inside using Vicks text melted because of it. There was some kind of some problems with it. The girls. There are some of the show contractors that were red hue with the read because you it is reading everything. Doesn't matter. What is their reading? Everything okay? A za can see now everything works fine. And now let's practice the wheat function. Um, by comparing content of two fights. So how to do something like that? Well, let's delete this thing because we don't know the immediate anymore. And now let's try to check. Defies are equal. How checked? Well, if and let's create a function are fires they call and we'll send here to five. You should also create two fights here, so let's do it that way. Fight one fight too simple. One simple to let's copy it. With the short cuts on, Let's name simple toe So you have good note to five, which ah, a cool. And now, when the 51 is open on in the same time filed two is opened. Then the things that are here who can check if everything is working fine. So let's run the program as you can see fighter open so we can work with them. And no if our feisty call. So we should create a prototype of the function which we return. Bolin. When fight or equal will take you to five. Andi So five streams. So it take to five things here, but fighting doesn't have a copy constructor. So we have to take you. It has a pointer will take pointer to that five. So we open it here and we sent exactly the exact copy. Well, with exact instance off the object here. Right. So we send the five here, um, from this place here. So it's an address. Fight one and address all five to. So if are five equal, then do something. Um, now we should implement these function here. This is not the prototype. So we have to name that fights. Well, we can blame it a and being. So now I have got you a pointer so we can use pretty easy functions by using this kind of operator Andi s, so we can check if ice are equal. I guess it's the best way to check if two fights are the same. If they are equal is the check. If they are the same science firstly, because you know, they are the same size. It means that when they are not the same size, it means they're not equal. And we will not need to check. Bye bye. Why did each character and lose our precious time? However, system the computer time? Eso It's pretty easier to do it that way. Um, but of course, if the equal, if the two fights are equals, for example, like now and somebody change something like that? One character only. Then we should check Bye bye. One by the Czech. Exactly. If something is not well, something is not equal there. Okay, so first of the check this ice, I guess we should create function which would check site size of the fight and off course. We also take here there f stream five stream on. And here when somebody's sent, if I would take it and we will set that seek with the Sikh, get function at the end of a pointer, indicator off the reading and because it said there we can now read the size of filing stories for example, in temporary, very bold and take it with the tell get function. And now we need to remember is very important to back to the begging of five. Because otherwise we might have problems later. Where here We might have problems because we're used advice on Remember the last thing sending the others here. So we're operating off five that are here or that are here when we use when we send them here. So we need to exactly be at the same place where where it was when we send it, right? Well, maybe we should even check worries to fight at the Where is the tile? Get when? When we send a fight here. But what? It would be complicated with him to write a lot of God which is not needed in that simple program. Um, because there are probably thousands off things that we won't probably get away. This is just threatening program. Okay, so let's just said it like that. And now return the size five so size off five return. Okay, so it returns it here, and now we can use it que So ain't five. Size one equals, and you can send their A and fais I still and we can send be Okay, now you might be Why I'm not sending their address, the fires a pointer, so it should take an address. Okay, but a also pointer on and it is pointing to others. So the value of the vory boat is an address. And the value of that for Abel is here. So we are sending really here, and others is a Then take out here here. We have to send an address off fire One. Why? Because when we are sending here and address what we are expecting here and others. Okay, so and we have got here now. Fights That's one equal size of five basis. We have to fight size and we can just check the five size one equals site five size do Then we can easy do something I was we can send to the output. See out. Five are no equal size of fice size of fice not equal and gonna return false. Um so we can send if arf icicles because five are equal. Otherwise we won't say anything because we've sent by such issue something that so now only on this program. As you can see, we have got the message for ice are equal because well, it's returning through by default. Fights are equal. And now when we change some things on Lee one let there as you can see fighter Also he calls So you have to repair it. We have to fix it when fights are equal. We have to check Bye bye bye. But when we for example at here that a single letter as you can see if size off fights are not equal. So it means that fights are just different. Right? Uh so I guess and maybe we can do it. Us. See out five. No, this thing. Something. Okay, So now let's check it by by bite by bite. So it is the hardest part of this program, but well, it's not that hard when we know functional. Great. And we know something like I function. We discovered man Mori compare. So it stands for memory. Compare Ondas you Congrats! It is comparing memory that is indicated by some kind off point of exam. Okay, so we need thes function. We also need to include the strength library And now let's used that star Slim Create a place where we was safe for, For example, when you have a 51 So when they have a fine and we read something went to read it to some kind of place So we can later compare these two values with something that I and be rid. We need to places to store temporary for comparing. So first, let's, I guess do something like that character. Five one buffer equals new character. And now we should use the size of the fight him size of that fight because they are equal. So maybe that's just create you, tempore Variable, which will stay the five size so five size one. And now with this program oh way need to close and dead way 515 through Buffer. Well, of course, we do what we did late it that way because we don't want to have a leak from our program. So I wanted it that way. And now we should say how many buys you want to. It's a buffer size buffer size. So now we have accountant off the Fire one and content on the five to the buffers, and we can compare them. We can compare them with the function that I mentioned in there, which is memory compare, which is comparing whatever data is inside, and we are using memory Come Per and I am sending you 51 buffer and five to buffer. And we also have to say how many bites we want to compare from Bobo that buffers. So we are sending a buffer size and it is very important. Memory Camper is own polls when it's not equal to zero, so when is greater than zero or lower than zero. Well, one is great. And then zero, then 51 batteries has good, simple guns when his lower confined toe buffer has problems. So more couple is working like that. And because of that, we have to on do it the way we have to create the conditions like that. And now well, we consent that fights are not cool and we can also return false. Remember that when we read, um, Falls here way won't be ableto delete, he'll our dynamically allocated memories. So we have to delete it again. Here. Well again for the program. It is the first time in this life off goat because if that condition is met well, this lines won't be around at all. Andi visa versa. They think these lines at 16. 61 won't be executed if the condition off this Ah, this condition is not met. So let's on the program. And as you could see, fights are call wider recall. Because if I recall well, now let's change one character so like that. And let's around the program. As you can see Fighter nautical vice unknown. The same one off the bite was different. Something like that Okay, so let's go to death time when everything was cool. And now let's imagine that this being waas on image well, this program would walk. But now image that date would be, for example, that movie, which would be, for example, free gah bots or maybe even more. Wow, then thes buffer size would be big. Well, as a temporary, very bold take, Frida buys far off memory. Well, some some people maybe don't have even that much. Uh, then it would be a bad idea, right? So we should check the buffer sizes No to its well and big five size. We should created a bit different way. So if five size, it's bigger than, for example, 1024 bites. So it's bigger than one megabyte, then, please, that well, that's created declaration like that. And now let's initialize it here with their not five size but only 1024. Otherwise, buffer size should be equal to fight because, well, when the PFI size is lower than 1024 bites, why should we take 1024 bites? We can take on my example like, right now it's only, um, 40 49 by so way don't need toe. Take one megabyte on and now that's around our program. Ondas. You can see it's working, but the problem is Ah, our fights arm right now, very small. Let's for a second dui dead where the way that we with initialize it with only 10. It means that buffer sizes now lower. So it means that we really read on 10 by 51 and 10 bytes of fighter and we can compare on it to 10 buys of both five. So if, ah, if that first time behind will be equality, if I would be equal. But we need to read all fired one. So we need to work, Rip, it'll that things as long as we do know that the fire So how toe repeat things when you hear the world repeat, we need to remember to repeated with the loops because looks are created for repeating things, so creating do why look, which it is going to execute as long as the 51 we have a good state on the same time 52 will have, which is being this time because sent in Cuba it as a team. We'll have also good state. So we're gonna up. Repeat is as long as it's needed. Okay, so no one runs programs. Fights are cool on when you check into some things that, for example, here As you can see, fights are not equal One off The fight was different. Something waas roll I should say one off. At least one of the bike was different. Okay, so let's go back to the buffer side, which would be great, A bit more professional element because, you know ah, then by this, not much for a fire on. We will need to repeat this thing too many times. If it if I was big. So maybe even one mega by this? No, big. Maybe we should get 10 megabytes. 20 megabytes. It depends on the situation how important this task is and how far we wanted to be. Okay, that's all in the lesson. Thank you very much.
61. Put - loading characters from cin stream directly to file: Hello, everybody. Today we're going to dog about the function we just killed boot. And as you can guess, these function is putting a character on the street, all enlisting so it can be used also on, for example, see out. And it can be also used. The feisty. We need to remember that the fighting must be extreme or the output appstream on. It should use the flag out This. Okay, let's start from the example where we will put something on to see out. Well, let's imagine situation. We have got some kind of text, simple text, which we would like to divide with spaces. So this text is connect it and I don't want it to be connected and more how to do it. How to add space after each off the corrected and Senate adopted we want you don't want to modify this variable. He want to just send it to the out. Okay, so let's use the loop for so we can go to each of the character. Then let's do it that way. If I is lower than their extra length, length is the function that is returning the land of the string and now let's increase it. And now we should put something on the up. So what may be let's let's do something 1st 3 like that. But see out boot? A. When we do something that we'll put on a as you can see, we put an eye here. Ah, at the see out sing so we can put their also each of the characters. So let's do it. See out Put. And now let's And there first character second character, Turk Art until the so, as you can see now have this Texas connected. And now we like to put after Egypt did work. What? Only a small space. Let's put this past. And as you can see now we have a space between each of the correct. Okay, so this is a simple program. Now let's use it on the fighting. Let's imagine situation that I would like to run this program, and I would like to type things here like type characters and all the characters should be inserted put into the fire automatic area, all of them. So how to do it? Well, firstly were for sure going to use the lope so we'll get at each of the character that this put on the council is both inside the fight. So do White. And now do I went? But for example, let's K the correct character of able and anti of the character is, for example, not adopt that. So do why. And now let's take character here so we'll take it with the sea in get function. We're just taking what, one character and it's gonna return into this seat. No. One around this program. As you can see, you can type lots of things when we take that their program is end. So now we can also put something into the fire. And now we can put exactly the sea corrected. Okay, let's run the program and I'm typing a few things and I am typing. Get that. And when I closed it and when I opened fire. As you can see now, he could all the things that we typed here, right? Well, of course you know that thing because it's just here because we send it through the function through the looking, Um, so let's, for example, also do something like that. It's against you. Any type adult that and then type anything after it. We will get on things that are before the top. Okay, that's all in the blessing. Thank you very much.
62. Peek - peeking characters without extracting: Hello, everybody. Today we're going to talk about the pick function. What big picking means. Well, you can imagine Peak as a situation, for example, when a man is looking at the woman neck like they had a looking at it pretty fast and they don't want to be noticed. So it's just picking, looking at something pretty fast, giving the first grains and then looking correct, not being noticed. So picking is just looking fast and how it can be using the program languish. Well, as you can get. It is just looking at character. And then it's not extracting this character, just looking at it. So you know to be noticed and you can use it. Of course. Amanda Stream. So can you see that seeing on you can use it in five? Well, you can, by using the pick function, check if the first character is, for example, in teacher number. Or maybe it is just some kind off text a compactor. You can pretty fast check if you want to. You use it as an integer or as a street, so let's ride a program like that. For example, let's take from the seeing get one character and let's initialize it toe the variable, See? And now, if that see it's greater than that zero from the table asking some some kind of number. I don't remember exactly which one and in the same time see is lower than the nine because 01234567 years next to each other. We have got some kind of set here. So if the numbers are between each other, then we know that this character for she sure is a number, not a not an ABC, which could mean that it is a string, right? So otherwise it's a string. But here it is, an integer. And now we can just do something like that. Get the other thing from the output from the input. Sorry. So things that will be type you for example 54 then, Ah, the rest of the think that would be tight here would go to the scene and then I would go into the number and now we can send it to the art number is Ah, look into something like that. And of course, you can do the same. If it was three, right? So get into something like that. And when you're on this program and types inflict that, as you can see, first character is what extracted from the stream from the input. And we don't want situation. I did. We just wanted in this place what we would. We want it only toe peak to look at it pretty fast and do not extract the number. Now, as you can see, we can pretty easy do something like that on. Say, if something is a text, or maybe it's the number. Okay, that's all in the lesson. Thank you very much.
63. Putback - returning extracted character on stream: Hello, everybody. In the last lesson, we learned about the peak function. Right now we learn about the put back function, which is giving back a character that was extracted from the stream. So let's imagine situation again where we have get function here. And you know what? Typing cure something. And, well, we like to put back one here so we can just write something like scene. Put back the character on the stream. And then, as you can see now, when I type something like that, everything works again. Fine. Now you might be like, Well, but when do you speak when to use? Pulled back. You know, sometimes some people might arrived the cold, for example, using this function and then you need to somehow manage without changing their clothes. And then might be the post bag will be a good idea to use. Right. And for sure, Peking is faster than extracting something and then putting it back from the stream. Right? Or maybe you would like to, for example, not not putting back everything. Maybe you would like to extract the once something and you wouldn't like to put it's back in one situation. But put it back in other situation, right? There might be many things you would like to do. And anyway, this program is not proof. Bullets when you're a need and we do something like that is you concede still a number. We have got some kind of conversion here, but, you know, it's pretty good program. And it might be very fast sometimes because when you write something to the five, for example, you know how things are type there. Exactly. Maybe they are, for example, the diamond like that always. So they have got a deli meter between a space. So if something, something like that, we never happen because you didn't allow it when you were writing to the fight. So it doesn't matter because situations like that won't happen in a way, right? You know what information out there and the taking on the one character instead of going through each off the each of the character is off course faster. Okay, that's all in the lesson. Thank you very much.
64. Write - writing bytes to file: Hello, everybody. Today we're going to talk about the right function and as you can guess by looking at his name, it is what it is writing to the fight ass man and bite as we type. So it's a bit different from the normal operators that we use to insert to riding toe fight , which was that one. So if we have, for example, the array that we will call sample and we have got your simple tax and we have got here five, which is open for are putting and we sender sample and were on the program and we opened if I we'll see that we have got here a sample text on that cynical. So it is no inside. So why do we need another function when we have good? As I said, area this function can write as many bite as we type, so we can have a buffer which we can exactly say how many bites we want to write at once. Or maybe we can maybe want to take on the five characters he right, while 12345 or six characters, we we can exactly say how many characters who want to ride it once. And the cool thing is that it is writing every possible thing. What does it mean? Well, let's use the right function. Five. Right. Well, you need to send here, pointer. So the place where we want to start to write from and how many bites you want toe right inside from that place. Because these appointed point is pointing to the others. Right? So we are now sending here, for example, size off sample. So we're sending here. How, maney. 123456789 10 11. And and now character. So the ending correct. When you run this program, so you will notice. Then we also sent here and our character not only text characters. We could send him any possible think inside. Right? So what? What is different in the right function? You can, for example, send a character that is not ah, that that that we don't have on our keyboard, right? We can send their some kind off by that do not exist exactly in character forms Force, for example. Somebody eaters are in some kind off ankle coding and they don't have the meaning. There but they have exactly meaning for us. When we do some translation, what do I mean? What We can create a low level program, for example, that would compress something. And we like to compress something from, like that. Do something looking different, and it wouldn't mean anything in character for but it would mean something. The bite form and we could interpret it the other way, right? So you want to write a low level programming program? We would use the right function. Or, if we want to say how many characters you want to ride or common at once, we want to create a buffer. Then we would use the right function. So if you type something like that minus one, you'll notice that off course when we refresh it. As you can see, the NAL character has been removed. So a well, we can exactly check harmony off that is inside here. You can see a this 12 I said area. It's 123456789 10 11 and 12 Character now, So it's inserting every possible thing from the beginning where the sample pointer is pointing toe. So that also means that if we type for example, 60 here and we ran this program. As you can see, when we refresh defy, we would do some kind off gal bridge. Ah, we don't know exactly what these that letter at all with a t least I don't know. I've never seen it before because this editor is just a paying it and trying to interpret it because it is a taxi deterrence. Trying to interpret this is the text, but there is some kind of garbage in my Memoria off course when Iran, when you run this program, this garbage will look different way. And because you have some kind of other things there because the's, for example, addresses here can be used by other programs. Or maybe it's just not being used right now. Ah, at all because it was used by other program before there were just some kind of member being using because of it. There is a kind of garbage there, right and disease the finger. And as you can see the right function, right, anything into the fire, it doesn't matter if it's a typical character, right? It bites into the into the fine. Okay, that's all in that lesson. Thank you very much.
65. Gcount - counting characters from last operation: hell over. But today we're going to talk about the G count function. And as you can guess, this function is having name from get character count, which is what getting kind of characters that are being extra acted from the last extraction operation. And now here's the question. Was this extraction operation when we were getting extracting characters from the file? So from the function that great guideline ignore these functions. Ah, then the used with the g count to get how many characters were taken and when would be. When would we be good idea? Toe. Use it. Well, look here we have a name and surname and we'd like to know how many characters are being presented by name and stardom it but once, right? So I don't want to count. 12345 I would like to know exactly that these 25 14 16 or something like that. I like to know exactly how many characters were taken so how to do it. Well, let's create a simple program that we won't get each line until what until we get all the things from the Why so anti we meet world end off there. Fine, right. Well, do why? Fire is not ended. And now we will do fine. Get line. Ah, function which will won't get extract characters from the from the five and we need to save it somewhere. So we need to create a temporary bothersome, for example, with 2200 and 50 and bonds. So it is big one. I'm sure there is no name and sometimes so big and we're sending here a buffer And how many characters we want to get unless we meet What the guideline is were working like that we can meet also an end off line character. So it will get 250 contractors on this imp meets end of fine character. Okay, so ah, right now we consent to the output. Pretty easy that way. And as you can see her, go to your name and surname. Andi. It's working fine. But now I would like to also know how many characters were extracted by each off the deadline. So we need to only do something like G count here on will let it space. So look better. And as you can see, 21 characters are being presented by my name and something 11 by John Sniff 14 by Nikolas Clark I think works fine and it's where the G count function is working the same like get lung function by the same, I mean that it's working on an extreme so we can use it also on C in. And by that you can check how many characters were tied in the council. So when somebody types nothing, the council, you can you can later check how many characters were type pretty easy with it. We've just did function. Okay, there's only good lesson. Thank you very much.
66. Mini database: Hello, everybody. Today we're going to create an many database. What? I mean by me, that date up, It would have basic functions off the comebacks. It will be able tow at some kind of information. In our situation, it will be only people. It will be able to show that people who were able to add these people to save them, toe the fight toe, load them from the fire to said them by, for example, name or to remove a person from their base. So it is the program that we arrive today with all these factions. Okay, so let's start the adventure. What to do we start from I think we should start from the interface. We should communicate somehow with the user. So we should send him a man, right, Manu, something like that. And we should, for example, allow him to do a few things, for example, at person, on what, as we should allow, we should allow him to, for example, show some. I'll show all people inside the dot data and other options that we will at a later. But now we have got a small problem. How to get the OAP option that the guy want to choose, They user well, we can create a temporary variable here, for example, test and we can get it. We, for example, see in get function and later we can switch it test. And if the character is, for example, one, then we can send the output tests. Or you can just invoke function here that would add a person. Right now, we're just writing this program a little eso We're not doing everything like it should be bad. We're just testing, right? So it's test that still, and now we need on this program A. So you can see and was no declared ended function and lying Serie. It's and line When you're on this program, we can now add, persons show people. But when I click something, I need to type enter in order to do something in order to choose something from the men menu. So it's not cool. I would like toa tied one, and it should instantly invoke one off these functions here. How to do it, what we will use the get character function which is not coming from the sea in object. It is inside the library. We discolored like that. And the difference between this and that get function is that it will get immediately the character that this put into the input stream that is waiting for character so well, not when I take one. As you can see, it instantly showed us, Tess, you well, I creek to instantly test do so it's not working. Fine. But now I can't get the problem that the program is ending instantly. How to make it so it won't. And instantly. Well, for example, we can use a look, right? We can do all the time. Things that are inside. Unless, for example, somebody will Creek s Skype on the keyboard. So do why test is not equal to 27. 27 is a number in asking table that 3% escaped on the keyboard. So right now, when you know this program and escape, as you can see, the program is ended. But when I table while, as you can see, we have got here a test. So we invoke something here on. We have got to gay men 11 long Teoh. But one type something wrong on the menu menu appears nothing gets okay So it's not the thing that we would like toa achieve here. Exactly. But now, at this, the program is not ending. How to do it that way that we see the manual. But the things like that here with appear each time we choose something from them menu Well , we can use a function we just called system, and we can use a clear screen option here. Ah C l s stands for clear screen. So it is clearing a screen. And we also have to include this live dysfunction here, which is from the C C standard library and now one around this program. See as Tedy Syria. As you can see now, when I type one to nothing happens when I type anything else. Nothing happens when I type escape. I am getting out of the program. What's going on? Well, there is a small problem that one like league one here. It's taking it to the switch and it's right and it's Output Inc test. But you see, the program is not waiting for for us to see. It just cleaned the screen and again we can see the man you so we should somehow stop the program for a second here So we can allow our user to read this thing here or to do some thinking right so we could wait for him to, for example click Enter. I think it will be the best idea and how to do it. But we can use, for example, loop Why here and use the cat character function. And if that function is not equal to exactly 13 then this function with full and ever be run here. So it means that when I around these now, when the at persons you can see now we have the test here and now I can click every possible character and it will not stop even escape. It's no waiting only for enter now when I kick enter, as you can see. Finally the the thing that was here Waas cleared and again we can see the 13 15 and 16 lines here. So it's not working pretty fine. Ah, so it is just requiring to enter the under. We can create a function here, require enter Onda. We can implement it on before we should ask for enter. So the guy will know what to dio because It would be frustrating if we didn't say he has the trigger. Answer. Right. So click enter too. Counting you? No, As you can see. Mm. Oh, sir, I didn't invoke it. Should invoke it here one is waiting for enter. Nothing as we work. So I have time to read what happened here or do some thinking. Right? Okay, so we have to their working interface. So we should now implement functions, for example, adding function. So let's great you a function, which will they called at person. So this function will add a person to our database. And where we would like to add this person. I think we should start it temporary in our memory. And after it, we could save it to the fire. There is a small problem now how we should ride it. We could use classes. We could use a structure. But, you know, I don't know if all of you know class is good enough. I don't want to confuse you. And because of it, we will use the structures here. Um, which are easier to understand? You can also you can off course change this program toe the classes if you want to train. I think it would be good training of classes if you want. Oh, but right now I would like to show you how toe right to fight, how to load from fights, how to play with them. Right. So because this is the course about the if I it's not about the classes, right? So we will use the structure here, and we're at person by using the structure. So we create a structure and we will call it, for example, person. And this person will be presented by four different values. So, for example, a name which will be string soft Passard name by the age, which can be sure because it is short. It will not be a big number, a string which will represent telephone. Why string? Because in telephone can use sometimes parentheses around and things like that. Right. Okay, so it's looking like that. And now we should create ah variable. Which type would be person, for example, people. And for example, it can be created for 20 of them. So our that database can be bigger than 20. Person, of course. Is Kentucky £5 or something like that body. We take more memory. But above all of these solutions is not good. Because, as you can see, we are in a situation like that losing Memoria In situation like that, we can run into problems somebody want toe inside more people. The best solution to this is something go. This could list vector, but unlikely. We don't know it yet. At least not from the courses that I ah created how we talk about things like that in the next course about the library that allows exactly how how can you store more people more, More things dynamic. Ellie, Um by in professional way right now, we'll use these things here. OK? So clearly created people here for while we created a place for 20 people. And we can add person a new person right now. Here. So, world, first thing we should do, we should ask for data. So, uh, boot, we can ask for name, name, tied, name. See in. And we are getting into the people. And now we should use you some kind of index. Our name. Now what index? We should use it here. I think it should be zero. But later, when we at the first person. It should be one, then two, then freedom for. So I think we should create a global variable that represents how many people were added to the date up. It's so people in data base by default, global variables that are in teacher are zero. So we have got zero here. Now we can send it to the output. So people in data base number of people number off people in database consent eight here. And when we add the person, we should increase it and we should use it as index because at the started will be zero after reading one person to be want until them free. Ah, did we follow what I did? So the bomb balm and Bob so type Name, time, surname and type on age. Um, type telephone. Now we should change also names of rebels and it should ward right now when around this program and we could add person. As you can see, it's not doing anything good because, well, we didn't involve the function, so let's invoke it at birth. One type of name are kaddish, my son Name H telephone click enter to counting you and we added the person, but we can't show them because of it. We should create a function that we show these people well. And we should also say exactly how many people are here because they forgot to divert here . So it's going zero, something like that. It's one. Okay, so let's great the function that we show how many people are in the database. So Voight show people and let's implement it at the end of fire and let's involved it. So we do not forget what I do not forget again with somebody. Victor, I want to show people. Okay. I think that firstly, we should check if people in database it's bigger than zero because, well, what do we want to show if it's not bigger than zero? Otherwise, we would like to send to the output that there is nobody in database. Why the hell are you here? Okay, so people in database and now we can show all of them by just going to all off the people in area. Right? So you want to go through that? I would like to use what look, So let's create a four loop in Teacher I when I is lower than the people in database. Then I plus plus you consent to the output. That person with person index, which is I plus one. Why was I plus one? Because, well, way we could use the eye here. But I think we should use iPods one because, um, it's easier to say to people that in Texas starting from one than from zero on, the programmers understand it. Index is starting from zero. Right? So person in Texas one and then we can type name, which is from people. I that, uh, name that's not Koppett name serving H that that phone on the sub name it's and telephone. Now let's around the program at the person Bam, bam, bam, bam! Shovel people. As you can see, we cannot see them. We can add more off them, show people and as you can see, we can see all of them at once. It will be good idea at your online. Easier to see how it looks like. We could also at end line here so they look, look better And like that'll, Azi casino is looking better. So we cannot persons show people and but the problem is that when you run this program again, nothing is in database. And, well, database is wrong. If you can't load anything from it, he right? Because going a temporary variable right now it's not working could because of it, we should create a database inside. For example, if I we'll store people inside the fire so have to do it well. First, that we should create a function so safe people 25 we should involve that function and we'll added to the manor safe people to find on. Let's involved it case free. Mm safe people. Fine break. And at the end, we should run safe people to fight eso employment function in a day. Okay, so way showed open the five. For saving what? Like that I we should use for opening the fight for sale output 53 We can use fighting, but out with ice cream is used only for putting something inside. So I think it would be a good idea to use that one, and we can call it, for example, database text. We should also include the five stream here library, because otherwise it will not work at all. We should check the file opened prosperous, so five is open. But if fights opened and do something, get otherwise sent to the output that I couldn't create database or safe today, Safety data maze. If I is open, we should not forget to cause the fire. And now we can save something to eat. How we would like to say things to To death five. I think we should save them by, uh like we showed them. So we should send their names are name, age and telephone, name, surname, agent telephone and after eat. When we want to load something from the fight, we'll do the same. We will greet name, surname. Agent telephone would know that each off age off row inside the fight would represent and the person it for each furrows would represent the person. Right? So let's just inserted inside how to do it. I think it will be a good idea to use the group like here. But this time you are writing inside the fight No to the output. So just send everything inside the fight. But what we do know mean the labels here they are. No. Did it needed inside because we're not reading fires user body. It will be threat by computer. So we are insulting inside this thing. I think we should also insert at the start of the five how many people are saved inside. What? How many people are safe in database? Because we can use light of that, um, that variable to load people from date employees. Right. Okay, so let's check. It's working fine. People in database is every thinking. Right now. Up we shoot half, only one enter and off line character. Let's around the program. That's that's a few people. So, for example, myself and for example, Jones me at the person that has so cool name like show all people is he concedes, working fine, safe people to fire. Now I'm closing. Defy when I open it here. As you can see, we have got here now a database with each four roast representing what a new person. And at the beginning we have got how many people are here because we know how many people are here. Now we can read the file and they were free of them. Oh, we can at least showed how many people are in database. We have our reading all the fire, right? So it's easier to read at the beginning that hey, there are three people in the fight. You don't need to read the lighter. All the people then going through all of them and chicken comin off them. Where? Inside. Right. Okay, So show people, that person and we would like to load from the fight. So load people from the from five see out for load people from five case floor and let's implement it at the end. You so how to load? We'll use input. Five stream because it is the library created only four taking things from So that's great if I Well, let's open the FISA worry. We just call database text and we don't need to have any flax here like we didn't that he because flacking input fi stream my beef old is what and the input flak. So we can just read from it. And again, if five is open properly, then can do something. Otherwise we can say that they're five. Database text doesn't exist, Endsley. Okay, But if it exists, then I like to load too. People in database How many people are there? People in database because the first guy but the first line of present how many people were in database, right? And now, if people in database is bigger than zero because maybe there was nobody inside, then there's something otherwise sent it out with data but based ist empty. And though we should take everything from the file, you can do it two different ways. For example, we can create a four lope, and we can go to all of the people inside its site for so we can do it the same like it was down here. But right now we just change where we want to put things from. So we just put the dead way on the show. Look, when you run the program, um, there is no operator like that off coast. We should delayed the and lying corrective soon goes just taking things, inform fire and you can take some beautiful find put inside in one line. Until now, everything works fine when they think for as you can see, what a free people in database and we can see them pretty cool, isn't it? We should inform that Oh, no, people were loaded. Fine. If it proposing. Maybe on and it's been loaded. Okay, so we have good people inside our temporary memory, but you can use other solution. For example, you can do why you haven't read the file yet. So we're using the the flock that is representing into five. And we can do the same inside, but before it, we should create the eye here, load the people. And as you can see, it's also working. No, it's not working. Okay? It is good idea. Good that I didn't want because Well, you could also make a mistake. Like head. Now, do you work for? And as you can see, everything works fine. Why didn't work before? Because he all the time we're trying to put all people in tow on the one person. Right? So that's why it didn't work. Way had all the time. Zero here should increase the I hear each time around it. We around that looks right. Okay. So we can load. People are programming is getting better and better. Now, let's create something even harder. How to search through our database search data base search for a person case five on let's implement the function. So we want to search it that that database now we should check if there is anybody in database. Because why should we look for something that doesn't exist? If people in database is bigger than zero, then something otherwise say that there is nobody in database. What do you want to look for? People in database is greater than zero. So now we can look for simple. I think we can look for somebody by using for example name. So see out, uh, type the name off person. You want to look for something that string name, um, see in name. And them how to look for somebody. I think we could just go through all off the people inside the door. Right? And just check if that name is equal to the name that we type here. So for integer Ah, I equals zero when I is lower than how many people are in the database, and I'd post blast and now a faith. The name that will start here is equal to their name off. One off the person that we, uh, looking Teoh. Then we can just show we could break here if we find the guy on do no look for other people . But, you know, there can be two people on free people with the same name. So we should go through all the people. Unless, for example, we could ask for a second parameter and ask him how many people you want toe see, or something like that. Right? But well, we will just show every person that we the same name. Okay, so how to show it? Oh, I think we should just use the I think that we already created. So we do know, lose our precious time bomb. It's just so it by sos by sending to the person named Solon, Imagine telephone with that at all. Right here. Right. Such for a person? Well, it's first willing to loved everything. Shovel people. Um I would like to find the Jones off. Such for said person. Which name whose name is John. As you can see personally and exist Oh, Jones me Everything works fine. Search for myself. Hello. Here I am. Everything works fine. We can add another persons, for example, myself again will be duplicated to you and oh, Them went around the program again because I didn't load the five. First, you can also load the fire at the beginning. So people from five if you want, so we don't need to loaded the stuff each time to casino people has been loved the properly number of people in database show people Mexican. See, Everybody are there now at the person balm show all people. And now we can save people to fight. We could save those automatic Ari if we want to toe. But maybe it's not good. Always because somebody could make a mistake. And maybe it's good idea to allow somebody to save when he wants to say Okay, so we are saving. And now we want to look for our Kaddish and there you can see now have to people like that , and it's showing both records so everything works fine. Okay, so we can search the database how to remove people from database, does the question. So avoid remove person from date of its see out, remove a person from database case seeks, remove a person from database break bomb, and no, who should implement it? Okay, in the game, if people in database bigger than zero, then we have somebody to remove otherwise, What do you want? To remove you? Right? So there is nothing to remove. What do you want from? They want to take nothing from me. Okay, so, for example, let's remove person by index. Let's take index from somebody them. So who do you want to remove? Type Index online. See in index that's created for April here now, which check if index is well. If people in databases bigger than index because it's no bigger than way, can remove something that doesn't exist while it should be greater or equal to index because, well, if we, for example, wanted toe remove the person of index one will type your one and one person in database is not greater than one. It's equal to one. So in the situation when we have on the one person in database, we would have a problem. Okay, so on now. Oh sent it out. But there is nobody like that now how to remove it? It's a good question that took a dark broke a tower database. You That's, for example, did it this guy how to do it when I did it this thing and do something like that as you can see. Well, we moved all the records after John Smith to that place here. Right? So we could just do stuff, like bomb about them. Them Sam back, Ma'am. Map. Damn, man. But I'm showing you how program can do it, right? Stuff like that. Why, no. Okay, let's go to back today, um, to the picking of the fight like that. Let's do it by using the program. So let's use the for loop. And let's create a key temporary variable, which will start from index on when key slower, then people in database increase key. Now, we must ask why we initialized that variable here with index. Not with zero, because look here. We don't care if you want to remove Jones. Sniff about people that were before you want to just move these guys. Okay, that's what. And now we want to a sign the guy toe that the person that we want to remove persons that are after him, right? People did after him how to do it. We should also remind our says that that index here is what is really 1234567 So it is starting from one but the program program Kelly From what programmer knows that arise starts from zero. Okay, so we should go into the people. And this Something like e minus one. Dark name equals people and the guy after it. So key dog name. Why like that? Because imagine that we have four people in our database. So this thing is what? Before on somebody? Type two. So we have got to you, too. Is to lower than for. He has. So we are moving or removing guy, which is in position to minus one. So one, But because it is in a right, it's really a second guy. So everything works fine on. We are assigning here a guy after it, a guy which isn't 1/3 place, so everything should work. Fine. Okay. So names are name, agent telephone. It's, um, telephone. Mom. People has been loaded. Properly show people. Let's remove a person from database that sweep off my I could want Show that that database . As you can see, I'm not your animal. We should also remember that now we have one person less in our database. So we should what we should There are people in database something like that. I was not the program. Let's show the people in data pays. As you can see, we have four people here. So let's remove a person, for example, myself show all the people Askew can see I disappeared at this from the part first index the Reds removed from data Person from the data business. He moved myself again, and now I do know they exist. Oh, well. But as can see well, you can guess right now it's not saving automatically. So when I loved people from five, I am a game back. So what? We could automatically just to something like safe. You we could just invoke why not to try do it that way. So you know how have to do it. We can just people in a very safe people to fight so we could just show people. Let's remove a person that's removed myself. Shovel people. Hello, people from filing. Unlike that, I did not exist. Okay, So designed that lesson. Now we know how to create and meaning database that is able to add show people save people low. People search four people and remove people from a database. Thank you very much.
67. What's next?: Hello, everybody. So you have just walked all the readers about the C plus plus language. You're not an expert in the C plus plus language. What now? Where can use that knowledge? Where can you try? And I think that you should stop from training your programming abilities so you should start from creating your own very small programs that could solve some kind of problems. So you should start creating Calgary's Accurate is the way how to fix the problem, for instance, how to sort numbers. So here we are on the Wikipedia, and here we can learn a few things about the salt sorting algorithms. You can try toe right things like bobble sword or other things like that. Try toe and look for finks that would teach you how to do it on the Internet and after you find it. After you read things about sorting about, for example, bubbles. So try to do it on your own. Well, you could also train your skill right now by creating all the programs that I wrote in the course, but I yourself could try to own write them on your own because you know it will give you some experience. Do not try to write things during watching my videos by Try, but try to watch it, but try to ride them on your own. Okay, Well, what else can you do here? We have got the re ference off the C plus plus language and the sea. Of course, also, and because you can use the seeing the C plus plus language, you have got the library that I talked about. The first lesson you can now, for example, use the seam off library to compute a few things for his epic ocean sinners and other things you can use, for example, that input output libraries toe, for example. Um, open the fire and after it, for example, in put something into the fire or other things like that, you can now do something with that language. Right here, have the website about creation off graphic. You can create the graphic in the open G l. You have manito tutorials about the open gl. Ah, you have the tutorials about allegro. It's also about creating graphic here have, for example, the library about them visual C plus plus the language is same. But, you know, here you have the library, many functions that you can learn about, and after you learned them, you can create your own application. Discord, applications. Ah, you can try to learn about, for example, connection. Today, eight hour basis is on other things like that. Look on the Internet right now, you know, language perfectly, but you don't have so much ability. And so you need to train, train and one more time trains. Maybe someday I'll recover all the subjects I've just mentioned. But I will do it only if you like my videos and I will see that it's worth my time. Thank you very much for watching my videos. I'm real happy that I could teach you something. And I wish you guild lock in the programming adventure, have a good time, and find creating things.
68. What is STL?: Hello everybody. Today we are going
to talk about SDL, which stands for standard
template library. What does it mean in their name? Here, we have got
something like library. So it is some kind
of set of tools. They consist of C Plus
Plus template classes. We have talked about
templates already. They were looking like this. They didn't seem
to be as useful as they are on that
example, provably bad. Here you're going to see
how they were implemented. So they are very useful. You see in the upcoming
videos that templates, when they are used properly, they are very powerful. We call these
libraries standard. Why? Because it is a standard official library used by every C plus
plus programmer, which also means that
every programmer, including you, should know
how to work with SDL. So to sum up, STL provides you with classes, template
classes, right? And also functions that
solves common problems with storing and managing data that we're going to talk
about in future lectures. So can you give us at
least one example, Eric? Well, SDL provides lots of special containers for
holding and for storing data, as well as functions for e.g. sorting elements in these
containers. So e.g. when we are creating an array, Let's go into something
very practical. We need to know how many
elements it will store, right? So if we do something like e.g. this, we are creating an array that can store ten elements
and that's all right, the size is ten and it can
just increase on its own. We can just add 11th or
lemon 12th alignment. We can just add more elements that we
can store here, right? If we try to add another lemon, our program with just
casually just stop working. And STLs solves this problem. So you won't need to
think about that anymore. It's solved this with
something called vector, okay? But about this, we're going
to talk in future lectures. So have a good day
and as always, feel free to ask any questions.
69. VECTOR - how to use it? Why is it useful?: Hello my friends. Today we are going to talk about very important topic
and it's vector. Well, this vector, vector
is just a container that has got in
the behind scenes. So somebody has programmed it something very similar to error, which means that this
is a container that can hold values one after another. You can access them using indexes like normally
you would do. But the syntax here is a bit different to create
a vector, right? You can access the front of vector to access
the first element. You can access the
box so the end of the vector using the bag method. And well, you can
hold values inside. So why do we even bother learning about vectors
when they are so similar? Are they? Well, they have
two methods like dead maybe adding more of them. Yes, there are many,
many, many, many methods. We'll talk about them in future. But there is one very
important difference between the vector
and the right. Whenever you add a new
element to vector, it's gonna be
automatically increased. Okay? So when you add
four elements, well, in this case because 1234, fifth element, it's
going to be added here. Without any problems. This vector is going
to become bigger. When you add a new
element to it. You can insert elements here in-between these two
All lemons, a new one. You do not need to change
the values like e.g. change the value of this, tear the lemon before
the lemon in order to insert something here, right? You can just put something
here between this and this. Pretty powerful. This gives us a bit more
options than the IRA, right? You don't need to know the size of vector when you
are creating it, you can just create a vector. That's all. You create a vector, then you can just use it. You don't need to
ask the user who is going to use your program, things like how many users
are you going to add, right? Then, then, okay, he
wants to add five users. So let's create an array
with the pointers, the dynamic allocation
for five users. Or maybe let's, let's e.g. create a tunnel element
or every Jackson case. This is not the way
it should look like. Write everything here,
works in the behind thing. You do know the need to add all thing about
debt, that skill. That's why I love vectors. How to use vectors. In order to do it, we need
to include vector at the top of your program because this
is the external library. So include vector. Then you need to type the vector because
this is the object. And to be honest, vector is a template class. So in order to create a
template object, right, you need to specify what types gonna be
hold inside vector, what types of variables, right? And in our case we say
it's gonna be integers. You could type pyranose ring. You could type here
your own type, right? It's just informing what types are gonna be hold inside vector. In our case, we're going
to put the integers. That's why we call this
vector whole numbers, because integers
are whole numbers. And now we can do many
things with that. We can, as you can see, domain. But first, let's focus on the method that is
called push back. What does it do? As the name suggests? It pushes to the back the value
that we're going to send. In our case, like here
we have an empty vector, it has gone up, put it here
right at the first position. If we had four
elements like here, it will add it at the end, at the back of the vector. So let's do something like that. Push back one. Oh, well done. There are lemons. We need 24 -45.350. So we have just pushed
back four times. So we put something at the
end of the vector Mu values. We need to remember we can't put here values that are
not integer now, right? Like that. So you can
see we have got an arrow here because this is a string. Alright? So we've just push it back. So can we access these
elements somehow? Yes, we can. Because in the background we
have good really an array. Well, yes, we can do
something like that. We can access
elements like this. 012. 125 -45, 350, great. So we can access each
element like this, or we can use the
method like this. Method add, so get the
lemon that position zero. Oh, okay, this alignment is one. The cool thing is,
as you can see, we haven't specified anywhere
the size of vector, right? Well, Molly, if we had era here, we will need to
specify the side here. We do not need to do it at all. We can just add new elements
as many as we want. Can we change the
values like e.g. can we change the value of
the whole numbers like e.g. this form the second position
to like e.g. five-hundred. Is it possible? Yes, it is. Whole numbers like that. As you can see,
that's how you change the value of the element
at the position 123. So position on the
third position to 500. You might be wondering now, why did I even learned about MRAs are egg Really
I lost so much time. Well, firstly, the vector is something that was invented,
invented later. That's the first thing. The second thing is that when you're increasing the
size, the like the ad, when you don't know exactly how many elements are going to be in your program, then this is not like, it's not like it's free. The things that happens
here in the background, there needs to be things done
in the background, right? So how can I show you this? Look. I do something like that.
C out whole numbers. Size, size, will see that the size of it is four because we have
four elements, right? Okay, that's cool. But there's something
also like capacity. So it means how many lemons
these vector really can hold. So this is, as you
can see now, four. So it's impossible to
add a new element. Now. No, no, no, no, It's possible. But when we push back another
lemon, look what happens. We have got here size five. So we have five lemons.
It's true, right? 1,234.5. But capacity is equal to eight. So the amount of elements that can be hold in
vector is now eight. What happened here? Well, vector tries to assume how many
elements aren't going to be hauled in your
vector in order to not create a vector just
in case that can call e.g. one thousands to millions of
elements because there's no, What do you go underneath? Every time? You need to remember that every integer is about
four bytes, right? So it would be stupid to do
something like that just in case when we had
only four elements, the size was four. But after we added
the fifth element, it increase the
size, the capacity, the capacity of
the vector to aid. Because right now if you
add another element, it will not need to
increase the size, the capacity. As you can see. Why does it do it like that? Well, imagine that normally if you have to do it manually, if there were no vectors, if you had an array that, that is like four elements,
like four-element array. And if somebody wanted to have more elements like five or
ten later in your program, you will need to
copy entire array. You would need to
get every value from this array and put it into another array that
will be size of ten, e.g. and you will need
to do it this way. Alright? Well, it takes time, right? So that's why vector
increases its capacity. Just in case a bit more. We have got now it
at the size eight, just in case when we start
pushing new values like that, you will notice that when
we get to the capacity, the size is the same, but when we again
add a new element. The capacity increase to 16, so it doubled
because the vector, notice that it's better to maybe create a
bigger vector, okay? Because it takes time to resize
things in the background. So this is cool to have
a feature like that, but this is not like free thing for efficiency
or of your program, right? So that's why when you know exactly how many
lemons are gonna be in your program is better
to use arrays, e.g. otherwise, well, it's
better to use it because it takes the job that you would need to do
manually from you, right? It increases when
it should increase. When you push two main
elements to the back, right? You also don't need to specify the size of the
vector at this time. That's why this is powerful. And of course, most time this is the thing that
you're going to use, right? The next reason is why we haven't learned
about vectors at the start is that this
syntax is complicated. How would even somebody could explain to the person who
doesn't know C plus, plus. What is this vector with this, something like this,
angle brackets and int. What has happened here, what we have learned about something with this class
templates already, right? But they were pretty hard comparing to what we
have learned so far. So in order to understand
what's going on here, you need to first learn lots
of syntax from the C plus, plus lots of contents. It's not so easy to
use light like that. Well, you could just
tell her, Hey, you know, that's how we'd work dissolve, you does type here vector
and then you type int. And this is just some
kind of container. Well, that's all
right. But that's not how you should learn things. That's why. First, you learn about errors. And the next reason is that it doesn't mean that others
are not using arrays. Nmr, if you see an array and it's going
to be used with pointers, especially we know libraries. You would be confused
if you were, if you knew only about
something called, is called vector is not
like that, would be stupid. And then the next reason is
that when we start creating, now, when we want to start, make things like e.g. inserting, notice that there is an insert method that
allows you to e.g. insert something in the middle. You can do something like, hey, that's inserted at
the position three and let's put there e.g. 500. It's not going to work. Why? Because here in this place, we need something called
disk called iterator. Also, if you want to
remove a value using the eraser method which is
used for erasing values. Also, you cannot just put
here five when we run this, as you can see, it's
not working fine. You'll need to put the iterator. And this is also a bit complicated topic and we cannot talk about
it in future lectures. That's only lesson. Thank you very much.
70. C++11 - how to enable the flag? How to set starting values of vector?: Hello my friends. Today you will learn how
to set initial values for vector without having to
use the push back methods. This is a slow way to
add values when you know these values before you hit this button here, right
before compilation. So we use the curly bracket, then we type what
values you want to have at the start in our vector. Of course, we can
still enlarge it. We can add alignments, whatever what we did before. So we can just cut
this into this. However, notice that when
we click Play button, this will not work.
Why is it so? Because as you can see, we
have got here an error. And this error states that
we need to enable the flock, the C plus plus 11 flag. If you are using
different editor, maybe it will not
need to be done. However, in cold blocks, you need to go into settings
than in the compiler. And then you need to
choose this option here, because these new feature in the C Plus Plus language
comes in the C plus plus 11. Of course, you can choose
the newest version, or this doesn't matter. The most important thing
for you is to choose at least C plus plus
11 in this case. So now when we hit it, as you can see, now,
it compiles fine. And we can easily get to e.g. whole numbers of zero
and see the value of it, which is, as you can see, one. So everything works fine. You can initialize starting
values pretty fast. And this is the way that
we're going to do in future lectures because that way we can easily see what is it, the first position,
second, third, and fourth. It will be hard to go through values using
the whole numbers. Push back, right? If we just had to
see what's going on. So if you are using
different IDE and it doesn't work
for you, right? They need to enable the flag and you don't know how to enable it. Then just put into the
Google name of your editor. Then at how to enable
C plus plus 11 flag, and you will find
the instruction how to do it pretty fast. Please notice that if
you are a programmer, you need to be able to
adapt and you need to be able to search for
information in Google. This might be even
an exercise for you. If it's not working in your IDE, you should be able to
solve problems like that. And in order to solve them, really, it's not so hard. You just need to simply put precise words that we explain the problem
that you want to, that you are trying to solve. There's only that lesson. Thank you very much
and have a good day. If you have any questions. As always, feel free to ask.
71. What are iterators? How to use them?: Hello my friends.
Today we're going to talk about Iterators. But before we get to that, to better understand and
remember what an iterator is. Let's think about
the word iteration. Because we have met with
this word before, right? It meant repetition. And we were talking about this word when we're talking
about a simple loop, like the one here, iteration meant each transition, each repetition of the loop. So when everything is
executed from here and here, once we make an iteration, repetition of dead things, the instructs reactions that are inside the loop for, right? Well, we can even execute
this code and as you can see, we have got now
here what iteration repetition number one up to ten. We have here ten repetition. And this variable here, which is called AI, is really holding
what it's holding, which repetition is made, right? So this thing is
really iterator. Look, this thing is
called eye because the first letter
here is iterator. That's why we call it hi. Yes, this is an iterator, a simple version of the one that we're going
to learn about soon. But this is an iterator. So what does iterator? It's something that is indicating which
repetition is being made. In case of loops. But in case of the vector
is going to indicate which alignment is
going to be punted to. Okay, we're gonna point
elements inside our containers. And here we can point also to
something like one element. After all alignments, we can point to these elements here. In case of SDL, the iterator is not an ordinary variable
light here, right? So it's not an integer, but it is an object. And that object points to a
specific element position in the container, like e.g. vector, there are
many more containers, not only vector that in mind, and it points to the
specific position. E.g. the iterator can point
to the beginning to the end, to the second, third element
that we have talked. Similarly, like pointers can point to elements in the array. But in this case these very important and this is an object. Soon you will know why. But you might be
wondering why do we use object instead of
something like that here, lagging in the case
of loops, right? Hey, this is simple. We here we have on
the I equals to zero, then one, then two,
then three, then four. Why do we use object like that? Why can it be like a number? This is because not
all the data in the container from the SDL
must be one after another. Which means, well, when you
look at the data in memory, this is 20, doesn't need
to be before ten, right? In the sequence of memory. They don't need to be arranged one after another.
This is important. Data in an ordinary
array, right? That we learned about
longtime ago is indeed arrange in the computer memorial
one after another. But the data in the
case of SEL containers is not necessarily
arranged that way, okay? And relationships between
following elements due to optimization may
be different, okay? That's why they don't need
to be one after another. You do. Optimization is not
only because the how to store of them become
about how to jump between each of the elements. This can really improve
somethings in behind the scenes. I don't want to go into details right now because this is not a topic of this lecture, we just need to
learn this lecture. What is iterator, which
is object that is indicating specific
alignment, right? This may be, this may be
this inside the continent. That's all that we need to know, but I just want to
understand the bid, why they chose to use
object here, right? Why did they complicate? So the things that you're
going to see soon because hey, you might be like, Oh, I don't we use just the COP, the things that we're
learning right now? Let's just keep note. Don't skip it because
this is pretty important. So believing for now
that content is do not necessarily have to be stored in computer memory followed
by Jada, right? You don't need to know what, how it works in the background. And just write down. You just need to know
what an iterator is. Simply an object indicating a specific position
in the container and you can use it with the help
of methods provided by SDL. How can we use the iterator? How can we create them? Because this is very
important, right? We have taught so much
what is iterated, but we haven't created
him in one so far, so much lost time. Now, this is not lost time. Remember that when
you're learning something deeply like I just, I've just shown you, you going to remember
it for longer time. You're going to understand
what's going on is, this is very important thing. When you are learning
programming, you should always try to
learn things like that way. Okay? So how do we create an iterator that will help
us traverse through e.g. whole numbers containers. So it will help us indicate each element and show
it on output e.g. well, in order to do it, we need to write what
container type first. Okay? So the type
of this container, this vector is
really this. Okay? So we just did it. Then we need to use what? Two columns. And then we need to type
iterator is very important. This thing must be here. And then we need to
name our iterator. So let's call it e.g. IT okay. Slay that. We can call
it whatever you want. Barb, I think this
is a good name for iterator that we don't
know what's going to hold. And it's gonna be called IT. So we have just created
an empty iterator that can be used to
traverse container, which type is like that. However, we have not connected this thing here, up here, right? We need to now generate the
iterator that is already indicating this first
element and there is a specific method that
can be used for them. Look, When are we going
to use the equals sign? And we go not the IP or
the name of the container. Now that and then we're going to type
something like begin. This method is
going to return us iterator to the firm that
is indicating right now, that is pointing, right? He's pointing here, exactly
here to this first element. And we're going to
save it here, right? So this, IT is really now pointing to the
element 20, right? But how can we access
the value here? The cool thing about iterators
is that they have syntax. So the way we use them, very similar to the
pointers, they created it. So that way, even though
this is an object, right? So you don't need to
relearn everything again. How to access them and how
to retrieve these alignment, how to jump between
elements and so on, so on. You can use the syntax
from fontanels, which means that in order
to access the value, we just need to use the reference operator
like that, right? And we're gonna
see on the output, Let's maybe this
under the comment. As you can see, we have got here 20. So everything works fine. The, IT is pointing now to the
first element which is 20. Well, if the syntax is
similar to the pointers, the end means that we
can jump using them. Pause incrementation
like that, right? So we have jumped
from pointing here, pointing here, using these
polls incrementation here. And when we play,
as you can see, it's then we can jump ahead to two elements ahead just by using
something like e.g. this easily. And it means that we're going
to see as the next value, not for what are we gonna see? What minus three? As you can see,
it's minus three. So we can jump is later, we can use the,
we can jump back. It's all up to us. What we're going
to do here, right? It jump one bag, It's four because we
jumped from here back, backwards, one position. So that's how you use it. And yes, you might be really, we could do something like that, the loop Ferraro and everything would work
fine. Yes, it would. But not for every case. There are many containers and iterators are
taking advantage. This is very important of optimizations that are
in the background, okay? That's why you're going to
use in the future iterators, which are objects
that are indicating specific alignments inside
container, like e.g. vector or maybe another
container with different type. But we're going to talk about different types
in future lesson. Thank you very much.
72. How to iterate vector? How to use loops to process elements in a container?: Hello, my grant in
the last lecture, I showed you how to
print values manually. However, that's not how
we do things, right? When there is something
that looks similar, it's always trying
to use a loop. So if you want to print
every value from container, we should use loop
how to use it? Well, let's create a while
loop that will be infinite. So we need to print
something first, right? So we're going to print
what the value like this. The problem is that
right now in the, IT, we are pointing to the
first position here, and we're gonna see 20
and we're gonna see 24. So we need to somehow move
from here to here after each time the instruction
inside is executed. So we need to write IT plus, plus, right, because
this allows us to jump. So now we go on to be able
to jump from here to here, then here, then here, then here, and then to something
what is called end inside an iterator. And we need to stop moving forward because there is
nothing more after that. So in order to stop it, we need to change the condition of look,
how do we change it? We need to write
something like that. If I is not equal to the end. And in order to get this end, we use the method
that is called end. And the method returns here, the position, here,
the nth position. The cool thing about
these methods is that if something had
changed inside the vector, somebody had inserted
something into the vector, erased, the end will be updated. This always gives you
the last position here. Where after the element
that at the end, It's gonna give you this
position here at the end. Always. Well, so we are just checking if i t is not equal to
whole numbers that end. And this is gonna
finish our loop. That's why, that's why when
we execute our program, we can see that we have
virus 2010 for -3.25. Everything is working fine. So that's how you can go through every alignment using the wide, how to do the same thing
using the for loop. So we're going to
do something like that for two semi-colons. And well, inside we need to
print the values, right? Let's make spaces
here like that. I always create
for loop like this because it's easier
for us when to initialize the thing that
is going to be incremented. So this is the iterator, right? So we can get it
from here to here. I have one semicolon to match. So let's remove it. And then we need to
make a condition. The condition is
the same like here. So we can copy it
from here to here. And we need to also
increase our iterator. And that's how we have good now, look for that goes through
each element in our vector. So that's how you go through
every element using loops. And there is also one more loop that we're
going to learn in future that is going to look a bit better and easier to use
using iterators. But that's how you use
the y and for-loop. And well, as an exercise, I would like you to stop
executing loop for loop. Why? Whatever you choose
when the value that is pointed by the iterator is
equal to e.g. minus three. I want you to print 20104. And if the value is
equal to minus three, then I want you to break it. That's the only lesson. Thank you very much.
73. auto keyword - C++11: Hello my friends. Today you are going to
talk about auto keyword, which automatically, That's why it's called auto
in first deduce. So it draws conclusion
what type of variable is variable by what
is assigned to it. So when we type e.g. something like
integer, then e.g. we go type here
number of people, and we assign to this
variable e.g. 20. Notice that we have got here specified integer as the
type of this variable. And now when we print
this value outside like that, what will happen? As you can see, we have
got here value 20. However, if I change
this here, e.g. 225 here, we still have
20 because we said that, Hey, here is gonna be
integer, That's all. So we made a conversion behind the scene because
this is tedious. That's all. However, if we use auto keyword, that type here is
of that variable, number of people is gonna be deduced by what is
assigned to it. So here we have got clearly 25, which is a double, right? So which means that
we're going to see here 25, everything works fine. Should we always use
auto keyword and when should we use it
in case like here, when we have good here
a very long time, believe me, these types
can even get bigger. This is a great time
to use auto because it doesn't change the
ability of our code. So when we read our code
is even easier to read. We can clearly see when we are looking at
something like that, that begin method is used
to what to get iterator. We care what five
is that iterator? To be honest, we don't care. We just want to go through every alignment inside the loop. We really don't care what's going to be here, exactly right. We know that whole
numbers is here, declared and we can clearly see that it's vector of integers. So repeating things like
that again here, right? Vectoring. And the iterator, it takes what time,
your precious time, and also it doesn't increase the readability
of your code. So when you are using templates, when you are using iterators, it's good idea to
use auto keyword. However, what should we do? We are using simple
variables like this here. When you are looking at
the self-descriptive name, like number of people, we can guess that this thing is probably number of people. Okay, So that's
probably not dabble. But we need to deduct
that by looking at the name of variable
and it takes some time. So in cases like that, at least, I think it's just better to
specify the type of variable. Like this. We girls, well, at least I think it's
easier to read and it makes more sense when you are looking
at code like this, you do not need to
take your time to deduct bar by looking at
the name of variable, what is going to
be here assigned. Okay, so for simple types, seal, use integer,
double string and so on. Okay? This is gonna make
your code easier to read, hovering cases like that. Really. This thing is very useful. It speeds up your
writing of your code. It makes your code
easier to read, so please use it. Longer lesson. Thank
you very much.
74. ranged based loop for - C++11: Hello my friends. Today we are going to talk
about range based loop. For it is a loop that loops. So it repeats things
inside its body as long as there are elements
within the range. This is the range within
the scope of the container. And this is very
cool because we go now make this thing here above. Very short. It's gonna be easier to read, is going to be easier to write. This range base FOR loop is available since C plus plus 11. So you need to also
make sure that you are following the newest
version and how to use it. Well, in order to use
it, you type for. It's called loop for. But there's a difference here. We do not use semi-colons, we use a normal single column. And on the right side, we put the container
that we want to play with that we want
to take elements from. So this is the range that
we're interested in. And yes, this loop is gonna
be repeat things inside here, right inside the border. As long as there were
alignments to go through. And we can save these
elements instantly, automatically without
even thinking about it. Just by putting here a variable that is going
to hold it temporarily. So we can e.g. do something
like that nth number. And now we can do
something like that. See how that number. And you will notice that it's going to work the same
as the loop above. It did the same but look
stain times easier to read. And well, you don't need to
write so much things, right? So this thing will
repeat how many times? 12345 times, because there are five numbers in range, right? In this scope. If we had
added one more number, it would repeat one more time. So this is cool because, well, we didn't need to create
this condition here. We didn't need to vote in a sharp initialize the iterator, and we didn't need to increase data writer after each
iteration, right? So that's pretty useful thing and it makes our job easier. The cool thing also
is that notice that if we did
something like that, Let's create here and
number like that. And let's assign to
it something like this and something like that. The truth is that in
the behind scene, this is what it's done, right? This is like exactly this
thing that is above here. Okay, so we are creating 3D temporary variable
and we're assigning it the value that is under this iterator that is indicated
by this iterator. And that's how it works
in the behind the scene. Great thing, easy to read, easy to maintain code. I highly recommend using it. Most time you will see that
people use here because well, it's easy to see what numbers are inside the container, whole
numbers, right? So it's still readable. So we can do
something like that. And it works the same lesson. Thank you very much.
75. ranged-based loop for - & - how to prevent making a copy: Hello, my friend. We
know how to print the values from here
from the vector, but how can we change
the values inside the vector using this loop for? Well, in order to do it, the first thing that
you probably think about is doing
something like that. So we need curly brace,
bracket, brackets, because what do we need to add
more than one instruction? And now we want to change
the number, right? So let's change e.g. each number like this, Let's multiply every number here by ten and you run the program, you will notice
that we have good Now values multiplied
by ten, right? But it's true. Well, let's, let's, let's
do something like that. Let's create another loop for and that's just
print the values. Again. You will notice that original
values has not changed. Let's maybe take this under the comments so
it's easier to see. Notice that in the first part, we have got devices that are changed and in
the second part, we have a good day
original values. So did they change or not? Notice that before
I told you that this here is really
something like here. So to be honest, we
are creating here what a temporary variable
we assign to it. What is indicated
by iterator, right? So we'll make a copy here. And to be honest, we just did something
like that, right? So we are making the
operation on a copy, not the original, Right? So is the possibility
to work on original. What would you do without the knowledge of
these loops here? Well, notice that we could use the reference
variables, right? We could add here
a reference sign. And now we are working
on original because reference variable is
referring to original, we just different name, right? So this NR is really now
referring to original. So that's why we
also going to add here a reference variable. And now, yes, we change the
values of original contain. So that's how we do it. So if we want to change
our original values, we should use reference
variable here. However, is it only the only
thing that happens here? Notice that when we are
not making a copy here, imagine that we don't have a
container of whole numbers. We have a container
of books, e.g. imagine that you are coming to library and you want
to borrow a book. Do you want to wheel somebody from library and make a
copy of the book for, you know, he will give you
a regional book, right? That's why we should
use for objects. If you don't want to
make a copy constructor, the copy constructor
being involved, right? If you don't want to invoke copy constructor
from the object, you should always use
a reference, okay? Because otherwise, just by going through every
element from e.g. container of book, he
would make a copy of this book just to see
what is inside the book. That would be horrible for the performance of your program. That's why you should use
reference here always. And also when you are not doing anything with your values inside, you've got adjusts, e.g. going through every element, then it's good idea to
use constant because then you are informing the
gonads, change anything. You're not able to change
any value here, right? So for the sake of
printing values, you can add here constant. This is an information for
other programmers that you are not doing any changes
with the number from here, without DDR not
informing them about it. And also you're allowing them
to change the value here. You're not supposed to happen. This might lead to error. Of course, this is just
additional modification. We don't use it. This is not, this is
not like 100% error or is it just makes your
code easier to read. And as I said, you're informing others about potential things that
might happen in your code. However, you need to remember
about this reference. Especially when you are
working with objects here. Because otherwise you
go not always invoke a copy constructor just for
the sake of printing values. We then would be just horrible. To make sure you understand the point that
I've talked about. I've created the bulk that has got a constructor
that just says, Hey go constructor is invoked. And we have got here a
method that gives info, Hey, I'm book and the
copy constructor that just says some stuff, that's our copy constructor
instructions right? Now notice that when we're
creating a vector here, okay, so let's take
this, Let's cut this. You will notice that
we are invoking what constructors and copy constructors,
right? That's normal. Now notice that when I
invoke this first part here, notice that we are
invoking on the ward, Hey, I'm book, okay, So we are really printing what is inside each
of the book here, right? We've got the info from
the original book. However, if we remove this here, notice that what happened. Hey, I'm book some copy
constructor instruction handbook, some copy constructor
instructions. So we are really
creating a copy, like I said here, right? If we do not use a
reference variable, we are making a company. And this leads to
problem because, well, right now this graph
is just small, right? But imagine that
this book has tons of stuff done in the
copy constructor, right? Just to see what is inside
every object of container. Jesus thinks too much time. Imagining that for
every time you want to see what is
inside each book, you are making a
copy of entire book. You are printing entire
each page from the book. Again, that's just,
that's takes time, right? That's why when you
are going to objects, especially just what,
use reference here. That's something that lesson. Thank you very much.
76. Finding specific amount of odd numbers: Hello my friends.
Today we are going to write a program that will ask the user how
many odd numbers, one after another, should be
presented on the council. So if the user input seven, we cannot show on
console 135-79-1113, there are seven numbers
that are odd numbers and they are gonna be
shown to the user. So how do we approach
a problem like that? Firstly, we need
to see how should we create an odd number? How do we check if a
number is odd number? We need to use a modular
operator for that case. So look, when we have got
expressions like that, one module two is equal to one. Why? Because 1/2
gives us a reminder. It is one, and while
this is the rest here, so we have got here
one to module two, on the other hand,
is equal to one. So there is no remainder, there is nothing left. So it's zeros free, divided by two is one half. And this half is root one, right? It's one reminder. And 4/2 is two. There is no remainder
again, so with zeros. So we can see here is some
kind of pattern, right? Because there is 101010 and what we're looking for
numbers like what, 13.5. So we can see from that that the numbers that
we're looking for are rechecking the
condition like this, right? When we have a
situation like this, we need to use the
conditional statement in order to find
numbers like this, but we need to also generate
somehow these numbers. In order to generate numbers, I think it would be best
to use the loop four. And let's start numbering
values from zero, generating values from zero. So if I is lower, e.g. then let's start from ten, then I plus, plus. And notice that when we
do something like that, we're going to see
on the console what numbers 0-9 and what? This is, this part that we
are looking for right now. And we can do
something like that. If I, if I modulo two is equal to one because we are looking
only for these numbers. Because these numbers
are odd numbers. Then you can see we have good now 13579.
Yeah, that's good. We've just going to write it. Harman numbers, five
of them, right? 123455. When we have
got here, what, ten? If we type here, Example 20, we're going to have 101234, 567-89-1010 values like
that, the odd numbers. So we can see by looking
at this that we need to times more value needs to be two times bigger than
the user asks for, right? So let's do something like that. Let's create a
variable that we hold. How many odd numbers
should be generated? Let's ask you, Sara,
how many odd numbers do you want me to generate? Something like this? Let's put that into how many odd numbers. And now we need to
use this here, right? But when somebody types ten, notice that we have with
five numbers as expected, because there are two
times less of them, we need to multiply
this value here by two. Now any type ten, we have got ten odd numbers
that are one after another. And that's how we
solve the problem. But still we need
to odd numbers. The odd numbers mean to
say which one is which. And in order to do it, we need to create a
temporary variable like e.g. integer. Let's call it e.g. index because it will show the index or the order
number, whatever. And let's assign to it one. And now we can do
something like that. Index. Let's also add this here. So it looks better,
something like this. And now when we put it to work, you notice that we have
got here everywhere. What one? We need to increase the index, and we can do it in two ways. The first way is to do it
here is the fastest way. As you can see, now
we've got 20 numbers. But some of you might
do something like this, and this is a typical error. Because notice that we're
going to have here now what 2468, what happened here? This is a typical
error because we, as humans tend to think that when something has got
the same indentation, it's got that instruction is really affecting this
conditional statement. That's not true. In order to combine more than one instruction
is very important. To combine more than
one instruction, we need to use curly
brackets like this. And now that works fine. Wherever I think that we
can leave it like this. In this case. This is pretty easy to
read. Index plus, plus. Now when we type e.g. five, it's going to
be five odd numbers, one after another, and
everything works fine. However, this only, the only
way to solve this problem, of course, no dominant other ways to solve this problem, e.g. we didn't need to even learn
about this thing here. To be honest, we could
solve it like that. Let's maybe come on this
so we don't lose it. Like this. Let's copy it here for a second. Let's see what is
the pattern here. We have good numbers one after
another that are bigger. By each. Jump, by H change. They are different
by two, right? One plus two is 33,
plus two is 55, plus two is 77, plus nine is 99, plus two is 11, and so on. So to be honest, we
call jazz world. Instead of adding one to the I, we could add word to. Right. Now we wouldn't
need a condition. And we could just do
something like this. As you can see, the
program works fine too, but we need to find odd numbers. So we need to start not from
zero apart from one bomb. And to be honest,
this is also faster. But I wanted to show you this
thing here because well, in this case, we can
solve this like this. But there is very
often when you need to use the modulo operator
for cases like, hey, let's do something. And not every time, but once in two times, right? This is great idea to make a loop that does
something not every, every time, but once in two
times or once in three times, once in four times,
one is five times. We can e.g. execute code once in a while, not every time the
loop runs everything. So this is very
useful knowledge. However, as you can see, if if you think you don't need to always do
everything the same way, you can solve the problem in many other ways, like e.g. here. That's all in that lesson. Thank you.
77. The absolute value: Hello, my friend. Today I will show
you how to count absolute value of some
kind of number, e.g. you have number minus five. How to use absolute
value on this number? Well, it means that you are changing negative numbers
into positive ones. So minus five is going
to be turned into five. If you have a positive number, you just don't do anything. There is nothing to be changed. If you have zero, you
also don't do anything. So in order to do, to change a negative number
into positive number, what would you
normally do in math? You just need to multiply
minus five Pi minus one, and you will get phi. In other cases, we just
don't need to do anything. So let's create a
temporary variable that will hold the value
input by the user. So enter the number
e.g. like this. And now we can go and get this number and we go
not change it into, into the number that is multiplied by minus
one, minus one. But doing, can we
do it always? Now? We can because if
somebody put 20 here, it will be -20 days. So we need to make a condition. If x is lower than zero, then yes, we can do
this instruction. Otherwise didn't do anything. And then we're going
to put on the screen the absolute value
is equal to x. When we now compile
it with -20 days, you can see it's 20 when
we do anything else. So e.g. for or zero, nothing is gonna change
because the condition here is gonna be executed only. That instruction here
is going to be executed only if the condition
here is met. And that's how you can
solve it manually. But you can also use
from the cmath library. You need to include
the cmath library in order to make it work. Something called this is
called App abs function. Abs stands for apps, so epsilon value, right? Abs, and this thing
will just do it for us. So when we compile the program
and we type minus 550, we have good number 50. So right now we have just
created this function. Right now, we just
made it on our own, or is it a good idea to do
things like that manually? Well, if you don't
know how to do, if you don't know about the
existence of some functions, then the knowledge
that is useful. But also, this is a good idea to practice your
programming skills. It's good idea to create your
functions that are already written by others in order to practice your
programming skills. Because sometimes there might
be a chance that there is no library with a function that can solve your problem
like e.g. in this case. And then the skill of programming
might be on high level. And you can then solve problems
like this on your own. That's on that lesson.
Thank you very much.
78. Spelling the word backwards: Hello everybody. Today I will show you how
to create a program that will spell the word
backwards. What does it mean? It means that you want
to change it then the n, like James, into S, E, M, a j. So we just want to read the word from the buck. How to do it? Well, in order to read
it from the back first, we need to know
how to access each of the letter inside the word. How to do it. Well, let's do
something like this. As you can see, we can act as the first letter using
the index, like an array. We can access each of the
elements of the string. So we could do
something like that. For this specific case, 0120123. There is one more for the last element is
at the position four. Notice that we have here five characters because we are standard thing
counting it from zero. When we do something like that, you will notice that we have
good James here, James. But we want to do it
backwards, right? So we really should do
such like this, right? But the problem is that we
are doing it of course. But that's how you should
create your programs. You should try to think
on very simple case, how to solve the problems. Because now you can easily
see that all we need to do is access each of the latter using the index
that is decreasing by one. And by saying that
you should probably already know that we should
use what line, right? But we need to come
not 0-4 but 4-0. In order to do it, we need
to create a variable that will start be equal
to what to four. For this specific case, of course we're
going to upgrade it. But for this specific case, it's going to be equal to four. And now we need to make a condition and condition
that will look like that. And should we increase i here? No, because we increase i
we will have then what, 45678910 and so on. When to decrease it
here is equal to zero. Now, when we do
something like this, you will notice that
we have got here what, 4321, but we don't have zero. Why? Because we have got here a sign that is greater
than zero, right? Means greater than zero. We need to check if I is
greater or equal to zero. Otherwise, when I
is equal to zero, the condition is not met
because zero was not met, because zero was not equal, was not greater than zero. But now we have
got the condition that checks if the I is greater
or equal to zero, right? Now, because of that. Now when we do something
like that, as you can see, we have 4,321.0, so
everything works fine. We have good. Now this index is here. So we need to do is, let's remove that and light
and just type here like this. And as you can see, we
have good now here, what we want it, as you
can see as m a j, right? So everything works fine, but for this specific case, but when we change it to whatever else is
not going to work. So we need to assign here what the length of
the word minus one, because as you can see here, we have five characters inside. But we assigned here for, because we start
counting from zero. So we need to do something
like word that length, which will get us there. Length of the word, which is five characters
in this case minus one. And now it's also going to work, but it's also going to
work for every other. Where did we invent? One? You can see it's working fine. The W. So we can type here now
whatever we want and we're going to spell
the word backwards. That's only good lesson. Thank you very much.
79. How many digits are inside a number?: Hello, my friend. Today I
will show you how to count numbers of digits
inside a whole number. A number that type is integer. So normally we would
count it like that, 1234. And we can see that on the output we should get
for that to be honest, computer should count
it pretty similarly. But from behind, when
we have got 5,254, we could divide
this number by ten, and then we are, we're here. And then we can divide it
again, and we are here. And then you can
divide it again. We are here and then we
have wood zero, right? And so it means that we
should count and we should divide as long as we do
not get zero, right? When we get zero, it means that we
have finally counted every number inside the number. So let's create a
temporary number. Let's e.g. assigned to it 124. So it will be easier too. Understand the
concept and lights, e.g. do something like this. Number divided by ten. Let's see what will
be their result. As you can see, it's 12. 12 when we divide 124, we should get what
12th point for, right? No, that's not true. If we use double number, that's true. However, if you use
the whole numbers, like integer, always
the output is integer. Remember about that? I talked about it at the
start of the course. But what? Things
can be forgotten? That's why I remind you. Okay, so as you can
see, it's 12th. Okay, let's, let's do it again. But let's firstly
do something like that number divided by ten. And here we will show
the result like this. Okay? So we can retry, we can do something like this. And as you can see, when we
have got 12/10, it's 1.2. So because it's, it should
be integer is 11/10, is 1/10 is zero because 0.1
should be zero as integer. Well, so it's 123, right? Three times we need to increase something that we count
the number of digits. So if something is being
repeated a few times, it means we should use loop
with the condition of what? Do things such as this? When, until we have good number zero as the result
of the division, right? Let's use here a
shortcut like this now. So we will have it a bit shorter version and easier to read it.
You can see it works. Also fine. And let's use a loop. While number can
be divided by ten. We need to increase
something like e.g. digits plus button. However, we need to
create these digits. Then they assign to it
e.g. at, start at zero. And we can type number
of digits, e.g. digits, right? And let's see what will happen. As you can see, number of
digits is equal to zero. The question is, why? Notice that we have
changed here from line 17 to line 24 hour number. We change it to finally
to zero because we use this expression here. This arithmetic operator,
which changes the number. So we have got here
right now zero. And we are trying to
divide it by ten. So 0/10 is equal to zero and this thing is
not going to increase. Okay, so it means we need to
delete what we did before. And now, as you can
see, number of digits, it's not true because it's
what free, which means, we should just
start counting from zero but from one, Right? This way, as you can see, we have good number
of digits, three. And when we flip on the
one digit like this, we will have number
of digits, one. So everything works fine. Now
we can change the number to some fingers and it's going
to count it proper, 12345. But there is a problem
in our solution. Notice that we are
really changed. The number that's
not, that's not good. That's not good. Because, well, later if you want to use
this number in your code, because it's equal to zero. So that's why you can
solve this problem in two ways. How to solve it? Well, firstly, we
could just create a temporary number that we'll call to the number just for
the calculation like this. And our problem is solved. As you can see, we kept
the original number. However, I think the
best solution in this case is to just
create the function int, get number of digits of number that is
going to be sent here. Right? Now we need to just do what? Do the same thing that
we did here, like this. And what do we need, of course, create and digits and just
return the DG's at the end. Like this. And what we need to number
that is going to be sent here. What we can call it
whatever we want, e.g. number, the temporary
number right now. It is actually
temporary variable, but what we can call
it whatever you want. And we can just invoke
it like this right now. Like we can send here number. We do not need this
temporary number here now. And well, as you can see, what we need to delete this now. And as you can see, number of digits is five and we have got the number,
the original value. Why is it so? Because always when you send value as an argument
to the function, you are making here, copy of that variable, right? So when we are working on
these variable like here, so we change the value
to something else. We finally, the number
here is equal to zero, right? You can check it. You can see it's zero. Could do something
like I am here. You can see here,
I am here, right? But we haven't changed the
original value which is here. And the cool thing
is now that we can invoke it, what many times? Well, we do not need to
send a variable here. We can just send a
number like this. And we can see for each of them, how many digits are
inside a number. We can repeat the
same code many times. That's why functions
are so great. There's only the lesson. Thank you.
80. Multiples of number up to...: Hello. Today I will show
you how to create a program that will
find multiples of number up to a
number that we provide. So firstly, we need
to think about what are multiples of e.g. number five. Notice that I showed here
numbers like 051050. So what is connected to them? Notice that when we multiply five by n natural number, e.g. zero, we're going to
achieve zero when we multiply it by the next
natural number, one, you're gonna get 55
multiplied by two is 105, multiplied by three
is 15, and so on. So that's how we achieve the
multiples of number five. But how can we check if the number is a multiple
of another number? Well, when we look at
this number here, e.g. notice that when we
divide five by five, we going to achieve what? One and there is
no remainder, ok, so there is nothing left
when we divide ten by five. Notice that the result is two. There's also no remainder. We had the number e.g. 1212/5 is two point something, there is something there
is a remainder, right? So this is not a
multiple of number five. So I think that the
best way to look for the multiples of some
kind of number is to use the modulo operator, right? So let's, let's assign here
to the variable number to find multiples of fat
of e.g. number five. And let's create the conditions. So if the number that we
are looking for, e.g. ten, Module number to find
multiple off is equal to zero, so there is nothing left, there is no remainder. It means that we found
that the number right, we typed here manually it, but soon we'll change
it into variable. So let's write something
like ten is multiple of this number here, like this. And when we compile this, you can see ten is multiple
of five, which is true. If we change it to e.g. 13, you will notice that
there is nothing here. So that's how we find if the number isn't multiply
of another number. Now we need to generate
this number, right, starting from water, e.g. zero. So in order to do it, I think it would be best to use the loop
because we need to check as many times as we
want as the user won't. If this condition is met and change this part of our code, we need to change it into what? 123 456-789-1011, up to
the number that we tell. So let's create a
loop like this. And is e.g. lower than the number provided? So e.g. number provided. And let's say that of course
this is the number that is provided by the user
rights, e.g. 50. Then I plus, plus. And now we just need to check each of the number
like this and combine. As you can see, zeros
multiple 55101512, up to four to five. But as you can see, we didn't include what
number 50 really depends if we want to check the
last number or not. It's up to us how we want to
create our program, right? So we can do something
like this and then 50 is going to be included. Now we can easily change
it to e.g. let's say 13. And we will find
every number that is multiplied of number
13 up to 50, right? And when we compile it, as you can see, 013-20-6309,
political right. That's all good lesson.
Thank you very much.
81. Finding largest number (max value): Hello. Today I will show
you how to find from the numbers that are inside
that or that are separate. The largest number will use
three methods to do it. Firstly, we'll focus
on how to do it manually inside
our main function. Then we'll create
our own functions. And then I will show you
how to solve this problem using external function
created by somebody else. Okay, let's start from what
should we do if we want to find the biggest
number from e.g. this set here, right? Two minus 411540. We can start to see it's 150, but the computer doesn't know
exactly which one is the biggest when he doesn't
check every number, right? So you will need to
check every number. So we need to repeat that. Check kink. It means that we need to use what loop every time when you
need to repeat something, it needs, you need to use loop. So let's create a loop that will start from the
start of the array. And then if I is lower than
the size of our array, right? So right now it's the size for like we will
get four numbers here. Then we need to increase I. Now the question
is how do we check if something is bigger
than other thing? We just need to compare one
number to another number. But what should we compare to? What I suggest we
going to create a temporary variable that we call temporary maximum number. And then we're
going to assign to it the first number
from our array. Like this. Well, we could call
it a maxim like this. Now, we cannot compare
If the maximum number, which is right now
the first number in our array is bigger than or. In this case, let's take e.g. if it's lower than the new number that we're
going to compare it to. So to sample of I. And if it's true, it means then we need to just change the
maximum number, right? Because, hey, this guy is
bigger than our maximum number, so it means we need
to change it to this number that is here, right? Well, that's all. We can just type. Maximum number by grace. And you will notice
the S that is 150 and it's true if
you increase 150, if we change it to, let's do something like here. You will notice that this
number is the bigger one. So everything works fine. That's good. But how does it work in the, can we optimize it a bit? Well, look, firstly, the
maximum number here is equal to what to do. And we can compare if two is lower than what
sample of zero, which is also two, should we compare the first
number to the first number? Now, let's start
our loop from one, because we just can omit
this first comparison. And this will be a bit faster. Of course, this is almost four hour fast
temperatures solid Solomon's not
disabled, but why not? Let's upgrade I program. So now we're going
to compare if two is lower than minus
four, which is not true. So we cannot just not going to invoke this instruction
here in line 16. If two is lower than
150, it's true. So our max is going
to be changed into 150.150 lower than 40? No. That's why it's going
to stay at 150. That's how it works. Political, right? So let's update our program because what did we
had more arrays. And that will be useful, right? So because we will need to repeat what this
code many times. So we need to create
a function that will do the job for us. Let's create a function
that will return integer because it will
return the maximum number, e.g. find max value. And it will take what? It will take numbers,
array of numbers. And we also need the array size. Because when we pass them
arrow here, compiler cannot. That's how C plus plus Borg just know the size of the
array and then model. So we need to pass
the very sites. And what? We need to just copy
this pink to here. And now we're not going to see out the maximum number which
is going to return it. We need to change
the names, right? Like this. And the
array size is here. And to be honest, that's all. We can now, pretty easy
use it like this c out. And the max value of set is. Find max value. We can ascend up the
sample and the array size. Array size, like this. And like something's
not working, is because I deleted
the curly bracket. Depending upon by a mystic. As you can see, max
value of set is 150. So everything works fine and
we can now reuse it on many. Alright, so that's pretty cool. Now, what should we do next? Should somehow be able
to do such things on values that are not
inside arrow will be, when we have two
numbers is easy to compare one to another.
Three amperes. Well, we could still make some comparisons
with conditions, but to be honest, it's best
to put this into an array. But the problem if
inputting these into error is that we need to always
know the size of error. What if there will be
more values like this single numbers that are
coming from e.g. the user. That's not cool. We
will need to create a dynamic array That takes
time to call these bigger. It doesn't look good. I think it's best
to use what we have learned in lectures before. It's called vector. And then we can do
something like that. But let's create
another function. But this time the parameters
will be what will be vector. We're going to take a vector. And let's do
something like this. Vector also can what
we can also assign the first element from the vector that is
going to be sent here. And we're going to return
the maximum value. But we need to create a
bit different functions inside the different loop. Because we're going to
use the for each loop. We're going to use stuff like
that, auto keyword numbers. So for each number inside
numbers that are here, we're going to check if the number is bigger
than the maximum value, then we need to do what? We need to just change the maximum number into
the number that is bigger. Now, the question is, how do we use our
newly created loop? Now, our newly created function? Well, we need to
send here a vector. But how do we send the
vector of these numbers? You can do it two ways. We can create a temporary
vector and call it e.g. temporary vector and
put it there, a, B, and C. That's how we
can initialize vector, right, with these numbers here. And you can just send this here and we'll get as the result 50. So everything works fine. But well, creating this temporary vector here doesn't look good, right? Like we're never going
to use it again, right? So I think in this case we
could just comment this, something like this,
like we created. And we forget about this, which is needed only for the sake of finding the
maximum value, right? That is, you can see
now it works fine. So now the cool thing is that we can put
here minimum numbers. We do not need to
change the array size. We just put numbers
and the new number. If it's the largest one
is going to be found. This is pretty cool. And that's how you solve
it manually, right? When you want to create
your own function. However, it's good to know
that you can use from the NGO written library IF function that will do the job that
we've just done here for you. So let's copy it like this. And let's make
something like this. So we know that we are
now doing something else. There is a function
that is called inside this lab
during max element. And how to use it. You need to send, if
you want to check the array for the
largest number, for the maximum element, you need to send
their data array, then the array plus the
array size, like this. And let's see what
will be the result. You can see it's an address and maximum and just returns the address of the
largest element. So how to change the
address into the value? You need to use the
asterisk operator, which is used on addresses in order to extract
from them the value. So we just need to
palpate asterisks. And now as you can
see, yes, it's true, it's 150 found inside this array here.
Pretty cool, right? If you want to use the
vector like we did before, how do we use it? This time? I think we should create a temporary vector
like we did before. We need to send here the first element and the
last element iterator. Write this. We need to just tie. We need to know from where to start our search and
where to end it. Mostly when we do it, we do it from start
to the end, right? So that's why we sent
the begin and end. This way. As you can see, we got
the value which is 50, is 15, goes well, here we added this number. Here. As you can see, it's
just the largest one. You can do the same as an
exercise to mean value. But how to find the Min element? Well, I think you'd get
asked when I said it. But you can always check the algorithm library
inside Google. You can type the
algorithm max element and you will probably find
how to find the Min element. Also. Remember that you as
a future program I reuse should be able to
search Google lesson. Thank you.
82. Can 3 sides create a triangle?: Hello. Today I will
show you how to create a program
that will check if free sites can be used
to create a triangle. How to check
something like that? Where can I find an
answer like that? Well, you need to
just Google it. Just type in Google
triangle condition. That's how you solve problems. As a programmer, you do not
need to re-invent the wheel. How to check if, if free sites can create
a triangle, okay? You just type into Google, and after you do it, you will find out
that each side of the triangle is smaller than the sum of the
other two sides. Okay? That's the condition
that needs to be met. And that's what we need
to do as programmers. We need to program this
condition into life. So if a is smaller
than b plus c, and then the same time
B is lower than a plus c. And the same time C
is lower than a plus b, then we can create a triangle, each side of
triangle, each side. So a, b, and c is smaller than the sum of the other
two sides, right? This is the condition
that needs to be met in order to create a
triangle from free sites. And you can just type, yes, we can create a triangle. Something like this. Otherwise. No, we can't create a triangle. When we compare it.
As you can see, we can create a triangle. Well, we have a site
that has good 50 land. So the attitude that's 100%, they can't make a triangle
like this, right? But let's e.g. writing five. And as you can see, yes, it is possible we can
create a triangle. That's the only lesson.
Thank you very much.
83. Is it a rectangular triangle?: Hello, How do we check if a triangle is also
rectangular triangle? The triangle which
has one right angle. Well, we should use
something what is called Pythagorean theorem that says that when you take one
of the side of the triangle and you square it plus another side of the
triangle and you square it. It must be equal to the longest
side of triangle squared. Okay? So if this condition is met, then it must be true. This triangle is also
rectangular one. So we need to just make another
condition right inside. After we check if
triangle is triangular, because fairness,
we need to check if we can create a triangle, then we should check
if it can become the rectangular triangle, right? So let's make a condition
like above here. So a multiplied by a
plus b multiplied by b is equal to c multiplied by c. And if it's true,
then we can e.g. add. It's also recta rectangular
triangle like this, e.g. and when we compile it, as you can see, yes, we
can create a triangle. But if we type here e.g. 34.5, which I know will give the triangle that
is rectangular. You can check it out. If
you do this operation here, you will see that, yes, it's also
rectangular triangle. The problem is that we
do not need to expect. We can expect from
the user that he will put the values like this. So the longest is at the end. What if you put
values like this? So as you can see,
yes, we can create a triangle which is true, but this triangle is
also rectangular bar, the longest value is here. So we can, we need to check
not only this condition here, we need to check something
like this or like this. And we need to just
put the longest. Willing to assume that probably
the longest side is here, not at sea, but at e.g. B. Let's change it to be here. We need to change it to see now. And here we need
to assume that the longest one is at a site. And we need to change
it to sit here. And now, as you can see, it's also rectangular triangles, so it checks properly if
it's rectangular or not. We do not need to
care about the order at which sites are
put into the program. If we put the value that doesn't create a
rectangular triangle, it will just show we
can create a triangle. And if we put something
too big, like this thing, now we can't create a triangle from these
numbers above here. That's the only lesson. Thank you very much.
84. Factorial iteratively: Hello. Today you will learn
what is factorial and how to count it using loops. So how to count these
using iterations? Because every repetition inside the loop is called iteration. And what is then factorial? Factorial is a product of positive integers up to
the provider number. So it is a multiplication of all these integers
up to that number. So if you have one and this site is responsive
for FactoryGirl, the result is one because there is only one
number up to one, right? Two factorial is one multiplied by two because
there are two numbers, 1.22 integer numbers, right? Free is one multiplied by two by three because
there are three numbers up 234 is one multiplied
by two by three by 4.5 is one multiply by three by three by
four by five, right? Up to the number that
is presented here. And we need to multiply
every number like this. How do we count the factorial? We just need to multiply every
number up to that number. And I think the
best solution this time to solve the problem
is your slope, right? Because look for, is
almost looking like this. We can create I when
I is equal to one, when I is lower than
the factorial provided, then I plus plus. And what we need to do, we need to multiply
itself, right? We need to multiply one by two. If we want to count e.g. the factorial of two. And if we want to multiply, count the factorial free, we need to multiply what
we did here by three. We need to, if we want to
count the factor of four, we need to multiply the
result of here by this. If we want to multiply
factorial of five, we need to multiply
this by this. And the solution is before. So we need to create
a temporary variable. Let's call it e.g. unsigned because well, it might hold big numbers in future. Let's call it e.g. result, and let's
assign to it to I. And we need to vote. We need to multiply
itself by the eye. And to be honest, that's all. Um, I think we should put it into the function,
we will look better. So unsigned factorial and we need a number
that is integer. And let's put it here. And we need to return
the result, right? Result. And here is factorial that we sent some number e.g. like this. And let's can then see
out factorial of e.g. free because it's easy to count. H6, right? One multiplied by two
by three is fluorine. Hey, it's me, six. It's six. If we change it to four, we should have one to four. That's true. If we
change it to five, we should have 120 is also true. So we sent here what five? And this condition is here
because we need to go up to, from one up to five. And we have got one, not zero because zero is not just going to give
us zero when we multiply anything by zero
is always zero, right? That's why we start
the result with one. And then we multiply by, I would just increasing
every time it's one. When we do something like
the result is equal to one, I is equal to one. Then we multiply one
by one, which is one. Then we have got here too. So we multiply one by
two and we have two. Then we have I equal to free. And it's gonna be two multiplied
by three, which is six. Then we're going to have
what I equal to 4.4 multiplied by six is
equal to 2045100 2010. So on, it depends on
what we put here as a number that we send into this function. That's
all in the lesson. Thank you very much.
85. Factorial recursively: Hello my friends. Today we are going to take
about recursive function. What is recursive function? It is just a function
that invokes itself inside its body.
What does it mean? It means that you have
a function like this. You just type factorial
of e.g. here. It means, yes, this is
recursive function because hey, this function invokes
itself inside. But the problem is that
when we invoke it now, it will never stop, right? Because hey, we're invoking a function inside
another function. There is no way to stop it. It's going to invoke forever. Well, we can show it, right. A look at this. We can show the number
like this outside. And you will notice that we
have got what always form. Then it's just going
to repeat itself. Well, how do we stop a function like this
from invoking itself? When to omega condition? Somehow we need to
make a condition. But firstly, we need to change the number
to something else. Because if you make a
condition like this, if number is equal to e.g. four, then stop. So we will still be by
returning something static, something that we've
stopped the function. We have finally something
that is going to be returned. Then we have good
just what, 5.0, which is the five
that is sent here. It's five. And then we invoke the
factorial of four. Because four is equal to
four, we returned zero. But we can do
something like this. If number, we can invoke
number minus one. And this time we can
do something like e.g. if number is equal to
zero, then we'll stop. And you will notice that we have numbers like 543210, right? If we do here, e.g. 50, we have numbers starting
from 50 up to zero. Because we stopped invoking
the function when we met, when the computer met
the condition like this. Okay? The question is, how
are we going to use it in real life
programming situation, not just for counting
numbers 50-0. Let's look at our
factorial program from the last lecture. Well, the sample. Notice that factorial
of five is really, what is really a factorial
of four multiplied by five. Because what, this thing is
really factorial of four, so we can paste it here, right? So it's really like this. So to be honest, it's really something like that factorial of five is really equal
to factorial of what? Of four, right? Because really this sign
here is really well, it's really a function. Multiplied by five. Factorial of four
is really what? Factorial of three
multiplied by four, which is factor L4. Four minus one, which is
three multiplied by four, and so on, right? Three is equal to, to multiply it by Free. Free, Free, Free,
Free minus one is, of course two here is three. But notice that this number
here is just one lower. And we can use it. We can use it here by
doing something like this, let's return the factorial of n minus one multiplied by N. The number here is one. Let's return one. Now what is something? We have got? What? If we type here five? Then we have got factorial
of five minus one, which is four
multiplied by five. So this, this situation, right? Factorial of five is going to invoke a function
inside itself, like factorial of four. And then we multiply
by five here. Then again, it's going to invoke itself until there
is a situation where the number is here gonna be equal to one and
then it will be. One finally, I think
the cool way to imagine that a bit better is
to do something like this. Let's copy this
into the program. And then imagine that we
have got here what five? So five is equal to one. This is not true. Then five minus one
multiplied by five. Let's go put it here. So this changes
into what entities. But without this, now
we have got what? This is four, this is not gonna be returned because
this is not true. Let's come here. And to be honest, our program, our computer doesn't know what is
factorial of five. Now, he needs to
involve factorial of four to find out what to return. He doesn't know. So this factorial of four
function would look like this. If firm for four minus one, which is three multiplied
by four, right? Like this. And we've
got like this. And then what happens? We have got free, free to free. And it goes like this. And then we have what? 2212. And we have good something like this. And finally, we have 11. And here is zero
and here is one. But because this is true, firstly, this is not
going to be returned. One is going to be written. We finally stopped invoking a function inside
another function. So here we have got
finally a result. So you have good
finally situation where we have got here one and this number one here
is going to go where? It's gonna go here to here. And you have got what? One multiplied by two is two. And then that value
is going to go here. So factor of two was two and we have to
multiply it by 36. And these girls here, six multiplied by four is 24. And this goes here. And 24 multiplied
by five is 120. And that's all right. We have finished
the invocation of all the functions from the last. So notice that in order to really return the
value at the start, our computer doesn't
know the value here. He can do it. That's why he need to invoke function sided
serve again, again, again until there is a time when there is
function that returns the value that is no longer gonna be written from
another function, right? So the static value
like this, e.g. one. And then our computer
computes, computes, it, calculates every function from the last two,
the first one. And that's why we have
a solution like here. Alright? Okay, Let's go back to
how it looked like. So as I said at the beginning, recursive function
is a function that invokes itself inside his body. But you need to
always remember about condition that stops executing function inside
another function. Otherwise you have
good something like almost infinite loop. But the problem is that
while loop is just executing instructions
after another instruction in the recursive function, you will not get a result
that you want until you get what you get the value
from the last execution. So that doesn't mean
that it's fast. Iterate iterations are
faster than recursion. So the question is, where should you use recursive function? Well, driller are
situations like e.g. when you are looking at folders. Because inside a folder there is another
folder and there can be another folder
than ten can be five that you are looking for. And you can search inside folders using
recursive functions, and this is the
best way to do it. So this is not something
that is not useful. This is pretty useful, but not for things that will have too many levels
of going inside up to e.g. 1015. Okay, that's pretty cool. But when you go like
5,100 levels inside, then that's not a good idea to use recursive, recursive
functions, right? That's all in the lesson. Thank you very much.
86. Fibonacci iteratively: Hello. Today I will show
you how to count specific number of
Fibonacci sequence, sequence of numbers from Bernard sheet looks
like this here. And we want to e.g. put into our program
seven and we want to find out the Fibonacci. It means. But the question is, how do we count
Fibonacci numbers, these numbers that are
one after another here? Well, Phil Knight chain, in order to count it, said that you need to sum
two previous numbers. Okay? So the next number is found by adding up two numbers before it. But we need to start
from somewhere, right? Because otherwise, there
wouldn't be a way to do it because we wouldn't
know what are the two previous numbers. The Fibonacci of zero
is equal to zero. Fibonacci of one
is equal to one. And that's where we start from. Fibonacci of two is just the
sum of two previous numbers. So zero plus one
is equal to one. Fibonacci of three is the sum of two previous numbers
for Fibonacci, really of one plus two plus
Fibonacci of one, right? So it is one plus one, which is equal to two. Fibonacci of four
is really what? Sum of two previous numbers. So two plus one is
equal to three. Fibonacci of five is
three plus Fibonacci of six is five plus
three, which is eight. Fibonacci of seven
is eight plus five, which is 13, and so on, right? So that's how we count it. 13 plus eight is 21. And so on. Here
are more of them. We need to somehow programming. So if somebody do
something like e.g. this, the results should be 13. Okay, so let's program. Firstly, we should work
program the thing here, because this is a unique
situation, right? So if the number that is gonna be sent here is equal to zero, we should just return zero. If another situation, the
number is equal to one, we should just written one. The question is,
what should we do? Now? When the number is
different than 0.1, we should just work
at zero to one. If the number is
equal to two, right? But what if the number is
equal to 456 and so on? We need to somehow
update these values. And we need to repeat that many times until we get the
number that we want to find. How to solve this problem. Well, I think we called create temporary
variables like e.g. previous number. But previous example we
call it previous left, which is equal to zero, and previous right, which
we assigned to it one. Y. Notice that this is going to be the left one and this is going to be
derived on right, because we need to sum
two numbers before it got the name the variable
different, right? I think a and B would
be hard to memorize. But when you have previous
left and previous right, we know that this
is the previous number on the left side and this isn't previous numbers on
the right side that we don't want to sound,
right? Let's start. They are equal to 0.1 inch. In future we need to what
we need to change it. E.g. if there is 01, then we need to have it 11. Then we need to have it at 12, then we need to
have it to three. And then we need to change
it into 35 and so on. That's how we gonna
create these numbers. So let's start from this body. In order to do that, we also need a temporary variable called result that is going to hold the values that aren't
gonna be repeated. And then we need a loop. And I propose to start this
loop from two because we need to omit like this
to first situations. Then it is loop is going to
execute until the I is gonna be equal or lower
than n i plus plus. And now what we need to do, we need to assign to
result the previous left, right, plus previous Right. That's pretty okay
for the first number, but what to do later? How do we increase
all these things? I told you that we need to work. We need to change the
previous left into one, which is what? Previous, Right? Right. So we can just
write Previous right now. And now I need to change the
previous right into what? Into their sum that we have got. Now, the result into
real result, result. Why don't worry
Soon it will be a bit easier to understand when
we do something like that. Let's create a comment. I would just start
equal to two and n, which is where sales
equal to seven. And result now is equal to what? Previous left, which would
start is 00 plus one. Nothing we could. Previous left is
equal to zero here. Previous is equal to one, so zero plus one is one, right? So previous lab is now gonna
be in previous bright, which is not one. So we can now will
be reviews, right? Is equal to result
which is now one. Then we would increase
i in our loop. The condition is true. And now what happens? The result is equal to previous left
plots previous Right. It's not the value that
is here, but here. Now, it's going to
be equal to two. And we change previous
life into previous ride, which is now one. But previous ride is going
to increase to result. And result gonna be
now equal to two. We're going to increase four is four less than or
equals seven years. So the condition is true. And the previous class, previous ride is
equal to 2k plus one. So it's true. Previous left is equal to
produce right, which is two. And this is cannot be free. Now, here is gonna be
five condition is true. So we cannot add two
plus three is five. And then what? Free? 56.3 plus five, which is eight. And previous left, is
now equal to five, and result is equal to eight. And now here we have seven. And that's why we need to have here lower than or
equal to n. Otherwise, the condition is not
true and we cannot go on a candidate last step, which is important for
us because Fibonacci of seven is not
what eight is 13. Okay, so that's why we have
got here lower or equal to n. And now we have got
here as a result. And brave eight plus five is 13. And so here is gonna be invoked instructions like previous left is equal to previous ride, which is eight and here is 30. And the condition now
is not true, right? So we just need to
return our result. We can write it like this. Now when we invoke it, as you can see, it starting. So now we can type
a number like e.g. 14 and we get this
number here for 177. That's how we can count any number from the
Fibonacci sequence.
87. Fibonacci recursively: Hello my friend. It's time to make
the same program we did in the last lecture, but this time use seeing
the recursion version. So we want to invoke a function
inside another function. How do we solve a
problem like this? Well, we have the same
conditions like before, right? Because if n is equal to zero, then we have to return zero. If n is equal to one, we have two written one. This part is totally not needed. We need to think about what should we return
here in this place? In order to count Fibonacci? Look, when you have
Fibonacci of eight. This is really what
the previous number, which is 13, plus the previous number
from 13, wages, eight. And bad. Well, Tilton is really
Fibonacci of seven. So we could write it like this. And Fibonacci of six,
Israeli eight, right? So we can write it like this. So Fibonacci of n is
really the number before it and the number
before the seven. Write the number, the
result of this function. Well, if we do something like depth Fibonacci of
n is equal to what? N minus one, right? Because, well,
eight minus one is seven plus Fibonacci
of n minus two, because minus two is six. So we add, this thing is like the solution to find
any Fibonacci number. So the previous number plus the previous number from
this number, right? So we can really just the
same thing here, right? Fibonacci of n minus one plus
Fibonacci of n minus two. And to be honest, this is all that we need to do. If we type aid, you will notice that the
result is 21 we just drew. And how does it work? Well, we just the recursion invoke this function
and this function to find out what is the result. The problem is
that there will be no result until the
1.0 is returned. Like I showed you in
the last lecture. There were two
lectures before when we solve the problem
of factorial, right? So this is just going to invoke itself until
it get as a result, 1.0, it is this. And this then is going
to just add it up until it gets to the point of Fibonacci of the solution like this is called because
it looks pretty neat, right? Well, if you compare
this program, well, this looks pretty complex
comparing to this, right? There, you need to understand how recursion works
in this situation. So this is a bit complicated, but if you understand it, then this is looks pretty
neat, right? It's cool. This is hard to look at. What happen if we type here e.g. 60. And here we type 60. As you can see, we have
got instantly result. What will happen here? As you can see, we
are waiting for the result and it's
not coming up. Even though I have pretty
fast computer built with me. Okay, if we type here e.g. 14, we'll get the result. But we had to wait
a few seconds. 45, let's see. You can see here are
waiting and it's not here. Finally, we get the result, but as you have
noticed, it takes time. So this is the note obtain file to use for
counting things like this. Here you had the result
of sixteenth-century. Here you had to wait
for the 45 number. So if there is
Accounting involved and you need to go deeply into this invoking function
inside another function, then do not use recursion. So why did we use it here? Because to be honest, all the internet
on the programs in new diversities use this
program as an example. And to be honest, it's pretty cool example
to just show how it works. But it's not optimal
for things like that. So you might be asking yourself, where should I even bother using the recursion if it's so slow? Slow, it's slow because you
invoke inside function, inside another function
and another function is invoking another function inside another function, so on. That's why it's so slow. Because in order to get
the result at the start, you need to invoke
every function to up to the written one or
zero in this case. So it takes time. Bat, notice that when
we are looking at e.g. folders here, right
folder sector. Notice that we have got here how many levels of
that structure? 1234. This is not much right? When we type in five, we're gonna get the
result pretty far. And this is a great way to use the recursion because you can use it to search
inside folders. You can make a
function that will cert inside folders, right? And look for items like folders or files until there is
nothing to look for. And you can do it
using these neat, this cool, awesome syntax. This is not going to take
longer because there are only 55 steps or maybe 910. This is pretty good idea to
use searching like this. How would you solve it? Well, you will create the function for
searching items for so search for phi,
search for files. And of course this would be
called search for files. And here you will need to
return something like e.g. nothing or the item that is found until everything is found. This of course, pretty spit Speedway speeding way of
explaining how it works, right? But this is the places where
you could use recursion. This place is just to show
you how it works, right? Because this solution may
be doesn't look good. It's gambling, but
it works faster. And that's how we should
procreate our programs. Thank you very much.