Ask Question
Today, 17:29

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.

+4
Answers (1)
  1. Today, 18:08
    0
    Following are the code in the C+ + Programming Language.

    //define class and inherited the parent class

    class WindowWithBorder : public Window

    {

    //access modifier

    private:

    //set integer variable

    int borderWidth;

    //set integer variable

    int windowWidth;

    //access modifier

    public:

    //definition of the constructor that accept an integer type argument

    WindowWithBorder (int);

    //definition of the function

    int getUseableWidth ();

    };

    //set constructor outside the class

    WindowWithBorder::WindowWithBorder (int y)

    {

    //initialization in integer variable from function

    windowWidth = getWidth ();

    //initialization in integer variable from the argument list

    borderWidth = y;

    }

    //set function from outside the class

    int WindowWithBorder::getUseableWidth ()

    {

    //return output

    return windowWidth - borderWidth;

    }

    Explanation:

    Here we define a class "WindowWithBorder" which inherit their parent class "Window", inside the class.

    Set two integer data type private variables "borderWidth" and "windowWidth". Write the definition of the "windowWidth" class constructor that accept the integer type argument list. Write the definition of the function "getUseableWidth () " which is integer type.

    Then, we define constructor outside the class which accept the integer type argument list "y" inside it.

    we initialize in the variable "windowWidth" from the function "getWidth () ". Initialize in the variable "borderWidth" from the argument of the constructor.

    Finally, we define function in which we perform the subtraction of the variable "windowWidth" from the variable "borderWidth" and return it.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Assume the existence of a Window class with a function getWidth that returns the width of the window. Define a derived class ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers