Quiz week 14: Autoevaluation

--Originally published at Let's CODE

I have made my Autoevaluation for the class and this is the result. Autoevaluation – TC1017 Mastery – Sheet1 After a depp reflection, I realize that I need to learn how to use Scilab, make some recursions, and investigate what was the meaning of the las row of the document. I feel satisfied with my … Continue reading Quiz week 14: Autoevaluation

Lots of Problems (Quiz week 9)

--Originally published at Programming Path

This quiz was veeeery long. There were 10 problems, but we only had to do 8 problems.

1. Escribe el función distancia cual recibe 4 números (x1, y1, x2, y2) cuales representan dos puntos en espacio (x1,y1) y (x2,y2). El método debe regresar la distancia entre los dos puntos. Recuerda que el valor cuadrada del hipotenusa del triangulo es igual que la suma de las cuadradas de los otro dos lados del triangulo (the hypotenuse squared is equal to the sum of the squares of the other two sides).

Quiz9

2. (5 puntos) Escribe un función que se llama triangulo cual recibe un parámetro size y imprime un triangulo derecho como el siguiente. El renglón mas grande debe llevar size numero de “T”. SOLO imprime los “T”s y los endlines. Nota que no hay characteres (espacios) a la derecha de los T’s. Debe usar un ciclo “for” para controlar el repetición.

PQ2

 

3. Escribe la función factorial cual recibe un entero “x” y regresa el valor de x! Recuerda que 0! = 1, 1! = 1, 2! = 2, 3!= 6, 4! = 24, etc. Para los de Python: NO PUEDES usar el factorial como parte del module “math”

PQ3

4. Escribe una función que se llama promedio_lista que recibe un parámetro (una lista (Python) o arreglo/Vector de C++) de valores float y regresa como float el promedio de los números en la lista.

PQ4

5. Escribe una función que se llama smallest_of_four cual recibe cuatro valores float como parametros y regresa el minimo (más pequeño) de los valores. Ojo: puede recibir unos valores iguales.

Click to view slideshow.

6. Escribe una función que se llama fibonacci cual recibe un número n (puedes dar por cuenta que valor mayor o igual que cero) y regresa y valor correspondiente del serie de fibonacci,

PQ6
PQ7.png
PQ10
?
Continue reading "Lots of Problems (Quiz week 9)"

Distance (Quiz week 9)

--Originally published at Programming Path

The assignment of the quiz was to ask for two coordinates and calculate the distance between them. It needed to have floats and a function as well.

This problem was very easy, because in school they made me calculate the distance a lot of times. I only add the math library (<cmath>) because I elevate to the power and resolve a square root.

Here is the code:

Quiz9

Thanks for reading.


Quiz week 11: Partial #2 Review

--Originally published at Let&#039;s CODE

The teacher gave us a document with 10 problems to solve. This with the objective of practicing the topics that we have seen during the semester.   Exercise 1: Write a function that calculates the distance between two points in a coordinate plane. I used the Pythagoras theorem. #include <iostream> #include <math.h> using namespace std; … Continue reading Quiz week 11: Partial #2 Review

Quiz #9

--Originally published at Programming

The instruction was:

Write a function that receives four parameters: x1, y1, x2, y2 which are all floating point values.

The function is called distance and returns (float) the distance between x1,y1 and x2,y2 on the cartesian coordinate plane.

Quiz #8

--Originally published at Programming

Fill out that survey here: http://url.kenbauer.me/midtermsurvey

The instruction was:

  • Write a function that calculates returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series. So fibonacci(0) returns 0, fibonacci(1) returns 1, fibonacci(2) returns 1 and so on. Note that we are using the modern definition where the sequence starts with zero. You should try to implement this with two solutions: one with a loop and one with recursion. Which do you think is “better”, which looks more “elegant”, which is more “efficient”?

 


Miracle!!

--Originally published at my programming blog

Miracle-Ahead.png

( Photo credit to: Natalie Nichols)

Today I finished the quiz in the class!! Normally I finish the quiz during the day because I need to search for tutorials on how to do a code related to the quiz, or because I am completely lost! But this time with Ken’s explanation that the coordinates made a triangle I understood perfectly, also thanks to my project team that explained me the idea to make the code.

So the quiz was to ask the user for two coordinates (x1, y1, x2, y2) and then make a function that returns the distance between those two coordinates.

