You are on page 1of 3

#include<iostream>

#include<fastream>

#include<stdlib.h>

#include<cmath>

#include<iomanip>//Para formatear la salida

Struct Punto{

int x;

int y;

};

double Distancia(Punto p,Punto q );

using namespace std;

int main()

{ ifstream f1;

f1.open(“puntos.txt”);

ofstream f2;

f2.open(“EcuacionRecta.txt”);

if (f1.fail() || f2.fail())

cerr<<”Error en la apertura de archivos…”<<endl;

exit(1);

double DistML=-1;

double DistMC= 65535;

double Dist;

Punto orig ={0.0},p;

Punto pmco, pmlo;


(while (I f1.eof())

f1>>p.x>>p.y;

Dist = Distancia(p. orig);

if (Dist>=DistML)

{ DistML=Dist;

pmlo.x=p.x;

pmlo.y=p.y;

if (Dist<= DistMC)

{ DistMc = Dist;

pmco.x = p.x;

pmco.y=p.y;

double RectaLong = Dstancia(pmlo,pmco);

double m=(double)(pmlo.y – pmco.y)/(pmlo.x – pmco.x);

f2<<”Recta formada por: “<<endl;

f2<<”Punto p(“<<pmco.x” , “<<pmco.y<<”)”<<endl;

f2<<”Punto q(“<<pmlo.x” , “<<pmlo.y<<”)”<<endl;

f2<<”Pendiente = “<<setiosflags(ios : : fixed)<<setprecision(4)<<m<<endl;

f2<<”Longitud = “<<RectaLong<<”u”<<endl;

f2<<”Ecuacion de la Recta : y – “<<pmco.y<<” = ”<<m<<”*(x – “<<pmco.x<<”)”<<endl;

f1.close(); f2.close();

cout<<”Los Datos se guardaron con éxito …” endl ;

return 0;

double Distancia (Punto p, Punto q)

Return sqrt(pow(p.x – q.x, 2) + pow(p.y – q.y,2)); }

You might also like