QUIZ #2

El quiz 2 de este semestre consta de 2 diferentes funciones. Tuve mas complicaciones al elaborarlo comparado con el primer quiz apesar de que en esta ocasión, elaboramos un número menor de programas.

¿Porqué fue mas complicado para mi elaborar este quiz? Bueno, en esta ocasión los programas encargados, a mi parecer, fueron muy diferentes, y si tuve que ocupar ayuda de compañeros que efectivamente saben como hacer estos programas para que me orienten y me pudieran enseñar.

1111

Programa 1 – POWER

Este programa eleva un número con potencias, ¿Qué significa esto? El usuario selecciona el número base, y después elige un número que sirva de potencia, por ejemplo:

Número base: 2

Potencia: 5

Lo que va a hacer la potencia es elevar 5 veces el número base, en este ejemplo el 2 que es nuestro número base.

Quiz 2 Ejercicio 1

Link GitHub: Quiz #2 Prog1

Programa 2 – STARS

Este programa es más sencillo que el de potencia, al usuario se le pregunta cuantas estrellas desea que el programa ponga, y ese mismo número, es el que termina mostrando el compilador Cygwin.

Por primera vez en este curso se utilizó el tipo string, ya que las estrellas no son números, de igual manera se utilizó el int para que se pudiera elegir un número entero, que es el número de estrellas.

Quiz 2 Ejercicio 2

Link GitHub: Quiz #2 Prog 2

NOTA: El código de este programa es distinto al que se le mandó por correo al profesor Ken Bauer por el hecho de que no estaba del todo completo, cosa que me di cuenta tiempo despues repasando el blog del curso.

 

quiz 2

Este Quiz dure un enviarlo porque no sabia utilizar funciones en ese entonces, sin embargo y como ya habia mencionado anteriormente gracias a los videos tutoriales de loscerritosrifa.wordpress.com pude entender la mecánica de las funciones.

Afortunadamente en este quiz solamente fueron dos códigos, estos trataban sobre:

el primero trataba sobre crear una función externa que a la cual se le debía llamar superpower y lo que hacia esa función era elevar un numero hasta la potencia de otro numero, claro, estos dos números iban a estar delimitados por el usuario. para poder crear este código lo que hice fue abrir un ciclo for donde el la literal i se utilice como contador de las veces que el numero a, por si mismo hasta llegar el numero b.  link superpower

en el segundo código trata sobre poner el numero de asteriscos que el usuario que que se le muestren, de igual forma se utiliza una función con un ciclo for para que cada vez que se este incrementando el numero desde 1 hasta el limite, se vaya agregando una estrellita más. link estrellas

Captura de pantalla 2016-02-18 22.57.50Captura de pantalla 2016-02-18 22.57.45

Test the knowledge 😁

So this is quiz#2 in which we had to:

 ►Create a program with the following function.
 Write a function called superpower ♛ that has receives two parameters (ints) and returns an integer which is first parameter raised to the power of the second, which is to say it returns a^b.  There are many ways to do this, but the intent is for you to use a loop or recursion.

►Create a program with the following function.
Write a function called stars 🌟 that has one parameter of type integer and PRINTS that many stars on a single line, so if we call the function with stars(5), the function will print like this: *****

Here is the link to the quiz #2 ☛ https://github.com/mfcanov/Quiz-2.git

Quiz 2

I have trouble with the two problems of the quiz. For the superpower I didn’t want to download the library and put the formula. So I try hard to solve it and it end up well I think. For the stars, I had no clue I was doing, so I used Isaac code as reference to do what I needed to do, and somehow it helped me to understand the problem.
Here are the codes:quiz2
quiz2b

Quiz 2

In this quiz, to make the program run, you needed to create also a function.

Like in the first problem. Captura de pantalla 2016-02-16 a las 8.42.12You needed to create the function superpower and to declare the integers a and b in it.
The program should make the result of the first number powered to the second. But all in one function. Also inside the function you need to declare everything you will use, only in the int main, you will type int a, b. Because until then the program ask you for them.

