-
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;
}
-
- 15
- 3
- 45
- Compilation Error
- None of these
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.