编写一个程序实现一个矩阵类,通过重载+,-,*运算符来实现矩阵的加,减,乘操作.
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/05 07:07:03
编写一个程序实现一个矩阵类,通过重载+,-,*运算符来实现矩阵的加,减,乘操作.
最好用C++实现,
稍微有点问题,编译通不过啊,
最好用C++实现,
稍微有点问题,编译通不过啊,
// ---------------- ---------------------
// ----------------------------------------------------------------
// 假期无聊,实现的矩阵类,模板哦!哈哈.
/// ------------- ---------------
/// ---------------------------------------------------
#include
#include
#include
using namespace std;
template < class T >
class CMatrix
{
public: //------------------ 构造部 -------------------------
CMatrix( void );
CMatrix( unsigned h, unsigned w );
CMatrix( const CMatrix& m );
CMatrix( const vector& vec );
CMatrix( const vector& vec,unsigned h,unsigned w );
~CMatrix(void);
private: //------------------- 数据部 ---------------------------
vector m_vec_data;
unsigned m_u_width;
unsigned m_u_height;
public: // ------------------- 重载运算符 -------------------------
/// --- 以下均要求T具有如下运算能力:+ - += 等用到的.
//取值运算
T& operator() ( unsigned row, unsigned col );
T operator() ( unsigned row, unsigned col ) const;
//赋值运算
CMatrix& operator = ( const CMatrix& );
CMatrix& operator += ( const CMatrix& );
CMatrix& operator -= ( const CMatrix& );
CMatrix& operator *= ( T );
CMatrix& operator /= ( T );
//二元运算符
CMatrix operator + ( const CMatrix& ) const;
CMatrix operator - ( const CMatrix& ) const;
CMatrix operator * ( const CMatrix& ) const;
CMatrix operator * ( T ) const;
CMatrix operator / ( T ) const;
bool operator == ( const CMatrix& ) const;
bool operator != ( const CMatrix& ) const;
public: // -------------------- 操作函数部 -------------------------
void transpose();
inline bool empty();
inline long size();
inline unsigned height();
inline unsigned width();
public: // ------------------ 输入输出 ----------------------
// 注意:矩阵元素必须支持输入输出,否则程序会错误!
/*friend ostream& operator friend ostream& operator > ( istream& is,CMatrix& ma );
template < class T > friend istream& operator >> ( istream& is,CMatrix& ma );
};
/**-----------------------------------------------------------------------------
* 输出
*------------------------------------------------------------------------------
*/
template < class T >
ostream& operato
// ----------------------------------------------------------------
// 假期无聊,实现的矩阵类,模板哦!哈哈.
/// ------------- ---------------
/// ---------------------------------------------------
#include
#include
#include
using namespace std;
template < class T >
class CMatrix
{
public: //------------------ 构造部 -------------------------
CMatrix( void );
CMatrix( unsigned h, unsigned w );
CMatrix( const CMatrix& m );
CMatrix( const vector& vec );
CMatrix( const vector& vec,unsigned h,unsigned w );
~CMatrix(void);
private: //------------------- 数据部 ---------------------------
vector m_vec_data;
unsigned m_u_width;
unsigned m_u_height;
public: // ------------------- 重载运算符 -------------------------
/// --- 以下均要求T具有如下运算能力:+ - += 等用到的.
//取值运算
T& operator() ( unsigned row, unsigned col );
T operator() ( unsigned row, unsigned col ) const;
//赋值运算
CMatrix& operator = ( const CMatrix& );
CMatrix& operator += ( const CMatrix& );
CMatrix& operator -= ( const CMatrix& );
CMatrix& operator *= ( T );
CMatrix& operator /= ( T );
//二元运算符
CMatrix operator + ( const CMatrix& ) const;
CMatrix operator - ( const CMatrix& ) const;
CMatrix operator * ( const CMatrix& ) const;
CMatrix operator * ( T ) const;
CMatrix operator / ( T ) const;
bool operator == ( const CMatrix& ) const;
bool operator != ( const CMatrix& ) const;
public: // -------------------- 操作函数部 -------------------------
void transpose();
inline bool empty();
inline long size();
inline unsigned height();
inline unsigned width();
public: // ------------------ 输入输出 ----------------------
// 注意:矩阵元素必须支持输入输出,否则程序会错误!
/*friend ostream& operator friend ostream& operator > ( istream& is,CMatrix& ma );
template < class T > friend istream& operator >> ( istream& is,CMatrix& ma );
};
/**-----------------------------------------------------------------------------
* 输出
*------------------------------------------------------------------------------
*/
template < class T >
ostream& operato
编写一个程序实现一个矩阵类,通过重载+,-,*运算符来实现矩阵的加,减,乘操作.
定义一个分数类fraction,重载运算符+,-,x,使之能用于分数的加减乘,编写程序,实现两个分数的和差积
用C++编写程序,定义一个复数类,编写程序重载四则运算符和++、--运算符,实现复数的相关运算;
c ++ 实现一个的n*n矩阵类,重载符号*以实现矩阵相乘
编写一个分数类fraction ,其分子、分母为整数,通过重载运算符+、-、*、/ ,实现该类数据之间的四则运算
重载矩阵加法运算.设A,B,C均为m行,n列的矩阵,程序能实现C=A+B的操作.
定义一个复数类,通过重载运算符:+、-、*、/,直接实现两个复数之间的四则运算.
有两个矩阵A和B,均为3行4列,求两个矩阵之和.重载运算符+和-,实现两个矩阵想加和想减
定义一个复数类CComplex,通过重载运算符 + ,直接实现两个复数之间的加法运算.
定义一个复数类,通过重载运算符:*,/,直接实现二个复数之间的乘除运算
编写一个程序 ,采用方法重载分别实现圆、三角形、矩形、椭圆的面积计算
定义一个矩阵类,重载运算符+与*,以完成两矩阵相加与相乘运算