cs11_c++_lab2
Matrix.hh
class Matrix
{
int row;
int col;
int *p;
public: Matrix();
Matrix(int x,int y);
~Matrix(); Matrix(Matrix &m); int getrows();
int getcols(); void setelem(int x,int y,int elem); int getelem(int x,int y); void add(Matrix &m); void subtract(Matrix &m); bool equals(Matrix &m);
};
Matrix.cpp
#include "Matrix.hh"
#include <cassert>
#include <iostream> using namespace std; Matrix::Matrix()
{
row=;
col=;
p=;
} Matrix::Matrix(int x,int y)
{
assert(x>=);
assert(y>=);
row=x;
col=y;
p=new int[row*col];
for(int i=;i<row*col;i++)
p[i]=;
} Matrix::Matrix(Matrix &m)
{
row=m.row;
col=m.col;
p=new int[row*col];
for(int i=;i<row*col;i++)
p[i]=m.p[i];
} Matrix::~Matrix()
{
delete[] p;
} int Matrix::getrows()
{
return row;
} int Matrix::getcols()
{
return col;
} int Matrix::getelem(int x,int y)
{
assert(x>=);
assert(y>=);
return p[x*col+y];
} void Matrix::setelem(int x,int y,int elem)
{
assert(x>=);
assert(y>=);
p[x*col+y]=elem;
} void Matrix::add(Matrix &m)
{
assert( (row==m.row) || (col==m.col) );
for(int i=;i<row*col;i++)
p[i]+=m.p[i];
} void Matrix::subtract(Matrix &m)
{
assert( (row==m.row) || (col==m.col) );
for(int i=;i<row*col;i++)
p[i]-=m.p[i];
} bool Matrix::equals(Matrix &m)
{
bool b=true;
if( (row!=m.row) || (col!=m.col) )return false;
for(int i=;i<row*col;i++)
if(p[i]!=m.p[i])
{ b=false;return b;}
return b;
}
cs11_c++_lab2的更多相关文章
- cs11_c++_lab7
wcount.cc #include <iostream> #include <map> #include <string> #include <algori ...
- cs11_c++_lab6
expressions.hh #ifndef EXPRESSIONS_HH #define EXPRESSIONS_HH #include "environment.hh" #in ...
- cs11_c++_lab5待修改
heap.hh #ifndef HEAP_HH #define HEAP_HH #include <iostream> #include <stdexcept> #includ ...
- cs11_c++_lab4b
SparseVector.hh class SparseVector { private: //结构体不一定会用到,不用初始化 struct node { int index; int value; ...
- cs11_c++_lab4a
SparseVector.hh class SparseVector { private: //结构体不一定会用到,不用初始化 struct node { int index; int value; ...
- cs11_c++_lab3
Matrix.hh class Matrix { int row; int col; int *p; void copy(const Matrix &m); void clearup(); p ...
- cs11_c++_lab1
lab1.cpp #include "Point.hh" #include <iostream> #include <cmath> using namesp ...
- Jquery实现自动生成二级目录
在博客园开通博客以后,就看到某位博友写的js自动生成目录的文章,当时觉得生成目录能给阅读带来方便,所以就直接拿来使用了.用了一段时间以后,发现只能生成一级目录,不能生成多级目录,有点美中不足.所以想着 ...
- 导出目录的JS代码,与目录的三级标题测试
二级标题 三级标题 三级标题 三级标题 三级标题 三级标题 二级标题 三级标题 三级标题 三级标题 三级标题 三级标题 这里是现在页尾目录功能的代码源码: <!-- 目录索引列表生成 --> ...
随机推荐
- Notes of learning AutoLayout
在XCode5中,如果我们添加一个Button或者Label,或者其他的什么标准View,而不设置任何constraints,IB会自动生成constraints,而这些constraints是fix ...
- OrCAD搭建Access数据库
刚进入到一个小公司,接到的第一个电路设计的案子是从零开始的,辛苦就不说,关键是这么不严谨,容易出错,于是乎,问题来了,能否从零开始着手建立个类似于以前公司的数据库,管理原理图封装,PCB封装及规格书! ...
- Poisson Distribution——泊松分布
老师留个小作业,用EXCEL做不同lambda(np)的泊松分布图,这里分别用EXCEL,Python,MATLAB和R简单画一下. 1. EXCEL 运用EXCEL统计学公式,POISSON,算出各 ...
- 防止apache下面直接输入目录访问文件
有些项目链接会暴露服务器上面的文件地址,如何访问文件被访问呢 方法一: 在项目入口文件下面新加一个.htaccess文件(apache开启重写模式才会加载这个文件,否则这个文件配置不会生效) 文件中加 ...
- Socket编程基础——Socket选项
有些情况下,我们需要对Socket行为和属性进一步控制,例如修改缓冲区大小,查看Socket状态,这就需要设置/获取Socket选项. 1.获取Socket选项int getsockopt(SOCKE ...
- SE03 打包请求
请求打包,是传输请求时候常用的一种方法.步骤如下:注意点:1.打包请求一定仔细检查,不要遗漏 如果请求不多,分开传是更好的方式,不容易遗漏,导致问题, 2.请求释放后才 ...
- eclipse中运行项目时报Class not found的错误
环境:Groovy/Grails Tool Suite 3.1.0.RELEASE(BASED ON ECLIPSE JUNO 3.8.1).JDK1.6 运行class的main方法,或启动juni ...
- 排序算法总结(三)选择排序【Select Sort】
一.原理 选择排序的原理非常简单,就是选出最小(大)的数放在第一位,在剩下的数中,选出最小(大)的数,放在第二位......重复上述步骤,直到最后一个数. 二.过程 原始数据 第一次排序,选出最小的数 ...
- bll编译错误
如果在项目中 ,bll有函数,却引用报错 原因很可能是因为bll在生成程序集的时候,没有生成好.其中有错误 解决办法. 1.将bll,web,dal重新生成 2.注意bll的生成,该添加的添加,该排除 ...
- MySql数据库索引原理
写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...