[B]Expression evaluation using Emit[/B] This class was designed to evaluate simple mathematical expressions. But instead of developing a routine to do the calculating, we use Emit to dynamically build a method that does the math for us. IMPORTANT: This is done with integer math. 7/2*3 = 9, not 10.5 (or even 10) To use this class first create an instance of the class, then pass a string to the Process method that contains your equation. It will return the value of this expression. [code]Evaluate e = new Evaluate(); int value = e.Process("1+8*(3-4/5)/7+((23-5)/2)+7)");[/code] The main method of this class, Process(), does …

Member Avatar
Member Avatar
+3 forum 2

I am trying to transform a infix mathematical expression into a postfix expression using the shunting yard algortihm but can only get so far by writing the pseudo code because I know exactly what to do through logical thinking but can't write the code that will help me do it. If you can have a look at the code I wrote and help me in writing the code, I will really appreciate it. Same with evaluating/calculating that postFix that was transformed. I also wrote the pseudo code for that function with the hope that someone will be able to help …

Member Avatar
Member Avatar
+0 forum 7

Hi basically i need help , i am not good with c++ but i am trying my very best. i am currently stuck with trying to do an infix to postfix conversion that reads from a textfile. The text file contains the infix notations and the code is suppose to convert the infix to postfix notations and then solve it. My code displays the contents of the text file fine but i am lost on how to connect it with my converting code. If anybody can help i would greatly appreciate it. for example the text file infix.txt would contain …

Member Avatar
Member Avatar
+0 forum 2

#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #define size 400 using namespace std; char infix[size],postfix[size],Stack[size]; int top; int precedence(char ch) { switch(ch) { case '^':return 5; case '/':return 4; case '*':return 4; case '+':return 3; case '-':return 3; default:return 0; } } char Pop() { char ret; if(top!=-1) { ret=Stack[top]; top--; return ret; } else return '#'; } char Topelem() { char ch; if(top!=-1) ch=Stack[top]; else ch='#'; return ch; } char Push(char ch) { if(top!=size-1) { top++; Stack[top]=ch; } } int braces(char* s) { int l,r; l=0;r=0; for(int i=0;s[i];i++) { if(s[i]='(') l++; if(s[i]=')') r++; } if(l==r) return 0; else …

Member Avatar
Member Avatar
+0 forum 5

