Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program Matrix Arithmetic URGENT NEED ANSWER TODAY HELP ME FIX MY PROGRAM TO FOLLOW THE INSTRUCTIONS BELOW Program: Allows the user to add, subtract

C++ Program Matrix Arithmetic

URGENT NEED ANSWER TODAY

HELP ME FIX MY PROGRAM TO FOLLOW THE INSTRUCTIONS BELOW

Program: Allows the user to add, subtract and multiply of floating point matrices. It will be read from text files. Results will be written to text files. Put comments of the code.

The program allows the user to specify two matrices, A and B from files. Both matrices are initialized as 1x1 matrices containing 0s at the start.

Each row of the matrix is encoded in a separate line. The number of floating point numbers that could be extracted in sequence from the first line of the file determines the number of columns of the matrix. The numbers in a row are separated from each other by one or more white spaces. The row ends if either the end of the line has been reached or the next item on the line cannot be interpreted as a valid floating point number.

The number of rows of the matrix is determined from the number of lines, following the first line of the file, from which it is possible to extract the required number of floating point numbers (equal to the number of columns determined from the first line of the file).

The application implements a program loop, where each iteration of the loop consists of the following actions, in sequence:

* the properties of A and B are displayed

* the options available are displayed

* the user is prompted for a choice

* if the choice is valid, it is implemented

* feedback regarding the outcome of implementing the choice is displayed

Never clear the screen. Previous interactions between the application and the user must remain visible, except that the screen should be cleared if there is an option to clear the screen and the users avails of that option.

It is sufficient to display the dimensions of A and B when displaying their properties.

There must be options that allow the user to do the following:

* have new values for A imported from a file

* have new values for B imported from a file

* compute A+B

* compute A-B

* compute AB

* compute BA

* export the latest valid computation to a matrix file specified by the user

* terminate the application

Display only options that are valid. Do not display options for addition and subtraction if the two matrices cannot be added. Do not display options for computing a product if the product is not defined. Matrix files produced by the application should encode valid matrices that could be imported into either A or B.

A matrix retains its previous value if a request is made to replace it with a value that turns out to be invalid. For instance, the first line of a file might not contain anything that could be interpreted as being the first row of a matrix.

FEATURES THAT IS STRICTLY REQUIRED: **Write modular code.

**The program should have command line mode and interactive mode

**The program should never stop, goes into an infinite loop, crashes, nor hangs on any input, whether valid or invalid, except that the user may stop the application intentionally.

**The program will ask for two files (A and B) and will show the result (there should be another file made for result)

************************************************************

************************************************************

SOURCE CODE TEMPLATE (STRICTLY REQUIRED TO USE)

#include #include #include #include #include #include #include #include #include #include #include #include #include

using namespace std;

vector> add(const vector> & matrA, const vector> & matrB) { }

vector> subtract(const vector> & matrA, const vector> & matrB) { }

vector> multiply(const vector> & matrA, const vector> & matrB) { }

int choices(vector>& matrA, vector>& matrB, vector>& reset, char& choice, char& choiceToPrint, int& rowsA, int& rowsB, int& colsA, int& colsB) { // Put here all choices (operations, change matrix, save to external file, and exit) }

int choicesNotEqual(vector>& matrA, vector>& matrB, char& choice, int& rowsA, int& rowsB, int& colsA, int& colsB) { // kapag hindi equal yung rows and columns ng matrix A at B, choices:(change matrix A, change matrix B, exit) }

void printerA(ifstream& fileA, vector>& matrA, string tempstr, int tempint, int& rowsA, int& colsA) { // for printing matrix A to command prompt }

void printerB(ifstream& fileB, vector>& matrB, string tempstrB, int tempintB, int& rowsB, int& colsB) { // for printing matrix B to command prompt }

int main(int argc, char ** argv) { vector> reset; //File A string A=argv[1]; vector> matrA;

ifstream fileA(A);

if(!fileA.is_open()) { cout << "Cannot open File A" << endl; } else { printerA(fileA, matrA, tempstr, tempint, rowsA, colsA); }

fileA.close(); //End of File A

//File B string B=argv[2]; vector> matrB; ifstream fileB(B);

if(!fileB.is_open()) { cout << "Cannot open File B" << endl; } else { printerB(fileB, matrB, tempstrB, tempintB, rowsB, colsB); }

fileB.close(); //End of File B

while(choice!='h') { //loop the function "choice" here // 'h' for exit }

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

1.what is the significance of Taxonomy ?

Answered: 1 week ago

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago

Question

Name is needed for identifying organisms ?

Answered: 1 week ago