Advertisement
Sinux1

MyFirstClass

May 27th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include "utilities.h"
  2.  
  3. class Rectangle {
  4. private:
  5.     int _height;
  6.     int _width;
  7.  
  8. public:
  9.     //Constructor to initialize to zero
  10.     Rectangle()
  11.         :_width{}, _height{}
  12.     {}
  13.     //Constructor to initialize to parameter values
  14.     Rectangle(int initial_width, int initial_height)
  15.         : _width{ initial_width }, _height{ initial_height }
  16.     {}
  17.     //Member functions that do not change const values
  18.     //are made const in case of future const instance
  19.     int get_width() const { return _width; }
  20.     int get_height() const { return _height; }
  21.     double get_area() const { return static_cast<double>(_width)
  22.         * static_cast<double>(_height); }
  23.     bool is_square() const
  24.     {
  25.         bool flag = (_height == _width) ? true : false;
  26.         return flag;
  27.  
  28.     }
  29.     void resize(int new_height, int new_width)
  30.     {
  31.         if ((new_height > 0) && (new_width > 0))
  32.         {
  33.             _height = new_height, _width = new_width;
  34.  
  35.         }
  36.         else
  37.         {
  38.             cout << "Error: Values not greater than"
  39.                 << "zero are set to default value\n";
  40.         }
  41.  
  42.     }
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement