I need to write a reverse polish notation calculator and do not have a clue how to start. The only thing I have is the header file. This thing is due tomorrow at 3pm and I am backed into a corner. If someone can help me or write this for me I will paypal you money, if you just want to give me a kick in the ass to get started I would really like that too!

Here is the assignment.

write a computer program that uses a stack of 10 (maximum), inputs both polar (angle in degrees) and recta ngular values, and provides their sum, difference, product or quotient. The input is to be a “string” variable in either
± 123.456, ± 123.456 rectangular format ( x-coordinate, y-coordinate format) or
± 123.456< ± 123.456 polar format (the angle in degrees follows the”<”). Note that these strings should have no blanks in them (“cin” can be used here). Also, the “ ± ” and decimal point are to be optional. Some input validation should be attempted. If a single character is entered, it should be a +, -, * or / symbol as the RPN operator following two vector operands. Up to 10 vectors can be stacked before an overflow occurs. After each vector entry, the 10 current memory stack values should be displayed. If an operator was entered, the 10 current memory stack values should also be displayed with the result of the operation just completed always at the bottom of the stack. Options to clear the stack and quit should be available to the user.

*kicks ass*

You should have started this long ago.

*kicks ass*

You should have started this long ago.

I understand that, taking 18 hours this semester and just ran out of time.

Did you read the link? I've had semesters where I've taken 17-18+credits. The trick is time management. A social life is good, but not at the expense of your grades.

We can't offer much help unless we have a starting point.

Start out small then build on your starting point until you have all your functionality required.

You're welcome to ask for help if you post correctly, but I suggest you not waste any more time here that could be better spent working on your program.

Did you read the link? I've had semesters where I've taken 17-18+credits. The trick is time management. A social life is good, but not at the expense of your grades.

We can't offer much help unless we have a starting point.

Start out small then build on your starting point until you have all your functionality required.

You're welcome to ask for help if you post correctly, but I suggest you not waste any more time here that could be better spent working on your program.

yes I read the link, thanks for that.


ok so I am going to get 2 classes that convert rect>polar and polar>rect, then get those to push the values onto the bottom of the stacks and go from there. sound like a good gameplan?


I'm trying to write it one small piece at a time, it is just hard to know what piece to begin with.

Depending on what you want to do, another option is a "coordinate" class that can give you either one at any time. That way, you only need 1 stack that holds coordinates then you can use the appropriate public interface function(s) for what you need.

I know this is a mess with notations and stuff everywhere, but do I seem to be on the right path here? I can't figure out how to push the value to to stack or how to get the values in the first place. I have been reading about the shunting yard algorithm and I think I've just confused myself

#include <iostream>
#include <string>
#include <stack>
#include<cmath>
using namespace std;

//Function declaration (prototype)
void rect_to_polar(double, double, double&, double&);
void polar_to_rect(doubt, double);
int main()
{
    char response;
    
    cout<<"Entry format: Polar=Magnitude<phase angle "
    cout<<"or rectangular real, imaginary
    cin>>response;
    
      {
      
    double x, y, mag_conversion, ph_conversion;
    
    cout<<"The value of x in rectangular coordinates is: ";
    cin>>x;
    cout<<"The value of y in rectangular coordinates is: ";
    cin>>y;

//Call to rect_to_polar() function    
    rect_to_polar(x, y, mag_conversion, ph_conversion);
    cout<<"The polar magnitude is: "<<mag_conversion<<endl;
    cout<<"The polar angle (from the x axis) in degrees is: "<<ph_conversion<<endl<<endl<<endl;
    
    
}
}
else{
     class polar
{
  double radius;
  double angle;

  double getx()
    {return radius*cos(angle);} //These two function
  double gety()                 //convert this polar objects
    {return radius*sin(angle);} //into x and y rectangular coords

 public:
   polar()
   {radius=0.0;angle=0.0;}

   polar(float r,float a)
    {
      radius=r;
      angle=a;
    }

   void display()
    {
      cout<<"("<<radius<<", "<<angle<<")";
    }

  polar operator + (polar o2)
  {
    double x=getx()+o2.getx();
    double y=gety()+o2.gety();
    double r=sqrt(x*x + y*y);   //converts x and y to
    double a=atan(y/x);         //Polar co-ordinate.
    return polar(r,a);
  }
};
     
  
         
//rect_to_polar() function header
void rect_to_polar(double r, double i, double& m, double& p)
{
     m = sqrt(pow(r,2)+pow(i,2));
     p = atan(i/r);
     
//Convert from degrees to radians     
     p=p*180/3.14159;
     
//Correct for quadrants II and IV     
     if (r < 0 && i >=0) p = p + 180;
     if (r < 0 && i <0) p = p - 180;
     
     
   return;        
}     




/*

stack<string> calculator_string

....

mystack.push(conversion_values)

calculator_string.pop() <- returns next value on stack

calculator_string.size() <- returns size of stack

*/

Did you cut/paste or did you type directly in the posting box? You have a double-quote messed up on Line 16.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.