Develop a university payroll application. There are two kinds of internee in the university salaried internee, hourly internee. The system takes as input an array containing internee objects, calculates no.of days spent in the university polymorphically, and generates results.
#include<iostream>
using namespace std;
class Internee
{
public:
virtual int GetDays()=0;
};
class Salaried:public Internee
{
int days;
public:
Salaried(int _days)
:days(_days){}
int GetDays(){return days;}
};
class Hourly:public Internee
{
int hours;
public:
Hourly(int _hours)
:hours(_hours){}
int GetDays()
{
//Suppose that 1 university working day is 8 hours
int days=hours/8;
return days;
}
};
int main()
{
const int N=6;
Internee *p[N]={new Salaried(23),new Hourly(128),new Salaried(10),
new Salaried(15),new Hourly(160),new Hourly(144)};
int noOfdays=0;
for(int i=0;i<N;i++)
{
noOfdays+=p[i]->GetDays();
}
cout<<"Total no of days spent in the university are "<<noOfdays;
}
Comments
Leave a comment