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代码,与目录的三级标题测试
二级标题 三级标题 三级标题 三级标题 三级标题 三级标题 二级标题 三级标题 三级标题 三级标题 三级标题 三级标题 这里是现在页尾目录功能的代码源码: <!-- 目录索引列表生成 --> ...
随机推荐
- hdu 2079
ps:昨天刚做了个母函数的,觉得不太熟,今天又是母函数..很好.. 代码: #include "stdio.h" #include "string.h" ]; ...
- Qt + FFmpeg 本地音频播放器
http://pan.baidu.com/s/1hqoYXrI
- 使用HelloCharts绘制柱状图
首先下载依赖库 ,有现成的jar包:hellocharts-library-1.5.8.jar 在需要的布局中直接使用: <lecho.lib.hellocharts.view.ColumnCh ...
- [GodLove]Wine93 Tarining Round #3
比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44857#overview 题目来源: ZOJ Monthly, July 2 ...
- Python 基礎 - 用戶交互程序
現在就來寫一個簡單的 用戶輸入 的程式,這是一個互動模式,需要使用者自已輸入 #!/usr/bin/env python3 # -*- coding:utf-8 -*- username = inpu ...
- GridView的DataFormatString格式化字符串
DataFormatString="{0:格式字符串}" 0:代表字段本身 冒号后面的代表希望的格式 比如 {0:yyyy-MM-dd} 显示的时间类型就是2016-04-11 ...
- ipvsadm命令使用方法
由于LVS(IPVS)是工作在内核空间的,因此要在用户空间对其进行配置和管理就要用到ipvsadm,ipvsadm是LVS在用户空间的管理命令. 一般在安装linux(CentOS6.5)时该命令是为 ...
- Spring概况
1. Spring是什么 Spring是一个开源框架,为了解决企业应用开发的复杂性而创建的,但现在已经不止于企业应用. 是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. ——从大小与开 ...
- 为 C# 代码生成 API 文档(译)
原文地址:http://broadcast.oreilly.com/2010/09/build-html-documentation-for-y.html#comments Sandcastle 功能 ...
- 切换到android studio环境
下载: android-studio-bundle-135.1740770-windows.exe sysimg_arm-21_r03.zip 设置环境变量: ANDROID_SDK_HOME ...