已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include using namespace std;class Matrixprivate: int cols,cols1; int *p,*q,*z,*f,*p1,*p2; static int rows;public: /static int rows; Matrix(); / rows=0; / cols=0; / cols1=0; / p=new introws*cols; / p1=new introws*cols; / p2=new introws*cols; / q=new intcols*cols1; / z=new intcols; /f=new introws*cols1; void sr(); void sc(); void sr1(); void sc1(); / Matrix() / / deletep; /deleteq; /deletez; /deletef; /deletep1; /deletep2;/ ;int Matrix:rows=2;Matrix:Matrix() cols=0; cols1=0;void Matrix:sr() p=new introws*cols; p1=new introws*cols; p2=new introws*cols; q=new intcols*cols1; z=new intcols; f=new introws*cols1; cout默认rows=2,pelase enter cols:cols; coutendl; cout请输入矩阵内容:endl; / p=new introws*cols; for(int t=0;tpt; coutplease enter cols1:cols1; cout请输入矩阵内容:endl; / q=new intcols*cols1; /z=new introws*cols1; for(int y=0;yqy; coutendl; int m=0;z0=0;int o=0; for(int i=0;irows;i+) for(int j=0;jcols1;j+) for(int k=0;kcols;k+) m+; zm=zm-1+pi*cols+k*qk*cols1+j; / m+; fo=zm; m=0;z0=0;o+; void Matrix:sc() for(int i=0;irows;i+) coutendl; for(int j=0;jcols1;j+) coutfi*cols1+j ; void Matrix:sr1() cout默认rows=2,pelase enter cols:cols; coutendl; cout请输入第一个矩阵内容:endl; p=new introws*cols; for(int i=0;ipi; cout请输入第二个矩阵的内容:endl; p1=new introws*cols; for(int j=0;jp1j; p2=new introws*cols; for(int i=0;irows*cols;i+) p2i=pi+p1i; void Matrix:sc1() cout矩阵相加结果为:endl; for(int i=0;irows;i+) coutendl; for(int j=0;jcols;j+) coutp2i*cols+j ; int main() Matrix m1; Matrix m2; Matrix m3(m1);/复制构造函数 Matrix m4(m2);/复制构造函数 cout加法请输入1,乘法请输入2:x; switch(x) case 1:m4.sr1(); m4.sc1();break; case 2: m3.sr(); m3.sc();break; default:cout数据库中不存在x数字的功能endl; coutl; return 0;#include using namespace std;class matrixpublic:matrix();matrix(int a,int b);matrix() ;matrix(const matrix &m);int getmatrix();void outputmatrix();matrix(int,int,int*);int lines;int rows;int *p;matrix:matrix(int a,int b) cout构造了一个a行b列矩阵endl; lines=a; rows=b; p=new int*lines; for(int i=0;irows;i+) pi=new introws;matrix:matrix(const matrix &m) cout拷贝了一个m.lines行m.rows列矩阵endl; lines=m.lines; rows=m.rows;p=new int*lines;for(int i=0;irows;i+) pi=new introws;for(int i=0;ilines;i+) for(int j=0;jrows;j+) pij=李特 2014/11/16 19:37:19m.pij;int matrix:getmatrix() cout输入矩阵数据endl;for(int i=0;ilines;i+) for(int j=0;jpij;if(cin) return 1;else cout输入有误endl;cin.good(); return 0; void matrix:outputmatrix() for(int i=0;ilines;i+) for(int j=0;jrows;j+) coutpij ; coutendl; matrix:matrix() for(int i=0;ilines;i+) cout矩阵第i+1行被释放endl; delete pi; matrix operator+(const matrix& mat1,const matrix& mat2) matrix mat3(mat1); for(int i=0;imat1.lines;i+) for(int j=0;jmat1.row李特 2014/11/16 19:37:46s;j+) mat3.pij+=mat2.pij; cout调用+时临时变量将被释放endl; return mat3;matrix operator-(const matrix& mat1,const matrix& mat2) matrix mat3(mat1); for(int i=0;imat1.lines;i+) for(int j=0;jmat1.rows;j+) mat3.pij-=mat2.pij; cout调用+时临时变量将被释放endl; return mat3;int main() int a,b; cout请输入矩阵行数和列数:ab; ma
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年湖北省鄂州市事业编单位人员招聘笔试备考试题及答案详解
- 2026年银川市西夏区中小学编制教师招聘笔试参考题库及答案详解
- 2026年大同市南郊区中小学编制教师招聘考试参考试题及答案详解
- 2026年乌鲁木齐市天山区事业编单位人员招聘笔试备考题库及答案详解
- 2026年宝鸡市陈仓区中小学编制教师招聘笔试模拟试题及答案详解
- 2026年甘肃省兰州市中小学编制教师招聘考试备考试题及答案详解
- 2026年伊春市南岔区中小学编制教师招聘考试参考试题及答案详解
- 2026年青岛市李沧区中小学编制教师招聘笔试参考试题及答案详解
- 2026年广安市广安区事业编单位人员招聘笔试备考试题及答案详解
- 2026年四川省乐山市中小学编制教师招聘笔试参考题库及答案详解
- 2026年湘教版七年级下册数学期末能力检测卷(含答案可下载)
- 重大事故隐患判定标准与学校安全法规制度深度解读课件
- 2026江粮集团科技创新与品控检验中心校园招聘1人备考题库及参考答案详解
- 2026中共深圳市龙岗区委政法委员会招聘聘员4人备考题库(广东)附答案详解ab卷
- 重庆公务员 2026真题及答案
- 广告油漆施工方案(3篇)
- 2025年天津市和平区小升初语文试卷
- 地下室涂料施工方案
- 2026年度秋季中国工商银行软件开发中心校园招聘200人笔试历年典型考题及考点剖析附带答案详解
- 健康与安全管理制度手册(标准版)
- 虫媒传染知识讲座课件
评论
0/150
提交评论