QUIZ #3

Este es el quiz #3 del curso de programación, consiste en realizar 2 programas.

1111

Programa 1 – Distancia entre puntos

La función de este programa es que te permite calcular la distancia entre 2 puntos dentro de un plano cartesiano, el hecho de que sea en un plano cartesiano, significa que un punto tiene 2 componentes, (x , y). Las componentes del primer punto son :(x1 , y1); y las componentes del segundo punto son: (x2 , y2).

Se obtienen las diferencias tanto de las componentes y (y2-y1) y de las components x (x2-x1) y se elevan al cuadrado; posteriormente se suman los 2 resultados y se obtiene la raíz cuadrada de esa suma.

Quiz 3 Ejercicio 1

Link GitHub: Quiz #3 Prog 1

Programa 2 – Sucesión de Fibonacci

En el código de este programa se encuentra una fórmula en la cual obedece a la sucesión de Fibonacci, gracias a esta página (Fibonacci) pude saber bien a que se refiere esta serie de números. Este programa se produce totalmente gracias al loop for.

Quiz 3 Ejercicio 2

Link GitHub: Quiz #3 Prog 2

¡Fibonacci! #Quiz3

Hola de nuevo, y creo que después de mucho tiempo voy a postear de nuevo y esto se debe a que… ¡Me di cuenta que los Quizes también se deben de postear! Imaginarán mi cara cuando me di cuenta de esto, pero en fin, los códigos siempre estuvieron en mi Github así que esto es puro trámite, a continuación explicaré de lo que va cada parte de mi código.

portada-49

Sí, esta sucesión está en todos lados.

1: Esta parte del código tiene debe de tener dentro de él una función, dicha función deberá de calcular la distancia que existe entre 2 puntos en un plano X, Y y constó de lo siguiente:

# Este código te ayudará a encontrar la distancia entre 2 puntos y también te ayudará a encontrar la sucesión de números Fibonacci.

import math # Este módulo permite usar math.sqrt.

# ------------------- Primera parte del código -------------------

def distancia(x1, x2, y1, y2):
 d = math.sqrt(((x2 - x1)**2)+((y2 - y1)**2))
 print("La distancia es 5 unidades", d)

distancia(x1=int(input("Inserta el valor para x1: ")), y1=int(input("Inserta el valor para y1: ")),
x2=int(input("Inserta el valor para x2: ")), y2=int(input("Inserta el valor para y2: ")))

2: Esta parte de mi código se encarga de calcular una famosa sucesión en todo el universo, y además, creo que también es uno de los códigos más populares debido a que todos los maestros siempre se encargan de dejarlos en cualquier curso de programación. De cualquier modo, este es mi código:

 

# --------------------- Segunda parte del código -----------------

fi = 1.618033988749895


def fibonacci(n):
fibnum = (fi ** n - (1 - fi) ** n) / math.sqrt(5)
print("El resultado es", round(fibnum))

fibonacci(n=int(input("Introduce el número hasta el cuál quieres que llegue la serie Fibonacci: ")))

Este ha sido de lejos, uno de los Quizes más fáciles. A

Continue reading “¡Fibonacci! #Quiz3”

#Quiz 3

En matemáticas, la sucesión de Fibonacci es la siguiente sucesión infinita de números naturales:

1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597

La espiral de Fibonacci: una aproximación de la espiral áurea generada dibujando arcos circulares conectando las esquinas opuestas de los cuadrados ajustados a los valores de la sucesión;1 adosando sucesivamente cuadrados de lado 1, 1, 2, 3, 5, 8, 13, 21 y 34.
La sucesión comienza con los números 0 y 1,2 y a partir de estos, «cada término es la suma de los dos anteriores», es la relación de recurrencia que la define.

Screen Shot 2016-02-13 at 2.17.00 PMScreen Shot 2016-02-13 at 2.17.07 PMEn el siguiente programa lo que tuve que realizar, fue pedir los puntos de un plano en x y y; esto para obtener la distancia.

Utilizando la siguiente fórmula:

distan16

 

 

Aquí se encuentran los códigos disponibles: https://www.dropbox.com/s/m07tamvbgsp62wd/fibo.cpp?dl=0

https://www.dropbox.com/s/muuh3sludl8u36q/distance.cpp?dl=0

QUIZ 3

This quiz took me a while, not only because I finished it on last class, but I haven’t had time in the partials week.
Anyway, the first quiz was kind of easy because you only needed to follow the formula of the distance of two points in the plane.

 

So I look up in google for the formula and I found this one on http://www.elosiodelosantos.com/sergiman/div/formula_dos_puntos.htm
and the formula wasdistancia_0 and I just create the function of the program based on the formula.
Also, I needed to include the cmath library, in order to be able to use  “sqrt” that is the square root. One of my classmates told me that.Captura de pantalla 2016-02-20 a las 21.10.17

The link of my github account on this code is at the end.

 

For the second exercise, we needed to create a program which can tell you the value of a location in the fibonacci’s serie.
Honestly at the beginning I was so frustrated because I have no idea how to do it. I look up to the formula but i was this one: fibonacci-sequence-formula, and I didn’t understand it. So my friend Miguel gave me a hand. Told to put those 4 integers to use them on my code. Finally with his help we could create this code and I worked. You should see my face at the moment.

Captura de pantalla 2016-02-20 a las 21.10.30

