City Suvidha...your one stop Search

C++ Programs

Go Back to List

Program to implement the friend function.

 


#include<iostream.h>
#include<conio.h>

class B;

class A
{
private:
int a;
public:
void geta()
{
cout<<"enter a:";
cin>>a;
}
friend void add(A x, B y);
};


class B
{
private:
int b;
public:
void getb()
{
cout<<"enter b:";
cin>>b;
}
friend void add(A x, B y);
};


void add(A x,B y)
{
cout<<"sum is:"<<x.a+y.b;
}

void main()
{
A x;
B y;
x.geta();
y.getb();
add(x,y);
getch();
}

Output:


enter a:10
enter b:20
sum is:30
 

If any of you want  to submit your programs and contribute to site please mail us at:

citysuvidha@gmail.com

  Click here to have a look at  List of programs

You can download all the programs in a zip file also. For this you have to do one thing. Just register at the citysuvidha forum  and start any thread of any topic.  Once you start the thread and put your request, admin will automatically send you the desired zip file.