152. Write a program to access the private member of class by using friend function?

#include<iostream.h> #include<conio.h> class demo { private:                 int x,y; public:                 void get()                                 {                                 x=10;                                 y=20;                                 }                 friend void show(demo obj); }; void show(demo obj) {                 cout<<"X = "<<obj.x<<endl;                 cout<<"Y = "<<obj.y<<endl; } void main() {                 demo d;                 clrscr();                 d.get();                 show(d);                 getch(); }

Advertisements

151. Write a program to pass the object by call by reference technique?

#include<iostream.h> #include<conio.h> class validity { private:                 int mfg,exp,yr; public:                 void read()                                 {                                 cout<<"Enter Manufacturing Year of Product : ";                                 cin>>mfg;                                 cout<<"Enter Expiry Year of Product : ";                                 cin>>exp;                                 }                 void period(validity &obj)                                 {                                 yr=obj.exp-obj.mfg;                                 cout<<"The Valid Period of Product Is : "<<yr;                                ... Continue Reading →

150. Write a program to pass the object by call by address technique?

#include<iostream.h> #include<conio.h> class validity { private:                 int mfg,exp,yr; public:                 void read()                                 {                                 cout<<"Enter Manufacturing Year of Product : ";                                 cin>>mfg;                                 cout<<"Enter Expiry Year of Product : ";                                 cin>>exp;                                 }                 void period(validity *obj)                                 {                                 yr=obj->exp-obj->mfg;                                 cout<<"The Valid Period of Product Is : "<<yr;                                ... Continue Reading →

Object as function parameter: –

Object as function parameter: - We have three ways to pass the object as actual argument to the formal argument of object type of function definition. Call by value Call by address Call by reference Call by Value: - An actual object will be passed as separate copy (Not master copy) to the formal argument.... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: