main.cpp 1.8 KB

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