云南大学面向对象程序设计实验实验报告8.docVIP

  • 19
  • 0
  • 约4.63千字
  • 约 10页
  • 2016-10-18 发布于江西
  • 举报

云南大学面向对象程序设计实验实验报告8.doc

云南大学面向对象程序设计实验实验报告8.doc

云南大学软件学院实验课程报告 Report School of Software, Yunnan University 个人成绩 序号 学号 姓名 专业 成绩 1 20101120244 李云聪 数字媒体技术 2 学  期: 2013—2014学年秋季学期  课程名称: 面向对象程序设计实验 任课教师: 郁 湧 实验题目: lab8 小 组 长: 李云聪 联系电话: 电子邮件: 294265421@ 完成提交时间:2013年 11 月 20 日 说明:本实验在实验六的基础上实现 一 实验目的 构造一个矩阵matrix,里面包括构造器和相关成员函数,并能对输入的两个矩阵在判断两矩阵能否进行加减乘的基础上进行加减乘运算。 二 具体设计 定义变量line,col为矩阵的行数,列数,elems为用于存储矩阵的元素的数组。有三个构造函数matrix(),matrix(int,int),Matrix(const Matrix m)。关于取和设定这些值的成员函数很常规,就不多说。还需要说的就是,这个类设计中重载了 加 减 乘 数乘 转置 赋值 运算符,用的是友元的方式。 三 实现源码 matrix.h #pragma once #ifndef MATRIX_H #define MATRIX_H #includeiostream using namespace std; class Matrix { private : int line; int col; int *elems; public : Matrix(); Matrix(int l,int c); Matrix(const Matrix m); void setLine(int l); void setCol(int c); void setElems(); int getLine() const; int getCol() const; void print() const ; Matrix operator= (const Matrix m); //重载赋值 Matrix operator~ () const; //重载转置 friend Matrix operator+(const Matrix a, const Matrix b); //重载加号 friend Matrix operator-(const Matrix a, const Matrix b); //重载减号 friend Matrix operator*(const Matrix a, const Matrix b);//重载乘号 friend Matrix operator(const int a, const Matrix b);//重载数乘 ~Matrix(); }; #endif matrix.cpp #includematrix.h #includeiomanip Matrix::Matrix(){} Matrix::Matrix(int l,int c) { setLine(l); setCol(c); elems = new int[col*line]; } Matrix::Matrix(const Matrix m) { line = m.line; col = m.col; elems = new int[line * col]; for(int i = 0;i line * col;i++) elems[i]= m.elems[i]; } void Matrix::setLine(int l) { line = l; } void Matrix::setCol(int c) { col = c; } void Matrix::setElems() { int i,size = col*line; for(i = 0;i size; i++ ) { cinelems[i]; } } int Matrix::getLine() const { return line; } int Matrix::getCol() const { return col;

文档评论(0)

1亿VIP精品文档

相关文档