DreamsCoder.com

We Code your Dreams


home > Friend Function Demonstration in C++




Friend Function Demonstration in C++





#include
#include

class student
{
	int roll_no;
	char name[20],address[40];
	
	public:
		friend void getdata(student,course);
//Friend function declaration

};


class course
{
	int c_id,duration;
	char c_name[20]

	public:
		friend void getdata(student,course);
//Friend function declaration
		
};

void getdata(student s,course c)
{
	cout<<"Enter roll no";
	cin>>s.roll_no;
	cout<<"Enter name";
	cin>>s.name;
	cout<<"Enter address";
	cin>>s.address;
	cout<<"Enter course id";
	cin>>c.c_id;
	cout<<"Enter course name";
	cin>>c.c_name;
}	


void main()
{
	student s1;
	course c1;
	getdata(s1,c1);
	getch();
}

Label - cpp





by - Chinmay Mahajan





Are you looking for something else?


Suggested Programs




Why C++ used in Clipper?


What does extern mean in a function declaration?


Virtual Destructor in C++


Vector Demonstration Program in C++