123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #include <iostream>
- #include <string>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include "cStack.h"
- unsigned const int FIRST_MASS = 100;
- using namespace std;
- using std::cout;
-
- cStack cStack1;
-
- void abstract ();
- double get_number (char *mass);
- double cosine ();
- double sinus ();
- double addition ();
- double subtraction ();
-
- int main () {
-
- while (true) {
-
-
- char comand[12];
-
- double number = 0;
-
- scanf( "%s%le", &comand, &number);
-
- cout << "comand = " << comand << " number= " << number << endl;
-
-
- char rrr[3][55] = {"pule","Ls", "CC"};
-
- cout << "ewef " << rrr[0] << endl;
-
- if (0 == strcmp(rrr[1], comand)) {
- cout << "Its work \n";
- }
-
- /*
-
- double number;
-
- char mass[FIRST_MASS];
-
- for (int i = 0; i < FIRST_MASS; i++ ) {
- mass [i] = ' ';
- }
-
- gets(mass);
- if (mass [0] == 'p' && mass [1] == 'u' && mass [2] == 's' && mass [3] == 'h' && mass [4] == ' ') {
- number = get_number (mass);
- cStack1.push (number);
-
- cout << "cStack1.stack_size = " << cStack1.stack_size () << endl;
- }
-
- if (mass [0] == 'c' && mass [1] == 'o' && mass [2] == 's') {
- if ( cStack1.stack_size () == 0) {
- cout << "No elements in stack \n";
- }
- else {
- cosine ();
- cout << " work cos\n";
- }
-
- }
-
- if (mass [0] == 's' && mass [1] == 'i' && mass [2] == 'n') {
- if ( cStack1.stack_size () == 0) {
- cout << "No elements in stack \n";
- }
- else {
- sinus ();
- cout << " work sin \n";
- }
-
- }
-
- if (mass [0] == 'a' && mass [1] == 'd' && mass [2] == 'd') {
- if ( cStack1.stack_size () <= 1) {
- cout << "No enough elements in stack \n";
- }
- addition ();
- cout << " work addition \n";
- }
-
- if (mass [0] == 's' && mass [1] == 'u' && mass [2] == 'b') {
- if ( cStack1.stack_size () <= 1) {
- cout << "No enough elements in stack \n";
- }
- else {
- subtraction ();
- cout << " work subtraction \n";
-
- cStack1.show_stack ();
- }
-
- }
-
- if (mass [0] == 'e' && mass [1] == 'n' && mass [2] == 'd') {
- cout << "rezalt = " << cStack1.pop () << endl;
- // goto metka1 ;
- break;
- }
- */
- }
-
-
- return 0;
- }
- double get_number (char *mass) {
-
- double num = 0;
- int degriz = 1;
- double part_of_number = 0;
- int counter = 4;
- for (int i = 4; i < FIRST_MASS; i++) {
- if ((int)mass[i] >= 48 && (int)mass[i] <= 57) {
- //cout << "1 if get_number mass" << i << " " << mass[i] << endl;
- counter ++;
- }
-
- }
- //cout << "counter = " << counter << endl;
- for (int i = counter; i != 4; i--) {
-
- // cout << "get_number mass" << i << " " << mass[i] << endl;
- if (mass[i] != ' ') {
- part_of_number = ((int)mass[i] - 48) * degriz;
- degriz = degriz * 10;
-
- num += part_of_number;
- }
-
- }
-
- //cout << "определено число = " << num << endl;
- return num;
- }
- double cosine () {
-
- double result = cos (cStack1.pop ());
- cStack1.push (result);
-
- cout << "OK \n";
- return result;
- }
- double sinus () {
-
- double rezalt = -999999;
- double element = 0;
-
- element = cStack1.pop ();
- cStack1.push (rezalt = sin (element) );
-
- cout << "OK \n";
- return rezalt;
- }
- double addition () {
-
- double rezalt = -999999;
- double element1 = -999999;
- double element2 = -999999;
-
- element1 = cStack1.pop ();
- element2 = cStack1.pop ();
-
- cStack1.push (rezalt = (element1 + element2));
-
- cout << "OK \n";
- return rezalt;
- }
- double subtraction () {
-
- double rezalt = -999999;
- double element1 = -999999;
- double element2 = -999999;
-
- element1 = cStack1.pop ();
- element2 = cStack1.pop ();
-
- cStack1.push (rezalt = (element1 - element2));
-
-
- cout << "OK \n";
- return rezalt;
- }
- void abstract () {
- cout << "Hellow ! \n"
- << "Comand Enter like \n"
- << "push 232 \n"
- << "sin \n"
- << "cos \n"
- << "add \n"
- << "sub \n"
- << "end " << endl;
- }
|