Assume the existence of a Window class with a function getWidth that returns the width of the window. Define a derived class WindowWithBorder that contains a single additional integer instance variable named borderWidth, and has a constructor that accepts an integer parameter which is used to initialize the instance variable. There is also a function getUseableWidth, that returns the width of the window minus the width of the border
LANGUAGE: C++
CHALLENGE:
Assume the existence of a Window class with a function getWidth that returns the width of the window. Define a derived class WindowWithBorder that contains a single additional integer instance variable named borderWidth, and has a constructor that accepts an integer parameter which is used to initialize the instance variable. There is also a function getUseableWidth, that returns the width of the window minus the width of the border
SOLUTION:
class WindowWithBorder :public Window{ public: WindowWithBorder(int); int getUseableWidth(); private: int borderWidth; int windowWidth; }; WindowWithBorder::WindowWithBorder(int y){ windowWidth = getWidth(); borderWidth = y; } int WindowWithBorder::getUseableWidth(){ return windowWidth - borderWidth; }