Advertisement
myamikova9

C++4_12

Nov 12th, 2019
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1.  
  2.  
  3. //  main.cpp
  4. //  CLab4_12
  5. //
  6. //  Created by Anna on 04.11.2019.
  7. //  Copyright © 2019 Anna. All rights reserved.
  8. //
  9.  
  10. #include <iostream>
  11. using namespace std;
  12.  
  13. class Counter{
  14.    
  15. public:
  16.     int number;
  17.     Counter(int num){
  18.        
  19.         number = num;
  20.     }
  21.     void print(){
  22.     cout << "A + B = "<<number << endl;
  23.    
  24.     }
  25. //    int Ostatok(){
  26. //        return n%13;
  27. //    }
  28. };
  29. Counter operator + (Counter c1, Counter c2){
  30.     return Counter(c1.number + c2.number);
  31. }
  32.  
  33. int main(int argc, const char * argv[]) {
  34.  
  35.     int a = 0, b = 0;
  36.     while(true)
  37.     {
  38.         cout << "Введите первое число: ";
  39.         cin >> a;
  40.         if(!cin)
  41.         {
  42.             cout << "Неверно! Повторите ввод.\n";
  43.             cin.clear();
  44.             while (cin.get() != '\n');
  45.         }
  46.         else break;
  47.     }
  48.    
  49.     cout <<"A = "<< a << endl;
  50.     a = a % 13;
  51.    
  52.     while(true)
  53.     {
  54.         cout << "Введите второе число: ";
  55.         cin >> b;
  56.         if(!cin)
  57.         {
  58.             cout << "Неверно! Повторите ввод.\n";
  59.             cin.clear();
  60.             while (cin.get() != '\n');
  61.         }
  62.         else break;
  63.     }
  64.     cout <<"B = "<< b << endl;
  65.     b = b % 13;
  66.     cout <<"Oстаток от деления A на 13 равен "<< a << endl;
  67.     cout <<"Oстаток от деления B на 13 равен "<< b << endl;
  68.     Counter c1(a);
  69.     Counter c2(b);
  70.     Counter c3 = c1 + c2;
  71.     c3.print();
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement