Completed

C++ recursive two programs

Program 1: Computing determinants of matrices

Computing determinants of matrices is a key part of several matrix operations, among them is one way to compute the inverse of a matrix. Computing the determinant of an n x n matrix can easily be expressed recursively. Before seeing how, we need a definition.

Submatrix

A submatrix of an n x n matrix is a matrix of size (n-1) x (n-1) created by removing one row and one column from the original n x n matrix. We will use the notation Sr,c(M) to denote the submatrix created by removing row r and column c of M. For example, given the matrix, M:

10 11 12 13

20 21 22 23

30 31 32 33

40 41 42 43

the matrix S1,2(M) would be:

10 11 13

30 31 33

40 41 43

Recursive algorithm for computing the determinant

Base Case: The determinant of a 2x2 matrix, M, is a single floating point number:

M[0][0]*M[1][1] - M[1][0]*M[0][1]

Recursive expression: The determinant of an n x n matrix M (n > 2) – written as det(M) – can be defined recursively as:

det(M) = M[0][0]*det(S0,0(M)) - M[0][1]*det(S0,1(M)) + M[0][2]*det(S0,2(M)) ... M[0][n-1]*det(S0,n-1(M))

or equivalently:

Notice the alternating signs in the two equivalent expressions above.

class Matrix

Create a class Matrix to represent a square matrix of double precision floating point numbers that includes the following public methods:

class Matrix // always a square matrix

{

public:

Matrix(std::istream& inp, int n); // Create storage for n x n matrix and read its n*n values from "inp"

Matrix(const Matrix& M, int r, int c); // Create Sr,c(M); if M is nxn, the new matrix will be (n-1)x(n-1)

double det() const; // implement the recursive algorithm outlined above

}

Storage for each Matrix instance must be dynamically allocated and be of exactly the size needed. You will recall that there are (at least) two very different ways to do this. In one case, the Matrix elements will be stored in a structure whose base pointer is of type "double*"; in the other, the base type will be "double**".

Development and Testing

Your program is to open the file whose name is in argv[1]. Assuming the std::ifstream variable connected to this file is inFile, the Executive will loop doing the following:

int n;

while (inFile >> n)

{

Matrix M(inFile, n);

// ... print the matrix with appropriate formatting. Do so either by overloading

// operator<< for class Matrix, or write and use a Matrix print method

double determinant = [login to view URL]();

// print the determinant with appropriate label and formatting

}

There will be more than one matrix on the file. Data will be read in row-major order, starting with row 0. A set of data for one such matrix in a file will be read as:

n m00 … m0(n-1) … m(n-1)0 … m(n-1)(n-1)

As indicated in the code above, the "n" will be read by the Executive; the matrix itself will be read by the Matrix constructor.

Program 2: Driving a tank through electric fields

This program will be to develop a recursive backtracking solution to solve the problem illustrated and explained in the image on the right. Your program will read the description of an electric field from a file. The first two numbers in the file are the number of rows and columns in the grid. The remainder of the file will contain the (nRows * nCols) non-blank characters as indicated in the figure on the right. There must be exactly one 'S' and exactly one 'E'.

Skills: C++ Programming

See more: write scrabble method java, write ppm method examples java, write java method create node digit, write java method multiply large numbers, write java method put large number linked list, write query dispalying oracle date data descending order, write query displaying oracle date data descending order, write search method java jcreator, write matrix method java, write work method statement, c est quoi e learning, c# example programs with output, c sharp programs freelance, e book to freelance write, e marketing methods, recursive programs, sorting techniques in c with programs, C++ small programs, c++ programing programs, write c++ simple programs

About the Employer:
( 1 review ) Lawrence, United States

Project ID: #21891307

Awarded to:

Kugashia98

I'm a Computer Science graduate with High Distinction, I work on such coding problem on a daily basis.

$60 USD in 2 days
(0 Reviews)
0.0

9 freelancers are bidding on average $42 for this job

BeshoyMousaKhair

...............................................................................................................................

$40 USD in 7 days
(11 Reviews)
3.5
Artemrodin1987

Hello, I have just read your requirement very careful and I am sure that I can finish it for 1 hours because I am a professional C/C++ expert with strong algorithm. Now I don't have even one review because I am a new f More

$50 USD in 1 day
(2 Reviews)
1.4
iphonedev118

hi sir. i already studied your task in details. i am an expert in c++/c, data structure. i have a lot of experiences in this field. if you ping me, you will get a good result in short time. thanks. Waiting for your rep More

$20 USD in 1 day
(2 Reviews)
1.4
harissheikh255

Hello there, I can do coding in C++, C# using OOP ,Data Structures .If it is an assignment then I will do coding in easiest manner. Please reply for further details if u consider my proposal Thanks.

$20 USD in 1 day
(4 Reviews)
1.4
liujianmin

Hi, Glad to apply to your offer. I have gone through your job description in depth, and now I am sure that I can develop what you want exactly to your expectations, OR more. I have been through many frameworks that bo More

$20 USD in 7 days
(1 Review)
0.6
MirkoBorjan1985

Hi I am an experienced C/C++ Expert. I have read your job description carefully and am interested in your project. I am an experienced coding extensively for more than 8++ years. I am sure that I am ready to finish th More

$40 USD in 1 day
(1 Review)
0.4
DataSME

I will write both the program with proper comments in the code as well as a Word document containing the documentation about these programs so that you may scale or edit these in future by understand it using the docs More

$30 USD in 7 days
(0 Reviews)
0.0
Jng93Slv3

Hi! I'm interesting your project very well. I am a full time developer and i can work more than 10 hours in a day. I am mastering c++ and I'm a good Engineer. And also I have many experience and good skill about algor More

$100 USD in 1 day
(0 Reviews)
0.0