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

Write and test two functions det2() and det3(). The det2() functionshould accept

ID: 3614303 • Letter: W

Question

Write and test two functions det2() and det3(). The det2() functionshould accept four doubles corresponding to the coefficients of 2by 2 matrix and return its determinant (a double). The det3()function should accept the nine coefficients of a 3 by 3 matrix andreturn its determinant by calling det2() to calculate the required2 by 2 determinants. Complete the following steps:
*Write a main() driver function that prompts the user to enter thecoefficients of either a 2x2 or 3x3 matrix.
*Depending on the type of matrix enter either call det2() ordet3().
Have the main() function display the value of the determinant.

What I have so far works for everything except the 3x3determinant... which I have stuck a couple tests in and the t1 andt2 terms are not coming up with the right values for somereason.

Please highlight what you change / explain what I did wrong for alifesaver rating.

my code:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

//function declarations
double det2( double, double, double, double);
double det3( double, double, double, double, double, double,double, double, double);

int main()
{
//variables
double type, d2, d3, a11, a12, a13, a21, a22, a23, a31, a32,a33;

//input
cout<< "Welcome to the determining Determinantsprogram!"<< endl;
do
{
cout<< "Enter the the type of square matrix (2 or 3) ";
cin >> type;
} while ( type != 2 && type != 3 );

if (type == 2)
{
cout << "Enter numbers corresponding to the row and columnsubscripts" << endl;
cout << "a11: ";
cin >> a11;
cout << "al2: ";
cin >> a12;
cout << "a21: ";
cin >> a21;
cout << "a22: ";
cin >> a22;

d2 = det2(a11, a12, a21, a22);

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);

cout << "The determinant is: " << d2 << endl;

}

if (type == 3)
{
cout << "Enter numbers corresponding to the row and columnsubscripts" << endl;
cout << "a11: ";
cin >> a11;
cout << "al2: ";
cin >> a12;
cout << "a13: ";
cin >> a13;
cout << "a21: ";
cin >> a21;
cout << "a22: ";
cin >> a22;
cout << "a23: ";
cin >> a23;
cout << "a31: ";
cin >> a31;
cout << "a32: ";
cin >> a32;
cout << "a33: ";
cin >> a33;

d3 = det3(a11, a12, a13, a21, a22, a23, a31, a32, a33);

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);

cout << "The determinant is: " << d3 << endl;

}

return 0;
}

//determinant functions

double det2( double a11, double a12, double a21, double a22)
{
//cout << "in det2" << endl; //test

return (a11*a22)-(a21*a12);
}

double det3( double a11, double a12, double a13, double a21, doublea22, double a23, double a31, double a32, double a33)
{
double d3, t1, t2, t3;
d3= (a11*(det2(a22, a23, a32, a33))) - (a22*(det2(a12, a13, a32,a33))) + (a31*(det2(a12, a13, a22, a23)));

//cout << "in det3" << endl; //test

t1= (a11*(det2(a22, a23, a32, a33))); //test
t2= -1*(a22*(det2(a12, a13, a32, a33))); //test
t3= (a31*(det2(a12, a13, a22, a23))); //test



cout<< t1 << " " << t2<< " " <<t3<< endl; //test

return d3;
}

Explanation / Answer

#include #include #include using namespace std; //function declarations double det2( double, double, double, double); double det3( double, double, double, double, double, double,double, double, double); int main() { //variables double type, d2, d3, a11, a12, a13, a21, a22, a23, a31, a32,a33; //input cout a33; d3 = det3(a11, a12, a13, a21, a22, a23, a31, a32, a33); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote