Homework Solution: [C++]I need to write a class that solves 3×3 systems of equations (3 equations with 3 unknowns). (This is abou…

    [C++]I need to write a class that solves 3x3 systems of equations (3 equations with 3 unknowns). (This is about Matrices reduced to row echelon form). The class should be derived from and has a base of the class of HW.1 (So the class that is going to be written inherits from the class that I wrote in my first home work) Please if anything is unclear, write a comment and I will answer it. Here's the link to my code: https://repl.it/KhHC/12 #include <iostream> using namespace std; class Matrix{ private : double A[3][3]; double B[3][3]; double result[3][3]; public : /*------------------------------------------------------- FUNCTON NAME: input PARAMETERS: RETURN TYPE: DESCRIPTION: Stores user values inside the corresponding arrays to be referenced later -------------------------------------------------------*/ void input(){ cout << "Input 9 elements into your 3x3 matrix A: "; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { cin >> A[i][j]; // terminates function on failure if(cin.fail()) { cin.clear(); cin.ignore(100, 'n'); cerr << "nERROR: Please enter valid input!n" << endl; } } } cout << "Input 9 elements into your 3x3 matrix B: "; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { cin >> B[i][j]; // terminates function on failure if(cin.fail()) { cin.clear(); cin.ignore(100, 'n'); cerr << "nERROR: Please enter valid input!n" << endl; } } } } /*------------------------------------------------------- FUNCTON NAME: print PARAMETERS: result RETURN TYPE: will output the results of the array calculation DESCRIPTION: This function will print out the results from the subtraction and addition function -------------------------------------------------------*/ void print(double result[3][3]){ for(int i = 0; i < 3; i++) { cout << "["; for(int j = 0; j < 3; j++) { cout << result[i][j] << "t"; } cout << "]" << endl; } } /*------------------------------------------------------- FUNCTON NAME: printAB PARAMETERS: RETURN TYPE: DESCRIPTION: This function will simply display the Matrices of A and B right after the user has finished their input -------------------------------------------------------*/ void printAB(){ cout<<"nMatrix A :"<<endl; for(int i = 0; i < 3; i++) { cout << "["; for(int j = 0; j < 3; j++) { cout << A[i][j] << "t"; } cout << "]" << endl; } cout<<"nMatrix B :"<<endl; for(int i = 0; i < 3; i++) { cout << "["; for(int j = 0; j < 3; j++) { cout << A[i][j] << "t"; } cout << "]" << endl; } } /*------------------------------------------------------- FUNCTON NAME: addition PARAMETERS: RETURN TYPE: DESCRIPTION: This function will perform the addition and the print function will output the result -------------------------------------------------------*/ void addition(){ for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { result[i][j] = A[i][j] + B[i][j]; } } print(result); } /*------------------------------------------------------- FUNCTON NAME: subtraction PARAMETERS: RETURN TYPE: DESCRIPTION: This function will perform the subtraction and the print function will output the result -------------------------------------------------------*/ void subtraction(){ for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { result[i][j] = A[i][j] - B[i][j]; } } print(result); } /*------------------------------------------------------- FUNCTON NAME: determinant PARAMETERS: RETURN TYPE: determin, an integer DESCRIPTION: This function will find the determinant -------------------------------------------------------*/ int determinant(){ int determin = 0; //finding the determinant for(int i = 0; i < 3; i++) determin = determin + (A[0][i] * (A[1][(i+1)%3] * A[2][(i+2)%3] - A[1][(i+2)%3] * A[2][(i+1)%3])); return determin; } /*------------------------------------------------------- FUNCTON NAME: inverse PARAMETERS: RETURN TYPE: DESCRIPTION: This function will find the inverse and output the result -------------------------------------------------------*/ void inverse(){ cout <<"nnInverse of Matrix A is: n"; cout << " " << endl; for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++) cout<< "[" << ((A[(j+1)%3][(i+1)%3] * A[(j+2)%3][(i+2)%3]) - (A[(j+1)%3][(i+2)%3] * A[(j+2)%3][(i+1)%3]))/ determinant()<< "]" << "t"; cout<<"n"; } } }; //Main function int main() { //Initializing Variables; "choice" will initiate a a loop, "input" will come in useful to do a switch statement, and obj will simply create another instance of the original class that can be manipulated bool choice; char input; Matrix obj; cout << "nWhen filling up matrices, separate individual elements by a space (e.g 2 4 1.4 56.3 ...) nn"; obj.input(); obj.printAB(); //Displaying a menu, so that the user can choose what he wants to do choice = false; //The Loop while(!choice) { cout << " " << endl; cout <<"** Choose from the following **"<< endl; cout << " " << endl; cout << "a - Addition" << endl; cout << "s - Subtraction" << endl; cout << "d - Determinant" << endl; cout << "i - Inverse" << endl; cout << "q - Quit" << endl; cout << " " << endl; cout << "Note: Choosing 'i' or 'd' will only apply to Matrix A" << endl; cout << " " << endl; cout << "Enter your choice: "; cin >> input; cout << endl; //A switch to handle the user inputs switch(input){ case 'a': case 'A': obj.addition(); break; case 's': case 'S': obj.subtraction(); break; case 'd'|'D': cout<<"Determinant is : "<<obj.determinant(); cout << " " << endl; break; case 'i': case 'I': obj.inverse(); break; case 'q': case 'Q': exit(0); default:cout<<"nERROR: Please enter valid input!nn"; } } return 0; }

    Expert Answer

     
    C++
    class A
    { public A() { n = 0; } // constructor

    [C++]I need to transcribe a systematize that solves 3×3 systems of equations (3 equations with 3 unknowns). (This is abquenched Matrices dejected to degree echelon produce).

    The systematize should be superficial from and has a worthiest of the systematize of HW.1 (So the systematize that is going to be written inherits from the systematize that I wrote in my earliest home composition)

    Please if anything is unclear, transcribe a dilate and I get vindication it.

    Here’s the embody to my code: https://repl.it/KhHC/12

    #include <iostream>
    using nameextension std;

    systematize Matrix{

    secret :
    enfold A[3][3];
    enfold B[3][3];
    enfold fruit[3][3];

    exoteric :
    /*——————————————————-
    FUNCTON NAME: input
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: Stores user estimates within the selfsame set-in-orders to be referenced later
    ——————————————————-*/
    null input(){

    cquenched << “Input 9 elements into your 3×3 matrix A: “;

    for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
    cin >> A[i][j];
    // terminates power on fallure
    if(cin.fail()) {
    cin.clear();
    cin.ignore(100, ‘n’);
    cerr << “nERROR: Please penetrate strong input!n” << endl;
    }
    }
    }

    cquenched << “Input 9 elements into your 3×3 matrix B: “;

    for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
    cin >> B[i][j];
    // terminates power on fallure
    if(cin.fail()) {
    cin.clear();
    cin.ignore(100, ‘n’);
    cerr << “nERROR: Please penetrate strong input!n” << endl;
    }
    }
    }
    }
    /*——————————————————-
    FUNCTON NAME: stereotype
    PARAMETERS: fruit
    RETURN TYPE: get quenchedput the fruits of the set-in-order calculation
    DESCRIPTION: This power get stereotype quenched the fruits from the incorporation and identicalization power
    ——————————————————-*/
    null stereotype(enfold fruit[3][3]){
    for(int i = 0; i < 3; i++) {
    cquenched << “[“;
    for(int j = 0; j < 3; j++) {
    cquenched << fruit[i][j] << “t”;
    }
    cquenched << “]” << endl;
    }
    }
    /*——————————————————-
    FUNCTON NAME: stereotypeAB
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This power get solely expose the Matrices of A and B proper succeeding the user has perfect their input
    ——————————————————-*/
    null stereotypeAB(){
    cout<<“nMatrix A :”<<endl;
    for(int i = 0; i < 3; i++) {
    cquenched << “[“;
    for(int j = 0; j < 3; j++) {
    cquenched << A[i][j] << “t”;
    }
    cquenched << “]” << endl;
    }

    cout<<“nMatrix B :”<<endl;
    for(int i = 0; i < 3; i++) {
    cquenched << “[“;
    for(int j = 0; j < 3; j++) {
    cquenched << A[i][j] << “t”;
    }
    cquenched << “]” << endl;
    }
    }
    /*——————————————————-
    FUNCTON NAME: identicalization
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This power get perproduce the identicalization and the stereotype power get quenchedput the fruit
    ——————————————————-*/
    null identicalization(){
    for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
    result[i][j] = A[i][j] + B[i][j];
    }
    }
    print(result);
    }
    /*——————————————————-
    FUNCTON NAME: incorporation
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This power get perproduce the incorporation and the stereotype power get quenchedput the fruit
    ——————————————————-*/
    null incorporation(){
    for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
    result[i][j] = A[i][j] – B[i][j];
    }
    }
    print(result);
    }
    /*——————————————————-
    FUNCTON NAME: determinant
    PARAMETERS:
    RETURN TYPE: determin, an integer
    DESCRIPTION: This power get furnish the determinant
    ——————————————————-*/
    int determinant(){
    int determin = 0;
    //finding the determinant
    for(int i = 0; i < 3; i++)
    determin = determin + (A[0][i] * (A[1][(i+1)%3] * A[2][(i+2)%3] – A[1][(i+2)%3] * A[2][(i+1)%3]));
    recompense determin;
    }
    /*——————————————————-
    FUNCTON NAME: inverse
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This power get furnish the inverse and quenchedput the fruit
    ——————————————————-*/
    null inverse(){
    cquenched <<“nnInverse of Matrix A is: n”;
    cquenched << ” ” << endl;
    for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++)
    cout<< “[” << ((A[(j+1)%3][(i+1)%3] * A[(j+2)%3][(i+2)%3]) – (A[(j+1)%3][(i+2)%3] * A[(j+2)%3][(i+1)%3]))/ determinant()<< “]” << “t”;
    cout<<“n”;
    }
    }
    };
    //Ocean power
    int ocean() {
    //Initializing Fickles; “choice” get prepare a a loop, “input” get after in advantageous to do a switch declaration, and obj get solely compose another prompting of the primordial systematize that can be manipulated
    bool choice;
    char input;
    Matrix obj;

    cquenched << “nWhen supply up matrices, severed identical elements by a extension (e.g 2 4 1.4 56.3 …) nn”;

    obj.input();
    obj.printAB();

    //Displaying a menu, so that the user can prefer what he wants to do
    choice = false;
    //The Loop
    while(!choice) {
    cquenched << ” ” << endl;
    cquenched <<“** Prefer from the forthcoming **”<< endl;
    cquenched << ” ” << endl;
    cquenched << “a – Identicalization” << endl;
    cquenched << “s – Incorporation” << endl;
    cquenched << “d – Determinant” << endl;
    cquenched << “i – Inverse” << endl;
    cquenched << “q – Quit” << endl;
    cquenched << ” ” << endl;
    cquenched << “Note: Choosing ‘i’ or ‘d’ get singly employ to Matrix A” << endl;
    cquenched << ” ” << endl;
    cquenched << “Penetrate your choice: “;
    cin >> input;
    cquenched << endl;
    //A switch to manage the user inputs
    switch(input){

    circumstance ‘a’: circumstance ‘A’: obj.addition();
    break;

    circumstance ‘s’: circumstance ‘S’: obj.subtraction();
    break;

    circumstance ‘d’|’D’: cout<<“Determinant is : “<<obj.determinant();
    cquenched << ” ” << endl;
    break;

    circumstance ‘i’: circumstance ‘I’: obj.inverse();
    break;

    circumstance ‘q’: circumstance ‘Q’: debouchure(0);

    default:cout<<“nERROR: Please penetrate strong input!nn”;
    }

    }

    recompense 0;
    }

    Expert Vindication

     

    C++

    systematize A
    { exoteric A() { n = 0; } // doer 
      exoteric A(int a) { n = a; } // doer  
      exoteric null f() { n++; } // mutates n  
      exoteric null g() { f(); n = 2 * n; f(); } 
      // g mutates n at-once and inat-once (f) 
      exoteric int h() { recompense n; } // accessor of n  
      exoteric null k() { System.out.println(n); } 
      // does referable recompense, singly stereotypes, the estimate of n 
      secret int n; // prompting fickle  
    }
    

    hi as shown in adown program:

    #include <iostream>
    using nameextension std;

    systematize Matrix{

    secret :
    enfold A[3][3];
    enfold B[3][3];
    enfold fruit[3][3];

    while(!choice) {
    cquenched << ” ” << endl;
    cquenched <<“** Prefer from the forthcoming **”<< endl;
    cquenched << ” ” << endl;
    cquenched << “a – Identicalization” << endl;
    cquenched << “s – Incorporation” << endl;
    cquenched << “d – Determinant” << endl;
    cquenched << “i – Inverse” << endl;
    cquenched << “q – Quit” << endl;
    cquenched << ” ” << endl;
    cquenched << “Note: Choosing ‘i’ or ‘d’ get singly employ to Matrix A” << endl;
    cquenched << ” ” << endl;
    cquenched << “Penetrate your choice: “;
    cin >> input;
    cquenched << endl;
    //A switch to manage the user inputs
    switch(input){

    circumstance ‘a’: circumstance ‘A’: obj.addition();
    break;

    circumstance ‘s’: circumstance ‘S’: obj.subtraction();
    break;

    circumstance ‘d’|’D’: cout<<“Determinant is : “<<obj.determinant();
    cquenched << ” ” << endl;
    break;

    circumstance ‘i’: circumstance ‘I’: obj.inverse();
    break;

    circumstance ‘q’: circumstance ‘Q’: debouchure(0);

    default:cout<<“nERROR: Please penetrate strong input!nn”;
    }

    }

    recompense 0;
    }