c++写一个矩阵类写一个矩阵类,矩阵类的参数包含矩阵的行、列和矩阵数据元素,其中矩阵行、列是整型,矩阵数据元素是浮点型,
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/09/22 11:31:13
c++写一个矩阵类
写一个矩阵类,矩阵类的参数包含矩阵的行、列和矩阵数据元素,其中矩阵行、列是整型,矩阵数据元素是浮点型,达到如下要求:
1)\x09构造函数
(1)\x09一个无参数的构造函数,将矩阵的行、列都初始化为2,矩阵数据元素都初始化为0.
(2)\x09一个含有三个参数的构造函数,能够指定矩阵的行、列和矩阵数据元素.
(3)\x09一个复制构造函数.
2)\x09运算符重载
(1)\x09重载加号运算符,两个行和列都相等的矩阵才能进行加法运算.
(2)\x09重载 == 运算符,如果两个矩阵的行、列和矩阵数据元素分别相等才返回true.
3)\x09写一个成员函数sum(),返回矩阵所有元素之和.
4)\x09输入输出运算符的重载
(1)\x09输入运算符>>的重载.
(2)\x09输出运算符
写一个矩阵类,矩阵类的参数包含矩阵的行、列和矩阵数据元素,其中矩阵行、列是整型,矩阵数据元素是浮点型,达到如下要求:
1)\x09构造函数
(1)\x09一个无参数的构造函数,将矩阵的行、列都初始化为2,矩阵数据元素都初始化为0.
(2)\x09一个含有三个参数的构造函数,能够指定矩阵的行、列和矩阵数据元素.
(3)\x09一个复制构造函数.
2)\x09运算符重载
(1)\x09重载加号运算符,两个行和列都相等的矩阵才能进行加法运算.
(2)\x09重载 == 运算符,如果两个矩阵的行、列和矩阵数据元素分别相等才返回true.
3)\x09写一个成员函数sum(),返回矩阵所有元素之和.
4)\x09输入输出运算符的重载
(1)\x09输入运算符>>的重载.
(2)\x09输出运算符
#include
#include
using namespace std;
class CMatrix
{
private:
int x;
int y;
float * fValue;
public:
CMatrix();
CMatrix(int x,int y,float value);
CMatrix(const CMatrix & mx);
float sum() const;
friend CMatrix & operator+(const CMatrix &a,const CMatrix &b);
friend bool operator==(const CMatrix &a,const CMatrix &b);
friend ostream & operator(istream & op,const CMatrix & cm);
};
CMatrix::CMatrix()
{
x=2;
y=2;
fValue=new float[x*y];
for(int i=0;ix=x;
this->y=y;
fValue=new float[x*y];
for(int i=0;ifValue==cm.fValue)
return;
this->x=cm.x;
this->y=cm.y;
this->fValue=new float[cm.x*cm.y];
for(int i=0;ifValue[i]=cm.fValue[i];
}
CMatrix & operator+(const CMatrix &a,const CMatrix &b)
{
assert(a.x==b.x && a.y==b.y);
CMatrix * cm=new CMatrix(a.x,a.y,0);
cm->x=a.x;
cm->y=a.y;
for(int i=0;ix*cm->y;i++)
cm->fValue[i]=a.fValue[i]+b.fValue[i];
return *cm;
}
bool operator==(const CMatrix &a,const CMatrix &b)
{
assert(a.x==b.x && a.y==b.y);
for(int i=0;iy;i++)
temp+=this->fValue[i];
return temp;
}
ostream & operato
#include
using namespace std;
class CMatrix
{
private:
int x;
int y;
float * fValue;
public:
CMatrix();
CMatrix(int x,int y,float value);
CMatrix(const CMatrix & mx);
float sum() const;
friend CMatrix & operator+(const CMatrix &a,const CMatrix &b);
friend bool operator==(const CMatrix &a,const CMatrix &b);
friend ostream & operator(istream & op,const CMatrix & cm);
};
CMatrix::CMatrix()
{
x=2;
y=2;
fValue=new float[x*y];
for(int i=0;ix=x;
this->y=y;
fValue=new float[x*y];
for(int i=0;ifValue==cm.fValue)
return;
this->x=cm.x;
this->y=cm.y;
this->fValue=new float[cm.x*cm.y];
for(int i=0;ifValue[i]=cm.fValue[i];
}
CMatrix & operator+(const CMatrix &a,const CMatrix &b)
{
assert(a.x==b.x && a.y==b.y);
CMatrix * cm=new CMatrix(a.x,a.y,0);
cm->x=a.x;
cm->y=a.y;
for(int i=0;ix*cm->y;i++)
cm->fValue[i]=a.fValue[i]+b.fValue[i];
return *cm;
}
bool operator==(const CMatrix &a,const CMatrix &b)
{
assert(a.x==b.x && a.y==b.y);
for(int i=0;iy;i++)
temp+=this->fValue[i];
return temp;
}
ostream & operato
c++写一个矩阵类写一个矩阵类,矩阵类的参数包含矩阵的行、列和矩阵数据元素,其中矩阵行、列是整型,矩阵数据元素是浮点型,
矩阵类的设计,用C++,要求:定义矩阵类,包含行、列和矩阵数据元素;
矩阵类的设计定义矩阵类,包含行、列和矩阵数据元素;要求至少设计以下各功能模块: 输入矩阵
C++中输入矩阵的行和列,A矩阵元素是行+列,B矩阵元素是行-列,输出A矩阵B矩阵.C矩阵为A乘以B.输出C矩阵
写一个矩阵类 急写一个矩阵类,并能求矩阵的迹,要求该矩阵的元素用动态数据表示,按矩阵的样式在输入和输出流上进行重载.
C语言输入一个3行5列的矩阵数据,输出矩阵中每行最大值
一个矩阵乘以另一个矩阵得到的是矩阵吗?行矩阵乘列矩阵得到的那个东西是矩阵?
为什么要将第一个矩阵每列*第二个矩阵每行数据相乘的和为新生成的矩阵上的一个元素值?
C语言实现有两个分别是2行3列和3行2列的矩阵,其数据均由键盘输入,这两个矩阵相乘后是一个2*2的矩阵
matlab:产生一个10行10列的矩阵;矩阵里的元素只能是1---10;求代码;谢谢
输入矩阵的行数(m)和列数(n),输入数据建立一个m*n的矩阵,在屏幕上显示该矩阵;将矩阵中元素的位置顺时针旋转900.
线性代数问题:一个行矩阵乘以列矩阵或者一个列矩阵乘以行矩阵会的到什么