Menu
Popular Courses
Search
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class sample;
4.
class sample1
5.
{
6.
int width, height;
7.
public:
8.
int area ()
9.
{
10.
return (width * height);}
11.
void convert (sample a);
12.
};
13.
class sample
14.
{
15.
private:
16.
int side;
17.
public:
18.
void set_side (int a)
19.
{
20.
side = a;
21.
}
22.
friend class sample1;
23.
};
24.
void sample1::convert (sample a)
25.
{
26.
width = a.side;
27.
height = a.side;
28.
}
29.
int main ()
30.
{
31.
sample sqr;
32.
sample1 rect;
33.
sqr.set_side(6);
34.
rect.convert(sqr);
35.
cout
Options:
A .  24
B .  35
C .  16
D .  36
Answer: Option D

In this program, we are using the friend for the class and calculating the area of the square.
Output:
$ g++ friend2.cpp
$ a.out
36



Was this answer helpful ?
Next Question

Share this page with your friends!

Latest Videos

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)
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
Real Numbers Part 7 Class 10 Maths

Latest Test Papers

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