153. Write a program to access private members of two different classes uses?

#include<iostream.h>
#include<conio.h>
class two;            //Declaration of Class
class one
{
private:
                int x,y;
public:
                void get()
                                {
                                x=10;
                                y=20;
                                }
                friend void show(one obj1,two obj2);
};
class two
{
private:
                int z;
public:
                void get()
                                {
                                z=30;
                                }
                friend void show(one obj1,two obj2);
};
void show(one obj1,two obj2)
{
                cout<<"X = "<<obj1.x<<endl;
                cout<<"Y = "<<obj1.y<<endl;
                cout<<"Z = "<<obj2.z<<endl;
}
void main()
{
                one a;
                two b;
                clrscr();
                a.get();
                b.get();
                show(a,b);
                getch();
}

153.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: