-
What is the output of this program?
#include <iostream>
using namespace std;
class Example
{
int W, H;
public:
void set_values (int, int);
int RectArea () {return (W * H);}
friend Example duplicate (Example);
};
void Example::set_values (int p, int q)
{
W = p;
H = q;
}
Example duplicate (Example RectParameter)
{
Example Rect;
Rect.W = RectParameter.W * 2;
Rect.H = RectParameter.H * 3;
return (Rect);
}
int main ()
{
Example Rectangle, RectangleB;
Rectangle.set_values (2, 3);
RectangleB = duplicate (Rectangle);
cout << RectangleB.RectArea();
return 0;
}
-
- 36
- 3
- 2
- Compilation Error
- None of these
Correct Option: A
In this program, we are using the friend function for duplicate function and calculating the area of the rectangle.