/*
Class is a friend of another class Sum
*/
#include<iostream>
using namespace std;
class Demo;
class Sample
{
int a;
public:
void accept(Demo &D);
void display(Demo &D);
void sum(Demo &D);
};
class Demo
{
int b;
public:
friend class Sample;
};
void Sample::sum(Demo &D)
{
int c;
c=a+D.b;
cout<<"\n\n Addition:"<<c;
}
void Sample:: accept(Demo &D)
{
cout<<"\n\n Enter two number: ";
cin>>a>>D.b;
}
void Sample:: display(Demo &D)
{
cout<<"\n A:"<<a;
cout<< "\n B:"<<D.b;
}
int main()
{
Sample s;
Demo d;
s.accept(d);
s.display(d);
s.sum(d);
return 0;
}
Class is a friend of another class Sum
*/
#include<iostream>
using namespace std;
class Demo;
class Sample
{
int a;
public:
void accept(Demo &D);
void display(Demo &D);
void sum(Demo &D);
};
class Demo
{
int b;
public:
friend class Sample;
};
void Sample::sum(Demo &D)
{
int c;
c=a+D.b;
cout<<"\n\n Addition:"<<c;
}
void Sample:: accept(Demo &D)
{
cout<<"\n\n Enter two number: ";
cin>>a>>D.b;
}
void Sample:: display(Demo &D)
{
cout<<"\n A:"<<a;
cout<< "\n B:"<<D.b;
}
int main()
{
Sample s;
Demo d;
s.accept(d);
s.display(d);
s.sum(d);
return 0;
}