Search This Blog

Monday, 12 November 2012

Write a program for accessing private data members from other class (friend class)

#include<iostream.h>
#include<conio.h>
class emp
{
int eno;
char na[20];
public:
friend class sal;
};
class sal
{
int sal;
public:
emp d;
void input()
{
cout<<"Enter the eno:";cin>>d.eno;
cout<<"Enter the name:";cin>>d.na;
cout<<"Enter the salary:";cin>>sal;
}
void out()
{
cout<<endl<<"Eno is:"<<d.no<<endl<<"Name is:"<<d.na<<endl<<"Salary is:"<<sal;
}
};
void main()
{
sal s;
clrscr();
s.input();
s.out();
getch();
}

Input:
Enter the eno :102
Enter the name:Gopinath
Enter the salary:15000

Output:
Eno is :102
Name is:Gopinathan
Salary is:15000


No comments:

Post a Comment