Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Since no one answered my C++ question, i will ask again Please this is urgent!! **Help me fix my code, the code that I made

Since no one answered my C++ question, i will ask again

Please this is urgent!!

**Help me fix my code, the code that I made is not following the instructions given to us. (I'll put the instruction bellow)

Source Code:

/* Program to read 2 files and store data into 2 matrices Display 2 matrces Do add/sub/mul operation Take filenames and operation as input Display operation result */ #include #include #include using namespace std; //Function prototypes void printMatrix(int* matrix[], int row, int col); void matrixAdd(int* matrix1[], int* matrix2[],int row1, int col1,int row2,int col2); void matrixSub(int* matrix1[], int* matrix2[], int row1, int col1, int row2, int col2); void matrixMul(int* matrix1[], int* matrix2[], int row1, int col1, int row2, int col2); int main() { //Matrix storage arrays int **mat1=0, **mat2=0; //Row column sizes int row1, col1,row2,col2; //Read filename names and operation string filename1, filename2, operation; //Read inputs cin >> filename1 >> filename2 >> operation; //File read objects ifstream in1, in2; in1.open(filename1); in2.open(filename2); //Error check in file open if (!in1 || !in2) { cout > row1; in1>> col1; mat1 = new int*[row1]; for (int i = 0; i >mat1[i][j]; } } in1.close(); //Display first matrix cout > row2; in2 >> col2; mat2 = new int*[row2]; for (int i = 0; i > mat2[i][j]; } } in2.close(); //Display second matrix cout

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

Instructions

image text in transcribed

image text in transcribed

Please do update the code and if ever, add implementation just to reach the requirements

Matrix Arithmetic C++ 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 should have command line mode and interactive mode The program never should 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 allows the user to specify two matrices, A and B from files. Both matrices are initialized as 1x1 matrices containing O's at the start. Matrix data for a matrix with mrows and n columns are encoded in a text file as follows: 21,1 a 1,2 ... 21,n optional comments a21 a 2,2... az,n optional comments am 1 am, 2 ... am,n optional comments optional comments 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. Note: Write modular code. Matrix Arithmetic C++ 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 should have command line mode and interactive mode The program never should 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 allows the user to specify two matrices, A and B from files. Both matrices are initialized as 1x1 matrices containing O's at the start. Matrix data for a matrix with mrows and n columns are encoded in a text file as follows: 21,1 a 1,2 ... 21,n optional comments a21 a 2,2... az,n optional comments am 1 am, 2 ... am,n optional comments optional comments 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. Note: Write modular code

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions