// @topic T090m12d04x50 inheritance and virtual functions // @brief implementation code for Shape, Rectangle, Circle #include <cstdlib> #include <iostream> #include "shapes.h" Shape::Shape() : cx( 0 ), cy( 0 ) { }//Shape::Shape Shape::Shape( int cx, int cy ) : cx( cx ), cy( cy ) { }//Shape::Shape // constructors Circle::Circle() : Shape( 1, 1 ), m_radius( 1 ) { }//Circle::Circle Circle::Circle( int cx, int cy, int radius ) : Shape( cx, cy ), m_radius( radius ) { }//Circle::Circle // operations void Circle::compute_center() { }//Circle::compute_center int Circle::radius() const { return m_radius; }//Circle::radius // make rectangle a unit-sized square Rectangle::Rectangle() : x1( 0 ), y1( 0 ), x2( DEFAULT_RECT_SIZE ), y2( DEFAULT_RECT_SIZE ) { compute_center(); }//Rectangle::Rectangle int Shape::get_cx() const { return cx; }//Shape::get_cx int Shape::get_cy() const { return cy; }//Shape::get_cy void Rectangle::compute_center() { cx = ( x1 + x2 ) / 2; cy = ( y1 + y2 ) / 2; }//Rectangle::compute_center int Rectangle::width() const { return std::abs( x1 - x2 ); }//Rectangle::width int Rectangle::height() const { return std::abs( y1 - y2 ); }//Rectangle::height void Circle::draw() const { std::cout //<< __LINE__ //<< __FILE__ << __FUNCTION__ << " cx == " << get_cx() << " cy == " << get_cy() << " r == " << radius() << "\n"; }//Circle::draw void Rectangle::draw() const { std::cout << __FUNCTION__ << " cx == " << get_cx() << " cy == " << get_cy() << " w == " << width() << " h == " << height() << "\n"; }//Rectangle::draw