Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Count {
  6. public:
  7.     int k = 0;
  8.     int r = 0;
  9.     void oper1(int a, char ch, int b);
  10.     void oper2(char s, int b);
  11.     int print();
  12. };
  13.  
  14. void Count::oper1(int a, char s, int b) {
  15.     switch (s) {
  16.         case '+':
  17.             r = a + b;
  18.             break;
  19.         case '-':
  20.             r = a - b;
  21.             break;
  22.         case '*':
  23.             r = a * b;
  24.             break;
  25.         case '%':
  26.             r = a % b;
  27.             break;
  28.     }
  29.     k++;
  30. }
  31.  
  32. void Count::oper2(char s, int b) {
  33.     switch (s) {
  34.         case '+':
  35.             r = r + b;
  36.             break;
  37.         case '-':
  38.             r = r - b;
  39.             break;
  40.         case '*':
  41.             r = r * b;
  42.             break;
  43.         case '%':
  44.             r = r % b;
  45.             break;
  46.     }
  47.     k++;
  48.  
  49. }
  50.  
  51. int Count::print() {
  52.     return r;
  53. }
  54.  
  55. int main() {
  56.     int a, b;
  57.     char s;
  58.     Count count = Count();
  59.     cin >> a >> s >> b;
  60.     count.oper1(a, s, b);
  61.     cin >> s;
  62.     while(s != 'C') {
  63.         cin >> b;
  64.         count.oper2(s, b);
  65.         if(count.k % 3 == 0)
  66.             cout << count.print() << endl;
  67.         cin >> s;
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement