C++ :: Evaluating Postfix Expression Using Stacks

Nov 3, 2013

i feel like im really close to completing this but i cant seem to get the result printed out i dont think im calling my evaluate function correctly and its not performing the operations..

#include <iostream>
#include <stack> //stack header file
using namespace std;

[Code].....

View 1 Replies


ADVERTISEMENT

C/C++ :: Infix To Postfix Conversion And Evaluating Expression

Apr 12, 2015

I am trying to convert from infix to postfix, and then evaluating the postfix expression to get the final answer. I am having a severe problem though, because for somereason the conversion is not working at all. For example, when I input the first infix expression:

24 + 33 * ( 7 - 5 ) + 8 / 3 it ouputs 24 33 7 5 - 5 ) + 8 / 3( 7 - 5 ) + 8 / 3* ( 7 - 5 ) + 8 / 3+ 33 * ( 7 - 5 ) + 8 / 3 8 3/ 3+ 8 / 3

Which is obviously very wrong. I am not really sure where the problem is though.

Below I have included all of the code needed. I also had to create my own stack class, so I will include it too .

#include "stacks.h"
#include <iostream>
using namespace std;
bool IsOperand(char C) {
if(C >= '0' && C <= '9') return true;
if(C >= 'a' && C <= 'z') return true;

[Code] .....

View 1 Replies View Related

C++ :: Convert From Infix Expression To Postfix Using Stacks?

May 24, 2014

I need to convert from an infix expression to postfix using stacks!

#ifndef EXPRESSIONMANAGER_H_
#define EXPRESSIONMANAGER_H_
#include <iostream>
#include <stack>
#include <string>
#include <sstream>
using namespace std;
class ExpressionManager : public ExpressionManagerInterface{

[code]....

View 2 Replies View Related

C/C++ :: Convert Infix To Postfix Using Linked Lists And Stacks - Program Stop Working After 1st Call

Sep 28, 2014

I was given a task to convert infix to post fix using both linked lists and stacks in the code so this is what i have written but the problem is it is giving me same error at three different places "missing function header(old style format?)

#include <iostream>
#include <string>
using namespace std;
const int size = 100;
class stack{
private: // Declare a structure for the list

[Code] ....

View 12 Replies View Related

C++ :: Converting Expression From Postfix To Infix

Oct 1, 2013

Program which convert expression from PostFiz to Infix and also wants to evaluate them....

View 3 Replies View Related

C :: Evaluate Postfix Expression (floating Point Numbers)

Apr 4, 2013

The question was to evaluate postfix expression (floating point numbers). I had been able to implement stack data structure using one way singly linked list linked list but I am not been able to extract the original input by the user expressions like

ex:
1. 252.124 3453.7 * 46.3 346.2 23.6 ^/$
2.45.23 87.045 * 6.5 ^$
etc,($ELIMETER)

How to take such inputs from the user for proper evaluation . Previously I tried to extract separate digits from integer and decimal fields and computed numbers. The method is very lengthy. Any optimised way for taking such input!

View 7 Replies View Related

C :: Program To Evaluate Postfix Expression Using Array Implementation Of Stack

Apr 26, 2014

Write a program that evaluates postfix expression using array implementation of stack.

The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.

The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.

Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20

typedef struct{

[Code] ....

View 1 Replies View Related

C++ :: Evaluating Logical Boolean Expressions

Jan 10, 2013

I am looking for a library to aid me in evaluating Boolean expressions. For example, i have an expression like this:

(1*(5+3)+9*65/5-(354*4565*5643+98) >= 12345) && ( 654*987+123 || (2345 > 23423 && 1 != 2)))

(It can also be much longer!) and would like to evaluate them to a true/false boolean.

There are tons of libraries to calculate the (numerical) result of a mathematical expression, but this is not what i want to do.

View 5 Replies View Related

C++ :: Implement Program For Evaluating Infix Expressions

Dec 3, 2014

Also, can't use namespace std for this.

#include<iostream>
#include<stack>
#include<fstream>
#include<iomanip>
#include<queue>
#include<cassert>

[Code] ....

/* It will read in a infix expression from a text file.check if the parentheses in the input expression are balanced.convert the infix expression into a postfix expression and evaluate the expression.*/

int main() {
string expression;
string postfixExpression;
double result;
testBalanced();

[Code] ....

View 8 Replies View Related

C++ :: Simple Multiplication And Division Not Evaluating Correctly

May 29, 2013

At one point in my C++, non-CLR program, the following code:

Code:

unsigned int size = 3;
float maxX = (float)(int(size-1))/2.0f;
std::cout << maxX;

outputs 107. Is it something about a conversion from unsigned int to float?

View 6 Replies View Related

C++ :: Evaluating Arithmetic Expressions Using Recursive Descent Parser?

Feb 25, 2013

I have the following code to calculate arithmetic expressions :

#include <iostream>
using namespace std;
using namespace std;
const char * expressionToParse = "6.5-2.5*10/5+2*5";
char peek(){
return *expressionToParse;

[code]....

The problem is that it does not work properly with decimal numbers for example it evaluates 6-2*10/5+2*5 = 12 which is correct but for 6.5-2.5*10/5+2*5 it returns 6 instead of 11.5 .

View 3 Replies View Related

C++ :: Write A Calculator Using Two Stacks

Apr 13, 2014

I just started by defining a stack class (stackDouble). I need to write a program that accepts an infix calculator expression, with the following operators (**, exponentiation, /, division, and, -, subtraction. The operator precedence is exponent, division, and subtraction.I need to use a stack of doubles and a stack of strings, of which I can write two classes, or write a single stack template. The user will input the expression just via cin, and there will be a # before every number, a ! before each operator, and a . at the end of the expression. '#', '!', or '.' can be input into a char variable, numbers into a double variable and operators into a string variable.

For example, the following would output 6:

# 3 ! / # 2 ! / # .5 ! ** # 2 .

As stated above, I already made up a stackDouble class. What would I need to do to create the other class (I don't think I want to do it with a template)?

Code:
#include <iostream>
#include <string>
using namespace std;
class stackDouble{

[code]....

View 2 Replies View Related

C++ :: How To Make A Template That Has 2 Stacks

Jan 11, 2015

How do I make a Template that has 2 stacks ?

Code:

template <class T>
class A {
};
template <class T>
class B {
};

is this code correct ?

View 1 Replies View Related

C++ :: How To Create A Deque Using 2 Stacks

Nov 27, 2013

I am trying to create a deque using these stacks but I failes again and again.

struct deque {
int key;
dek *next;
} *left = NULL, *right=NULL;
struct elem{

[Code] ......

View 5 Replies View Related

C/C++ :: Reverse String Using Stacks?

Oct 29, 2014

As part of my hw assignment i need to reverse a string using stacks. This is my attempt and so far its not working.

// reverse.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"

[Code].....

View 3 Replies View Related

C++ :: Data Structure - Program Using Stacks

Nov 3, 2013

Given a set of different types of paired symbols; determine whether it is balanced or not (the opening and closing version of each type are paired correctly). Any other type of characters may appear in the input will be neglected.

For example:
(**(*[*])****) is balanced, also [{}**[]**()]** is balanced. But ((*{*)*}) is unbalanced as well as [()***[]***{*(*)}.

Write a C++ program that requires a string containing and expression as an input from the user and check for balanced bracket pairs using stack data structure.

Here is my code which give me nothing when I run it.

#include <iostream>
#include <string>
using namespace std;
class CustomStack {

[Code] ....

View 1 Replies View Related

C++ :: How To Implement Main Queue Functions Using Two Stacks

Nov 8, 2014

How to implement the main queue functions Enque() and Deque() using two stacks S1 & S2. You allowed only to call push () and pop() functions of the two stacks to implement Enque()and Deque() functions.

#include<iostream>
using namespace std;
const int size=5;
int arr[size];
int front=-1,rear=-1;
bool isfull() {
if(rear==size-1)

[Code] .....

View 4 Replies View Related

C++ :: Graph Search Algorithm - Recursion Using Stacks

Mar 22, 2013

Any example of a graph search algorithm that uses a recursion and linked list based stacks to determine a route from a single point on a graph to another single point on a graph?

View 3 Replies View Related

C/C++ :: Recursion In Stack To Get Maximum Element And Copying Stacks

Nov 22, 2012

I am still new to stacks and recursion and am trying to implement two functions using recursion to get the maximum element in a stack and copying one stack into the other but it keeps repeating some elements and i dont understand why!!

this is the code for the functions:

void copyStack(MyStack &firstStack, MyStack &secondStack) {
    if(!firstStack.empty())    {
        string x=firstStack.top();
        firstStack.pop();
        //secondStack.push(x);

[Code] ....

View 2 Replies View Related

C++ :: Recursive Boolean Function - Compare Two Stacks And Returns True If Identical

Oct 21, 2014

The question is to write a recursive boolean function that compares two stacks and returns true if they are identical. This is where I get stuck:

If the top items of both stacks are the same, the recursive call always returns true, because 'true' is saved on top of the return stack.

Here is my code:
template<class Type>
bool identicals(stackType<Type> s1, stackType<Type> s2) {
if(!s1.isEmptyStack() && !s2.isEmptyStack()) {
if(s1.top() != s2.top())

[Code] ....

View 2 Replies View Related

C/C++ :: Calculate Postfix Notation

Feb 15, 2015

My program suppose calculate postfix expression.

Ex. 5 4 + 3 10 * + the answer is 39 because if I change it to infix, it's (5 + 4) + (3 * 10)

I need to use vector to compute the value. Here is what I think. First, I save leftmost from the string. If it is a number, I push. If that is a operation, I pop twice and push the result. By doing it until the string is emptied, the vector will only contain the final answer. And here is my code

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
vector<int> stack;
string input;

[Code] .....

When I put 1 1 + or 2 2 +, it showing me a correct answer, but when I put the above example which is 5 4 + 3 10 * +, it shows 30 instead of 39.

View 8 Replies View Related

C/C++ :: Infix To Postfix Notation

Sep 14, 2014

I'm trying to make an infix to postfix notation calculator. The difficult thing is th stack class is custom. It's not to hard to understand, I don't know if the fact that it is that way will not allow me to receive support. The difference is that the pop functions is as such:

stack<char> conversion;
char temp;
conversion.pop(temp);//It receives a parameter and puts the popped element in there.
conversion.peek(temp);//Places the top element in said parameter

not only that... but these are boolean functions. they return true if the operation was completed. So they can be used as conditions.

#include<iostream>
#include<string>
#include<stdio.h>
#include"stack.h"
using namespace std;
int main(void) {
Stack<char> conversion;
string infix,inter,temps;

[Code] .....

The error is that i am mismanaging parenthesis handling and i can't seem to grasp where and how.

An example input is:(35+7)-(9-2)
that input gives me:35 7 + 9 2 ) -
but another input such as :(35+7)/7
outputs as: 35 7 + 7 /. Totally fine.

View 3 Replies View Related

C++ :: Infix To Postfix Using Stack Conversion

Mar 8, 2013

I am Getting following errors I don't know why.I have mentioned the lines (in comments) where these errors are occurring.
__________________________________________________
warning C4018: '<' : signed/unsigned mismatch
error C2064: term does not evaluate to a function taking 0 arguments
error C2064: term does not evaluate to a function taking 0 arguments
__________________________________________________ _

Code:
/////////////////////////////////////////////////
//libraries
/////////////////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;

[Code] .....

View 1 Replies View Related

C :: Postfix And Prefix On Array Pointer

Apr 25, 2013

first code,

Code:

int aRRay[] = {2,4,8,-2,-1,100};
int *ptr;
int loop;
ptr = &aRRay[0];
}

[code].....

first code result, " aRRay[] " and " ptr + loop " are in the same result
second code result, " aRRay[] " and "ptr + loop " are in the same result too,
third code result, " aRRay[] " and "ptr + loop " are in the same result Except "aRRay[4] = -1 with ptr + 4 = 100 " and "aRRay[5] = 100 with ptr + 5 = 14"

Question:Why the third code had a different result ? Its only because of the increment ++ptr or the round brackets on the *(++ptr) ?

View 4 Replies View Related

C++ :: Postfix Operator Overloading Error

Jul 27, 2012

Recently, i successfully overloaded postfix operator to class counter by using Object and Class. Now, i want to overload same postfix operator to Inheritance. I created my code and generated in compiler. But, my compiler signaled me uncommon error(saw first time) and i couldn't generate any idea where my actually mistake is.

Here is my Code which objective is to count the number increasingly or decreasingly as per object created of CountDn class.

Code:
#include <iostream>
using namespace std;
class Counter // base class
{
protected : // NOTE : Not Private
unsigned int count;

[Code] ....

Error :|41|error: no 'operator++(int)' declared for postfix '++', trying prefix operator instead|
|42|error: no 'operator++(int)' declared for postfix '++', trying prefix operator instead|
|42|error: no match for 'operator=' in 'c2 = c1.CountDn::<anonymous>.Counter:perator++()'|
|44|error: no 'operator--(int)' declared for postfix '--', trying prefix operator instead|

View 10 Replies View Related

C :: Return Local Variable - Infix To Postfix

Nov 21, 2014

So I have been working my way through this assignment and I'm just stuck now. I cannot get this work properly It just tells me I'm trying to return a local variable when attempting to return postfix in the to_postfix function. It is line 97 that wont compile. Also I cannot change anything in runner.c.

Calculator.c
Code:

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ctype.h>
4 #include <string.h>
5 #include "stack.h"

[Code] .....

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved