este es mi segundo programa ke corrio correctamente..este es su codigo
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
class Punto{
private:
float x,y;
Punto *nxt;
public:
Punto(float=0,float=0,Punto* =NULL);
void leeDatos(void);
void modifNxt(Punto* p);
float dameX(void);
float dameY(void);
Punto* dameNxt(void);
};
Punto::Punto(float a, float b, Punto* c):
x(a),y(b),nxt(c){
}
void Punto::leeDatos(void){
cout<<endl<<"Dame el valor de la X: ";
cin>>x;
cout<<endl<<"Dame el valor d ela Y: ";
cin>>y;
}
void Punto::modifNxt(Punto* p){
nxt=p;
}
float Punto::dameX(void){
return x;
}
float Punto::dameY(void){
return y;
}
Punto* Punto::dameNxt(void){
return nxt;
}
class Lista{
private:
Punto *inicio,*fin;
public:
Lista(Punto* =NULL,Punto* =NULL);
void nuevoPunto(void);
float SumaX();
float SumaY();
float SumaXY();
float SumaX2();
};
Lista::Lista(Punto* a,Punto* b):
inicio(a),fin(b){
}
void Lista::nuevoPunto(void){
if(inicio==NULL){
inicio=new Punto;
inicio->leeDatos();
fin=inicio;
}
else{
fin->modifNxt(new Punto);
fin=fin->dameNxt();
fin->leeDatos();
}
}
float Lista::SumaX(){
float SX=0;
Punto *aux;
for(aux=inicio;aux!=NULL;){
SX=(aux->dameX()+SX);
aux=aux->dameNxt();
}
return SX;
}
float Lista::SumaY(){
float SY=0;
Punto *aux;
for(aux=inicio;aux!=NULL;){
SY=(aux->dameY()+SY);
aux=aux->dameNxt();
}
return SY;
}
float Lista::SumaXY(){
float SXY=0;
Punto *aux;
for(aux=inicio;aux!=NULL;){
SXY=((aux->dameX())*(aux->dameY()))+SXY;
aux=aux->dameNxt();
}
return SXY;
}
float Lista::SumaX2(){
float SX2=0;
Punto *aux;
for(aux=inicio;aux!=NULL; ){
SX2=(pow(aux->dameX(),2)+SX2);
aux=aux->dameNxt();
}
return SX2;
}
int main(){
system("cls");
Lista L;
int M,N,O;
float V,m,b,R;
cout<<"\tMinimos Cuadrados"
<<endl<<endl<<"¿Cuantos Puntos a Dar?: ";
cin>>N;
M=N-1;
O=N-M;
do{
cout<<endl<<"Valores del Punto "<<O<<" :"<<endl;
L.nuevoPunto();
O++;
}
while(O!=(N+1));
m=(N*L.SumaXY()-L.SumaX()*L.SumaY())/(N*L.SumaX2()-pow(L.SumaX(),2));
b=(L.SumaX2()*L.SumaY()-L.SumaX()*L.SumaXY())/(N*L.SumaX2()-pow(L.SumaX(),2));
cout<<endl<<"¿Que Valor de X Deseas Calcular?: ";
cin>>V;
R=m*V+b;
cout<<endl<<"El Valor de Y para X= "<<V<<" es de: "<<R;
getch();
return 0;
}
No hay comentarios:
Publicar un comentario