Question

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 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;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$175.00

or $1 if you
register a new account!

Related Homework Solutions

Problems Using Programming Language C
Homework Solution
$88.00
Computer Science
Programming
Algorithms
C
Structures
CSV Files
Pointers
Loops
Arrays
File Management
Variables
Statements
Input
Output
Tables
Linked Lists
Memory Allocation
Strings
Integers
Why Cable TV Prefers FDM Over TDM
Homework Solution
$10.00
Computer Science
Cable
TV
FDM
TDM
Frequency
Division
Multiplexing
Time
Signal
Data
Bandwidth
Destination
Allocation
Scheme
Telephone
Cloud Computing (2000 words)
Homework Solution
$58.00
Cloud
Computing
Service
Model
Delivery
IaaS
PaaS
SaaS
Software
Infrastructure
Platform
NIST
Challenge
Distributed
Environment
General Questions from Various Computer Science Branches
Homework Solution
$20.00
CSS
XML
Authentication
Authorization
RDBMS
Tree
Data
Structure
IT
NAND
Gate
Address
IP
Netmask
Network
Venn
Diagram
NTP
Server
Query
Database
Normalization
Relational
Data
Sorting Algorithms Using Programming Language C
Homework Solution
$63.00
Computer Science
Programming
C
Heap
Recursion
Quick Sort
Bubble Sort
Functions
Algorithms
Modification
Partition
Arrays
Loops
Statements
Variables
Pointers
Experiments
Data Sets
Random Numbers
Get help from a qualified tutor
Live Chats