Question
C++ Error upon run Description Resource Path Location Type expected ';' at end of member declaration operand.h line 13 and expected ')' before '&' token
C++ Error upon run “Description Resource Path Location Type expected ';' at end of member declaration operand.h line 13” and "expected ')' before '&' token operand.h line 13".
operand.h***
#ifndef OPERAND_H
#define OPERAND_H
class Operand: public Expression{
public:
static Expression* parse(stringstream& in); ←---------------Line 13
};
#endif // OPERAND_H
parse.h****
using namespace std;
#ifndef PARSE_H
#define PARSE_H
string parseName(stringstream& in);
#endif // PARSE_H
parse.cpp****
#include
#include
#include
#include
#include "parse.h"
using namespace std;
string parseName(stringstream& in){
char alnum;
string name = "";
in >> ws;
while (isalnum(in.peek())){
in >> alnum;
name += alnum;
}
return name;
}
operand.cpp****
#include
#include
#include
#include
#include
using namespace std;
#include "expression.h"
#include "subexpression.h"
#include "operand.h"
#include "variable.h"
#include "literal.h"
#include "parse.h"
#include "or.h"
#include "and.h"
#include "equality.h"
#include "greaterThan.h"
#include "lessThan.h"
#include "ternary.h"
#include "negation.h"
Expression* Operand::parse(stringstream& in){
char paren;
int value;
in >> ws;
if (isdigit(in.peek())){
in >> value;
Expression* literal = new Literal(value);
return literal;
}
if (in.peek() == '('){
in >> paren;
return SubExpression::parse(in);
}
else
return new Variable(parseName(in));
return 0;
}
Project2.cpp****
#include
#include
#include
#include
#include
#include
using namespace std;
unordered_map
int evaluateExpression(stringstream& expression);
int evaluateSubExpression(stringstream& subExpression) {
char operation;
subExpression >> operation;
if (operation == '(') {
return evaluateExpression(subExpression);
} else {
string variable;
subExpression >> variable;
return symbolTable[variable];
}
}
int evaluateExpression(stringstream& expression) {
char operation;
expression >> operation;
int result = evaluateSubExpression(expression);
while (expression >> operation) {
if (operation == ')') {
return result;
}
int rightOperand = evaluateSubExpression(expression);
if (operation == '+') {
result += rightOperand;
} else if (operation == '-') {
result -= rightOperand;
} else if (operation == '*') {
result *= rightOperand;
} else if (operation == '/') {
result /= rightOperand;
}
}
return result;
}
void parseAssignments(stringstream& assignment) {
string variable;
char assignOp;
int value;
while (assignment >> variable >> assignOp >> value) {
symbolTable[variable] = value;
}
}
int main() {
ifstream inputFile("input.txt");
if (!inputFile) {
cerr << "Failed to open the input file." << endl;
return EXIT_FAILURE;
}
string line;
while (getline(inputFile, line)) {
stringstream expression(line);
char paren;
expression >> paren;
if (paren != '(') {
cerr << "Invalid expression: " << line << endl;
continue;
}
int result = evaluateExpression(expression);
cout << "Expression: " << line << "\nValue = " << result << endl;
}
inputFile.close();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer The error youre encountering expected at end of member declaration and expected before token ...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