So first:

(I included the library cmath, to use the sqrt and the power function)

  1. The coordinates make a triangle! the only thing you need to do is calculate the hypotenuse of the triangle with the Pythagorean theory.So remember the the formula is c^2= a^2 + b^2
  2.   So I made my function, I called it Distance (float) and my parameters were the floats x1, y1, x2, y2.
  3. Inside my function I declared two integers distancex and distancey, distancex was equal to   the difference between x2 and x1 (The value of “a” in the Pythagorean formula) and that I raised it to the power of 2, I did the same but now with the values of y (which will be equal to the value of “b” in the formula).
  4. Then I declared a float named total_distance which was equal to the square root of distancex + distancey.
  5. And my function returned the value of total_distance.
  6. In my int main I declared the variables floats (x1, y1, x2, y2) and asked the user for the coordinates and then I printed the answer by calling the function Distance.

Here’s my code:

#include <iostream>
#include <cmath>
using

Screen Shot 2017-03-09 at 10.27.17 AM
Screen Shot 2017-03-09 at 10.18.50 AM
Continue reading "Miracle!!"

Quiz Week 9: The distance between coordinates

--Originally published at Let&#039;s CODE

The task for today was only creating a function that could calculate the distance between two pair of coordinates on the cartesian coordinates plane that were given for the user. In the quiz was not necessary to create the entire program, but the function cause it was the only part required. To make this part … Continue reading Quiz Week 9: The distance between coordinates

Lists!

--Originally published at my programming blog

The assignment of last week was to ask the user for 10 values and then calculate the standard deviation with those values, then you needed to change your program so that the user could tell you how many values he wanted to enter.

It was easy to calculate the standard deviation when you ask the user for 10 values, but when I wanted the user to tell me the size of the array I had a lot of problems.

This is what I did:

  1. First I did my function and in the parameters I included the array and the integer size (which is the size the user will enter).
  2. Then I declared my values which were floats, sum=0, average, sum2=0 and SD
  3. Then I did a for loop where while i was less than the value of size there will be a sum of values.
  4. Then that sum that was calculated I divided it by the integer size to calculate the average.
  5. Then I did another for loop where when i was less than the size, then there will be a sum2 that will be equal to the sum of the  first value entered minus the average and that to the power of 2, (so you need to include the cmath library).
  6. Then I equaled SD to the sum2 divided bye the size of the array, and my function will return SD.
  7. In my int main I declared the integer size and I asked the user for the value of size.
  8. Then I declared my array with the value inside the brackets “size”. So that the program knows that the size of my array is equal to the size entered by the user.
  9. Then I asked the user for the values and I did a for loop where while i
    screen-shot-2017-03-06-at-10-39-48-am
    screen-shot-2017-03-06-at-10-40-01-am
    screen-shot-2017-03-06-at-10-40-58-am
    Continue reading "Lists!"

This is getting hard….

--Originally published at my programming blog

Today I had to do the quiz #8 which was to create a function where I needed to calculate the nth number in the Fibonacci sequence. I had a lot of trouble with this quiz!!!!! I didn’t go to class, so I couldn’t ask to my classmates or to Ken, so I searched for a lot of examples and tutorials of different codes for this program and with what I understood I created my own program.

What I did was:

  1. In my function I only declared one value x, which will be the number the user will enter.
  2. Then I made an if that if x was equal to something less than 2, then the fibonacci number would be x.
  3. Then I declared 3 values, n1, n2 and n, where n1 is 0 (the first fibonacci number) and n2 is 1 (the second fibonacci number) and n the total value of the fibonacci number we will calculate.
  4. Then I did a for loop and as you can see on the code I equal n to n1 + n2, n1 equals n2, and n2 equals to n (This are the operations to obtain the fibonacci number).
  5. And the return value was n.
  6. The in my int main I asked the user for the value of a number in the fibonacci sequence which is the integer value.
  7. Then to print the number I called the function but I changed the inside of the parenthesis to the int value so that the fibonacci number can be calculated based on the value the user entered.
  8. And that’s it.

I hope you understand it! If not here are some examples of different codes and a tutorial that can give you an idea to create your own code. Also check the work of our classmates in

Screen Shot 2017-03-02 at 10.37.04 PM.png
screen-shot-2017-03-02-at-10-53-17-pm
Continue reading "This is getting hard…."