Home > Back-end >  Imperfect C program won't run, have the people help change
Imperfect C program won't run, have the people help change

Time:09-30

1: define two two-dimensional array is used to store matrix
2: input/output: input with operation of two matrices, the output result
Add: 3: matrix determine whether two matrices can be combined, such as, calculating the sum of two matrices, and the result output
4, 5 by reduction condition with 3
6, the number of matrix and multiplication: enter the Numbers, matrix and the number of each product, as a result, the output
7: matrix transpose: calculate each matrix transpose, result output
#include
3 # define R
using namespace std;
The class Matrix
{
Public:
int i,j;
Matrix (int a);
Friend Matrix operator + (Matrix & amp; a);
Friend Matrix operator - (Matrix & amp; a);
Friend Matrix operator * (Matrix & amp; a);
Friend Matrix shucheng (Matrix & amp; a);
Friend Matrix zhuanzhi (Matrix & amp; a);
Private:
Int p [R] [R].
};
Matrix: : Matrix ()
{
for(int i=0; i{
for(int j=0; jP [I] [j]=0;
}
}
Matrix& Matrix: : operator + (Matrix & amp; A)
{
Matrix c;
{
for(int i=0; i{
for(int j=0; jC.p [I] [j]=p + Amy polumbo [I] [j] [I] [j];
return c;
}
}
}
Matrix& Matrix: : operator - (Matrix & amp; A)
{
Matrix c;
For (int I=0; i{
For (int j=0; j{
C.p [I] [j]=p [I] [j] - Amy polumbo [I] [j];
return c;
}
}
}

Matrix& Matrix: : operator * (Matrix & amp; A)
{
Matrix c;
For (int I=0; i {
For (int j=0; J & lt; R; J++)
{
For (int k=0; KC.p [I] [j]=p [I] [k] * Amy polumbo [k] [j];
return c;
}
}
}
Matrix& Matrix: : shucheng (Matrix & amp; A)
{
Int b;
For (int I=0; i {
For (int j=0; J & lt; R; + + j)
{
C.p [I] [j]=b * Amy polumbo [I] [j];
return c;
}
}
}
Matrix Matrix: : zhuanzhi (Matrix & amp; A)
{
Matrix m, n;
M=a;
For (int I=0; i {
For (int j=0; J & lt; R; + + j)
Nancy (polocy) pelosi [I] [j]=m.p [I] [j];
Return n.
}
}
Int main ()
{
Matrix a, b, c, d, f, e, g, X, k;
A, b, c, d, e, f, g;
cin> A;
cin> b;
C=a + b;
D=a - b;
E=a * b;
F=X * a;
G=X * b;
Cout<& lt; Endl<" Matrix a is: "& lt; CoutCoutCoutCout<" The sum of two matrices A and B is: "& lt; CoutCout<" Type A, B, the difference between the two matrices is: "& lt; CoutCout<" Product of two matrices A, B: "& lt; CoutCout<" Matrix A and number multiplication is: "& lt; CoutCout<" Matrix B and number multiplication is: "& lt; CoutCoutCout<Cout<" Matrix A2 transposed to: "& lt; Cout<return 0;
}

  • Related