26.8.15

Create a class called 'EMPLOYEE'

Create a class called 'EMPLOYEE' that has

-     EMPCODE and EMPNAME as data members

-     member function getdata( ) to input data

-     member function display( ) to output data

Write a main function to create EMP, an array of EMPLOYEE objects. Accept and display the details of at least 6 employees.


#include<iostream.h>

#include<conio.h>
#include<iomanip.h> class Employee

{
private:  int empcode;
char empname[10]; public: void getdata();

void display();
};
void Employee::getdata()
{
cout<<"\nNAME :"; cin>>empname; cout<<"\nCODE :"; cin>>empcode;

}
void Employee::display()
{
cout<<endl<<setw(20)<<empname<<setw(10)<<empcode;
}

int main()

{
Employee Emp[6]; clrscr();
cout<< "Enter employee details:\n "; for(int i=0;i<6;i++)
{

cout<<"\nemployee "<<i+1<<endl; Emp[i].getdata();
}

cout<<"\nEmployee details are as follows :"; cout<<"\n\n"<<setw(20)<<"NAME"<<setw(10)<<setiosflags(ios::right)<<"CODE";

cout<<"\n------------------------------
";
for(i=0;i<6;i++)

Emp[i].display();

getch();

return(0);

}

*************************OUTPUT*********************************

Enter employee details:

employee 1


NAME :ashok


CODE :111


employee 2


NAME :annapurna


CODE :112


employee 3


NAME :anupama


CODE :113


employee 4


NAME :anuradha


CODE :114


employee 5


NAME :ashraya


CODE :115


employee 6


NAME :akash


CODE :116


Employee details are as follows :

NAME
CODE

----------------------------------------------

Ashok
111

annapurna
112

anupama
113

anuradha
114

ashraya
115

akash
116


No comments:

Post a Comment

Comment Here