Menu
Popular Courses
Search
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
int width, height;
6.
public:
7.
void set_values (int, int);
8.
int area () {return (width * height);}
9.
friend sample duplicate (sample);
10.
};
11.
void sample::set_values (int a, int b)
12.
{
13.
width = a;
14.
height = b;
15.
}
16.
sample duplicate (sample rectparam)
17.
{
18.
sample rectres;
19.
rectres.width = rectparam.width * 2;
20.
rectres.height = rectparam.height * 2;
21.
return (rectres);
22.
}
23.
int main ()
24.
{
25.
sample rect, rectb;
26.
rect.set_values (2, 3);
27.
rectb = duplicate (rect);
28.
cout
Options:
A .  20
B .  16
C .  24
D .  None of the mentioned
Answer: Option C

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

of the rectangle.
Output:
$ g++ friend1.cpp
$ a.out
24



Was this answer helpful ?
Next Question

Share this page with your friends!

Latest Videos

Chapter 1 - GLOBAL STEEL SCENARIO & INDI Part 1 : (13-04-2024) ICA 2024
Chapter 1 - RMHP / OHP / OB & BP Part 1 : (14-02-2024) GPOE 2024
Cube & Cuboid Part 1 Reasoning (Hindi)
Data Interpretation (DI) Part1 Basic Concepts Reasoning (Hindi)
Counting Figures Part 1 Counting Of Straight Lines Reasoning (Hindi)
Direction Sense Test Part 1 Reasoning (Hindi)
Real Numbers Part 7 Class 10 Maths

Latest Test Papers

Test paper 1 Reasoning & DI
Chapter 3.1 : INTRODUCTION GPOE/GPA 2024
Chapter 1.1 : INTRODUCTION GPOE/GPA 2024
Chapter 2.3 : COAL HANDLING PLANT - Set 1 GPOE/GPA 2024
Chapter 1.1 : Personnel Functions- An overview GFM 2024