I am working on a project for class. I have to write a program that reads in an infix expression and converts and it to postfix and evaluates it. Currently I have it to where I can convert an infix expression with no parentheses to postfix, but am having some trouble figuring out how to handle parentheses. import java.util.*; public class InfToPost { private Stack<String> convStack; private Stack<String> evalStack; private String infixExp; private String postfixExp = ""; private int temp; private int result; public InfToPost(String exp) { String str = ""; infixExp = exp; convStack = new Stack<String>(); evalStack = …

Member Avatar
+0 forum 0

Hi, Please help me debug this code. I made a Stack template with two parameters: type and size. I am using it two times: first in conversion from infix expression to postfix (here, <char,50> stack is used), then in evaluation of postfix expression (here, <long double, 50> stack is used). There is an error while using 2nd stack. how to debug it. #include <iostream> #include <cctype> #include <cmath> using namespace std; template <class T,int size> class Stack { private: int top; T *nodes; public: Stack (); int empty (void); void push(T &); T pop(void); T pop(int &); ~Stack (); }; …

Member Avatar
Member Avatar
+0 forum 4

i have problem in convert infix to postfix some expression evaluate it correctly and other no ex: c\*(a+b) evaluate it correctly but A\*(B\*C+D)+E doesn't evaluate correctly and there is another problem in finding result my code // convert.h const char SIZE=100; class stack { public: stack(); bool isempty()const; bool isfull()const; void push(char num); void pop(char &elm); void cntres(); int topnum; void print(); void result(stack &post); private: char data[SIZE]; int top; }; // convert.cpp #include<iostream> #include"convert.h" #include<cstddef> #include<cstring> using namespace std; stack::stack() { top=-1; topnum=top; } bool stack::isempty()const { return top==-1; } bool stack::isfull()const { return top==SIZE-1; } void stack::push(char elm) …

Member Avatar
Member Avatar
+0 forum 22

The program runs and gives the correct data until it gets to the 4th line of the input. At the 4th line, the calculation is incorrect and when it gets to line 6 of the input, it just stops completely. I can't quite figure it out. Any help is greatly appreciated! input: 5+7 6^2+1 3*8+6 5^4-6^4 5-3*7/4-9 8*(9/3-2)/4+5*6 5^3*4+(2+(9*8/(2*6*(8/4)))^2*8-5)/5^2-4 5-3*8/2^3 3^3^2*3 8*(6/3-2)/4+5*6+3 output: Infix : 5+7post fix :57+ Answer : 12 Infix : 6^2+1post fix :62^1+ Answer : 37 Infix : 3*8+6post fix :38*6+ Answer : 30 Infix : 5^4-6^4post fix :54^64^- Answer : 97 Infix : 5-3*7/4-9post fix :537*4/-9- …

Member Avatar
+0 forum 0

hi i want to convert the prefix form to postfix,prefix and infix form but when i input +5*62 it retuns only 2 what is wrong with my code can anybody help to solve this #include<stdio.h> #include<conio.h> #include<stdlib.h> #define Operator 1 #define notOperator 0 #define empty -1 struct node{ char item; struct node* leftchild; struct node* rightchild; }; void formatting(void); void getinput(void); int chkElement(char); void opFunc(char); void varfunc(char); void push(struct node*); struct node* pop(); void dispTree(void); void infix(struct node*); void prefix(struct node*); void postfix(struct node*); char equation[50]; int len,i; struct node* stack[25]; int stackPtr= -1; struct node* root; int main() { …

Member Avatar
Member Avatar
+0 forum 4

Hello community, I have an issued converting a arithmetic string called the infix, into a prefix output. In one of my methods i have an infinite loop. An example would be (a + b) * (c - d)===> * + a b - c d Here is my code: [CODE] public static String inToPrefix(String s){ Stack<Character> operator = new Stack<>(); Stack<String> operand = new Stack<>(); String output = ""; for (int i = 0; i < s.length(); i++) { char chValue = s.charAt(i); if((isDigit(chValue))||(isAlpha(chValue))){ operand.push("" + chValue); } else if(chValue == '('){ operator.push(chValue); } else if(isOperator(chValue)){ while(!operator.isEmpty()) { System.out.print("1"); if(priority(operator.peek())> …

Member Avatar
Member Avatar
+0 forum 2

Hi! I am trying to write calculator in c++ that takes an infix expression, converts it to postfix, and calculates. I have the code that will do this written, but when I try to turn it into a class it gives my a Segmentation Fault. Here is my code... [CODE=c++]//calc.h #ifndef INFIX_TO_POSTFIX_H #define INFIX_TO_POSTFIX_H #include "stack.h" #include <iostream> #include <string> #include <cctype> #include <cmath> class Calculator { public: void start(); void check(); bool error(string); void convert_postfix(string); void evaluate_postfix(string); private: MyStack<char> s; MyStack<int> ints; int priority; std::string exp; std::string postfix; }; #endif [/CODE] calc.cpp [CODE=c++]#include "calc.h" #include "stack.h" #include <iostream> #include …

Member Avatar
Member Avatar
+0 forum 2

So basically I need to find a way to evaluate an infix that's been converted into a postfix. The code below takes an entered infix and converts it into a postfix but I don't know how to take that postfix and evaluate it. Every single tutorial I've seen evaluates a postfix entered directly instead of a infix, so I have no clue what to do. So i decided to ask for help in doing this. Though to be honest, I'm more interested in reading material then direct code so I can understand it. But if you explain the code, that'd …

Member Avatar
Member Avatar
+0 forum 10

I need some idea how to correct this program. Though I think I understand the concept, my implementation is wrong. My program only prints the orignal string and does nothing with it. [CODE] public class ArrayStack<E> implements Stack<E> { protected int capacity; protected static final int CAPACITY = 1000; protected E S[]; protected int top = -1; public ArrayStack() { this(CAPACITY); } public ArrayStack(int cap) { capacity = cap; S = (E[]) new Object[capacity]; } public int size() { return (top + 1); } public boolean isEmpty() { return (top < 0); } public E top() { if (isEmpty()) throw …

Member Avatar
Member Avatar
+0 forum 1

here's the infix expression: [B]EXAMPLE 1[/B] a/(b+c)*d according to me, if [B]*[/B] is given higher precedence then [B]/[/B] , then this should be the postfix expression: [B]1) abc+d*/ [/B] if / has higher priority then * , then: [B]2) abc+/d*[/B] [B]question 1: [/B]which is correct?? 1 or 2 ? according to this link, [URL="http://www.cs.man.ac.uk/~pjj/cs212/fix.html"]http://www.cs.man.ac.uk/~pjj/cs212/fix.html[/URL] [B]EXAMPLE 2[/B] a*(b+c)/d gives abc+*d/ , in which case i think its assumed : [B]1)[/B]either * and / are given same priority, and the algo when checking priority, pops out the operator on stack if the priority of operator on stack[top] >= operator scanned from infix …

Member Avatar
Member Avatar
+0 forum 3

main.c [CODE]#include "stack.h" #include "stack_interface.h" #include "lex.h" #include <stdio.h> #include <stdlib.h> #define PUSH(s,c) if(push_char(s,c) == ERROR){ printf("Fatal error in pushing symbol on stack.\n") ; exit(1) ; } #define POP(s,c) if(pop_char(s,c) == ERROR){ printf("Fatal error in poping symbol off stack.\n") ; exit(1) ; } #define TOP(s,c) if(top_char(s,c) == ERROR){ printf("Fatal error in top operation.\n") ; exit(1) ; } int stackprec(stack *p_S) ; int inputprec(char c ) ; void skiptoeol() ; void clearstack(stack *p_S) ; main( int argc , char *argv[]){ stack S ; tokendata *p_token ; char stacksymbol ; bool eofreached = FALSE ; init_stack(&S) ; PUSH(&S , BOTTOMMARKER) ; do{ …

Member Avatar
Member Avatar
+0 forum 7

Hey, i know you are all probably very bored with the infix to postfix program and its many incarnations but i seem to be having a problem getting the linked list we have to use as a stack to work. More specifically; pushing to the stack, reading from the top of the stack and deleting from the stack are all ok, the problem comes from trying to read the empty stack to check that its empty (should return a "#") somewhere the error checking is not working and i cant for the life of me find out where!! header file: …

Member Avatar
Member Avatar
+0 forum 1

The End.