矩阵运算
设计要求:设计一个矩阵类
实现矩阵的求逆。转置
实现矩阵的加减乘除
我的QQ是331346263
帮忙的贵人请联系我```手机13721400445 28号要上交````
基础的东西最好自己动手写一写 ...
#include<iostream>
#include<iomanip>
using namespace std;enum { N=4 };
class matrix;
matrix operator + (matrix& x1,matrix& x2);class matrix
{
int a[N][N];
public:
matrix(int n = 0);
void reverse_matrix(); //顺时针逆转
void show_matrix();
friend matrix operator + (matrix& x1, matrix& x2); //矩阵加法
};
matrix::matrix(int n)
{
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
a[i][j] = n++;
}
void matrix::reverse_matrix()
{
int i, j, b[N][N];
for(i=0; i<N; i++)
for(j=0; j<N; j++)
b[j][N-i-1] = a[i][j];for(i=0; i<N; i++)
for(j=0; j<N; j++)
a[i][j] = b[i][j];
}void matrix::show_matrix()
{
for(int i=0; i<N; i++,cout<<endl)
for(int j=0;j<N;j++)
cout<<setw(4)<<a[i][j];
cout<<endl;
}matrix operator + (matrix& x1, matrix& x2)
{
matrix sum;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
sum.a[i][j] = x1.a[i][j] + x2.a[i][j];
return sum;
}int main()
{
matrix x1(1);//矩阵1
x1.show_matrix();
x1.reverse_matrix();//逆转矩阵1
x1.show_matrix();
matrix x2(2);//矩阵2
x2.show_matrix();
(x1+x2).show_matrix();//相加return 0;
}