Program to update content of data member by using concept of friend function.

#include
#include
class bca
{
private:
int x;
float y;
char z;
public:
void getdata();
void display();
friend void update(bca);
};
void bca::getdata()
{
cout<>x;
cout<>y;
cout<>z;
}
void bca::display()
{
cout<<"n Integer value is:"<<x;
cout<<"n Floating point value is:"<<y;
cout<<"n Entered character value is:"<<z;
}
void update(bca t)
{
t.x=(t.x)+15;
t.y=(t.y)+15;
t.z=(t.z)+15;
}
main()
{
class bca k;
clrscr();
cout<“;
k.getdata();
cout<<"n Update value for data member:";
k.display();
getch();
}

Leave a reply