Question
I failed to provide all of the classes on the previous question. I have a C++ program that takes input from input.txt, the program outputs
I failed to provide all of the classes on the previous question. I have a C++ program that takes input from input.txt, the program outputs to console. The program works until the input hits certain lines, mainly lines with double parentheses, percentages, question marks, pound signs, and tildes. Can I get an updated codes to correct this? I am very new to C++ (this is my first project).
project2.cpp*******
#include
variable.h****
class Variable: public Operand{ public: Variable(string name){ this->name = name; } int evaluate(); private: string name; };
variable.cpp****
#include
times.h****
class Times: public SubExpression{ public: Times(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() * right->evaluate(); } };
ternary.h****
class Ternary: public SubExpression{ public: Ternary(Expression* left, Expression* right, Expression* condition): SubExpression(left, right){ this->condition = condition; } int evaluate(){ return condition->evaluate() ? left->evaluate() : right->evaluate(); } private: Expression* condition; };
symboltable.h****
class SymbolTable{ public: SymbolTable() {} void insert(string variable, int value); int lookUp(string variable) const; void init(); private: struct Symbol{ Symbol(string variable, int value){ this->variable = variable; this->value = value; } string variable; int value; }; vector
symboltable.cpp****
#include
subexpression.h****
class SubExpression: public Expression{ public: SubExpression(Expression* left, Expression* right); static Expression* parse(stringstream& in); protected: Expression* left; Expression* right; };
subexpression.cpp****
#include
plus.h****
class Plus: public SubExpression{ public: Plus(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() + right->evaluate(); } };
parse.h****
string parseName(stringstream& in);
parse.cpp****
#include
or.h****
class Or: public SubExpression{ public: Or(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() || right->evaluate(); } };
operand.h****
class Operand: public Expression{ public: static Expression* parse(stringstream& in); };
operand.cpp****
#include
#include
negation.h****
class Negation: public SubExpression{ public: Negation(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return !(left->evaluate()); } };
minus.h****
class Minus: public SubExpression{ public: Minus(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() - right->evaluate(); } };
literal.h****
class Literal: public Operand{ public: Literal(int value){ this->value = value; } int evaluate(){ return value; } private: int value; };
lessThan.h****
class LessThan: public SubExpression{ public: LessThan(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() < right->evaluate(); } };
greaterThan.h****
class GreaterThan: public SubExpression{ public: GreaterThan(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() > right->evaluate(); } };
expression.h****
class Expression{ public: virtual int evaluate() = 0; };
equality.h****
class Equality: public SubExpression{ public: Equality(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() == right->evaluate(); } };
divide.h****
class Divide: public SubExpression{ public: Divide(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() / right->evaluate(); } };
and.h****
class And: public SubExpression{ public: And(Expression* left, Expression* right): SubExpression(left, right){ } int evaluate(){ return left->evaluate() && right->evaluate(); } };
input.txt****
(aa + 1), aa = 1, aa = 2; (6 % b) < 5, b = 4; (f ? 1 2), f = 0; ((x * 2.6) + (y - 3)), x = 1.5, y = 6; (( 7 / z_1) + (z_1 ^ 2)), z_1 = 2; (c > d), c = 9, d = 7; (e & 8), e = 5; (g # 1 2 3), g = 2; (tt + ss), tt = 2; ((a + 4) ~), a = 3;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started