Assume a class Window with accessor method getWidth that accepts no parameters and returns an integer.

Assume a class Window with accessor method getWidth that accepts no parameters and returns an integer.

LANGUAGE: C++

CHALLENGE:

Assume a class Window with accessor method getWidth that accepts no parameters and returns an integer.
Assume further an array of 3 Window elements named winarr, has been declared and initialized.
Write a sequence of statements that prints out the width of the widest window in the array.

SOLUTION:

if(winarr[0].getWidth()>winarr[1].getWidth() && winarr[0].getWidth()>winarr[2].getWidth())
    cout<<winarr[0].getWidth();
else if(winarr[1].getWidth()>winarr[0].getWidth() && winarr[1].getWidth()>winarr[2].getWidth())
    cout<<winarr[1].getWidth();
else if(winarr[2].getWidth()>winarr[0].getWidth() && winarr[2].getWidth()>winarr[1].getWidth())
    cout<<winarr[2].getWidth();
else if(winarr[0].getWidth()==winarr[0].getWidth() && winarr[1].getWidth()==winarr[1].getWidth())
    cout<<winarr[2].getWidth();

Add comment