El video explicando es el siguiente
Fundamentals and Solutions. Together!
En esta actividad se retoma lo anterior visto en el WSQ03 – Fun With Numbers, se efectuan:
Lo que hace diferente esta actividad de la WSQ03, es que ahora en la WSQ08, se emplea funciones, algo nuevo en este curso de programación, para declarar una función, se hace lo siguiente:
Se selecciona el tipo, en este caso se utiliza el int, seguido de eso, se nombra a la función, se abren paréntesis y dentro, se declaran las variables con su tipo (int);
Debajo, se ecribe return, y se escribe lo que tiene que hacer la función, ejemplo:
Ahora sigue escribir esto dentro del int main() {
Para poder realizar por primera vez funciones en programación, ocupé ayuda de una compañera que cursó esta materia en el semestre pasado, ella misma, me asesora en dudas que tengo cuando batallo programando.
Imágen del código completo y el compilador de este:
Link GitHub: WSQ08 – On To Functions
The functions are an important part of programming, apparently. Ken says we have to get used to using them and I probably will, some day, I hope. The bright side is that is really easy to define and call functions.
For this program we had to go back to the fun with number assignment, but now we are tasked to do the same operations with functions.
-Creating a function requires to have some established variables, then you have to select the parameters, after that you need to write the statement of the function, and finally you have to write the return statement or the result.
def res (a,b):
n = a – b
print(“The difference of those numbers is: “)
return n
def product (a,b):
n= a*b
print(“The product of those numbers is: “)
return n
-After you have defined the function you can call the function by writing the name of the function next to the parameters inside a parenthesis.
print (res (a,b))
print (product (a,b))
The program is this:
Hellooooooo! I’m about to do the most enjoyable code of the semestrer. It’s enjoyable because we’ll copy and paste most part of the code from WSQ03.
Do you remember WSQ03? If not, here’s the post.
Let’s start.
First of all we need do define all the functions.
We need a function for each result. Don’t forget to indicate the type of object for each variable:
After that, we’ll copy and paste the WSQ03 code. You can buid it from the ground, it’s not complicated, but of course is easier to copy and paste.
Theeeeen we’ll edit the part that prints the result replacing the mathematical process by the corresponding function.
Check line 16, 18 and 20.
The final result would be something like this:
That’s all for today. Here’s my code,as always. Have a nice weekend! 😀
en esta entrada, como su nombre lo dice, se trata de reciclar trabajos que ya hemos hecho pero con un nuevo aprendizaje.
Este programa trata de sobre multiplicar, restar, dividir y obtener el residuo de una división mediante, funciones externas al Main. esto con el fin de que sea mucho mas sencillo al momento de hacer tu función principal (que es la que usamos siempre). En este programa aprendí que ademas de la función en donde hacemos todo lo que queremos mostrar, también podemos hacer funciones por fuera y al momento de necesitarlas, simplemente las llamamos incluyendo los valores donde quieran evaluarse y listo, es así como se utiliza una función.
Ahora, para declarar una función lo que se necesita hacer es declarar el tipo de función que deseas (int, float, etc), después asignarle un nombre a la función,, acto seguido de esto y dentro de un parentesis, declarar las variables que vas a utilizar dentro de esa función. Después, se necesita realizar las operaciones o calculos que deseas realizar mediante la funcion y por ultimo, insertar el Return hacia el valor de la variables que quieres que finalmente muestre es decir :
int multiplicacion (int num1, int num2){
int mult=num1*num2;
return mult;
}
debo admitir que esto no lo hubiera aprendido sola si no fuera por el blog de loscerritosrifa.wordpress.com , es muy bueno explicando con videos y hacer ver los analisis de programacion en c++ de una manera muy sencilla.
les dejo el link de mi código.
Hello there, this task was really easy because it was already done in #WSQ03 “Fun With Numbers” the only difference is thata now we have to do it with functions.
here is th link to the code ► https://github.com/mfcanov/FunWithNumbers.git
I’m advancing, steb-by-step (as my old english books were named). So, now, WSQ#08, it’s basically WSQ#03 revisited. I found info here , Lynda.com is really a lifesaver, and working while in class and listening to AMON AMARTH!, I love viking metal! Death, wars, interesting gods (yeah, what we have around here is boring as fuck). Oh and also, I went to the movies, twice, to watch Deadpool, and it is so fucking awesome and funny, I thnk it’s squeezing it’s way to the top of my favoite movies. Enough chit chat, let’s move on, so, the program was quite easy, it’s just #03 with a name of each operation. Here it is:
So, as you can see, you name each operation you’ll use, addition, substraction, product, and division, not to forget the remainder of hte division if you need it for some reason.
Here’s the exe:
Ok now, I think numer 9 is gonna be a bit harder and I also didn’t finish quiz #3, so that’s what’s next. Later!
“I will not say: Do not weep; for not all tears are an evil” – Gandalf (yeah, I’m a LOTR fan, so what?)