//Downloaded From theonlinetutorials.com
//Program to illustrate Classes and objects
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class emp //Employee class
{
int empcode;
char empname[20];
char desig[20];
float bsal,hra,da,netsal;
void calculate();
public:emp()
{ //Assigning all values as 0
empcode=0;
bsal=0.0;
hra=0.0;
da=0.0;
netsal=0.0;
strcpy(empname,"Not Initialised");
strcpy(desig,"Not Initialised");
}
void input(); //Calling input and output functions
void output();
}ob[10];
void emp::calculate() //calculate function
{
netsal=bsal+hra+da;
}
void emp::input() //accept values from user
{
cout<<"\nEnter the employee code:";
cin>>empcode;
cout<<"\nEnter the employee name:";
gets(empname);
cout<<"\nEnter designation:";
gets(desig);
cout<<"\nEnter the basic salary:";
cin>>bsal;
cout<<"\nEnter HRA:";
cin>>hra;
cout<<"\nEnter DA:";
cin>>da;
calculate();
}
void emp::output() //Output values
{
cout<<empcode;
cout<<empname;
cout<<desig;
cout<<netsal;
}
void main()
{
clrscr();
int i,n;
cout<<"\nEnter the number of employees:";
cin>>n;
for(i=0;i<n;i++)
{
ob[i].input();
}
cout<<"\n\nCode\tName\tSalary\n";
for(i=0;i<n;i++)
{
ob[i].output();
cout<<endl;
}
getch();
}
Not Satisfied ? Just search & get the result
Related posts:
