- 1、本文档共5页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
模版实现矩阵综合运算
模版实现矩阵综合运算
程序代码
#includecassert
#includecmath
#includecstdlib
#includeiostream
using namespace std;
namespace NameVector{
#define DEFAULT_ALLOC 2
templateclass EITypeclass matrix;
templateclass EIType
class vector
{
private:
friend class matrixEIType;
EIType * data;
int len;
public:
int length()const{return len;}
vector();
vector(int n);
~vector(){delete [] data;}
vector(const vectorEITypev);
vectorEITypeoperator=(const vectorEITypeoriginal);
EITypeoperator[](int i)const;
void zero();
vectorEITypeoperator+(const vectorEITypev);
friend ostreamoperator(ostreams,vectorEITypev);
friend istreamoperator(istreamis,vectorEITypev);
};
templateclass EIType
void vectorEIType::zero()
{
for(int i=0;ilen;i++)data[i]=(EIType)0;
} templateclass EITypeEITypevectorEIType::operator [](int i)const{assert(i=0ilen);return data[i];}
templateclass EIType
vectorEIType::vector()
{
data=new EIType[DEFAULT_ALLOC];
assert(data!=0);
len=DEFAULT_ALLOC;
}
templateclass EIType
vectorEIType::vector(int n)
{
data=new EIType[len=n];
assert(data!=0);
}
templateclass EIType
vectorEIType::vector(const vectorEITypev)
{
data=new EIType[len=v.len];
assert(data!=0);
for(int i=0;ilen;i++)data[i]=v.data[i];
}
templateclass EIType
vectorEITypevectorEIType::operator=(const vectorEITypeoriginal)
{
if(this!=original)
{
delete[]data;
data=new EIType[len=original.len];
assert(data!=0);
for(int i=0;ilen;i++)data[i]=original.data[i];
}
return *this;
}
templateclass EIType
vectorEITypevectorEIType::operator+(const vectorEITypev)
{
vectorEITypesum(len);
for(int i=0;ilen;i++)sum[i]=data[i]+v.data[i];
return sum;
}
templateclass EIType
ostreamoperator(ostreams,vectorEITypev)
{
s(;
for(int i=0;iv.len-1;i++)sv.data[i],;
sv.data[v.len-1])endl;
return s;
}
templateclass EIType
istreamoperator(istreamis,vectorEITypev)
{
coutinputv.lendata:\n;
for(int i=0;iv.len;i++)
isv.data[i];
return is;
}
templateclas
您可能关注的文档
- 九年级阶段测试英语试题.doc
- 乐华MST 36KU机芯-P08系列维修资料.pdf
- 五年级寒假活动总结.doc
- 五上数学单元备课卡.doc
- 五年级小数乘整数.ppt
- 五年级数学试卷期中.doc
- 也请给后进生一个.docx
- 人力资源管理师三级综合复习题.doc
- 产能过剩条件下的宏观调控政策取向研究.pdf
- 人教版七年级下册期中考试题.doc
- 新高考生物二轮复习讲练测第6讲 遗传的分子基础(检测) (原卷版).docx
- 新高考生物二轮复习讲练测第12讲 生物与环境(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第3讲 酶和ATP(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第9讲 神经调节与体液调节(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第11讲 植物生命活动的调节(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第8讲 生物的变异、育种与进化(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第5讲 细胞的分裂、分化、衰老和死亡(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第5讲 细胞的分裂、分化、衰老和死亡(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第12讲 生物与环境(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第11讲 植物生命活动的调节(检测)(原卷版).docx
文档评论(0)