Tag Archives: #mastery11

MASTERY 11

Creating and calling functions in C++

In order to creat a function we need to give it a name first and we need to do that before main, like this:

You need to be clear about whay type of function you are creating, in this case is a boolean, and then followed by the instructions that the function will perform in case you call it.

Now, to call a function you need to type in the name of it, followed by the data that the function will use to work, in this case is “input”, but it can be any data you want, as long as it’s the correct type of data that the function is ready to process.

As you can see here I typed in bool and the name of the function is palindrome, that’s how you call it, I hope this comes useful.

 

Calling fuctions

Despues de pedir los valos de “n” y “d”, llamas a tu funcion asi:

print(suma(n,d))

para que imprima y haga las operaciones dentro de lo que esta en la funcion ya que tienes los valores.

 

This video could help you if you don’t understand the fuctions.

https://www.youtube.com/watch?v=OaYDfOCsKtE

Calling Python functions

I made a simple Python program where i call a function i just created in that same Python program.

To call a function, first you have to create one(You can see how to here) then you give the values or ask the user to input value or values to the function to work, the next step is to create a new variable and asign it the function, now you are up to call the function using a print you can print the valiabre you assigned to the function, it will print the result of the function with the numbers you or the user gived.

If you don’t know how to create a Python function, you may want to go and check the post I made about it! Here’s the link: http://jorgepadilla95.withknown.com/2015/creating-python-functions

Mastery11 and Mastery12

12.Creating Python functions.

In order to call a function we have to create it first, in python there are basic functions like sum or division. However we can actually create our own.

first we have to write “def”, in order to define our function. Now we have to write the name of our function, in this case I’m calling it sum_numbers, because we’re going to sum these numbers. Now we write in parenthesis the variables that we want to use. Then we’ll write the action that our function will do, this time is adding x plus y. Finally, we have to write “return answer” so the function give us the answer of the addition that we did there.

11.Calling Python functions

Now to call this function, we have to give them the value of variables, in this case num1 and num 2. Now we have to write the function, sum_numbers, but instead of having x and y, the actual value; num1 and num2. So now the function will make the addition of num1 and num2, the answer to this addition will be the value of the_sum. Now we only have to print “the_sum” in order to actually see the solution of  num1 + num2.

mastery 11 y 12

H0yos Adventures 2015-04-07 22:22:56

hi there i made my first video about calling and creating functions. its a really easy code but it explains how to create a function and calling it in the  main function,  

 

here is the link for the video tutorial: 

https://www.youtube.com/watch?v=SEX0X8RxJ9Y

here is the link for the code in git hub 

https://github.com/Hoyos1148/Mastery-11-12/blob/master/creating%20%26%20calling%20functions

#Mastery11

Mastery 11

I made a video for mastery 11!:


https://www.youtube.com/watch?v=wJ7mfUbzAWQ&list=PLrrr6RbIMUyO7_yla2UJEicn-OlHy3W7x&index=6

Mastery 11

Calling functions in C++

// function example

 <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z;
}

This program is divided in two functions: addition and main. Remember that no matter the order in which they are defined, a C++ program always starts by calling main. In fact, main is the only function called automatically, and the code in any other function is only executed if its function is called from main (directly or indirectly).

In the example above, main begins by declaring the variable z of type int, and right after that, it performs the first function call: it calls addition. The call to a function follows a structure very similar to its declaration. In the example above, the call to addition can be compared to its definition just a few lines earlier:

Mastery 11 
The parameters in the function declaration have a clear correspondence to the arguments passed in the function call. The call passes two values, 5 and 3, to the function; these correspond to the parameters a and b, declared for functionaddition.

At the point at which the function is called from within main, the control is passed to function addition: here, execution of main is stopped, and will only resume once the addition function ends. At the moment of the function call, the value of both arguments (5 and 3) are copied to the local variables int a and int b within the function.

Then, inside addition, another local variable is declared (int r), and by means of the expression r=a+b, the result of aplus b is assigned to r; which, for this case, where a is 5 and b is 3, means that 8 is assigned to r.