Home » C++ Programming » Functions » Question
  1. 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;
    }
    1. 36
    2. 3
    3. 2
    4. Compilation Error
    5. 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.



Your comments will be displayed only after manual approval.