The link to my GitHub account is right here.
https://github.com/antonioangelm24/TC101/blob/master/Quiz%203%20_%202%20-%20Fibonacci

https://github.com/antonioangelm24/TC101/blob/master/Quiz%203_1

 

Quiz 3

The first program for the quiz made me think, it was easy but I needed to work with functions. That was the hardest part, but I figured out to make everything with just 1 function. I used the math.h library.

DistanceDistancerunning

The second program was the Fibonacci number, this is the hardest program Ken has left us It is smaller than others but it needed a lot of logic to make it possible.

FibonacciFibonaccirunning

funciones y mas funciones (quiz 3)

este Quiz lo acabo de terminar porque me cuesta un poco hacer o mas bien entender, el funcionamiento de la recursión en una función. nuestra mente es tan cerrada que un proceso tan fácil no lo puede aceptar.

—–CODIGO 1—–link

muy sencillamente solo trata de calcular la distancia entre los puntos en un plano cartesiano, es decir, al usuario se le piden, los dos puntos compuesto por dos puntos cada uno -4 valores- (x1,y1)(x2,y2). y para calcularla distancia entre estos 4 valores (dos puntos). se obtiene el diferencia de y y el de x, ahora esos dos se elevan al cuadrado y se suman, para después sacarle la raíz cuadrada a esa operación.

Cabe destacar que para ese código, fue necesario utilizar la librería de matemáticas para obtener raíces y potencias. la librería es #include<cmath>.

Captura de pantalla 2016-02-18 23.09.19

ahora solamente llamamos en nuestra funcion main a la funcion distancia con los valores sugeridos por el usuario y se desplegara la respuesta deseada.

Captura de pantalla 2016-02-18 23.09.52

 

 

—–CODIGO 2 —Fibonacci— link

para este código, lo complejo es pensar en como plasmar la serie. sin embargo con el método de recursión, se trata sobre en vez de return muestre un valor en sí, va a regresar a dos anteriores llegando a términos de 1 y 0, para finalmente hacer la suma de la serie fibonacci. solo que ademas de hacer esa recursion puse unos condicionales para que que cuando el usuario pida 0, la respuesta sea cero, cuando el usuario pida 1, l respuesta sea 1, y cuando pido cualquier otro numero (siempre y cuando sea negativo) entonces se pueda calcular con la función.

Despues al igual que en otros códigos, solamente llamo a mi función externa en la Main ().

Captura de pantalla 2016-02-18 23.16.58

 

Quiz #3

#TC1017 #Quiz3

Well this quiz was really not so hard for me because I had already solved these exact problems a while ago, so they were quite simple to do.

For the first problem, calculating the distance between two coordinates all I had to do was search for the formula and implement it using a single function and asking the user for the variables, really not that different from WSQ08. This is the first time I use the math header to solve a problem since I needed to use both square roots and elevate to the power of two.

dist.proof.PNG

Source Code:

#include <iostream>
#include <math.h>
using namespace std;

int distance (int x1,int y1,int x2,int y2)
{
double result;

result = sqrt (pow((x2-x1),2) + pow((y2-y1),2));

cout << “The distance between the two coordinates is: ” << result << endl;
}

int main(){
int a, b, c, d;
cout << “Please enter the coordinates for x1:” << endl;
cin >> a;
cout << “Please enter the coordinates for y1:” << endl;
cin >> b;
cout <<“First coordinates: ” <<“(” << a << “,” << b << “)” << endl;
cout << endl;
cout << “Please enter the coordinates for x2:” << endl;
cin >> c;
cout << “Please enter the coordinates for y2:” << endl;
cin >> d;
cout <<“Second coordinates: ” <<“(” << c << “,” << d << “)” << endl;

distance (a, b, c, d);
}

 

For the second problem, calculating the last number of a user given Fibonacci series, the only real problem was getting the logic right, coding it was quite easy. I used a while loop to do so, but added a for loop as a comment which also runs the programm correctly.

Basically what this programm does is, since the Fibonacci series is

fibo.proof

Continue reading “Quiz #3”

Quiz III

Brace yourselves, the partial is coming. Meanwhile, we have to answer a third quiz.

quiz3instructions.png

At the first point we had to find the distance between two points. If you represent this as an a triangle, it would be like Image 1 where A is (x1,y1) and B is (x2,y2), so we had to find the value of h.

2000px-trigonometry_triangle-svg
Image 1

At first I tried to find the distance between each axis. This means what is the difference of x1 and x2 and what is the difference between y1 and y2. This got complicated to me since distance is absolute, yet the answer was given as negative in some occasions. This got fixed when I used a conditional to multiply it by -1 to make it positive.

 

Then I got to the point to find h. I used the basic pythagoras theorem (C^2=A^2+B^2)  and then use the squareroot to get the answer. Ken teached me that there was a simplier way: use the distance command. Yet, It have me errors when running so I kept it at my mode since it works. Of course this does not means I am not going to fix what Ken helped me with. The code and how it runs looks like this:

pythagoras

For the second part of the quiz I had  a big time learning what to do. Firstly because I did not even know what the Fibonacci Numbers are. After I knew what they are, I searched all over the internet to see how to do it. Technobeans showed me 5 different methods of how to do it; however, Naren’s method in the comments helped me better.

fabonacci

Remember to keep checking my GitHub to see the code clearer.

Time for you to meet Bloc Party’s “Helicopter”. I got into this band because of

helicopter

Continue reading “Quiz III”