Created
November 4, 2016 13:52
-
-
Save brayancruces/8adab50a4531b68bda207fbdc6224cf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<math.h> | |
#include<fstream> | |
using namespace std; | |
struct Tupla | |
{ | |
int X; | |
int Y; | |
}; | |
class Funciones | |
{ | |
public: | |
Funciones() {} | |
template<typename T> | |
double escalar(T* arreglo, int cantidad) { | |
double ProductoX = 1; | |
double ProductoY = 1; | |
//lambda | |
auto Escalar = [cantidad, &ProductoX, &ProductoY](T *arreglo)-> int { | |
for (int i = 0; i < cantidad; i++) | |
{ | |
ProductoX = ProductoX*arreglo[i].X; | |
ProductoY = ProductoY*arreglo[i].Y; | |
} | |
return ProductoX + ProductoY; | |
}; | |
return Escalar(arreglo); | |
} | |
template<typename T> | |
double modulo(T a, T b) { | |
auto Modulo = [](T a, T b) ->double { | |
return(sqrt(pow((b.X - a.X), 2) + pow((b.Y - a.Y), 2))); | |
}; | |
return Modulo(a, b); | |
} | |
template<typename T> | |
void Guardar(T* arreglo, int cantidad) | |
{ | |
ofstream Archivo; | |
Archivo.open("Ejercicio_1.txt"); | |
for (int i = 0; i <= cantidad-1; i++) | |
{ | |
Archivo << "(" << arreglo[i].X << ", " << arreglo[i].Y << ")" << "; "; | |
} | |
Archivo << endl; | |
Archivo << "El escalar: " << escalar(arreglo, cantidad); | |
Archivo << endl; | |
Archivo << "El modulo es: " << modulo(arreglo[0], arreglo[1]); | |
Archivo << endl; | |
} | |
}; | |
int main() | |
{ | |
Tupla *arreglo; | |
Funciones* V = new Funciones(); | |
arreglo = new Tupla[2]; | |
arreglo[0].X = 1; | |
arreglo[0].Y = 2; | |
arreglo[1].X = 4; | |
arreglo[1].Y = 6; | |
arreglo[2].X = 1; | |
arreglo[2].Y = 1; | |
for (int i = 0; i <= 2; i++) | |
{ | |
cout << "(" << arreglo[i].X << ", " << arreglo[i].Y << ")" << "; "; | |
} | |
cout << endl; | |
cout << "El escalar: " << V->escalar(arreglo, 3); | |
cout << endl; | |
cout << "El modulo es: " << V->modulo(arreglo[0], arreglo[1]); | |
cout << endl; | |
V->Guardar(arreglo, 3); | |
system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment