Advertisement
SenyaSych

Untitled

Mar 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     setlocale(LC_ALL, "RUS");
  11.     int n, k, r2;
  12.     float x, y, r1;
  13.     char str[256], sl[10], oper1, oper2;
  14.     fstream input;
  15.     ofstream output;
  16.     input.open("H:\\input.txt", ios::in);
  17.     output.open("H:\\output.txt", ios::out);
  18.     if (input)
  19.     {
  20.         while (!input.eof())
  21.         {
  22.             input.getline(str, 256);
  23.             cout << str << endl;
  24.         }
  25.         input.close();
  26.         input.open("H:\\input.txt", ios::in);
  27.         for (int i = 0; i <= 16; i++)
  28.         {
  29.             input >> sl;
  30.             switch (i)
  31.             {
  32.             case 5: x = atoi(sl);
  33.             case 6: oper1 = sl[0];
  34.             case 7: y = atoi(sl);
  35.             case 14: n = atoi(sl);
  36.             case 15: oper2 = sl[0];;
  37.             case 16: k = atoi(sl);
  38.             }
  39.         }
  40.         if (oper1 == '/') r1 = x / y;
  41.         else
  42.         {
  43.             if (oper1 == '-') r1 = x - y;
  44.             else
  45.             {
  46.                 if (oper1 == '*') r1 = x*y;
  47.                 else r1 = x + y;
  48.             }
  49.         }
  50.         if (oper2 == '+') r2 = n + k;
  51.         else
  52.         {
  53.             if (oper2 == '-') r2 = n - k;
  54.             else
  55.             {
  56.                 if (oper2 == '+') r2 = n + k;
  57.                 else r2 = n*k;
  58.             }
  59.         }
  60.         output << x << " " << oper1 << " " << y << " = " << r1 << endl;
  61.         output << n << " " << oper2 << " " << k << " = " << r2 << endl;
  62.         input.close();
  63.         output.close();
  64.     }
  65.     else cout << "” ©« ­Ґ ¬®¦Ґв Ўлвм ®вЄалв!" << endl;
  66.     system("pause");
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement