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(){
}
Comments
Leave a comment