You are on page 1of 1

EXPERIMENT NO.

2
AIM:- WAP to show the use of friend function to access the private data of a class.
Program:#include<iostream>
using namespace std;
class student
{
int rollno;
float marks;
char name[30];
public:
void getdata();
friend void detail(student);
};
void student::getdata()
{
cout<<"enter the name roll no and mark of student: "<<endl;
cin>>name>>rollno>>marks;
}
void detail(student s)
{
cout<<" deatils of the student are : "<<endl;
cout<<" roll no: "<<s.rollno<<endl;
cout<<" name: "<<s.name<<endl;
cout<<" marks: "<<s.marks<<endl;
}
int main()
{
student s1,s2;
s1.getdata();
detail(s1);
return 0;
}

Output:-

You might also like