1 Replies - 881 Views - Last Post: 11 October 2013 - 03:35 AM Rate Topic: -----

#1 teg01   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-October 13

Getting a strange error in my RPN Calculator program that uses array

Posted 11 October 2013 - 12:46 AM

My program uses a stack template class using array implementation to simulate an RPN calculator but I'm getting this strange error in my code.

Too few arguments to function call, single argument 'parameter' was not specified

I'm receiving errors in 3 different places and they all seem to be directed at my ".pop" function. I'm confused because I don't see any logic issues with that function nor any other issues that I can see.

They happen in the following places in my program in the .cpp:
for (Stack<double> copy = rpnStack; !copy.isEmpty(); copy.pop()) // line 23
rpnStack.pop(); // line 78
rpnStack.pop(); //line 83



Stack.h
#ifndef StackDriver_h
#define StackDriver_h

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

template <class DataType>
class Stack
{
public:
	Stack(); // default constructor
  bool isEmpty() const; // returns result of the condition -1 == top T/F
  void push (const DataType & parameter);
  bool peek (DataType & parameter) const;
  bool pop (DataType & parameter);
  void makeEmpty();
  inline int getTop() const;
  
private:
  DataType* data;
  int capacity;
  int top; // track newest value
};

template <class DataType>
inline int Stack<DataType>::getTop() const
{
  return top;
}

template <class DataType>
Stack<DataType>::Stack()
: capacity(2), data(new DataType[2]), top(-1){}

template <class DataType>
bool Stack<DataType>::isEmpty() const {return -1 == top;}

template <class DataType>
void Stack<DataType>::push(const DataType& parameter)
{
  if (++top == capacity)
    capacity << 1; //double the capacity as in Array
    data[top] = parameter;
}

template <class DataType>
bool Stack<DataType>::peek(DataType& parameter) const
{
  if (-1 == top) return false; // failed
  parameter = data[top];
  return true; // success
}

template <class DataType>
bool Stack<DataType>::pop(DataType& parameter)
{
  if (-1 == top) return false; // failed
  parameter = data[top--];
  if (top > 2 && top < capacity / 4)
    capacity >> 1; //halve the capacity
    return true; // success
}

template <class DataType>
void Stack<DataType>::makeEmpty() {top = -1;}

#endif 



rpnCalculator.cpp
//#include <stack>
#include <string>
#include <sstream>
#include <iostream>

#include "Stack.h"

using namespace std;

bool operatorNum(string variable);
void compute(const string& variable, Stack<double>& rpnStack);

int main()
{  
  Stack<double> rpnStack;
  string variable;
  
  while (true)
  {
    // collect user input
    cout << "Enter: ";
    
    for (Stack<double> copy = rpnStack; !copy.isEmpty(); copy.pop())
    {
      cout << copy.getTop() << " ";
    }
    
    cin >> variable;
    
    
    // get number
    double num;
    if(istringstream(variable) >> num) // input stream class to operate on strings
    {
      rpnStack.push(num);
    }
    
    // operator
    else if (operatorNum(variable))
    {
      compute(variable, rpnStack);
    }
    
    // when user quits "Q" or "q"
    else if(variable == "q" || "Q")
    {
      break;
    }
    
    // invalid output
    else
    {
      cout << "Try again" << endl;
    }
  }
  
}

bool operatorNum( string variable)
{
  string ops[] = {"-", "+", "*", "/"};
  
  for (int i = 0; i < 4; i++)
  {
    if (variable == ops[i])
      return true;
  }
  return false;
  
}


void compute(const string& variable, Stack<double>& rpnStack)
{
  double left, right, result;
  
  right = rpnStack.getTop();
  rpnStack.pop();
  
  if (!rpnStack.isEmpty())
  {
	  left = rpnStack.getTop();
	  rpnStack.pop();
  }
  
  if (variable == "-")
  {
    result = left - right;
  }
  
  else if (variable == "*")
  {
    result = left * right;
  }
  
  else if (variable == "+")
  {
    result = left + right;
  }
  
  else
  {
    result = left / right;
  }
  
  rpnStack.push(result);
  
}



Is This A Good Question/Topic? 0
  • +

Replies To: Getting a strange error in my RPN Calculator program that uses array

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2630
  • View blog
  • Posts: 4,190
  • Joined: 21-June 11

Re: Getting a strange error in my RPN Calculator program that uses array

Posted 11 October 2013 - 03:35 AM

Your pop method requires an argument, but you're not giving it one.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1