#ifndef _MATRIX_H
#define _MATRIX_H

class Matrix
{
    
private:
       
int     row;    // 矩阵的行数
        int     col;    // 矩阵的列数
        int     n;      // 矩阵元素个数
        double*    mtx; // 动态分配用来存放数组的空间
    public:
        Matrix(
int row=1int col=1);             // 带默认参数的构造函数
        Matrix(int row, int col, double mtx[]);    // 用数组创建一个矩阵
        Matrix(const Matrix &obj);                 // copy构造函数
       ~Matrix() { delete[] this->mtx; }        

        
void    print()const;                     // 格式化输出矩阵
        int     getRow()const { return this->row; }// 访问矩阵行数
        int     getCol()const { return this->col; }// 访问矩阵列数
        int     getN()const   { return this->n;   }// 访问矩阵元素个数
        double* getMtx()const { return this->mtx; }// 获取该矩阵的数组
        
        
// 用下标访问矩阵元素
        double     get(const int i, const int j)const
        
// 用下标修改矩阵元素值
        void     set(const int i, const int j, const double e); 

        
// 重载了一些常用操作符,包括 +,-,x,=,负号,正号,
        
// A = B
        Matrix &operator= (const Matrix &obj);
        
// +A
        Matrix  operator+ ()const { return *this; }
        
// -A
        Matrix  operator- ()const;
        
// A + B
        friend  Matrix  operator+ (const Matrix &A, const Matrix &B);
        
// A - B
        friend  Matrix  operator- (const Matrix &A, const Matrix &B);
        
// A * B 两矩阵相乘
        friend  Matrix  operator* (const Matrix &A, const Matrix &B);
        
// a * B 实数与矩阵相乘
        friend  Matrix  operator* (const double &a, const Matrix &B);
        
// A 的转置
        friend  Matrix  trv(const Matrix &A);
        
// A 的行列式值,采用列主元消去法
        
// 求行列式须将矩阵化为三角阵,此处为了防止修改原矩阵,采用传值调用
        friend  double  det(Matrix A);
        
// A 的逆矩阵,采用高斯-若当列主元消去法
        friend  Matrix  inv(Matrix A);
};
#endif        

矩阵计算程序实现
矩阵计算程序#include
<iostream.h>
矩阵计算程序#include
<math.h>                
矩阵计算程序#include
<stdlib.h>                
矩阵计算程序#include
<iomanip.h>             
矩阵计算程序#include
"matrix.h"
矩阵计算程序
矩阵计算程序
// 带默认参数值的构造函数
矩阵计算程序
// 构造一个row行col列的零矩阵
inv()

相关文章: