Answered Essay: To answer to a comment, the code is not already implemented. The code does not s

To answer to a comment, the code is not already implemented. The code does not solve 3×3 systems. It lacks the “ability” to do row reduced echelon calculations or Gauss Jordan elimination (it’s the same thing, here’s a link that explains it http://pages.pacificcoast.net/~cazelais/251/gauss-jordan.pdf)

The code that I posted simply provides the basis. You have to write a class that inherits from my class, so it gets the Matrix information that the user puts in, afterward the new class that you write will implement the Gaus Jordan calculation. I hope this clears up the confusion

[C++]I need to write a class that solves 3×3 systems of equations (3 equations with 3 unknowns). (This is about Matrices reduced to row echelon form).

If you do don’t know how to do this, please, don’t answer this question! If anything is unclear just comment, and I will try to clear up the confusion.

Additionally, 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)

This is important so that it has access to the Matrix information. Here’s the link to my code:

Essentially, it just needs to get expanded with another class that inherits from the first one to do the row echelon calculation.

#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 3×3 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 3×3 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;
}

Expert Answer

#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 3×3 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 3×3 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;
}

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?