C++ 实验一

一、CMatrix类代码

----- 1. 成员变量

private:
    int m_nRow ;
    int m_nCol ;
    double * m_pData ;

----- 2. 头文件

#ifndef CMATRIX_H
#define CMATRIX_H
#include<iostream>
#include<assert.h>
using namespace std;

class CMatrix
{
   
public:
	//构造方法
    CMatrix(); //无参构造
    CMatrix(int nRow, int nCol, double* pData);  //有参构造
    CMatrix(const char *strPath);  //外部数据流构造函数
    CMatrix(const CMatrix &m);  //拷贝构造函数
    
    //对象函数
    bool create(int nRow, int nCol, double* pData=NULL);  //对象初始化
    void Release();  //释放内存空间
    ~CMatrix();  //析构函数
    
	//对运算符+ = += ==的重载
    CMatrix& operator +(const CMatrix& m);  
    CMatrix& operator =(const CMatrix& m);
    CMatrix& operator +=(const CMatrix& m);
    bool operator ==(const CMatrix& m);
	
	//对操作符的重载
    double& operator[](int m)
    {
   
        assert(m_nCol*m_nRow > m);
        return m_pData[m];
    }
    double& operator()(int m, int n)
    {
   
        assert(m_nCol*m_nRow > m*n+n);
        return m_pData[m*n+n];
    }
    friend istream& 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值