Answer to Question #222499 in C++ for Jaguar

Question #222499
(c) Consider the partial class declaration of an Employee class below:
class Employee: protected Person{
public:
//...
double Rate;
double GetRate() const;
double GetHours() const;
private:
double Hours;
//...
protected:
double Pay() const;
//...
};

double Employee::Pay() const
{
if (DateOfBirth.GetYear() < 1967){
return Hours*Rate;
}
else{
return (Hours*Rate - (Hours*Rate*0.3));
}
}

(iii) Suggest two possible ways of resolving this compilation error.
1
Expert's answer
2021-08-04T14:10:58-0400
The first version


#include <iostream>


using namespace std;


class Person{


};
class DateOfBirth{
private:
	double Years;
public:
	double GetYear() const;
};


double DateOfBirth::GetYear() const{
	return Years;
}


class Employee: protected Person, public DateOfBirth{
public:
	//...
	double Rate;
	double GetRate() const;
	double GetHours() const;
private:
	double Hours;
	DateOfBirth DateOfBirth;
	//...
protected:
	double Pay() const;


	//...


};


double Employee::Pay() const{
	if (DateOfBirth.GetYear() < 1967){
		return Hours*Rate;
	}
	else{
		return (Hours*Rate - (Hours*Rate*0.3));
	}
}


void main(){
}



The second version:

#include <iostream>


using namespace std;


class DateOfBirth{
private:
	double Years;
public:
	double GetYear() const;
};
double DateOfBirth::GetYear() const{
	return Years;
}


class Person{
public:
	DateOfBirth DateOfBirth;
};




class Employee: public Person{
public:
	//...
	double Rate;
	double GetRate() const;
	double GetHours() const;
private:
	double Hours;
	//...
protected:
	double Pay() const;


	//...


};


double Employee::Pay() const{
	if (DateOfBirth.GetYear() < 1967){
		return Hours*Rate;
	}
	else{
		return (Hours*Rate - (Hours*Rate*0.3));
	}
}


void main(){


}

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
APPROVED BY CLIENTS