Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7715147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:18:45+00:00 2026-06-01T02:18:45+00:00

My task is to build a postfix calculator using a linked list to represent

  • 0

My task is to build a postfix calculator using a linked list to represent the stack. I have written the following code for the calculator, however I am receiving a compiler error that I do not understand. The error is coming from the postfixcalc.cpp file and is happening in the if-statement at operand2 = opers.getTop(op). The error reads, “value not ignored as it ought to be”. I am using Dev-C++ and have never encountered this type of message. Any insight would be appreciated. Also, I can provide the StackP files if needed.

/** @file postfixcalc.h*/
#include "StackP.cpp"
#include <string>

using namespace std;
const int MAX_CHARS = 100;

class postfixcalc
{
public:
/** Default constructor. */
    postfixcalc();

// postfixcalc operations:
    void read();
    void show();
    int eval();

private:
    string e;
    Stack opers;
    char stringInput[MAX_CHARS];
    char *p;
};


/** @file postfixcalc.cpp*/

#include <iostream>
#include <cstring>
#include "postfixcalc.h"

using namespace std;

postfixcalc::postfixcalc()
{}

void postfixcalc::read()
{
    cout << "Please enter a postfix expression: ";
    getline(cin, e);

}//end read

void postfixcalc::show()
{
    cout << e << endl;
}//end show

int postfixcalc::eval()
{
    int operand1, operand2, result;
    int op;

    p = strtok(stringInput, " ");
    while(p)
    {
    op = p[0];
    if( op == '+' || op == '-' || op == '*' || op == '/')
    {
        operand2 = opers.getTop(op);
        opers.pop();
        operand1 = opers.getTop(op);
        opers.pop();

        switch(op)
        {
            case '+':
                    result = operand1 + operand2;
                    break;
            case '-':
                    result = operand1 - operand2;
                    break;
            case '*':
                    result = operand1 * operand2;
                    break;
            case '/':
                    result = operand1 / operand2;
                    break;
        }//end switch
        opers.push(result);
    }
    else
    {
        opers.push(op);
    }
    p = strtok(NULL, " ");
}//end while
}//end eval

Here is the implementation of StackP

/** @file StackP.h */

#include "StackException.h"
typedef int StackItemType;

/** ADT stack - Pointer-based implementation. */
class Stack
{
public:
// Constructors and destructor:

   /** Default constructor. */
   Stack();

   /** Copy constructor.
    * @param aStack The stack to copy. */
   Stack(const Stack& aStack);

   /** Destructor. */
   ~Stack();

// Stack operations:
   bool isEmpty() const;
   void push(const StackItemType& newItem) throw(StackException);
   void pop() throw(StackException);
   void pop(StackItemType& stackTop) throw(StackException);
   void getTop(StackItemType& stackTop) const
      throw(StackException);

private:
   /** A node on the stack. */
   struct StackNode
   {
      /** A data item on the stack. */
      StackItemType item;
      /** Pointer to next node.     */
      StackNode    *next;
   }; // end StackNode

   /** Pointer to first node in the stack. */
   StackNode *topPtr;
}; // end Stack

/** @file StackP.cpp */

#include <cstddef>   // for NULL
#include <new>       // for bad_alloc
#include "StackP.h"  // header file

using namespace std;

Stack::Stack() : topPtr(NULL)
{
}  // end default constructor

Stack::Stack(const Stack& aStack)
{
   if (aStack.topPtr == NULL)
      topPtr = NULL;  // original list is empty

   else
   {  // copy first node
      topPtr = new StackNode;
      topPtr->item = aStack.topPtr->item;

      // copy rest of list
      StackNode *newPtr = topPtr;    // new list pointer
      for (StackNode *origPtr = aStack.topPtr->next;
       origPtr != NULL; origPtr = origPtr->next)
      {  newPtr->next = new StackNode;
         newPtr = newPtr->next;
     newPtr->item = origPtr->item;
      }  // end for

      newPtr->next = NULL;
   }  // end if
}  // end copy constructor

Stack::~Stack()
{
   // pop until stack is empty
   while (!isEmpty())
      pop();
   // Assertion: topPtr == NULL
}  // end destructor

bool Stack::isEmpty() const
{
   return topPtr == NULL;
}  // end isEmpty

void Stack::push(const StackItemType& newItem)
        throw(StackException)
{
   // create a new node
   try
   {
      StackNode *newPtr = new StackNode;

      // set data portion  of new node
      newPtr->item = newItem;

      // insert the new node
      newPtr->next = topPtr;
      topPtr = newPtr;
   }
   catch (bad_alloc e)
   {
      throw StackException(
     "StackException: push cannot allocate memory.");
   }  // try
}  // end push

void Stack::pop() throw(StackException)
{
   if (isEmpty())
      throw StackException("StackException: stack empty on pop");
   else
   {  // stack is not empty; delete top
      StackNode *temp = topPtr;
      topPtr = topPtr->next;
      // return deleted node to system
      temp->next = NULL;  // safeguard
      delete temp;
   }  // end if
}  // end pop

void Stack::pop(StackItemType& stackTop) throw(StackException)
{
   if (isEmpty())
     throw StackException("StackException: stack empty on pop");
   else
   {  // stack is not empty; retrieve and delete top
      stackTop = topPtr->item;
      StackNode *temp = topPtr;
      topPtr = topPtr->next;

      // return deleted node to system
      temp->next = NULL;  // safeguard
      delete temp;
   }  // end if
}  // end pop

void Stack::getTop(StackItemType& stackTop) const throw(StackException)
{
   if (isEmpty())
      throw StackException("StackException: stack empty on getTop");
   else
      // stack is not empty; retrieve top
      stackTop = topPtr->item;
}  // end getTop

This is the compiler error:

C:\Documents and Settings\Owner\My… In member function `int postfixcalc::eval()’:

35 C:\Documents and Settings\Owner… void value not ignored as it ought to be

37 C:\Documents and Settings\Owner… void value not ignored as it ought to be

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:18:46+00:00Added an answer on June 1, 2026 at 2:18 am
    void Stack::getTop(StackItemType& stackTop) const throw(StackException)
    
    int postfixcalc::eval()
    {
    int operand1, operand2, result;
        operand2 = opers.getTop(op);
    

    The getTop function does not return anything, and then you take that nothing and store it in an int. I think you wanted something more like this for that line:

       opers.getTop(operand2); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using nant to build our product and have written a custom task to
I have the following question: I was given the task - to build an
I have the following task: Build a personal dictionary for chinese characters. Users choose
I have a build task in rake defined with the following dependencies: desc 'Builds
i have the task to build an artifact of an application that should be
I'm trying to write an MSBuild task to build a database using FluentNhibernate mappings.
When I set out this morning the task seemed simple: build a list of
I'm using the Wix HeatFile task in a post build step <HeatFile OutputFile=Interop.dll.wxs File=..\Interop\bin\x86\$(Configuration)\Interop.dll
I have a custom build of a Unix OS. My task: Adding an IPSec
Task: to build hash using map, where keys are the elements of the given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.