QuestionQuestion

Write a C++ program that can solve system of linear equations with Gauss-Jordan Method. There should be a system of linear equations in the input file "gauss.dat" in the form of matrices.

For example: the system of linear equations:
3x+5y+2z=1
3x+2y+7z=1
3x+6y+8z=1

In the input file:
3 <------ is the dimension of the matrix
1   3   5 2
1   3   2 7   
1   3   6 8

You should get the matrices from the input file. Then solve the answer with Gauss-Jordan method.
The equations and the answers need to be put in the output file "gauss.txt".

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <string>


using namespace std;

void freeArray(int N, double **M){
    // De-Allocate memory to prevent memory leak
    for (int i = 0; i < N; i++)
       delete [] M[i];
    delete [] M;
}


double **AllocateArray(int N){
    double **M;
    M = new double*[N];
    for (int i = 0; i < N; i++)
       M[i] = new double[N+1];

    return M;

}

// read of set of equations
int readOneSetOfEquations(int *Num, double ***M,istream &inFile, int toScreen){
    char line[256];
    int value;
    string s;
    stringstream ss;
    // read dimension
    *Num=0;
    if(!inFile.eof()){
       if ( toScreen ==1){
            // from kdb
            do{
                cout << "Enter Number of rows ( from 2 to 9):";
                cin>> value;
                cin.clear();
                cin.ignore(INT_MAX,'\n');
                if(value <2 || value >9)
                   cout << "Error! Value must be in [2,9]"<< endl;
                else
                   break;...
$140.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats