Wednesday, 22 February 2012

friend function programme in C++ using two class


/*using friend function with two class*/
#include<iostream>
using namespace std;
class Two;  //define second class to avoid errors
class One  //first class
{
private:
int first;
public:
void data();
friend int num(One obj1,Two obj2)
}
inline void One :: data()
{
cout<<"enter the first number=>"<<endl;
cin>>first>>endl;
}

class Two
{
private:
int second;
public:
void data();
friend int num(One obj1,Two obj2)
}
inline void Two :: data()
{
cout<<"enter the second number=>"<<endl;
cin>>second>>endl;
}
int num(One obj1,Two obj2)
{
int Third=obj1.first*obj2.second;
cout<<"multiplication of two number is=>"<<endl;
cout>>third>>endl;
}
int main()
{
One New1;  //create new object of both class
Two New2;
New1.data();
New2.data();
num(New1,New2);
return 0;
}   //end of main

No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}