# Quiz 09 Distance

--Originally published at Solving problems with programming

In this quiz what we did is ask for the user fo 2 points for each it’s x and y coordinates. With the coordinates of the two points we can easily calculate the distance between them. To solve the problem we use strucutres that are variables that can be asigned to them multiple variables, it is like an array.

```#include <iostream>
#include <cmath>
using namespace std;

struct smurf{
double x;
double y;
};

double distance(smurf p1,smurf p2){
double dx, dy;
dx=p2.x - p1.x;
dy=p2.y - p1.y;
return sqrt(pow(dx,2)+pow(dy,2));
return 0.0;
}

int main() {
smurf punto1,punto2;
cout<<"Escribe la cordenada x del punto 1 "<<endl;
cin >>punto1.x;
cout<<"Escribe la coordenada y del punto 1"<<endl;
cin>>punto1.y;
cout<<"Escribe la coordenada x del punto 2"<<endl;
cin>>punto2.x;
cout<<"Escribe la coordenada y del punto 2"<<endl;
cin>> punto2.y;
cout<<"La distancia entre los dos puntos es "<<resultado<<endl;
return 0;
}

```

if you don’t understand structures here is anyway the solution without structures.

```#include <iostream>
#include <cmath>
using namespace std;
double distance (double x1,double y1,double x2,double y2){
double dx, dy;
dx=x2-x1;
dy=y2-y1;
return sqrt(pow(dx,2)+pow(dy,2));
}
int main() {
cout<<"Escribe la cordenada x del punto 1 "<<endl;
cin >>px1;
cout<<"Escribe la coordenada y del punto 1"<<endl;
cin>>py2;
cout<<"Escribe la coordenada x del punto 2"<<endl;
cin>>px2;
cout<<"Escribe la coordenada y del punto 2"<<endl;
cin>> py2;
cout<<"La distancia entre los dos puntos es "<<resultado<<endl;
return 0;
}```

# From here to there

--Originally published at Ken&#039;s Disciple 01

###### Picture by rawpixel.com

Never realized I didn’t post Quiz 09, so here it is, it is super simple you just have to make a function that calculates the distance between to cartesian points (there’s no explanation in this because I think by now you are perfectly capable of doing it).

Code:

Result:

My code at GitHub.

L.out

# Distance______! #Quiz09

--Originally published at It&#039;s me

This program was fuuuun, it was simple, we just needed to know/use the pythagorean triangle. The created function consisted in calculating the delta between of two points. E.g. x2-x1 and then applying the formula: c2 = a2 + b2 . Here is my code:

Original header image recovered from: https://www.flickr.com/photos/skynoir/14619099578/in/photolist-ogQGZ1-7YPT1Q-4UseZA-93uqTW-5cof6N-7KGmHu-DsRX6R-qwgS3n-8xtj6E-dKuM8o-917TAc-jayNo-9UjB2B-7o4uvb-rnjWcU-a3JoFT-3twFg-RJZAXa-oFjGB9-5WnvwS-a6Agou-6f82D6-oQddZE-6Ugw1H-e4UXR9-25QSpf-CTDyVf-bdnXxc-fDsobv-oXQBxa-bdsPsz-6UT8s-9t1Xyr-ecCAtc-SL6V-4CDcuy-aFvatc-deHg18-dWaa3K-73vGfK-n2n67c-4JEWVy-4mx7Qu-dBkcmV-6xQsAB-fsrCRy-9HiVEg-cQaph5-g9vTHj-eKhz43

# Quiz09, Distancia entre puntos

--Originally published at Aprendiendo a programar en C++

