140. Write a program to access private member of a class?

A. #include<iostream.h> #include<conio.h> class demo { private:                 int x; public:                 void read()                                 {                                 cout<<"Enter The Value of X : ";                                 cin>>x;                                 }                 void display()                                 {                                 cout<<"\nX = "<<x<<endl;                                 } }; void main() {                 demo d;                 clrscr();                 d.read();                 d.display();                 getch(); }... Continue Reading →

Advertisements

139. Write a program to access public member of a class?

  A. #include<iostream.h> #include<conio.h> class demo { public:                 int x;                 float y; }; void main() {                 clrscr();                 demo d;                 d.x=10;                 d.y=20.5;                 cout<<"The Value of X = "<<d.x<<endl;                 cout<<"The Value of Y = "<<d.y<<endl;                 getch(); } B. #include<iostream.h> #include<conio.h> class demo { public:                 int x;                ... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: