Advertisement
malixds_

Untitled

Mar 11th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #ifndef Calc_h
  2. #define Calc_h
  3.  
  4. class Calc
  5. {
  6.     int value;
  7. public:
  8.     void calc(int a, char oper, int b);
  9.     void calc(char oper, int b);
  10.     int getValue();
  11. };
  12. #endif
  13.  
  14. //////////////////////////////////
  15.  
  16. #include "Calc.h"
  17. #include <iostream>
  18. using namespace std;
  19.  
  20. void Calc::calc (int a, char oper, int b)
  21. {
  22.     switch (oper)
  23.     {
  24.     case '+':
  25.         this->value = a + b;
  26.         break;
  27.     case '-':
  28.         this->value = a - b;
  29.         break;
  30.     case '*':
  31.         this->value = a * b;
  32.         break;
  33.     case '%':
  34.         this->value = a % b;
  35.         break;
  36.     }
  37.     return;
  38. }
  39.  
  40. void Calc::calc (char oper, int b)
  41. {
  42.     switch (oper)
  43.     {
  44.     case '+':
  45.         this->value = value + b;
  46.         break;
  47.     case '-':
  48.         this->value = value - b;
  49.         break;
  50.     case '*':
  51.         this->value = value * b;
  52.         break;
  53.     case '%':
  54.         this->value = value % b;
  55.         break;
  56.     }
  57.     return;
  58. }
  59.  
  60. int Calc::getValue()
  61. {
  62.     return value;
  63. }
  64.  
  65. ////////////////////////
  66. #include <stdlib.h>
  67. #include <stdio.h>
  68. #include <iostream>
  69. #include "Calc.h"
  70. using namespace std;
  71.  
  72. int main ()
  73. {
  74.     int a, b;
  75.     char oper;
  76.     Calc res;
  77.     cin >> a >> oper >> b;
  78.     res.calc (a, oper, b);
  79.     int check = 1;
  80.    
  81.     cin >> oper >> b;
  82.     while (oper != 'C')
  83.     {
  84.         check++;
  85.         res.calc(oper, b);
  86.         if (check % 3 == 0)
  87.         {
  88.             if (check == 3)
  89.             {
  90.             cout << res.getValue();
  91.             }
  92.             else
  93.             {
  94.             cout << endl << res.getValue();
  95.             }
  96.         }
  97.         cin >> oper >> b;
  98.     }
  99.     return 0;
  100. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement