Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[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

[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 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, ' '); cerr << " ERROR: Please enter valid input! " << 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, ' '); cerr << " ERROR: Please enter valid input! " << 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<<" Matrix A :"<

cout<<" Matrix B :"<

cout << " When filling up matrices, separate individual elements by a space (e.g 2 4 1.4 56.3 ...) ";

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 : "<

}

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions