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.
.
.
Click on the title for the solution
.
.
.
Click on the title for the solution
.
.
This is the answer:
:
class WindowWithBorder :public Window
{
private:
int borderWidth;
public:
WindowWithBorder(int a){borderWidth=a;}
int getUseableWidth();
};
int WindowWithBorder::getUseableWidth()
{
return (getWidth() - borderWidth);
}
Another answer:
ReplyDeleteclass WindowWithBorder: public Window {
public:
WindowWithBorder(int borderWidth);
int getUseableWidth();
private:
int borderWidth;
};
WindowWithBorder::WindowWithBorder(int borderWidth) : borderWidth(borderWidth) {}
int WindowWithBorder::getUseableWidth() {return getWidth() - borderWidth;}