Members: Length and width) as a friend class of Square(Data Member: int side). Thus now, all the functions of Rectangle can directly access any private member of Square. In the main function, the first statement created an object 'square' of the class Square, thus calling its constructor and assigning 5 to its data member side. The second statement in the main fun
Write the program of object oriented
Declared Rectangle(Data Members: Length and width) as a friend class of Square(Data Member: int side). Thus now, all the functions of Rectangle can directly access any private member of Square.
In the main function, the first statement created an object 'square' of the class Square, thus calling its constructor and assigning 5 to its data member side.
The second statement in the main function created an object 'rectangle' of the class Rectangle.
In the third statement, 'rectangle' called the function shape() with the object of the class Square passed as its argument. In the 'shape()' function, the value of 'side' (private data member of Square) was assigned to length and breadth. The fourth statement called the function 'getArea' of the class Rectangle.
Step by step
Solved in 2 steps