矩阵计算器

矩阵计算器实现

能够实现从文件或控制台中读入相应的矩阵,可以在控制台输出显示相应的矩阵。

 能够完成矩阵的一般计算(两个矩阵相加、相减、相乘) 能够完成矩阵的除法、求逆计算 能够完成矩阵的多个运算符的混合计算。 

使用堆栈的思想完成运算命令的处理。

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>

#define DEFAULT_WIDTH 5
#define EPSILON 0.0001
#define MAX_MATRIX 10

using namespace std;

class Matrix
{
	double *arr;
	int ln, col;
public:
	Matrix() : arr(nullptr), ln(0), col(0) {}
	Matrix(const int L, const int C) : arr(L * C == 0 ? nullptr : new double[L * C]), ln(L), col(C) {}
	Matrix(const Matrix &m) : ln(m.ln), col(m.col)
	{
		int size = ln * col;
		arr = size == 0 ? nullptr : new double[size];
		for (int i = 0; i < size; ++i) arr[i] = m.arr[i];
	}
	Matrix(istream &is)
	{
		is >> ln >> col;
		int size = ln * col;
		arr = size == 0 ? nullptr : new double[size];
		for (int i = 0; i < size; ++i) is >> arr[i];
	}
	~Matrix()
	{
		delete[] arr;
	}
	double &operator ()(int, int) const;
	Matrix operator +(const Matrix &) const;
	Matrix operator -(const Matrix &) const;
	Matrix operator *(const Matrix &) const;
	Matrix operator /(const Matrix &) const;
	Matrix inverse() const;
	double det() const;
	friend istream &operator >>(istream &, Matrix &);
	friend ostream &operator <<(ostream &, Matrix &);
};

int width = DEFAULT_WIDTH;

Matrix matrix_error(const char *err_msg)
{
	cout << "Matrix error: " << err_msg <<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值