This is a sample C++ Program On Encapsulation. Using Encapsulation, here we ask the user to input details and then display the details of a student.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
class student
{
private:
int roll;
char name[25];
public:
void read()
{
cout<<"Enter Roll Number & Name Of The Student";
cin>>roll;
gets(name);
}
void print()
{
cout<<"Roll Number & Name Of The Student Is:";
puts(name);
cout<<roll;
}
};
void main()
{
clrscr();
student S;
S.read();
S.print();
getch();
}
OUTPUT:
Enter Roll Number & Name Of The Student:
25
Amrita
Roll Number & Name Of The Student:
25
Amrita
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com