Answer to Question #294834 in C++ for Zain

Question #294834

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.

 

1
Expert's answer
2022-02-07T08:04:16-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog