Write a program to perform Normal Function is a Friend of two classes 2

/*
  Normal Function is a Friend of two classes
*/
#include<iostream>
using namespace std;

class Demo;

class Sample
{
    int x;

    public:
           void accept()
           {
              cout<<"\n\n Enter any number: ";
              cin>>x;
           }

           friend void sum(Sample s,Demo d);
};


class Demo
{
    int y;

    public:
           void accept()
           {
              cout<<"\n\n Enter any number: ";
              cin>>y;
           }

           friend void sum(Sample s,Demo d);
};

void sum(Sample s,Demo d)
{
    int c;

    c=s.x+d.y;

    cout<<"\n\n Additioin: "<<c;
}


int main()
{
  Sample s;
  Demo d;

  s.accept();
  d.accept();

  sum(s,d);

  return 0;
}

Previous
Next Post »