Class girl is declared as a friend of class boy

Saturday, July 4, 2009 Leave a Comment

If you need more C++ programs then comment. More comments means the more number of programs. Don't forget to tell a friend.... Do you like this website?........Keep connected....

#include<iostream.h>
#include<conio.h>
class boy
{
private:
int income1;
int income2;

public:
void setdata(int in1,int in2)
{
income1=in1;
income2=in2;
}
friend class girl;
};
class girl
{
int income;
public:
int girlfun(boy b1)
{
return b1.income1+b1.income2;
}
void setdata(int in)
{
income=in;
}
void show()
{
boy b1;
b1.setdata(100,200);
cout<<"boy's income1 in show():"<<b1.income1<<endl;
cout<<"girl's income in show():"<<income<<endl;
}
};
void main()
{
clrscr();
boy b1;
girl g1;
b1.setdata(500,100);
g1.setdata(300);
cout<<"boy  b1 total income:"<<g1.girlfun(b1)<<endl;
g1.show();
getch();
}
                                      Output
Boy b1 total income :600
Boy’s income in show():100
Girl’s amount in show()=300

Related Posts :



0 comments »

Leave your response!