How to use Friend Function

Code

#include<iostream.h>
#include<conio.h>
class person
{
private:
	char name[20];
	long int phno;
public:
       void read()
       {
       cout<<"Enter the Name : ";
       cin>>name;
       cout<<"Enter Phone : ";
       cin>>phno;
       }
       void show()
       {
       cout<<"\n Name : "<<name;
       cout<<"\n Phone number : "<<phno;
       }
       };
class student:public person
{
 private:
	 int rollno;
	 char course[20];
 public:
	void read()
	 {
	 person::read();
	 cout<<"Enter the Roll : ";
	 cin>>rollno;
	 cout<<"Enter the Course : ";
	 cin>>course;
	 }
	 void show()
	 {
	 person::show();
	 cout<<"\n Roll.No : "<<rollno;
	 cout<<"\n Course : "<<course;
	 }
};
int main()
{
clrscr();
cout<<" How To Use The Friend Fuction \n";
cout<<" --------------------------------- \n";
student s1;
s1.read();
cout<<"\n ---------------------------------------";
cout<<" \n Displaying Student Information: ";
s1.show();
cout<<"\n ---------------------------------------";
cout<<"\n www.AhirLabs.com";
getch();
return 0;
}

OUTPUT

(Visited 222 times, 1 visits today)
Share with Friends :
Written by:

Leave a Reply

Your email address will not be published. Required fields are marked *