Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:13:23+00:00 2026-06-11T14:13:23+00:00

Sorry for bothering you but I need help. I have an assignment to make

  • 0

Sorry for bothering you but I need help.

I have an assignment to make a program with a classes and calculate linear regression, but my linked list class is just receiving one value and I don’t know why. The code compiles but it does not calculates the linear regression.

Here is my code:

#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<istream>
#include<string>


float a,b,r;
float X[20],Y[20],n = 10, z;
int intAux = 0, intI;
//double dblSumX,dblSumY,dblSumX2,dblSumY2,dblSumXY;
float dblSumX,dblSumY,dblSumX2,dblSumY2,dblSumXY;
//double dblSXX,dblSYY,dblSXY;
float dblSXX,dblSYY,dblSXY;

using namespace std;

// Clase Nodo
//p.base=
class Nodo {
float fltEstProxySize;
float fltDevelHours;
float fltEst;
Nodo* next;

 public:
  Nodo() {};
  void SetVariables(float data)
  {
      fltEstProxySize = data;
      fltDevelHours = data;
      fltEst = data;
  }

  void SetData(float EPS, float DH, float ES)
  {  
      fltEstProxySize = EPS;
      fltDevelHours = DH;
      fltEst = ES;
  };

  void SetNext(Nodo* aNext) 
  { 
      next = aNext;
  };

  float Data() 
  {  
      return(fltEstProxySize, fltDevelHours, fltEst);
  };

  Nodo* Next() 
  { 
      return next; 
  };
  };


 //p.
 //... Clase de la Lista ...
 class Lista {
Nodo *head;

 public:
  Lista() { head = NULL; };
  void Print();
  void Append(float fltEstProxySize, float fltDevelHours, float fltEst);
  void Delete(float fltEstProxySize, float fltDevelHours, float fltEst);
 };


/**
 * ... Imprime el contenido de la lista
 */
 //i.
