Quiz 03

Here is my blog post for the Quiz 3

  1. Write a function called distance (x1,y1,x2,y2) which receives four numbers which represent two points in the cartesian plane. The function should return the distance between the two points (x1,y1) and (x2,y2). Remember that the square of the hypotenuse of a right angle triangle is equal to the sum of the squares of the two other sides. Here is the link to my GitHub.

    Captura de pantalla 2016-05-04 a las 10.05.23 p.m..png

 

  1. Write a function called fibonacci which receives a single parameter“n”(anon-negative integer) and returns the nth number in the fibonacci series which is:
    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89… Here is the link to my GitHub

Captura de pantalla 2016-05-04 a las 10.06.04 p.m..png

Quiz #3

So, all the WSQs are done, now, moving onto the quizzes. I’ve done only #2 son here goes #3.

I found info on some blogs from classmates and on youtube. If you don’t know what the fibonacci numbers are, look here.

Here is the code for the first part:

quiz3 code

the exe:

quiz3 exe

 

Here is the fibonacci code:

fibonacci code

And the exe:

fibonacci exe

All set, moving on!

Quiz #3 :]

fib0

En este quiz tuve que realizar 2 códigos, ambos en base a funciones, el primero pedía al usuario dos puntos localizados en un plano cartesiano y en base a esta información procedía a obtener la distancia entre ambos puntos con la siguiente formula de distancia: 

images

El segundo fue un poco mas complicado ya que pedía introducir un numero y en base a este numero, imprime el número correspondido mediante la serie de Fibonacci, la cual es la siguiente:

images (1)

De esta manera si el usuario tecleaba el dato 0, aparecía de igual manera este mismo numero, en cambio si tecleaba el número 8, imprimía el dígito 21 y así conforme la sucesión de Fibonacci.

El quiz se nos entrego de la siguiente manera:

2016-02-12 (2).png

El primer código ya ejecutado:

Quiz_3_prog1.png

El segundo:

Quiz_3_prog2

Los códigos que yo realice en este quiz están en la siguiente liga de dropbox:

https://www.dropbox.com/sh/yy1dvqcmzb8au5z/AAC_oMoLQJEWgriEX6t92HBGa?dl=0

Quiz 03

Today we had to do Quiz number 3. Problem number one was about the distance between two points on a cartesian plane. Number two was way harder. We had to make a program that would calculate the Fibonacci series of numbers till the number that the user inputs.

Problem number one was easy for me. I just used the equation of the distance between two points, which is the Pitagorean Theorem applied.

distance-between-two-points-formula

My translation to C++ language was:  d = sqrt(pow((c-a),2)+ pow((d-b),2)), a, b, c and d being parameters of my function, input by the user.

The second problem was the one that troubled me. The most important thing while solving any kind of problem, be it C++ or physics is to really understand what you are being asked. So, that was my frst step, to understand what a Fibonnacci series is. It is the sum of a number plus the next one, starting on 0. So the series would look like this:

0,1,1,2,3,5,8,13…

0+1 = 1, 1+1 = 2, 2+1 = 3, 3+2 = 5, 5+3 = 8, 8+5 = 13, 13+8 = 21;

To translate this to a command in C++ was hard for me. But I did it the next way:

#include <iostream>

using namespace std;

int n, fI = 0, fII = 1, f;

int fibonacci(int n){
for (int t = 1; t < n ; t++){
f = fI + fII ;
fI = fII;
fII = f;
}
return f;
}
int main(){
cout << “Provide the nth number of the Fibonacci list that you want to print: “<< endl;
cin >> n;
cout << “Your number is: ” << fibonacci(n);
}

I created a function called fibonacci, with 1 parameter (the number of the series that the user wanted to output). Inside the

Quiz03.jpg

Continue reading “Quiz 03”