main.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <assert.h>
  7. #include <cstdlib>
  8. #include <vector>
  9. #include "sStack.h"
  10. #include "sCPU.h"
  11. #include "const_gurd.h"
  12. using std::cout;
  13. using std::endl;
  14. void abstract ();
  15. int main () {
  16. bool end_of_while = true;
  17. sCPU cpu1;
  18. sStack stack;
  19. Stack_constructor (&stack);
  20. //sStack_show (&stack);
  21. cpu_constructor (&cpu1, &stack);
  22. abstract ();
  23. while (end_of_while) {
  24. char comand [12];
  25. double number = 0;
  26. //std::vector< std::vector<const char> > analogue;
  27. //analogue.push_back(analogue1);
  28. const char analogue [][44] =
  29. {"push", "sin", "cos", "add", "sub", "mul", "end","last", "show"};
  30. scanf ("%s", comand);
  31. if (0 == strcmp(analogue [0], comand)) {
  32. scanf ("%le", &number);
  33. //cout << number << endl;
  34. }
  35. for (int i = 0; i < NUMBER_OF_COMAND; i++) {
  36. if (0 == strcmp(analogue [i], comand)) {
  37. switch (i) {
  38. case 0:
  39. sStack_Push (&stack, number);
  40. break;
  41. case 1:
  42. sCPU_sinus (&cpu1);
  43. break;
  44. case 2:
  45. sCPU_cosine (&cpu1);
  46. break;
  47. case 3:
  48. sCPU_addition (&cpu1);
  49. break;
  50. case 4:
  51. sCPU_subtraction (&cpu1);
  52. break;
  53. case 5:
  54. sCPU_multiplication (&cpu1);
  55. break;
  56. case 6:
  57. cout << "The calculation result: " << sStack_show_last_element (&stack) << endl;
  58. end_of_while = false;
  59. break;
  60. case 7:
  61. cout << "The last element: " <<
  62. sStack_show_last_element (&stack) << endl;
  63. break;
  64. case 8:
  65. sStack_show (&stack);
  66. break;
  67. } // end of switch
  68. } // end of if
  69. } // end of for
  70. } // end of while
  71. return 0;
  72. }
  73. /*!
  74. Gide to comand
  75. */
  76. void abstract () {
  77. cout << "Hellow ! \n"
  78. << "Comand Enter like \n"
  79. << "push 232 \n"
  80. << "sin \n"
  81. << "cos \n"
  82. << "add --- +\n"
  83. << "sub --- -\n"
  84. << "mul --- * \n"
  85. << "show \n"
  86. << "last \n"
  87. << "end " << endl;
  88. }