void Lista::Print() {

// ... Apuntador temporal ...
Nodo *tmp = head;

// ... No hay Nodos ...
if ( tmp == NULL ) {
    cout << "EMPTY" << endl;
    return;
}

// ... Existe un Nodo in the Lista ...
if ( tmp->Next() == NULL ) {
    cout << tmp->Data();
    cout << " --> ";
    cout << "NULL" << endl;
}
else {
    // ... Recorre la lista y la imprime ...
    do {
        cout << tmp->Data();
        cout << " --> ";
        tmp = tmp->Next();
    }
    while ( tmp != NULL );

    cout << "NULL" << endl;
}
  }

  //i.
  // ... Agrega un nodo a la lista ...
  void Lista::Append(float fltEstProxySize, float fltDevelHours, float fltEst){

// ... Aqui crea a Nodo nuevo ...
Nodo* newNodo = new Nodo();

newNodo->SetData(fltEstProxySize, fltDevelHours, fltEst);
newNodo->SetNext(NULL);

// ... Crea un apuntador temporal ...
Nodo *tmp = head;

if ( tmp != NULL ) {
    // ... El Nodo esta en la Lista ...
    // ... Recorre la Lista ...
    while ( tmp->Next() != NULL ) {
        tmp = tmp->Next();
    }
    // ... El ultimo Nodo de la lista ...
    tmp->SetNext(newNodo);
}
else {
    // ... Nuevo Nodo de la lista ...
    head = newNodo;
}
   }



   /**
    * ... Borra un Nodo de la Lista ...
    */
  //i.
  void Lista::Delete(float fltEstProxySize, float fltDevelHours, float fltEst){

// ... Crea un Nodo temporal ...
Nodo *tmp = head;

// ... No hay Nodos ...
if ( tmp == NULL )
    return;

// ... ultimo Nodo de la Lista ...
if ( tmp->Next() == NULL ) {
    delete tmp;
    head = NULL;
}
else {
    // ... Recorre los nodos ...
    Nodo *prev;
    do {
        //if ( tmp->Data() == data ) break;
        if(tmp->Data() == fltEstProxySize && tmp->Data() == fltDevelHours) break;
        prev = tmp;
        tmp = tmp->Next();
    } while ( tmp != NULL );

    // ... Ajusta los Nodos ...
    prev->SetNext(tmp->Next());

    // ... Borra el Nodo actual ...
    delete tmp;
}
   }



   //i.
   class RegresionLineal
   {
Nodo *head;
int i;
//double dblSumX=0,dblSumY=0,dblSumX2=0,dblSumY2=0,dblSumXY=0;
//double dblSumX,dblSumY,dblSumX2,dblSumY2,dblSumXY;
//double dblSXX,dblSYY,dblSXY;

   public:
RegresionLineal(){head = NULL;};
void Calculo();

  };

  void RegresionLineal::Calculo()
  {
for (intI=0;intI < 20; intI++)
{   
    //if (X[intI] != 0)
    //{
        dblSumX += X[intI];
        dblSumX2 += (X[intI] * X[intI]);
    //}

    //if(Y[intI] !=0)
    //{
        dblSumY += Y[intI];
        dblSumY2 += (Y[intI] * Y[intI]);
        dblSumXY += (X[intI] * Y[intI]);
    //}
}

dblSXX = dblSumX2 - dblSumX * dblSumX / n;
dblSYY = dblSumY2 - dblSumY * dblSumY / n;
dblSXY = dblSumXY - dblSumX * dblSumY / n;

// ... pendiente infinita ...
if (abs(dblSXX) == 0)
    //return 0;
    z=0;


// ... calcula la pendiente ...
b = dblSXY / dblSXX;
a = dblSumY / n - (b) * dblSumX / n;

// ... calcula el coeficiente de regresion ...
if (abs(dblSYY) == 0)
    r = 1;
else
    r = dblSXY / sqrt(dblSXX * dblSYY);


     }


     // ... ... ... ... ... ... ... ... ... ... ... ... ...
    int main()
    {
   // ... Variables auxiliares ...
       float fltMedia2 = 0;
       float fltDevStd1 = 0;
   float fltDevStd2 = 0;
   float fltSuma1 = 0;
   float fltSuma2 = 0;
   float fltCuenta = 0;
   int intF = 0;
   float fltAux1 = 0, fltAux4 = 0, fltMedia1, fltAux3;
float fltAux2 = 0;


Lista lista;
RegresionLineal RL;

// ... inicializa arreglo ...
for (intI = 0; intI < 20; intI++)
{
    X[intI] = 0;
    Y[intI] = 0;
}

// ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 

cout << "\nPlease introduce the values of table 1: (Note: to finish just type -1 and hit enter)\n";

while(!cin.eof())
{   //d.
    cout << "\nPlease introduce X: ";
    cin >> fltAux1;
    cout << "\nPlease introduce Y: ";
    cin >> fltAux2;
    cout << "\nPlease introduce the estimate: ";
    cin >> fltAux3;
    //d.
    //d.

    if ((fltAux1 == -1) || (fltAux2 == -1))
    {
        break;
    }
    else
    {
        lista.Append(fltAux1, fltAux2, fltAux3);
        X[intI] = fltAux1;
        Y[intI] = fltAux2;
        fltCuenta = fltCuenta + 1;
        intI++;
        cout << "fltAux1: " << fltAux1 << endl;
        cout << "fltAux2: " << fltAux2 << endl;
    }
}

lista.Print();
// ... Calcula la regresión lineal ...
RL.Calculo();
cout << "\na: " << a << "\n" << endl;

cout << "Suma X: " << dblSumX << endl;
cout << "Suma Y: " << dblSumY << endl;
cout << "Suma X2: " << dblSumX2 << endl;
cout << "Suma Y2: " << dblSumY2 << endl;
cout << "Suma X*Y:" << dblSumXY << endl;


return 0;
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:13:24+00:00Added an answer on June 11, 2026 at 2:13 pm

    Although there are several other problems/possible improvements in the code, the problem you are facing right now is because you haven’t reset intI to 0 before while loop in your main function.

    Following is the corrected excerpt of code:

    // ... inicializa arreglo ...
    for (intI = 0; intI < 20; intI++)
    {
        X[intI] = 0;
        Y[intI] = 0;
    }
    
    // ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 
    
    cout << "\nPlease introduce the values of table 1: (Note: to finish just type -1 and hit enter)\n";
    
    intI = 0;          //Corrected here
    
    while(!cin.eof())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, guys.I am quite new in mysql but I do need help from getting
Sorry if this is stupid question, but I'm new to MATLAB. I have a
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry gals & guys for a potentially dumb question but I have been looking
sorry for lamer question, but I really could not found subject. I have a
Sorry this is basic, but I'm new to Python and Django. I have a
Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
sorry for the dummy question but I cannot find a simple and clean way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.