And for the second program:

Captura de pantalla 2016-02-16 a las 8.42.21Kind of the same, but you need to print with * (stars), the number that you provide to the program. So the program print * in the same line, with this loop, until the int n, equals the int a, that it would be the number you’ve written.

Also you don’t need to use “int” with the function, you can use “void” because in this cae you don’t need to return anything.

 

As always, my link to my GitHub:
https://github.com/antonioangelm24/TC101
as Quiz2- a & Quiz2-b

QUIZ#2

quiz2

quuiz2
#1. Este es un programa para calcular una función con dos parámetros de entrada, donde el objetivo es obtener el resultado de la potencia de un numero, por la cual se utiliza un ciclo for, porque cuando el usuario ingrese hasta que potencia se elevara, es el numero de veces que el ciclo se repetirá, por lo que se sabe cuantas veces se irá ciclando y para eso es el ciclo for. Entonces, sabemos que hablando de multiplicaciones y potencia deben ser igualados a uno debido a que si fueran a 0 no tendría caso, cualquier numero seguiría dando cero, en cambio con uno, el primer numero daría el equivalente al numero multiplicado por uno, y éste al numero por el que se multiplique y así sucesivamente. En las instrucciones, dice que la función se debe llamar superpower, y sabemos que utilizamos dos variables, la base y la potencia, las nombramos “a” y “b” y comenzamos con el ciclo for con el contador incializando en 1, donde el contador debe continuar mientras sea menor o igual a la potencia que el usuario especifique e ira aumentando de uno en uno, observando la notación de esto en la línea 8. y en la línea posterior (9) se hace la operación donde pot=a*pot y la función nos regresa pot. Dentro del main, como ya dije se piden las variables que el usuario utilizará y al final se manda llamar la función con otras variables para no mezclar.
quuuiz2
Aquí esta compilado, lo que hizo al elebar el 5 a la 3 fue: 5x5x5=125.
quuuuiz2
#2. Este es un programa para imprimir el numero de asteriscos específicos. Para ejecutar este programa se debe usar el void, que sirve para que el programa sepa que no estas pidiendo que se guarde algo, si no que solo

quiznum2

Continue reading “QUIZ#2”

#Quiz2

I had this quiz quite some time ago, it was about time I wrote about this. 

Well, first of all, what the quiz asks us to do is create a file and write down a function called “superpower”. It should accept two parameters and return the value of first parameter elevated to the power of the second parameter, for example, superpower(a, b) should return the value of a^b power. This was my answer :

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 10.44.54 AM

Terminal :

Screen Shot 2016-02-15 at 10.45.09 AM

————————————————————————–

There. So the code works perfectly, maybe we could add some user-friendliness with some more strings. 

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 10.55.06 AM

Terminal :

Screen Shot 2016-02-15 at 10.54.13 AM

————————————————————————–

Nice going.

The next part of the quiz is to write a function called stars that accepts one parameter and prints as many stars in the same line. For example, stars(3) should print “***”, and stars(9) should print “*********” . 

This was my answer :

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 11.04.30 AM

Terminal :

Screen Shot 2016-02-15 at 11.05.27 AM

————————————————————————–

Done, right? The stars are printed in the same line because of the comma after the string. That should be enough. Not quite, the stars are printed, but the comma causes a space between each star. After thinking about this for a little, I figured we could append each star on a list and join them, but actually it’s easier to join them as it is, as a string. Talking about easier solutions, now that I think about it, multiplying the string would be way easier:

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 3.04.49 PM 

Terminal :

Screen Shot 2016-02-15 at 3.06.06 PM

Screen Shot 2016-02-15 at 3.06.22 PM

————————————————————————–

Yes, it works. Well, there must be more ways of doing this but I don’t think the solution can get any easier, so… I’m leaving this up to here. 

This is my post for the #quiz2 on my Programming Fundamentals course.