155. Example of constant member function

#include<iostream.h> #include<conio.h> class one { private:                 int x,y; public:                 void get()                                 {                                 x=10;                                 y=20;                                 }                 void show() const                                 {                                 x+y;                                 cout<<"Addition = "<<_AX;                                 } }; void main() {                 one obj;                 clrscr();                 obj.get();                 obj.show();                 getch(); }

Advertisements

154. Write a program to access private member of two different classes using friend class?

#include<iostream.h> #include<conio.h> class two;            //Declaration of class class one              //Friend class { private:                 int  x,y; public:                 void get()                                 {                                 x=10;                                 y=20;                                 }                 //Friend function as member function with respect to class one and none-member function with respect to class two                 void show(two t); }; class two {... Continue Reading →

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... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: