You are on page 1of 2

Friend Class 1

============================================
#include <iostream.h>

class Lahore;
class Multan;
class Punjab{
public:
Punjab()
{
Budget=0;
}

int getBudget(){return Budget;}


Punjab addFund(Lahore f1, Multan f2);

private:

int Budget;
};

class Lahore{
public:
Lahore(){budget=0;}
Lahore(int budget)
{
this->budget=budget;
}
friend Punjab Punjab::addFund(Lahore f1, Multan f2);

private:

int budget;
};

class Multan{
public:
Multan(){budget=0;}
Multan(int budget)
{
this->budget=budget;
}
friend Punjab Punjab::addFund(Lahore f1, Multan f2);
private:

int budget;
};

Punjab Punjab::addFund(Lahore f1, Multan f2)


{
Budget=f1.budget+f2.budget;
return *this;

void main()
{

Punjab punjab;
Lahore lahore(6000);
Multan multan(6000);
punjab.addFund(lahore,multan);
cout<<"\nTotal Fund = "<<punjab.getBudget();
cout<<endl<<endl;
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006