C++ 矩阵异常类设计

来源:互联网 发布:数据库巡检报告 编辑:程序博客网 时间:2024/05/20 06:25
#pragma once/****自定义矩阵运算异常的基类***/#include "CommonHeader.h"class BaseMatrixException{protected:int ErrorCode;int mRow,mCol;public:BaseMatrixException(void){};BaseMatrixException(int r,int c);virtual std::string getExceptionMesssage()=0;};/****矩阵奇异异常类***/class MatrixSingularException : public BaseMatrixException{public:MatrixSingularException(){};MatrixSingularException(int r,int c);MatrixSingularException(MatrixSingularException &Except);std::string getExceptionMesssage();};/****非方阵异常类***/class MatrixNonsquareException : public BaseMatrixException{public:MatrixNonsquareException(){};MatrixNonsquareException(int r,int c);MatrixNonsquareException(MatrixNonsquareException &Except);std::string getExceptionMesssage();};/****方法异常类***/class MatrixNoMethodException : public BaseMatrixException{private:std::string MethodName;public:MatrixNoMethodException(){};MatrixNoMethodException(int r,int c,std::string MethodName);MatrixNoMethodException(MatrixNoMethodException &Except);std::string getExceptionMesssage();};/****矩阵尺寸异常类***/class MatrixSizeException:public BaseMatrixException{private:std::string SizeDescribetion;public:MatrixSizeException(){};MatrixSizeException(std::string message);MatrixSizeException(MatrixSizeException &Except);std::string getExceptionMesssage();};enum MatrixExceptionCode{Singular=1,Nonsquare=2,NoMethod=3,SizeError};//以下是实现部分#include "BaseMatrixException.h"BaseMatrixException::BaseMatrixException(int r,int c){this->mCol=c;this->mRow=r;}MatrixSingularException::MatrixSingularException(int r,int c):BaseMatrixException(r,c){this->ErrorCode=Singular;}MatrixSingularException::MatrixSingularException(MatrixSingularException &Except){this->ErrorCode=Except.ErrorCode;}std::string MatrixSingularException::getExceptionMesssage(){std::ostringstream temp;temp<<"provit is 0 location is c"<<mRow<<","<<mCol<<")"<<std::endl;return temp.str();}MatrixNonsquareException::MatrixNonsquareException(int r,int c):BaseMatrixException(r,c){this->ErrorCode=Nonsquare;}MatrixNonsquareException::MatrixNonsquareException(MatrixNonsquareException &Except){this->ErrorCode=Except.ErrorCode;}std::string MatrixNonsquareException::getExceptionMesssage(){std::ostringstream temp;temp<<"the matrix dim is ("<<mRow<<"*"<<mCol<<"),is not a square"<<std::endl;return temp.str();}MatrixNoMethodException::MatrixNoMethodException(int r,int c,std::string MethodName):BaseMatrixException(r,c){this->ErrorCode=Nonsquare;this->MethodName=MethodName;}MatrixNoMethodException::MatrixNoMethodException(MatrixNoMethodException &Except){this->ErrorCode=Nonsquare;this->MethodName=Except.MethodName;}std::string MatrixNoMethodException::getExceptionMesssage(){std::ostringstream temp;temp<<"the method  is ("<<this->MethodName<<") is not be found"<<std::endl;return temp.str();}MatrixSizeException::MatrixSizeException(MatrixSizeException &Except){this->ErrorCode=Except.ErrorCode;this->SizeDescribetion=Except.SizeDescribetion;}MatrixSizeException::MatrixSizeException(std::string message){this->ErrorCode=SizeError;this->SizeDescribetion=message;}std::string MatrixSizeException::getExceptionMesssage(){return this->SizeDescribetion;}

0 0