




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年九年级语文上册 第一单元 第1课《沁园春 雪》教学设计1 新人教版
- 九年级化学下册 第8单元 金属和金属材料 课题3 金属资源的利用和保护 第2课时 金属资源的保护教学设计 (新版)新人教版
- 6营养要均衡 教学设计-2024-2025学年科学四年级上册教科版
- 自考现代教育技术实践课
- 联合申报合作协议
- ICU专科护理评审方法课件
- 《第五单元 唱歌 其多列》(教学设计)-2023-2024学年人教版(2012)音乐一年级下册
- 2024-2025版新教材高中化学 第1章 第1节 第1课时 物质的分类及物质的转化教学设计 新人教版必修第一册
- 七年级信息技术 8.3制作基本动画教学设计 人教新课标版
- 统计学培训课件
- 广西壮族自治区来宾市2023-2024学年八年级下学期4月期中考试数学试题(含答案)
- 股权委托管理协议(2025年版)
- 2025国家粮食和物资储备局直属和垂直管理系统事业单位招聘统一笔试重点基础提升(共500题)附带答案详解
- 2025年四川省成都市高考英语二诊试卷
- 2025年度海鲜餐厅品牌区域合作授权合同
- 企业文化-电力与能源战略参考题库2025版
- 社会行政自考试题及答案
- 2025年保险查勘员笔试试题及答案
- 7.2做中华人文精神的弘扬者教学设计 -2024-2025学年统编版道德与法治七年级下册
- 运维面试试题及答案
- 山东大学教师外其他专业技术岗位招聘真题2024
评论
0/150
提交评论