Para este quiz se nos pidió crear una  función que reciba 4 parámetros, “x1,x2,y1,y2” dichos puntos son las coordenadas de dos puntos en un plano cartesiano (x1,y1) y (x2,y2) respectivamente, con estos datos, nuestra función tiene que regresar la distancia que existe entre estos puntos, para esto utilizaremos la fórmula de pitágoras para la hipotenusa {c=sqrt(x^2+y^2)} cabe mencionar que sqrt = raíz cuadrada. Para obtener los valores “x” y “y”, tenemos que restar x1 a x2 (x2-x1) y el resultado elevarlo al cuadrado, lo mismo seria para las y, por lo tanto podríamos modificar la formula a {c=sqrt((x2-x1)^2+(y2-y1)^2)}; sin embargo he notado que los programas no corren correctamente cuando las formulas son muy largas, así que si se puede simplificar seria mejor hacerlo.

Es importante mencionar que se debe crear el código completo para probar la función, por código completo me refiero al int main() y poner la libreria cmath para poder usar la raíz.

Finalmente dejo un ss de mi código:

# #Quiz09 See the struct function explained!

--Originally published at Solving Problems with Programming

THIS IS THE #QUIZ9 WHOSE OBJECTIVE IS CREATE AND CALL STRUCK FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES USING RECURSION AND LOOPS. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 .

In this #QUIZ9 makes 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. (struct function)

Remember the distance between 2 points:

First let me show you the pictures of the quiz. At the beginning of the quiz we needed it to do this quiz in two ways one using a struct function and the other not. So let me show you the 2 solutions of this problem.

Solution with the struct function:

FIRST TO DO IN THIS #QUIZ09 with the struct solution is including the Library to call all the fuctions of inputs and outputs of data in languague C++ #MasteryTopic01

```#include <iostream>//Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01
```

Then, we need a library to call all the fuctions of MATH of data in languague
C++ #MasteryTopic01

```#include <cmath>//Library to call all the
//fuctions of MATH of data in languague
//C++ #MasteryTopic01
```

Next, we need a command that everytime goes with the instructions of input and outputs
of data that is call std but with this command helps writing these std out of the main because the machine factorizes them

```using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them
```

Then, we need this structure of a function where you have subrutines in order to make

Continue reading "#Quiz09 See the struct function explained!"

# QUIZ09

--Originally published at prgrm.co

In this week’s class, we needed to make a program that given coordinates would give back the distance between them.

```#include <iostream>
#include <cmath>

using namespace std;

float distance(float x1, float y1, float x2, float y2){
float a = x2 - x1;
float b = y2 - y1;

return sqrt(pow(a, 2)+ pow(b, 2));
}

int main(){

float x1, y1, x2, y2;

cout << "This program will calculate the distance between coordinates" << endl;
cout << "X1: "; cin >> x1;
cout << "Y1: "; cin >> y1;
cout << "X2: "; cin >> x2;
cout << "Y2: "; cin >> y2;

cout << "The distance between coordinates (" << x1 << "," << y1 << ") & (" << x2 << "," << y2 << ") = " << distance(x1,y1,x2,y2) << endl;

return 0;
}
```

I made a function that would give back “c”.

Image.

Here is the function:

```float distance(float x1, float y1, float x2, float y2){
float a = x2 - x1;
float b = y2 - y1;

return sqrt(pow(a, 2)+ pow(b, 2));
}
```

Featured image.

# QUIZ WEEK 9

--Originally published at how not to program

In this program we have to measure the distance between to coordinates. first we research for the function, wich, according to Math Warehouse, is:

If you want to make improvements or modifications, here is the code for you to copy and paste it anywhere.

#include <iostream>
using namespace std;

double distance (double x1,double x2,double y1,double y2)
{
double d=sqrt( pow(x2-x1,2) + pow(y2-y1,2) );
return d;
}
int main ()
{
double x1, x2, y1, y2;
cout << “Please input the values for x and y of the first coordinate” << endl;
cin >> x1;
cin >> y1;

cout << “Please input the values for x and y of the second coordinate” << endl;
cin >> x2;
cin >> y2;

double d = distance (x1, x2, y1, y2);

return d;
}

# Miracle!!

--Originally published at my programming blog

( 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