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.

3
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.

LANGUAGE: C++

CHALLENGE:

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.

SOLUTION:



class Window{
   int width,height;

   public:
   Window(int w,int h){
   width=w;
   height=h;
}

friend bool areSameSize(Window a,Window b){
   if(a.height==b.height && a.width==b.width)
      return true;
      return false;
   }
};

3 comments

  • Matt says:

    class Window
    {
    public:
    int width,height;
    Window(int w,int h)
    {
    width=w;
    height=h;
    }
    friend bool areSameSize(Window a,Window b)
    {
    if(a.height==b.height && a.width==b.width)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    };

  • vikki92 says:

    error received:
    • You almost certainly should be using: xPos
    • You almost certainly should be using: yPos
    • Solutions with your approach don’t usually use: :
    • Solutions with your approach don’t usually use: return
    ⇒ I haven’t yet seen a correct solution that uses: . (period)
    ⇒ I haven’t yet seen a correct solution that uses: ==
    ⇒ I haven’t yet seen a correct solution that uses: bool

  • vikki92 says:

    error received:
    • You almost certainly should be using: xPos
    • You almost certainly should be using: yPos
    • Solutions with your approach don’t usually use: :
    • Solutions with your approach don’t usually use: return
    I haven’t yet seen a correct solution that uses: . (period)
    I haven’t yet seen a correct solution that uses: ==
    I haven’t yet seen a correct solution that uses: bool

Add comment