Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- char sz[199] = "7+4/3";
- int nArr[11],
- nOp[11];
- int x = 0,
- y = 0; // Счётчик операторов
- int analis(char);
- void nonitor();
- void nonitor_Op();
- void foo();
- /////////////////////////////////////////////////////////////scanf("%s", sz); /
- int main()
- {
- setlocale(LC_ALL, "rus");
- // cout << "Введите арифметическое выражение: "; cin >> sz;
- cout << " sz = " << sz << endl;
- for(int i = 0; sz[i] != 0; i++)
- {
- cout << "anlis = " << analis(sz[i]) << endl;
- }
- nonitor();
- nonitor_Op();
- foo();
- return 0;
- }
- /////////////////////////////////////////////////////
- void foo()
- {
- int n = 1;
- for(int i = 1; i <= y; i++ )
- {
- switch(nOp[i])
- {
- case 1: cout << nArr[n] <<" + "<< nArr[n+1] <<" = "<<
- nArr[n] + nArr[n+1] << endl;
- break;
- }
- }
- }
- /////////////////////////////////////////////////////////////////////
- int analis(char c)
- {
- if(c >= '0')
- if(c <= '9')
- {
- //nArr[0] ++;
- x ++;
- nArr[ x ] = c - 48;
- return c - 48;
- }
- switch(c)
- {
- case '+': y++;
- nOp[y] = 1; break;
- case '-': y++;
- nOp[y] = 2; break;
- case '*': y++;
- nOp[y] = 3; break;
- case '/': y++;
- nOp[y] = 4; break;
- default: cout << "Error!\n";
- }
- return -1;
- }
- //////////////////////////////////////////////////////////////////////
- void nonitor()
- {
- for(int i = 1; i <= x; i++ )
- {
- cout << nArr[ i ] <<", ";
- }
- cout << endl;
- }
- //////////////////////////////////////////////////////////////////////
- void nonitor_Op()
- {
- for(int i = 1; i <= y; i++ )
- {
- cout << nOp[ i ] <<", ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement