Functions


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class BoxExample
    {
    double W;
    public:
    friend void printW(BoxExample box );
    void setW( double width );
    };
    void BoxExample::setW( double width )
    {
    W = width;
    }
    void printW(BoxExample box )
    {
    box.W = box.W * 3;
    cout << "Width of box : " << box.W << endl;
    }
    int main( )
    {
    BoxExample box;
    box.setW(15.0);
    printW( box );
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    We are using the friend function for printwidth and multiplied the width value by 3, So we got the output as 45.


  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. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, we are using the friend function for duplicate function and calculating the area of the rectangle.



  1. What is the use of function call operator?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    overloading the objects


  1. What will happen when the function call operator is overloaded?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    It will modifies how the operator is to be interpreted when applied to objects of a given type.



  1. Pick out the correct statement.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    virtual functions does not give the ability to rewrite a templated function