Question
C++ programming infix to postfix then evaluete getting your input from an external file and using template stack. Am needing help to fix my program
C++ programming
infix to postfix then evaluete getting your input from an external file and using template stack.
Am needing help to fix my program so that it can do what the professor wnats
convert infix to postfix using template stacks and perform the evalustion
thank you;
here is my program but need help fixing it.
//header file
#ifndef STACK_H
#define STACK_H
template
template
class Stacknode
{
friend class stack
public:
Stacknode(const T &, Stacknode *);
T getData()const;
//set pointer to next node
void setNextPtr (stackNode *nPtr)
{
nextPtr = nPtr;
}//end function
Stacknode *getNextPtr () const
{
return nextPtr;
}
private: T data;
stackNode *nextptr
};
//member function defination
template
stackNode
{
data = d;
nextPtr = ptr;
}//end constructor
//get data
template stackNode { return data; }//end fubnction get data #endif // STACK_H #endif // STACK_H #ifndef STACK_H #define STACK_H #include using std::cout; #include #include "stackNode.h" template class stack { public: stack(); ~stack(); void push(T &); T pop; bool isEmpty()const; T stackTop()const; void print()const; stackNode { return topPtr; } private: StackNode };//end class template //member function defination template Stack { topPTR=0; } template Stack { StackNode while(currentPtr!=0) { tempPtr=currentPtr; currentPtr=currentPtr->getNextPtr(); delete tempPtr; }//endwhile }//end destructor //push node template void Stack { stackNode topPtr=newPtr; }//end function push //pop node template T Stack { stackNode topPtr=topPrt->nextPtr; T poppedValue = tempPtr->data; delete tempPtr; returnpoppedValue; } //is stack empty template bool Stack { return topPtr==0; } template T Stack { return !isEmpty()?getTopPtr()->getData():static_cast }//end fuction stacktop //display stack template void Stack if(isEmpty()) cout<<"stack is empty"; else { cout<<"The stack is : "; while(currentPtr!=) { cout< currentPtr=currentPtr->nextptr; }//end while cout<<" "; }//end function print #endif // STACK_H #include "stack.h" //function prototype void convertToPostfix(char *char, char *const); bool isOperater(char) bool precedence(char,char); int main () { const int MAXSIZE = 50 char c; char inFix[MAXSIZE] char postFix[MAXSIZE] int pos = 0; cout<<"Enter the input file to read from"< string inFix; ifstream file; file.open("inputFile.txt") while(!file.eof()) { getline(file, inFix); int size = Infix.size(); convertToPostfix(inFix,postfix); cout<<"The expression in postfix is"< return 0; } void convertToPostfix(char *const infix, char *const postfix) { Stack int infixCount; int postfixCount; bool higher; char popValue char leftparen = '('; charStack.push(leftparen); charStack.print(); strcat(infix,")"); //convert the infix expresion to postfix; for(infixCount=0, postfixCount=o; charStack.stackTop();infixCount++) { if(isdigit(infix[infixCount])) postfix[postfiCount++]==infix[infixCount]; else if(infix[infixCount]=='(') { charStack.push(leftparen); charStack.print() } else if (isOperator(infix[infixCount])) { higher = true; while(higher) { if(isOperator(charStack.stackTop())) if (presedence (charStack.stackTop(),infix[infixCount])) { postfi[postfixCount++]=charStack.pop(); } else higher = false; } postfix[postfixCount]='\0'; } bool isOperator (char c) } if(c=='+'||c=='-'||c=='*'||c=='/'||c=='^') return true; else return false; } bool precedence(char operator1, char operator2) { if(operator1 =='^') return true; else if(operator2=='^') return false; else if (operator1=='*'||operator1=='/') return true; else if(operator1=='+'||operator1=='/') { if(operator2=='+'||operator1=='/') return false; else return true; } return false } }
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