Homework Solution: I need to write a class that is derived from and has a base the class of HW. 1 to solve 3×3 system…

    [C++] I need to write a class that is derived from and has a base the class of HW. 1 to solve 3x3 systems of equations (3 equations with 3 unknowns.). Since it says derived, I am assuming it means inheritance. Here's the link to the code (HW.1): https://repl.it/KhHC/12 #include 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 :"< 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 :"< 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 : "< 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; } alternatively,

    Expert Answer

     
    #include <iostream> using namespace std;

    [C++]

    I want to transcribe a tabulate that is conservative from and has a low the tabulate of HW. 1 to reresolve 3×3 systems of equations (3 equations with 3 unknowns.). Since it says conservative, I am stately it resources possession. Here’s the cohere to the legislation (HW.1):

    #include

    using nameextension std;

    tabulate Matrix{

    private :
    embrace A[3][3];
    embrace B[3][3];
    embrace development[3][3];

    public :
    /*——————————————————-
    FUNCTON NAME: input
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: Stores user values internally the similar decorates to be referenced later
    ——————————————————-*/
    void input(){

    cextinguished << “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 capacity on fall-shorture
    if(cin.fail()) {
    cin.clear();
    cin.ignore(100, ‘n’);
    cerr << “nERROR: Please invade substantial input!n” << endl;
    }
    }
    }

    cextinguished << “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 capacity on fall-shorture
    if(cin.fail()) {
    cin.clear();
    cin.ignore(100, ‘n’);
    cerr << “nERROR: Please invade substantial input!n” << endl;
    }
    }
    }
    }
    /*——————————————————-
    FUNCTON NAME: imprint
    PARAMETERS: development
    RETURN TYPE: achieve extinguishedput the developments of the decorate calculation
    DESCRIPTION: This capacity achieve imimimimsculpture extinguished the developments from the disjunction and restoration capacity
    ——————————————————-*/
    void imprint(embrace development[3][3]){
    for(int i = 0; i < 3; i++) {
    cextinguished << “[“;
    for(int j = 0; j < 3; j++) {
    cextinguished << development[i][j] << “t”;
    }
    cextinguished << “]” << endl;
    }
    }
    /*——————————————————-
    FUNCTON NAME: imprintAB
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This capacity achieve solely ostentation the Matrices of A and B suitable behind the user has high their input
    ——————————————————-*/
    void imprintAB(){
    cout<<“nMatrix A :”< control(int i = 0; i < 3; i++) {
    cextinguished << “[“;
    for(int j = 0; j < 3; j++) {
    cextinguished << A[i][j] << “t”;
    }
    cextinguished << “]” << endl;
    }

    cout<<“nMatrix B :”< control(int i = 0; i < 3; i++) {
    cextinguished << “[“;
    for(int j = 0; j < 3; j++) {
    cextinguished << A[i][j] << “t”;
    }
    cextinguished << “]” << endl;
    }
    }
    /*——————————————————-
    FUNCTON NAME: restoration
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This capacity achieve discharge the restoration and the imimimimsculpture capacity achieve extinguishedput the development
    ——————————————————-*/
    void restoration(){
    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: disjunction
    PARAMETERS:
    RETURN TYPE:
    DESCRIPTION: This capacity achieve discharge the disjunction and the imimimimsculpture capacity achieve extinguishedput the development
    ——————————————————-*/
    void disjunction(){
    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 capacity achieve experience 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 capacity achieve experience the inverse and extinguishedput the development
    ——————————————————-*/
    void inverse(){
    cextinguished <<“nnInverse of Matrix A is: n”;
    cextinguished << ” ” << 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 capacity
    int ocean() {
    //Initializing Variables; “choice” achieve inaugurate a a loop, “input” achieve end in suited to do a switch declaration, and obj achieve solely compose another solicitation of the primary tabulate that can be manipulated
    bool choice;
    char input;
    Matrix obj;

    cextinguished << “nWhen satisfaction up matrices, disjoined idiosyncratic 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) {
    cextinguished << ” ” << endl;
    cextinguished <<“** Prefer from the cethcoming **”<< endl;
    cextinguished << ” ” << endl;
    cextinguished << “a – Restoration” << endl;
    cextinguished << “s – Disjunction” << endl;
    cextinguished << “d – Determinant” << endl;
    cextinguished << “i – Inverse” << endl;
    cextinguished << “q – Quit” << endl;
    cextinguished << ” ” << endl;
    cextinguished << “Note: Choosing ‘i’ or ‘d’ achieve barely allot to Matrix A” << endl;
    cextinguished << ” ” << endl;
    cextinguished << “Invade your choice: “;
    cin >> input;
    cextinguished << endl;
    //A switch to feel the user inputs
    switch(input){

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

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

    subject ‘d’|’D’: cout<<“Determinant is : “< cextinguished << ” ” << endl;
    break;

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

    subject ‘q’: subject ‘Q’: egress(0);

    default:cout<<“nERROR: Please invade substantial input!nn”;
    }

    }

    return 0;
    }

    alternatively,

    Expert Defense

     

    #include <iostream>
    using nameextension std;
    tabulate Matrix
    {
    embrace A[3][3];
    embrace B[3][3];
    embrace development[3][3];
    public :

    // Compose a order control input matrix imimimimsculpture matrix, infer,subtract, determinant and inverse
    // here in tabulate we composed a funtion and tool in tabulate
    void input();
    void imprint(double[3][3]);
    void imprintAB();
    void restoration();
    void disjunction();

    // You can so persuade the fuction love that if you want
    int determinant(){
    embrace 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;
    }

    void inverse()
    {
    cextinguished <<“nnInverse of Matrix A is: n”;
    cextinguished << ” ” << 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”;
    }
    }
    };
    void Matrix::input()
    {
    cextinguished << “Input 9 elements into your 3×3 matrix A: “<< endl;

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

    cextinguished << “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 capacity on fall-shorture
    if(cin.fail()) {
    cin.clear();
    cin.ignore(100, ‘n’);
    cerr << “nERROR: Please invade substantial input!n” << endl;
    }
    }
    }
    }
    void Matrix::print(embrace development[3][3])
    {
    for(int i = 0; i < 3; i++)
    {
    cextinguished << “[ “;
    for(int j = 0; j < 3; j++) {
    cextinguished << development[i][j] << “t”;
    }
    cextinguished << “]” << endl;
    }

    }
    void Matrix::printAB()
    {
    cout<<“nMatrix A :”<<endl;
    for(int i = 0; i < 3; i++) {
    cextinguished << “[“;
    for(int j = 0; j < 3; j++) {
    cextinguished << A[i][j] << “t”;
    }
    cextinguished << “]” << endl;
    }

    cout<<“nMatrix B :”<<endl;
    for(int i = 0; i < 3; i++) {
    cextinguished << “[“;
    for(int j = 0; j < 3; j++) {
    cextinguished << A[i][j] << “t”;
    }
    cextinguished << “]” << endl;
    }
    }

    void Matrix::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);
    }

    void Matrix::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);
    }

    int ocean()
    {
    //Initializing Variables; “choice” achieve inaugurate a a loop, “input” achieve end in suited to do a switch declaration, and obj achieve solely compose another solicitation of the primary tabulate that can be manipulated
    bool choice;
    char input;
    Matrix obj;

    cextinguished << “nWhen satisfaction up matrices, disjoined idiosyncratic 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) {
    cextinguished << ” ” << endl;
    cextinguished <<“** Prefer from the cethcoming **”<< endl;
    cextinguished << ” ” << endl;
    cextinguished << “a – Restoration” << endl;
    cextinguished << “s – Disjunction” << endl;
    cextinguished << “d – Determinant” << endl;
    cextinguished << “i – Inverse” << endl;
    cextinguished << “q – Quit” << endl;
    cextinguished << ” ” << endl;
    cextinguished << “Note: Choosing ‘i’ or ‘d’ achieve barely allot to Matrix A” << endl;
    cextinguished << ” ” << endl;
    cextinguished << “Invade your choice: “;
    cin >> input;
    cextinguished << endl;
    //A switch to feel the user inputs
    switch(input){

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

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

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

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

    subject ‘q’: subject ‘Q’: egress(0);

    default:cout<<“nERROR: Please invade substantial input!nn”;
    }

    }

    return 0;
    }