mak23101991
Active Member
Matrix Addition
Problem Statement:
Develop a program to add two matrices. Program should accept input matrices to be added via files.
Absolute path of these file should be accepted through a command line argument.
The file format of the input files is described below. Your program should parse the input files and construct the input matrices.
In case of a bad input, program should output appropriate message as mentioned in output specification below.
Once the matrices are formed, apply appropriate logic to see if addition is possible.
If addition is possible, add the input matrices and output the result in format specified below.
Sample Output:
How to code this Please Help
Thanx in advance
Problem Statement:
Develop a program to add two matrices. Program should accept input matrices to be added via files.
Absolute path of these file should be accepted through a command line argument.
The file format of the input files is described below. Your program should parse the input files and construct the input matrices.
In case of a bad input, program should output appropriate message as mentioned in output specification below.
Once the matrices are formed, apply appropriate logic to see if addition is possible.
If addition is possible, add the input matrices and output the result in format specified below.
Code:
Information:
Matrix addition is the operation of adding two matrices that in turn produces resultant third matrix which is a sum of the two input matrices.
Code:
File Format
Each row is delimited by new line character
Columns within each row are space delimited
e.g.
A 3x3 matrix will be represented in the file as :
1 2 3
4 5 6
7 8 9
Code:
Input Format
Line 1 Absolute path of the first input file
Line 2 Absolute path of the second input file
Code:
Output
1. Input matrices which are inserted
2. Resultant matrix or appropriate error message
Code:
matrix1.txt :
3 3 1
5 9 2
6 4 2
matrix2.txt:
2 1 1
1 5 5
3 8 9
Input Matrix 1 :
3 3 1
5 9 2
6 4 2
Input Matrix 2 :
2 1 1
1 5 5
3 8 9
Valid Matrix dimensions for addition.
5 4 2
6 14 7
9 12 11
Code:
matrix1.txt :
7 3 1
7 2 5
2 6 4
matrix2.txt :
2 1
1 5
3 8
Input Matrix 1 :
7 3 1
7 2 5
2 6 4
Input Matrix 2 :
2 1
1 5
3 8
Invalid Matrix dimensions for addition.
Cannot add matrix of dimensions 3 with 3x2
Code:
matrix1.txt :
9 4 8
2 3 7
9 2 1
matrix2.txt :
1 2 3
4 5 6
1 ? 3
INVALID INPUT
Code:
matrix1.txt:
a b c
d e f
g h i
matrix2.txt:
2 8 5
8 5 2
0 2 4
INVALID INPUT
Thanx in advance