Question: my code in process feedback in C + + #include #include #include using namespace std; class MathExpressionStack { private: struct ExpressionNode { char character;
my code in process feedback in C#include
#include
#include
using namespace std;
class MathExpressionStack
private:
struct ExpressionNode
char character;
int lineNumber;
int position;
ExpressionNode next; Pointer to the next node
;
ExpressionNode top; Pointer to the top of the stack
public:
MathExpressionStack
top nullptr;
Constructor
~MathExpressionStack
while isEmpty
char c;
int l p;
popExpressionc l p;
Destructor
void pushchar ch int line int pos
ExpressionNode newNode new ExpressionNode;
newNode character ch;
newNode lineNumber line;
newNode position pos;
newNodenext top;
top newNode;
bool popExpressionchar& ch int& line, int& pos
if isEmpty
ch top character;
line top lineNumber;
pos top position;
ExpressionNodetemp top;
top top next;
delete temp;
return true;
else
ch ;
line pos ;
return false;
return true;
bool isEmpty const
return top nullptr;
;
bool isMatchingPairchar opening, char closing
return opening && closing opening && closing ;
int main
MathExpressionStack expressionStack;
string testInput "END";
string currentLine;
vector allLines;
int lineCount ;
cout "Enter expressions line by line. Type 'END' to finish input:
;
whiletrue
cout ;
getlinecin currentLine;
ifcurrentLine "END"
break;
allLines.pushbackcurrentLine;
getlinecin currentLine;
int lineCount ;
for const string& currentLine : testInput
ifcurrentLine "END"
Process each character in the current line
bool errorFound false;
for int i ; i allLines.size; i
lineCount i;
currentLine allLinesi;
for int j ; j currentLine.length; j
char currentChar currentLinej;
if currentChar currentChar
expressionStack.pushcurrentChar lineCount, j ;
else if currentChar currentChar
if expressionStackisEmpty
cout "Right delimiter currentChar
had no left delimiter found at line lineCount
char j endl;
errorFound true;
else
char lastOpening;
int lastLine, lastPos;
expressionStack.popExpressionlastOpening lastLine, lastPos;
if isMatchingPairlastOpening currentChar
cout "Mismatched operator lastOpening found at line lastLine char lastPos
does not match currentChar found at line lineCount char j endl;
errorFound true;
Check for unmatched opening delimiters...
while expressionStack.isEmpty
char ch;
int line, pos;
expressionStack.popExpressionch line, pos;
cout "Left delimiter ch at line line char pos had no right delimiter." endl;
errorFound true;
return ;
needs to return this putput given this input Enter expressions line by line. Type 'END' to finish input:
END
Mismatched operator found at line char does not match found at line char
Right delimiter had no left delimiter found at line char
Left delimiter at line char had no right delimiter.
but it returns Enter expressions line by line. Type 'END' to finish input:
END
Mismatched operator found at line char does not match found at line char Mismatched operator found at line char does not match found at line char
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
