Home > Back-end >  O great god see operator * function that wrong
O great god see operator * function that wrong

Time:09-23

#include
using namespace std;
The class Matrix {
Private:
Int N;
Int * * matrix;
Public:
Matrix ();
~ Matrix ();
Matrix (int);
Void init ();
Void unit ();
Void the display ();
Matrix& The operator + (Matrix&);
Matrix& The operator * (Matrix & amp;);
Matrix& The Mul (Matrix& , int);//matrix and power
};
Matrix: : Matrix () {N=0; }
Matrix: : ~ Matrix () {
int i;
for(i=0; iThe delete [] matrix [I];
The delete [] matrix;
}
Matrix: : Matrix (int n) (n=n;
Matrix=new int * [N].
int i;
for(i=0; iMatrix [I]=new int [N].
Int j;
for(i=0; ifor(j=0; jMatrix [I] [j]=0;
}
Void Matrix: : unit () {
int i,j;
for(i=0; ifor(j=0; jIf (I==j)
Matrix [I] [j]=1;
}
Void Matrix: : init () {
Int the row, col.
For (row=0; RowFor (col=0; ColCout<& lt;" Type "& lt; & lt;" (" & lt; cin> Matrix [row] [col];
}
}
Matrix& Matrix: : operator * (Matrix & amp; X) {
Int the row, col.
Int sum;
Matrix m (N);
For (row=0; RowFor (col=0; Colint i;
sum=0;
for(i=0; iSum=(sum + matrix [row] [I] * x.m atrix [I] [col]) % 256;
M.m atrix [row] [col]=sum;
}
X=m;//error ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
return x;
}
Matrix& Matrix: : the Mul (Matrix& X, int n) {
Int bri [1000].
int count=0;
While (n!=0) {
Bri (count)=n % 2;
N=n/2;
Count++;
}
Matrix m (N);
M.u nit ();
For (int I=count - 1; I> - 1; I -) {
M=m * m.
If (bri [I]==1)
M=m * x;
}

X=m;
return x;
}
Void Matrix: : display () {
int i,j;
for(i=0; ifor(j=0; jCout<& lt;" "<& lt; Matrix [I] [j];
}
Cout<& lt; Endl;
}
}
Matrix& Matrix: : operator + (Matrix& X) {
int i,j;
Matrix m (N);
for(i=0; iFor (j=0; jM.m atrix [I] [j]=matrix [I] [j] + x.m atrix [I] [j];
X=m;
return x;
}
Int main () {
int n;
Cout<& lt;" Input matrix order "& lt; cin> n;
Matrix N (N);
N.i nit ();
Cout<& lt;" The input power & lt; "" cin> n;
Matrix K (n);
K=N.M ul (N, N);
Cout<& lt;" For the matrix of: "& lt; K.d isplay ();
return 0;
}


  • Related