Skip to content

Commit 4f36ad1

Browse files
authored
Added Friend Class Program
1 parent d45ea2d commit 4f36ad1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

friendclass.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include<iostream.h>
2+
#include<conio.h>
3+
class ABC;
4+
class XYZ
5+
{
6+
int x;
7+
public:XYZ()
8+
{
9+
x=0;
10+
}
11+
void getdata(int b)
12+
{
13+
x=b;
14+
}
15+
friend void large(XYZ,ABC);
16+
};
17+
class ABC
18+
{
19+
int a;
20+
public:ABC()
21+
{
22+
a=0;
23+
}
24+
void getdata(int c)
25+
{
26+
a=c;
27+
}
28+
friend void large(XYZ,ABC);
29+
};
30+
void large(XYZ m,ABC n)
31+
{
32+
if(m.x>=n.a)
33+
{
34+
cout<<m.x<<" is large ";
35+
}
36+
else
37+
{
38+
cout<<n.a<<" is large ";
39+
}
40+
}
41+
void main()
42+
{
43+
int i,j;
44+
clrscr();
45+
ABC abc;
46+
cout<<"\nEnter the 1st number : ";
47+
cin>>i;
48+
abc.getdata(i);
49+
XYZ xyz;
50+
cout<<"\nEnter 2nd number : ";
51+
cin>>j;
52+
xyz.getdata(j);
53+
large(xyz,abc);
54+
getch();
55+
}

0 commit comments

Comments
 (0)