main.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include "cStack.h"
  7. unsigned const int FIRST_MASS = 100;
  8. using namespace std;
  9. using std::cout;
  10. cStack cStack1;
  11. void abstract ();
  12. double get_number (char *mass);
  13. double cosine ();
  14. double sinus ();
  15. double addition ();
  16. double subtraction ();
  17. int main () {
  18. while (true) {
  19. char comand[12];
  20. double number = 0;
  21. scanf( "%s%le", &comand, &number);
  22. cout << "comand = " << comand << " number= " << number << endl;
  23. char rrr[3][55] = {"pule","Ls", "CC"};
  24. cout << "ewef " << rrr[0] << endl;
  25. if (0 == strcmp(rrr[1], comand)) {
  26. cout << "Its work \n";
  27. }
  28. /*
  29. double number;
  30. char mass[FIRST_MASS];
  31. for (int i = 0; i < FIRST_MASS; i++ ) {
  32. mass [i] = ' ';
  33. }
  34. gets(mass);
  35. if (mass [0] == 'p' && mass [1] == 'u' && mass [2] == 's' && mass [3] == 'h' && mass [4] == ' ') {
  36. number = get_number (mass);
  37. cStack1.push (number);
  38. cout << "cStack1.stack_size = " << cStack1.stack_size () << endl;
  39. }
  40. if (mass [0] == 'c' && mass [1] == 'o' && mass [2] == 's') {
  41. if ( cStack1.stack_size () == 0) {
  42. cout << "No elements in stack \n";
  43. }
  44. else {
  45. cosine ();
  46. cout << " work cos\n";
  47. }
  48. }
  49. if (mass [0] == 's' && mass [1] == 'i' && mass [2] == 'n') {
  50. if ( cStack1.stack_size () == 0) {
  51. cout << "No elements in stack \n";
  52. }
  53. else {
  54. sinus ();
  55. cout << " work sin \n";
  56. }
  57. }
  58. if (mass [0] == 'a' && mass [1] == 'd' && mass [2] == 'd') {
  59. if ( cStack1.stack_size () <= 1) {
  60. cout << "No enough elements in stack \n";
  61. }
  62. addition ();
  63. cout << " work addition \n";
  64. }
  65. if (mass [0] == 's' && mass [1] == 'u' && mass [2] == 'b') {
  66. if ( cStack1.stack_size () <= 1) {
  67. cout << "No enough elements in stack \n";
  68. }
  69. else {
  70. subtraction ();
  71. cout << " work subtraction \n";
  72. cStack1.show_stack ();
  73. }
  74. }
  75. if (mass [0] == 'e' && mass [1] == 'n' && mass [2] == 'd') {
  76. cout << "rezalt = " << cStack1.pop () << endl;
  77. // goto metka1 ;
  78. break;
  79. }
  80. */
  81. }
  82. return 0;
  83. }
  84. double get_number (char *mass) {
  85. double num = 0;
  86. int degriz = 1;
  87. double part_of_number = 0;
  88. int counter = 4;
  89. for (int i = 4; i < FIRST_MASS; i++) {
  90. if ((int)mass[i] >= 48 && (int)mass[i] <= 57) {
  91. //cout << "1 if get_number mass" << i << " " << mass[i] << endl;
  92. counter ++;
  93. }
  94. }
  95. //cout << "counter = " << counter << endl;
  96. for (int i = counter; i != 4; i--) {
  97. // cout << "get_number mass" << i << " " << mass[i] << endl;
  98. if (mass[i] != ' ') {
  99. part_of_number = ((int)mass[i] - 48) * degriz;
  100. degriz = degriz * 10;
  101. num += part_of_number;
  102. }
  103. }
  104. //cout << "определено число = " << num << endl;
  105. return num;
  106. }
  107. double cosine () {
  108. double result = cos (cStack1.pop ());
  109. cStack1.push (result);
  110. cout << "OK \n";
  111. return result;
  112. }
  113. double sinus () {
  114. double rezalt = -999999;
  115. double element = 0;
  116. element = cStack1.pop ();
  117. cStack1.push (rezalt = sin (element) );
  118. cout << "OK \n";
  119. return rezalt;
  120. }
  121. double addition () {
  122. double rezalt = -999999;
  123. double element1 = -999999;
  124. double element2 = -999999;
  125. element1 = cStack1.pop ();
  126. element2 = cStack1.pop ();
  127. cStack1.push (rezalt = (element1 + element2));
  128. cout << "OK \n";
  129. return rezalt;
  130. }
  131. double subtraction () {
  132. double rezalt = -999999;
  133. double element1 = -999999;
  134. double element2 = -999999;
  135. element1 = cStack1.pop ();
  136. element2 = cStack1.pop ();
  137. cStack1.push (rezalt = (element1 - element2));
  138. cout << "OK \n";
  139. return rezalt;
  140. }
  141. void abstract () {
  142. cout << "Hellow ! \n"
  143. << "Comand Enter like \n"
  144. << "push 232 \n"
  145. << "sin \n"
  146. << "cos \n"
  147. << "add \n"
  148. << "sub \n"
  149. << "end " << endl;
  150. }