This is a sample program on encapsulation. Using encapsulation, here we find the characteristics of a cube.
#include <iostream.h>
#include <conio.h>
class Cube
{
int side;
int area, volume;
public:
void read()
{
cout<<"Enter The Side Of Cube:";
cin>>side;
}
void print()
{
cout<<"*********Characteristics Of Cube*********"<<'\n';
cout<<"Area: "<<6*side*side<<'\n';
cout<<"Volume: "<<side*side*side;
}
};
void main()
{
Cube C;
C.read();
C.print();
getch();
}
OUTPUT:
Enter The Side Of Cube:9
*********Characteristics Of Cube*********
Area: 486
Volume: 729
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