delix777

Спринт 4. Инициализация объектов и конструктор по умолчанию.

Jan 26th, 2024 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using namespace std;
  2.  
  3. class Rational {
  4. public:
  5.    
  6.     Rational (){
  7.         numerator_ = 0;
  8.         denominator_ = 1;
  9.     }
  10.    
  11.     int Numerator() const {
  12.         return numerator_;
  13.     }
  14.  
  15.     int Denominator() const {
  16.         return denominator_;
  17.     }
  18.    
  19.     void SetNumerator(int numerator) {
  20.         numerator_ = numerator;
  21.     }
  22.  
  23.     void SetDenominator(int denominator) {
  24.         if (denominator != 0) {
  25.             denominator_ = denominator;
  26.         }
  27.     }
  28.  
  29. private:
  30.     int numerator_ /*= 0*/;
  31.     int denominator_ /*= 1*/;
  32. };
Add Comment
Please, Sign In to add comment