What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

C++ Lab Codings

C++ Program for Friend Functions.

#include<iostream.h>
#include<conio.h>
class Operand2; //forward declaration
class Operand1
{
int a;
public :
void get()
{
cout<<"\n\n\t\tEnter the value of Operand1 : ";
cin>>a;
}
friend void add(Operand1,Operand2);
};
class Operand2
{
int b;
public :
void get()
{
cout<<"\n\n\t\tEnter the value of Operand2 : ";
cin>>b;
}
friend void add(Operand1,Operand2);
};
void add(Operand1 op1, Operand2 op2)
{
/* friend fn to add two numbers*/
cout<<"\n\t\t"<<op1.a<<" + "<<op2.b<<" = "<<op1.a+op2.b;
}
void main()
{
Operand1 op1;
Operand2 op2;
clrscr();
cout<<"\n\n\t\tPROGRAM TO ADD TWO NUMBERS USNIG FRIEND FUNCTION\n\n ";
cout<<"\n\t\tINPUT\n\n";
op1.get();
op2.get();
cout<<"\n\n\t\tOUTPUT\n\n";
add(op1,op2);
getch();
}

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com