Welcome everybody to this tutorial.
Today we're gonna go ahead and do a quite an important lecture on functions.
So functions is something that we are going to need for the creation of our keylogger
and you will soon see what they are.
Basically, you create a function to group code
and let's say we create another function outside of our main function, in which everything gets code
and everything works through from the main function
but we can also create functions outside of main, and then code them within the main function.
Why will we need this?
Well as I said, we need to group certain parts of the code
and create different functionalities for our program
that we are going to incorporate later on in process of the creation of the keylogger.
Now here's a simple example --
Suppose you need a function to add two numbers
Do you want to really write a plus be every time I mean ok he's a really simple
example but suppose you need the you needed addition subtraction division and
multiplication so those could be four functions and they could get called
whenever you would need to divide or numbers or something like that
functions can do extremely complex things they can do pretty much any thing
you can imagine and you can separate your code with them and reuse it
basically so if you have a function that is intended for one purpose you might be
in need of that purpose at a certain any later point of time during the creation
of programs you can just reused that particular function let me shoot us in a
practical example and it will be a lot a lot clearer so up here above the main we
will declare our functions and down here we will find them so to see when we will
write the proper code for them
functions have a return type so for me it is an integer
a utopian turn 0 the statement read at this instruction return 0 it terminates
the program but 00 is a integer and you see here in front of the function will
you always have to specify the return type so what are the main reasons by the
way that I thought perhaps using strictly technical terms that he
full-time programmer or use as because I barely learned in terms of C++ in terms
of other programming languages the only two things that I needed for my purpose
which is pretty much a part and that is what I'm trying to impress upon you as
well
fewer ads not a way to make games or something like that is purely a way to
create pretty much malicious code which we are not going to abused but we are
going to use for benevolent purpose in any case it will be an illegal purpose
so yeah just throw that in somewhere
anyway let's go ahead and start breaking our first function this function will
return integer as well or even better let's go ahead and make this function
returns a double double and you can't AP in sales call this function and
dysfunction to double values double A and then chroma double B functions do
not necessarily need argument need to receive these values so I will show you
in a moment how you get past these values to function so it can also be
like this this part can be empty no big deal
it all depends what it is meant to do so we have declared a function here and we
have put least a semicolon here but down below we will open up curly brackets and
we will start writing or function or we need to do is type in their return as
we've taped him before in the main and we can just a peer a plus being that's
it that's all we need to do we we can you can of course rate in more complex
code but for the title just use this as a demonstration and now just a pin
see out here and i cant AP in five and five is over here so some and then open
parentheses and here would type in mypin 35 colon
and let's go ahead pile that
the sum of three and five is this is basically the simplest example I could
give of pretty much the simplest function I could think up so it has a
return type of double it will return a doubled and we have named it sum you
could you can pretty much do you want as long as you use lowercase uppercase
letters underlines and then you have a double do double values inside 2002
double types inside this or not they don't have we have not a site that
values when we passed a min like this so just instead of writing this in here we
take in two values into a is substituted with 3d is given a value of three and
the is given a value of 5 which in turn is placed here which in turn is here
here there are added and did that value is returned so you can write these
functions for division and subtraction and pretty much all the functionalities
of week out later this is how to calc leaders are made you have a series of
these functions for every one of those options here actually with me just
calculator here
there we go so you have some basic functions here but if we switch to
scientific you have a lot more so you have these mathematical function here
cosine sine tension accept all of those functions have a mathematical
representation which in turn is written like this this would be for example of
function to add two numbers you could also write more complex mathematical
functions if that's something that you would be interested in what we gonna do
that now primarily because we needed and something is eating up my CPU well
apparently not just a slow virtual machine anyway
get so that would be one of them let's go ahead and deal with something else so
you can also have a void function which can do do something for you but it
doesn't necessarily need to return a number or anything about it doesn't need
to return a value so let's call this one
know what squalid welcome welcome and we're not gonna get any arguments but we
definitely can if we would like to do might do that a bit later on as in
voided doesn't return anything empty function of course there are things that
get the idea just saying that it cannot return a number in mind and we can just
a pins see out
well to somewhere where I have no idea
ok so let's put a semicolon the and and let's go ahead call this function down
below us see actual
but actually one would think here soon as something this is so much to show you
and i got a compressive welcome does not work
why does it not work or what is the problem let's go ahead and take a look
so
configuration parameters church and void
ok ok ok so we are this is able to actually deal with that but if I was
start explaining it that would be hilarious take forever but this is
actually pretty stupid this would be the equivalent of me typing in just take a
look at what I did I'm gonna write an example of why did they basically roads
see out and then something and then again see out and then again something
statement something just some random text so this is pretty stupid of my part
on my part
let's go ahead and just delete see out because we literally have no need for it
we can just call the function on its own and it will print out whatever we can to
protect and there you go
welcome to somewhere where no idea let's go ahead and tell here for center
so it has three and 58 welcome to somewhere I have no idea where if you
wanted to do vote like this you would need to get of course would need to be a
stream so a function that returns a string string is also another type of a
variable which can contain basically as I said spaces contain lots of letters
can pretty much tape in what ever you want
distinguished sure let's call it of course X and we're going to give it a
dream X gonna give it these ring X before we actually put it we will ask
the user kindly see out and what ever you would like
yeah actually do in a different sense well done and then we taped in C and
again we would need a some sort of a string in our main function because when
you define a variable inside a function somewhere that variable is only valid
for it that particular function there so let's go ahead and take the in string x
I can call this one again by the same name but it doesn't have any relation to
these three X in the function welcome here just leave it as it is and I will
take the end
see in X and will actually need a different on like this
get line
so this should work
decline is one of those functions that's embedded into C++ and it will use in
order to insert a whole line not just a single character and that's pretty much
all you need to know about Sealine this is its syntax you type in get low I need
a P&C in here and the newspaper stream here these text manipulation things will
come in handy later on we deal with a keylogger and down below
we're gonna go ahead and see see well come and we shall pass
expedite function that's actually so it's just go ahead
oh this look so the sum of three and five is eight enter whatever you would
like high here or take a wild guess their ego it says hi I am here or am I
take a wild guess there are several new things here basically the deadline which
we just need to see the syntax of it that's pretty much it you don't need to
completely understand it there is a whole background to this function and
you have these sort of functions which are basically just return types and you
type in the name whatever you like pretty much and specify the return type
in front of this fun this return type strain it will return a string string x
and that that X will be given to it by the user input so this is like an echo
something and it just gets printed back on the screen
fairly simple no lot of complications and just show you that
this would work without me actually importing anything it doesn't really
matter he doesn't need to have a X I can do this this this just say return and
then how is it going are you showing a totally see myself spending a lot of
things here to the horse is you use the slide my subliminal message that is
supposed to be like hidden in his number should do any harm
so go ahead and start over the program oh yes of course sorry to see out we
need something printed out because we've got from function and there we go
hey how's it going are you enjoyed the chorus please do not have used the
knowledge and at this particular function here says just turn that is all
the difference do it now you also have these things
charge hrs see this would be a single characters that single quotes there it
can be whatever character you would like it to be so what's a character something
like that
see out
and if I just go ahead and go just ate no big deal so we have charged and we
have a string which we can play around with complex things because we will need
strength that there'll be a lot of pics with a keylogger and there's no way of
doing it without strings or jars anyway
Jul farewell until next oriole