title: Implementing Scientific funtions to HP-35 C++ program
body: <p>I am having some problems in trying to Implement some Scientific functions such as, π (<strong>pi</strong>) and the functions <strong>chs</strong> (change the sign of X), 1/x (<strong>recip</strong>), <strong>log</strong> (decimal logarithm), <strong>ln</strong> (natural logarithm), ex (<strong>exp</strong>), √x (<strong>sqrt</strong>), <strong>sin</strong>, <strong>cos</strong>, <strong>tan</strong> (and their inverses <strong>arcsin</strong>, <strong>arccos</strong>, and <strong>arctan</strong>), and xy (<strong>pow</strong>).</p>
  <p>The function
  names should be accepted in either upper or lower case. Use the functions in the cmath library to do the actual work.
  The predefined constant <strong>M_PI</strong> contains the value of pi.</p>
  <p>Here is my code below in which I am trying to implement the scientific functions to:</p>
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  
  class HPStack
  {
      double stack[100]; //stack to store operands
      int top; //defines topmost position of stack
  //    const double PI = 3.1415926535897;
      double sin(double x);
  
  public:
      HPStack() //constructor to initialize top
      {
          top = -1; //defines empty stack
      }
  
      void push(double data) //adds operand to stack
      {
          top++;
          stack[top] = data;
      }
  
      double pop() //removes operand to stack
      {
          return stack[top--];
      }
  
      double peek() //gets topmost value of stack
      {
          return stack[top];
      }
  };
  
  int main(int argc, char *argv[])
  {
      HPStack stack;
      string line;
  
      while (getline(cin, line)) {
          stringstream expression(line);
          string token;
          while (expression &gt;&gt; token) {
              if (isdigit(token[0])) {
                  stack.push(atof(token.data()));
              }
              else if (token == &quot;sin&quot;)
              {
                  double sin(double x);
                  stack.push(sin(0));
              }
              else if (token == &quot;-&quot;) { // Addition Operation
                  double x = stack.pop();
                  double y = stack.pop();
                  stack.push(y - x);
              }
              else if (token == &quot;+&quot;) { // Subtraction Operation
                  double x = stack.pop();
                  double y = stack.pop();
                  stack.push(y + x);
              }
              else if (token == &quot;/&quot;) { // Multiplication Operation
                  double x = stack.pop();
                  double y = stack.pop();
                  stack.push(y / x);
              }
              else if (token == &quot;*&quot;) { // Division Operation
                  double x = stack.pop();
                  double y = stack.pop();
                  stack.push(y * x);
              }
              else if (token == &quot;M_PI&quot;) { // Division Operation
                  double pi = M_PI;
                  stack.push(M_PI);
              }
              else if (token == &quot;sqrt&quot;) { // Division Operation
                  double sqrt;
                  stack.push(sqrt);
              }
              else if (token == &quot;I&quot;) { // Division Operation
                  double arcsin;
                  stack.push(arcsin);
              }
              else if (token == &quot;arccos&quot;) { // Division Operation
                  double arccos;
                  stack.push(arccos);
              }
              else if (token == &quot;arctan&quot;) { // Division Operation
                  double arctan;
                  stack.push(arctan);
              }
              else if (token == &quot;exp&quot;) { // Division Operation
                  double exp;
                  stack.push(exp);
              }
              else if (token == &quot;pow&quot;) { // Division Operation
                  double pow;
                  stack.push(pow);
              }
              else if (token == &quot;log&quot;) { // Division Operation
                  double log;
                  stack.push(log);
              }
  
          }
          cout &lt;&lt; stack.peek()&lt;&lt;&quot;\n&quot;;
      }
  
      return 0;
  }
  </code></pre>
  <p>Is someone able to give me some help on this? I have started on it as you can see in how I have double PI but I am not having many luck in doing this.</p>