#include "stdafx.h"
#include
using namespace std;
class Matrix //rows行cols列整型矩阵
{
public:
Matrix(int r = 0, int c = 0);
~Matrix(){};
void Input();
void Output();
Matrix operator+ (Matrix&);
private:
int rows;
int cols;
int **n;
};
Matrix::Matrix(int r, int c)
{
rows = r;
cols = c;
n = new int *[rows];
for (int i = 0; i < rows; i++)
n[i] = new int[cols];
}
void Matrix::Input()
{
for (int i = 0; i < rows;i++)
for (int j = 0; j < cols;j++)
cin >> n[i][j];
}
void Matrix::Output()
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
cout << n[i][j] << " ";
cout << endl;
}
}
Matrix Matrix::operator + (Matrix& x)
{
Matrix tem(rows, cols);
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
tem.n[i][j] = n[i][j] + x.n[i][j];
return tem;
}
int main(int argc, char* argv[])
{
Matrix A(3, 3), B(3, 3),C(3, 3);
cout<<"请输入第一个3*3矩阵:"<
cout<<"请输入第二个3*3矩阵:"<
C = A + B;
cout<<"\n两个矩阵求和的结果为:"<
return 0;
}
Matrix(int m, int n); virtual ~Matrix(); int getValue(int i, int j) const; void setValue(int i, int j, int v); bool operator=(const,