- 19
- 0
- 约4.63千字
- 约 10页
- 2016-10-18 发布于江西
- 举报
云南大学面向对象程序设计实验实验报告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;
您可能关注的文档
- 6.计算机网络基础19549.doc
- 数据库模拟试题73564new.doc
- 奥斯卡获奖.docx
- 《电磁场与电磁波》必考复习题(2013年)new.doc
- 河海大学2012年硕士研究生招生专业目录及参考书目.doc
- 信号与系统实验三new.docx
- 房子小、智慧多,看了你再装修吧.doc
- 通信原理实验报告96542new.doc
- 常用液压图形符号-流体传动与控制new.doc
- 河南虢州会所酒店.doc
- 广东省广州省实验中学教育集团2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州大学附属中学2025-2026学年八年级上学期奥班期中物理试题(解析版).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(含答案).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(解析版).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 2026《中国人寿上海分公司营销员培训体系优化研究》18000字.docx
- 《生物探究性实验教学》中小学教师资格模拟试题.docx
原创力文档

文档评论(0)