C++ language

Demonstration Of Private
Previous Home Next

Demonstration Of Private And Public in C++

#include<stdio.h>
class demo
{
private :
int x,y;
public :
int a,b;
void getdata();
void putdata();
};
void demo::getdata()
{
cout<<"\n Emnter the value of x and y";
cin>>x>>y;
cout<<"\n Enter the value of a and b";
cin>>a>>b;
}
void demo::putdata()
{
cout<<"\n Enter the value of x amd y";
cout<<"\n Enter the value of a and b";
}
void main()
{
demo d;
d.getdata();
cout<<"\n the entered values are";
d.putdata();
d.a=10;
d.b=20;
cout<<"\n The value after moderation are";
d.putdata();
}

Output:

Enter value of x and y
23 79
Enter value of a and b
200
100
The entered values are
the value of x is 23 and y is 79
the value of a is 200 and b is 100
he value after moderation
the value of x is 23 and y is 79
the value of a is 10 and b is 20 
Previous Home Next