Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "utilities.h"
- class Rectangle {
- private:
- int _height;
- int _width;
- public:
- //Constructor to initialize to zero
- Rectangle()
- :_width{}, _height{}
- {}
- //Constructor to initialize to parameter values
- Rectangle(int initial_width, int initial_height)
- : _width{ initial_width }, _height{ initial_height }
- {}
- //Member functions that do not change const values
- //are made const in case of future const instance
- int get_width() const { return _width; }
- int get_height() const { return _height; }
- double get_area() const { return static_cast<double>(_width)
- * static_cast<double>(_height); }
- bool is_square() const
- {
- bool flag = (_height == _width) ? true : false;
- return flag;
- }
- void resize(int new_height, int new_width)
- {
- if ((new_height > 0) && (new_width > 0))
- {
- _height = new_height, _width = new_width;
- }
- else
- {
- cout << "Error: Values not greater than"
- << "zero are set to default value\n";
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement