49 lines
909 B
C++
49 lines
909 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <stack>
|
|
|
|
class RPN
|
|
{
|
|
public:
|
|
RPN();
|
|
RPN(std::string expression);
|
|
RPN(const RPN &other);
|
|
~RPN();
|
|
RPN &operator=(const RPN &other);
|
|
void setExpression(std::string expression);
|
|
int evaluate();
|
|
|
|
class NoExpressionException : public std::exception
|
|
{
|
|
public:
|
|
const char *what() const noexcept override;
|
|
};
|
|
|
|
class InvalidExpressionException : public std::exception
|
|
{
|
|
public:
|
|
const char *what() const noexcept override;
|
|
};
|
|
|
|
class DivisionByZeroException : public std::exception
|
|
{
|
|
public:
|
|
const char *what() const noexcept override;
|
|
};
|
|
|
|
class InvalidCharacterException : public std::exception
|
|
{
|
|
public:
|
|
const char *what() const noexcept override;
|
|
};
|
|
|
|
private:
|
|
std::string _expression;
|
|
|
|
bool isWellformed() const;
|
|
bool isOperator(char c) const;
|
|
int applyOperator(int a, int b, char op) const;
|
|
void printStack(std::stack<int> stack) const;
|
|
};
|