Ask Question
5 January, 06:52

Define the following Window class: - integer data members, width and height - a constructor that accepts two integer parameters (width followed by height) and uses them to initialize the data members - a friend function, areSameSize, that accepts two Window objects and returns a boolean indicating if they are the same size. Two windows are the same size if the widths and heights match.

+2
Answers (1)
  1. 5 January, 10:33
    0
    The code to this question can be given as:

    Code:

    class Window / / define class window.

    {

    private:

    int width, height; / /define global variable

    public:

    Window (int w, int h) / /define parameterized constructor.

    {

    width = w; / /holds parameter value.

    height = h; / /holds parameter value.

    }

    friend bool areSameSize (Window a, Window b) / /define friend function.

    {

    if ((a. height = = b. height) && (a. width = = b. width)) / /conditional statement.

    {

    return true; / /return value true.

    }

    else / /else block

    {

    return false; / /return value false.

    }

    }

    };

    Explanation:

    In the above code we define a class that is "Window". In this class we define private variable that is "width and height". In this class, we define a parameterized constructor and pass two integer variable that is "w and h". The w variable stands for width and h variable is stands for height. In this constructor, we use a global variable that holds constructor parameter value. In this class, we define friend function. This function is used to provide accessibility to private data members and member function outside the class. The return type of this function is bool because it will give true or false value. In this function, we use the conditional statement. In the if block we check a. height value is equal to b. height and a. width value is b. width. if it is true it will return true else it will return false.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Define the following Window class: - integer data members, width and height - a constructor that accepts two integer parameters (width ...” 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