fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #include "Stack.h"
  5.  
  6. int main ()
  7. {
  8. string str = "10-11*5+4/2";
  9.  
  10. cout << parse (str) << endl;
  11.  
  12. return 0;
  13. }
  14.  
  15. int parse (string& str)
  16. {
  17.  
  18. Stack theStack;
  19.  
  20. int first, second;
  21.  
  22. for (int n = 0; n < str.size (); n++)
  23. {
  24. switch (str [n])
  25. {
  26.  
  27. case '*':
  28. getTwoOffStack (theStack, first, second);
  29. theStack.push (first * second);
  30. break;
  31.  
  32. case '/':
  33. getTwoOffStack (theStack, first, second);
  34. theStack.push (first / second);
  35. break;
  36.  
  37. case '+':
  38. getTwoOffStack (theStack, first, second);
  39. theStack.push (first + second);
  40. break;
  41.  
  42. case '-':
  43. getTwoOffStack (theStack, first, second);
  44. theStack.push (first - second);
  45. break;
  46.  
  47.  
  48. char str [3];
  49.  
  50. str [0] = str [n];
  51. str [1] = '\0';
  52.  
  53. theStack.push (atoi (str));
  54. }
  55. }
  56.  
  57.  
  58. int returnVal = theStack.getTop ();
  59.  
  60. theStack.pop ();
  61.  
  62. return returnVal;
  63. }
  64.  
  65. void getTwoOffStack (Stack& theStack, int& first, int& second)
  66. {
  67.  
  68. second = theStack.getTop ();
  69.  
  70. theStack.pop ();
  71.  
  72. first = theStack.getTop ();
  73.  
  74. theStack.pop ();
  75. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:19: fatal error: Stack.h: No such file or directory
 #include "Stack.h"
                   ^
compilation terminated.
stdout
Standard output is empty