Thursday, 22 April 2021

CPP-Slip4-B

 

/*Write a C++ program to create a base class Employee (Emp-code, name, salary). Derive two classes as Fulltime (daily_wages, number_of_days) and Parttime (number_of_working_hours, hourly_wages). Write a menu driven program to perform following functions:

1.Accept the details of ' n ' employees and calculate the salary.

2.Display the details of ' n' employees.

3.Display the details of employee having maximum salary for both types of employees.*/

 

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

 

const int m=50;

 

class emp

{

public:

int empcode;

char empname[30];

public:

void get()

{

cout<<"\n Enter Employee Code.   :  ";

cin>>empcode;

cout<<"\n Enter Employee Name  :  ";

cin>>empname;                     

}

};

class fulltime:public emp

{

public:

 int no_of_days, daily_wages,salary1;

 public:

void getdata()

{

cout<<"\n Enter no_of_days:  ";

cin>> no_of_days;

cout<<"\n Enter daily_wages:  ";

cin>>daily_wages;

}

void cal()

{

salary1= no_of_days * daily_wages;

cout<<" \n Full-Time Salary:  "<<salary1;

}

void show()

{

cout<<"\n ----------------------------------\n";

cout<<"\n Employee Number    :  "<<empcode;

cout<<"\n Employee Name      :  "<<empname;

cout<<"\n Full Time Salary             :  "<<salary1;

cout<<"\n ----------------------------------\n";

}

};

class parttime:public emp

{

public:

int number_of_working_hours, hourly_wages, salary2;

public:

void get1()

{

cout<<"\n Enter Hourly Rate    :  ";

cin>> hourly_wages;

cout<<"\n Enter Working Hours  :  ";

cin>> number_of_working_hours;

}

void cal1()

{

salary2= hourly_wages * number_of_working_hours;

cout<<"\n Part Time Salary               :  "<<salary2<<endl;

}

void show1()

{

cout<<"\n ----------------------------------\n";

cout<<"\n Employee Number    :  "<<empcode;

cout<<"\n Employee Name      :  "<<empname;

cout<<"\n Part Time Salary             :  "<<salary2;

cout<<"\n ----------------------------------\n";                }

};

 

int main()

{

clrscr();

int num,ch,k,l,cnt;

 fulltime f1[5];

parttime p1[5];

 

cout<<"\n********** MENU ***********";

cout<<"\n1.Enter Details of Employee of FullTime";

cout<<"\n2.Enter Details of Employee of PARTTime";

cout<<"\n3.Fulltime Highest Salary";

cout<<"\n4.PARTTime Highest Salary";

cout<<"\n5.Exit.";

 do

{

cout<<"\nEnter your choice:";

cin>>ch;

 switch(ch)

{

case 1:

cout<<"\nHow many records you wish to enter for FullTime:";

cin>>k;

 

for(int i=0;i<k;i++)

 {

f1[i].get();

f1[i].getdata();

f1[i].cal();

f1[i].show();

}

break;

case 2:

cout<<"\nHow many records you wish to enter for PartTime:";

cin>>l;

 for(i=0;i<l;i++)

{

p1[i].get();

p1[i].get1();

p1[i].cal1();

p1[i].show1();

}

break;

 case 3:

cout<<"\n How Many Employee You Want to Display? : ";

cin>>cnt;

for(i=1;i<=cnt;i++)

{

f1[i].show();

}

int temp=0;

for(i=1;i<=cnt;i++)

{

if(f1[temp].salary1<f1[i].salary1)

temp=i;

}

cout<<"\n Employee with Highest Salary is : "<<f1[temp].salary1;

cout<<" \n And, Employee Name is : "<<f1[temp].empname;

break;

 

case 4:

cout<<"\n How Many Employee You Want to Display? : ";

cin>>cnt;

for(i=1;i<=cnt;i++)

{

p1[i].show();

}

int temp=0;

for(i=1;i<=cnt;i++)

{

if(p1[temp].salary2<p1[i].salary2)

temp=i;

}

cout<<"\n Employee with Highest Salary is : "<<p1[temp].salary2;

cout<<" \n And, Employee Name is : "<<p1[temp].empname;

break;

 case 5:

exit(0);

default:

cout<<"\nYou entered wrong choice:";

}

 }while(ch!=5);

getch();

return 0;

}