定义一个二维方阵类matrix

来源:百度知道 编辑:UC知道 时间:2024/05/30 13:47:14
拜托拜托
定义一个二维方阵类matrix。通过重载二目运算符“+”、“-”、“*”和一目运算符“~”,来实现矩阵加、矩阵加、矩阵减、矩阵乘以及矩阵转置。

给出了类定义,具体成员函数实现请看这个网址,你需要的函数都有。
http://www.cppblog.com/liyuxia713/archive/2009/04/16/80177.html
还有你给的悬赏分也太低了

//Matrix.h
//矩阵类定义

#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <string>
//using namespace std; 一般头文件中使用完全限定域名字,而不是包含命名空间,防止重复包含头文件时造成的资源浪费

class Matrix
{
//从流中读入矩阵
friend std::istream& operator >> (std::istream& is, Matrix A);
//输出矩阵
friend std::ostream& operator << (std::ostream& os, const Matrix& A);
//将矩阵输出到名为str的文件中
friend void print_file(const Matrix&A,const char* str);
public:
//定义空矩阵
Matrix() {elems = NULL; row = 0; col = 0;};
//定义m*n零矩阵
Matrix(int m, int n);
//定义m*n矩阵,由a初始化
Matrix(int m, int n, double *a, int size = 0);