Question
C++ Program Matrix Arithmetic URGENT NEED ANSWER TODAY THIS IS THE 9TH TIME IM POSTING THIS QUESTION DO NOT GIVE ME THE SAME ANSWER BECAUSE
C++ Program Matrix Arithmetic
URGENT NEED ANSWER TODAY
THIS IS THE 9TH TIME IM POSTING THIS QUESTION
DO NOT GIVE ME THE SAME ANSWER BECAUSE IT DOESNT MEET THE REQUIREMENT
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
PLEASE DO FOLLOW THE INSTRUCTIONS ABOVE SINCE THIS PROGRAM IS NOT COMPLETE AND IS WRONG
DO NOT GIVE ME THIS SOURCE CODE AS ANSWER SINCE SEVERAL EXPERTS ANSWERED ME THIS BUT THIS DOENT MEET THE REQUIREMENTS GIVEN
PLEASE DO HELP ME
#include
//Creating file to append the results ofstream file("Result.txt"); //Creating Add function to add two matrices void Add(float A[][3], float B[][3]) { float C[3][3]; int i, j; for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) C[i][j] = A[i][j] + B[i][j];
//Displaying values after adding cout<<" Addtion of the two float matrices (A+B) "; //Writing into file file<<" Addtion of the two float matrices (A+B) "; for(int i=0;i<3;i++) { for(int j=0;j<3;j++){ cout< } //Creating Subtract function to subtract two matrices void Subtract(float A[][3], float B[][3]) { float C[3][3]; int i, j; for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) C[i][j] = A[i][j] - B[i][j]; //Displaying values after adding cout<<" Subtraction of the two float matrices (A-B) "; file<<" Subtraction of the two float matrices (A+B) "; for(int i=0;i<3;i++) { for(int j=0;j<3;j++){ cout< file< } cout< } //Multiply function void multiply(float mat1[][3],float mat2[][3]) { int x, i, j; float res[3][3]; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { res[i][j] = 0; for (x = 0; x < 3; x++) { *(*(res + i) + j) += *(*(mat1 + i) + x) * *(*(mat2 + x) + j); } } } cout<<"After multiplying : "; file<<"After multiplying : "; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { cout << *(*(res + i) + j) << " "; file<<*(*(res + i) + j) << ",\t"; } cout << " "; file< int main() { fstream fs; fs.open("matrix.txt",ios::in); vector float A[18]; int iterate=0; for(auto iter:floatVec){ int col=0; for(auto k:iter) { //Adding values A[iterate]=k; iterate++; } } //now separating the values into two array float arr1[3][3],arr2[3][3]; int i=0; //Appending values in arr1 for(int row=0;row<3;row++) for(int col=0;col<3;col++) {arr1[row][col]=A[i]; i++;} //Appending values in arr2 for(int row=0;row<3;row++) for(int col=0;col<3;col++) {arr2[row][col]=A[i]; i++;} //Calling the functions Add(arr1,arr2); Subtract(arr1,arr2); cout<<" Multiplying A*B: "; multiply(arr1,arr2); //Changing the parameter cout<<" Multiplying B*A: "; multiply(arr2,arr1); file.close(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started