Q. Write in c++ a class called 'Employee'. Write class called 'Part time Employee' and Fulltime employee. write a method called 'monthly_pay' to compute cost of pay, part time employee is paid as per number of working hours and full time employee is paid as per no of working days. create different types of employees using array and compute the pay for all...?
----for the below code obtaining errors suggest me please----
#include<iostream>
#include<cstring>
using namespace std;
class Employee
{
protected:
char emp_name[50];
int emp_type;
double salary;
public:
Employee()
{
emp_name[0]='\0';
emp_type=0;
}
Employee(const char* n,int t)
{
strcpy(emp_name,n);
emp_type=type;
}
virtual double getSalary()
{
return 0;
}
virtual void monthly_pay()
{
cout<<"Employee in leave\n";
}
};
class Fulltime_employee: public Employee
{
int days;
public:
Fulltime_employee(int d)
{
days=d;
}
void monthly_pay()
{
salary=days*700;
}
double getSalary()
{
return salary;
}
};
class Parttime_employee:public Employee
{
int hours;
public:
Parttime_employee(int h)
{
hours=h;
}
void monthly_pay()
{
salary=hours*150;
}
double getSalary()
{
return salary;
}
};
main()
{
Employee *a[5];
for(int i=0;i<5;i++)
{
int type,opt;
char n[10];
cout<<"Enter employee name:";
cin>>n;
cout<<"Enter 1.Fulltime,2.Parttime:";
cin>>opt;
Employee(n,type);
switch(opt)
{
case 1: int d;
cout<<"Enter days:";
cin>>d;
a[i]=new Fulltime_employee(d);
break;
case 2: int h;
cout<<"Enter hours:";
cin>>h;
a[i]=new Parttime_employee(h);
break;
}
}
for(int i=0;i<5;i++)
{
a[i]->monthly_pay();
cout<<a[i]->getSalary()<<endl;
}
for(int i=0;i<5;i++)
{
delete a[i];
}
}
----for the below code obtaining errors suggest me please----
#include<iostream>
#include<cstring>
using namespace std;
class Employee
{
protected:
char emp_name[50];
int emp_type;
double salary;
public:
Employee()
{
emp_name[0]='\0';
emp_type=0;
}
Employee(const char* n,int t)
{
strcpy(emp_name,n);
emp_type=type;
}
virtual double getSalary()
{
return 0;
}
virtual void monthly_pay()
{
cout<<"Employee in leave\n";
}
};
class Fulltime_employee: public Employee
{
int days;
public:
Fulltime_employee(int d)
{
days=d;
}
void monthly_pay()
{
salary=days*700;
}
double getSalary()
{
return salary;
}
};
class Parttime_employee:public Employee
{
int hours;
public:
Parttime_employee(int h)
{
hours=h;
}
void monthly_pay()
{
salary=hours*150;
}
double getSalary()
{
return salary;
}
};
main()
{
Employee *a[5];
for(int i=0;i<5;i++)
{
int type,opt;
char n[10];
cout<<"Enter employee name:";
cin>>n;
cout<<"Enter 1.Fulltime,2.Parttime:";
cin>>opt;
Employee(n,type);
switch(opt)
{
case 1: int d;
cout<<"Enter days:";
cin>>d;
a[i]=new Fulltime_employee(d);
break;
case 2: int h;
cout<<"Enter hours:";
cin>>h;
a[i]=new Parttime_employee(h);
break;
}
}
for(int i=0;i<5;i++)
{
a[i]->monthly_pay();
cout<<a[i]->getSalary()<<endl;
}
for(int i=0;i<5;i++)
{
delete a[i];
}
}