Â
In this program, we are going to print Employee's Salary using data Encapsulation in C++ Programming Language.Â
Â
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class Employee
{
private:
// Private attribute
int salary;
public:
void setSalary(int s)
{
salary = s;
}
int getSalary()
{
return salary;
}
};
int main()
{
int a;
Employee myObj;
cout << "Enter Salary: ";
cin >> a;
myObj.setSalary(a);
cout <<"The Salary is: "<< myObj.getSalary();
return 0;
}
//.......Coded by RISHAB NAIR
The Code given below can be used in Turbo C++ Compilers: -
#include <iostream.h>
#include <conio.h>
class Employee
{
private:
// Private attribute
int salary;
public:
void setSalary(int s)
{
salary = s;
}
int getSalary()
{
return salary;
}
};
void main()
{
clrscr();
int a;
Employee myObj;
cout << "Enter Salary: ";
cin >> a;
myObj.setSalary(a);
cout <<"The Salary is: "<< myObj.getSalary();
getch();
}
//.......Coded by RISHAB NAIR
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP