-
What is the output of this program?
#include <iostream>
using namespace std;
class Example;
class Example1
{
int W, H;
public:
int Area ()
{
return (W * H);}
void convert (Example p);
};
class Example
{
private:
int side;
public:
void set_side(int p)
{
side = p;
}
friend class Example1;
};
void Example1::convert (Example p)
{
W = p.side;
H = p.side;
}
int main ()
{
Example Square;
Example1 Rectangle;
Square.set_side(5);
Rectangle.convert(Square);
cout << Rectangle.Area();
return 0;
}
-
- 36
- 25
- 16
- 9
- None of these
Correct Option: B
In this program, we are using the friend for the class and calculating the area of the square.