In C++, Compute Salary Of Full time Employee & Manager

#include<iostream>
using namespace std;

class Employee{

	protected:
		double baseSalary;
		int yearsOfService;

	public:
		Employee(double base, int years){
			baseSalary = base;
			yearsOfService = years;
		}

		virtual double salary() = 0;
};

class FulltimeEmployee : public Employee{
	public:
		FulltimeEmployee(double base, int years): Employee(base, years){}

		double salary(){
			double result = baseSalary;
			for(int year = 1; yearsOfService >= year; year++){
				result += (result * 0.05);
			}
			return result;
		}
};

class Manager: public FulltimeEmployee{
	protected:
		int nosDirectReports;
	public:
		Manager(double base, int years, int reports): FulltimeEmployee(base, years){
			nosDirectReports = reports;
		}

		double salary(){
			double result = FulltimeEmployee::salary();
			result += nosDirectReports * 0.1;
			return result;
		}
};

int main(){
	Employee *emp;
	emp = new FulltimeEmployee(300.0, 5);
	cout << "Fulltime Employee's salary: $" << emp->salary() << endl;
	emp = new Manager(300.0, 5, 4);
	cout << "Manager's salary: $" << emp->salary() << endl;
	return 0;
}
Download

Comments

Popular posts from this blog