develop your C++ program that can solve (ANY MATRIX) up to 15 equations with 15
ID: 3846282 • 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!!!
Thank you.
Explanation / Answer
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.
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.