#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>

int fcnt=0,pcnt=0,n=0;
class Employee
{
protected:
int emp_code;
char name[20];

public:
void getdata()
{
cout<<endl<<"Enter employee code: ";
cin>>emp_code;
cout<<endl<<"Enter employee name: ";
cin>>name;
}

void displaydata()
{
cout<<endl<<"Employee Code-"<<emp_code<<"\tEmployee Name-"<<name;
}

};//End of class Employee

class Parttime;

class Fulltime:virtual public Employee
{
float daily_rate;
int no_of_days;
float full_salary;

public:
void getfull()
{
cout<<endl<<"Enter Daily Rate: ";
cin>>daily_rate;
cout<<endl<<"Enter number of days of employee's working: ";
cin>>no_of_days;
full_salary=daily_rate*no_of_days;
}

void displayfull()
{
cout<<endl<<"Daily Rate=Rs."<<daily_rate<<"/-";
cout<<endl<<"Number of days of working="<<no_of_days<<" days.";
cout<<endl<<"Full time working employee's salary=Rs."<<full_salary<<"/-";
cout<<endl<<endl;
}
friend int search(Fulltime f[],Parttime p[],char []);
}f[10];//End of Fulltime class

class Parttime:virtual public Employee
{
int no_of_hours;
float hourly_rate;
float part_salary;

public:
void getpart()
{
cout<<endl<<"Enter number of hours of employees working: ";
cin>>no_of_hours;
cout<<endl<<"Enter hourly rate: ";
cin>>hourly_rate;
part_salary=no_of_hours*hourly_rate;
}

void displaypart()
{
cout<<endl<<"Hourly Rate=Rs."<<hourly_rate<<"/-";
cout<<endl<<"Number of hours of working="<<no_of_hours<<" hours.";
cout<<endl<<"Part time working employee's salary=Rs."<<part_salary<<"/-";
}
friend int search(Fulltime f[],Parttime p[],char []);
}p[10];//End of Parttime class

int search(Fulltime f[],Parttime p[],char name_search[])
{
for(int i=0;i<=fcnt;i++)
{
if(strcmp(f[i].name,name_search)==0)
return (1);
}
for(int j=0;j<=pcnt;j++)
{
if(strcmp(p[i].name,name_search)==0)
return (2);
}
return (0);
}

int main()
{
int choice;
clrscr();
do
{
cout<<endl;
cout<<endl<<"1.Accept the details of 'n' employees and calculate the salary.";
cout<<endl<<"2.Display the details of 'n' employees.";
cout<<endl<<"3.Search a given Employee.";
cout<<endl<<"4.Exit.";
cout<<endl<<"Enter choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<endl<<"Enter number of employees: ";
cin>>n;
for(int i=0;i<n;i++)
{
 int type;
 cout<<endl<<"1.Full Time Employee"<<endl<<"2.Part Time Employee";
 cout<<endl<<"Enter type: ";
 cin>>type;
 switch(type)
 {
   case 1:
   f[fcnt].getdata();
   f[fcnt].getfull();
   fcnt++;
   break;

   case 2:
   p[pcnt].getdata();
   p[pcnt].getpart();
   pcnt++;
   break;
  }
}
break;

case 2:
cout<<endl<<"Full Time Employees Details: ";
cout<<endl<<"____________________________________________________"<<endl<<endl;
for(i=0;i<=fcnt;i++)
{
f[i].displaydata();
f[i].displayfull();
}
cout<<endl<<"Part Time Employees Details: ";
cout<<endl<<"____________________________________________________"<<endl<<endl;
for(i=0;i<=pcnt;i++)
{
p[i].displaydata();
p[i].displaypart();
}
break;

case 3:
int flag=0;
char name_search[20];
cout<<"Enter name of employee to be searched: ";
cin>>name_search;
flag=search(f[],p[],name_search);
if(flag==1)
cout<<name_search<<" is a Full Time Employee!";
if(flag==2)
cout<<name_search<<" is a Part Time Employee!";
if(flag==0)
cout<<name_search<<" is not an Employee!";
break;

case 4:
exit(0);
break;

default:
cout<<endl<<"Wrong choice!";
}
}while(choice!=4);
getch();
return 0;
}

Post a Comment

Previous Post Next Post