Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

develop your C++ program that can solve (ANY MATRIX) up to 15 equations with 15

ID: 3849237 • Letter: D

Question

develop your C++ program that can solve (ANY MATRIX) up to 15 equations with 15 unknowns. Your program will be tested with a different matrix than the one given to you. Your program should be able to read in the text file solve the matrix......put the result on the screen as well as write the results to a text file. YOU DONT HAVE TO DO BACK SUBSTITUTION ONLY SOLVE FOR THE VALUE OF ONE VARIBLE.

Here is the data.txt:

I did this manually, i got ans: a=5, b=6, c=7, d=8, e=9

But he is going to check with other data too...

* Do not read the data.txt file under int main()

* Use header files #include <fstream>,#include <iostream>,#include <cmath>

* my professor is very picky, He only likes program like his way

* i am giving my last program as a reference, so you know what way my professor wants to do the program

using namespace std;

#include <fstream> //so we can read text files
#include <fstream> //so we can output to the screen
#include <cmath> //so we can compute square root of the argument

ifstream Infile; //declares Infile
float Arraything[100], mean, yyy; // declares variables with option for decimal place
void CalcMean(); // declares calcmean
void CalcStd(); // declares calcstd
void getData(); // declares getData
int numberofdatapoints; // declares numberofdatapoints as an integer

int main()
{
   getData(); //calls getData function
   CalcMean(); //calls CalcMean function
   CalcStd(); // calls CalcStd function
system("pause");
return(0); // ends program
}
void getData() //getData begins
   {  
Infile.open("thedata.txt"); // opens specified file
numberofdatapoints= 0; // sets numberofdata points to 0
while(!Infile.eof())//tells program to keep reading the file while it performs the following statement
{
Infile>>Arraything[numberofdatapoints]; // takes information in the file
cout<<Arraything[numberofdatapoints]<<" "; // displays information in the file
numberofdatapoints++; // sets numberofdatapoints with positive infinity
}
Infile.close(); // closes the file
   numberofdatapoints=numberofdatapoints-1; //sets value for numberofdatapoints
cout<<"number of data points "<<numberofdatapoints<<endl; // gives user information
   }
void CalcStd() // CalcStd begins
{  
float sum, summa, xxx; // declares local variables
int i; // declares local integer
for (i=0; i<=(numberofdatapoints-1); i++) //for loop allows for more than one input
{
   summa+=(Arraything[i]-mean)*(Arraything[i]-mean); // formula for standard deviation, allowing for the array.
}
xxx=((1.0/numberofdatapoints)*summa); // states xxx, allowing for manipulation of CalcStd
yyy=sqrt(xxx); // square root of xxx function
cout<<" the standard deviation is "<<yyy<<endl; // displays what the standard deviation is for the user
}
void CalcMean() // CalcMean begins
{
int i; // declares local integer
float sum=0; // declares variable sum, sets equal to 0
for (i=0; i<=(numberofdatapoints-1); i++) //for loops allows for more than one input
{
   sum=sum+Arraything[i]; // allows for multiple inputs by the user
   cout<<sum<<endl; // shows user data that is being added
}
   mean=sum/numberofdatapoints; // declares mean is sum over a
  
   cout<< "mean is... " <<mean; // tell user what the mean is.
}

*** This program just for reference to follow the style of my prof.

I posted this questions couple of days ago, but somebody replied with solution and that solution was not copyable and that does not have any comments. Please comments all the line and make sure i can copy that program. Use header files #include <fstream>,#include <iostream>,#include <cmath>..try to not use any other headerfiles please!!!

*** Whatever program i gave above that only for reference...to follow the style...i asked this questions already 3 times...someon gave wrong ans without any comments first and then someone just copy and paste my referral program!!!!!! Please this time, someone answered it right with all the given requirement please!!!!!

Thank you.

Explanation / Answer

#include<iostream>

#include<cstdio>

using namespace std;

int main(int argc, char **argv)

{

    void lu(float[][10], float[][10], float[][10], int n);

    void output(float[][10], int);

    float a[10][10], l[10][10], u[10][10];

    int n = 0, i = 0, j = 0;

    cout << "Enter size of 2d array(Square matrix) : ";

    cin >> n;

    for (i = 0; i < n; i++)

    {

        for (j = 0; j < n; j++)

        {

            cout << "Enter values no:" << i << ", " << j << ": ";

            cin >> a[i][j];

        }

    }

    lu(a, l, u, n);

    cout << " L Decomposition ";

    output(l, n);

    cout << " U Decomposition ";

    output(u, n);

    return 0;

}

void lu(float a[][10], float l[][10], float u[][10], int n)

{

    int i = 0, j = 0, k = 0;

    for (i = 0; i < n; i++)

    {

        for (j = 0; j < n; j++)

        {

            if (j < i)

                l[j][i] = 0;

            else

            {

                l[j][i] = a[j][i];

                for (k = 0; k < i; k++)

                {

                    l[j][i] = l[j][i] - l[j][k] * u[k][i];

                }

            }

        }

        for (j = 0; j < n; j++)

        {

            if (j < i)

                u[i][j] = 0;

            else if (j == i)

                u[i][j] = 1;

            else

            {

                u[i][j] = a[i][j] / l[i][i];

                for (k = 0; k < i; k++)

                {

                    u[i][j] = u[i][j] - ((l[i][k] * u[k][j]) / l[i][i]);

                }

            }

        }

    }

}

void output(float x[][10], int n)

{

    int i = 0, j = 0;

    for (i = 0; i < n; i++)

    {

        for (j = 0; j < n; j++)

        {

            printf("%f ", x[i][j]);

        }

        cout << " ";

    }

}