- Use initialization lists initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is cumbersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
- Use initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is cumbersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
- Use initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is cumbersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
- Use initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is combersomecumbersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
- The essentially do the same work.
hasBrackets
is essentially the same as!vector_parenthesis.empty()
. - In the
Expression
constructor, there is no need to treat the no-parentheses case specially. Iterating through an empty vector achieves the same effect. - Do you want to call them "brackets" or "parentheses"? Make up your mind!
- Use initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is combersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
- The essentially do the same work.
hasBrackets
is essentially the same as!vector_parenthesis.empty()
. - Do you want to call them "brackets" or "parentheses"? Make up your mind!
- Use initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is cumbersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
- The essentially do the same work.
hasBrackets
is essentially the same as!vector_parenthesis.empty()
. - In the
Expression
constructor, there is no need to treat the no-parentheses case specially. Iterating through an empty vector achieves the same effect. - Do you want to call them "brackets" or "parentheses"? Make up your mind!
Tracing the code starting from main()
, I didn't get very far until I noticed concerns.
Looking at your Expression
constructor...
Expression::Expression(std::string expression, bool sub) //NOTE: being a sub means that it was surrounded
//by brackets '(' ')'
{
hasBrackets = false;
expressionString = expression;
containsBrackets();
// //std::cout << "Successfully complete 'containsBrackets' function" << std::endl;
if (hasBrackets == true)
{
getParentheses();
// //std::cout << "Successfully complete 'getParentheses()' function" << std::endl;
getSubExpressions();
// //std::cout << "Successfully complete 'getSubExpressions()' function" << std::endl;
}
evaluate();
// //std::cout << "Successfully complete 'evaluate()' function" << std::endl;
}
- Use initialization lists.
- Your comment says, "being a sub means that it was surrounded by brackets '(' ')'". Why should that matter though? Indeed, you never even use the
sub
parameter. hasBrackets = false; containsBrackets(); if (hasBrackets == true) { ... }
is combersome. Why not writeif (hasBrackets = containsBrackets()) { ... }
? But even that is unsatisfactory...
Looking a containsBrackets()
and getParentheses()
...
void Expression::containsBrackets()
{
for(unsigned int index = 0; index < expressionString.size(); index++)
{
if (expressionString[index]=='(' ||expressionString[index]==')' )
{
hasBrackets = true;
}
}
}
void Expression::getParentheses() //Finds the parentheses and their positions in the expression
//so that their contents can be converted to sub expressions.
{
for (unsigned int index = 0; index < expressionString.size(); index++)
{
if (expressionString[index] == '(' || expressionString[index] == ')')
{
Parenthesis temporary(index, expressionString[index]); //Stores the position and type of the parenthesis
vector_parentheses.push_back(temporary);
}
}
/* ... */
}
- The essentially do the same work.
hasBrackets
is essentially the same as!vector_parenthesis.empty()
. - Do you want to call them "brackets" or "parentheses"? Make up your mind!
lang-cpp