Home » C++ Programming » Functions » Question
  1. 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;
    }
    1. 36
    2. 25
    3. 16
    4. 9
    5. None of these
Correct Option: B

In this program, we are using the friend for the class and calculating the area of the square.



Your comments will be displayed only after manual approval.