Algorithm-VSM
view release on metacpan or search on metacpan
examples/corpus_with_java_and_cpp/Mixin.cc view on Meta::CPAN
////////////////////// mixin class ManagerType //////////////////////
class ManagerType {
protected:
virtual double productivityGainYtoY() = 0;
virtual int getYearsInManagement() = 0;
virtual bool getEmployeeSatisfaction() = 0;
};
//////////////////////////// class Manager //////////////////////////
class Manager : public Employee, public ManagerType {
Department dept; // note same name as dept in Employee
// but different meaning. Here it is
// dept supervised and not
// department worked in
protected:
int yearsInManagement;
bool employeeSatisfaction;
public:
Manager( string name,
string address,
EducationLevel education,
Department aDept )
: Employee( name, address, education ),
dept( aDept ),
yearsInManagement( 0 ),
employeeSatisfaction( false ) {}
// Since senior-level managers do not belong to any particular
// department, the next constructor is actually for them
Manager( string name,
string address,
EducationLevel education )
: Employee( name, address, education ) {}
double productivityGainYtoY() { //(A)
int lastProd = dept.getProductionLastYear();
int prevProd = dept.getProductionPreviousYear();
return 100 * ( lastProd - prevProd ) / (double) prevProd;
}
void setDepartment( Department dept ){ this->dept = dept; }
int getYearsInManagement() { return yearsInManagement; }
void setYearsInManagement( int y ) { yearsInManagement = y; }
bool getEmployeeSatisfaction() { return employeeSatisfaction; }
void setEmployeeSatisfaction( bool satis ) {
employeeSatisfaction = satis;
}
virtual bool readyForPromotion(){
return ( ( yearsInManagement
>= MinYearsForPromotion ) ? true : false )
&& ( productivityGainYtoY() > 10 )
&& employeeSatisfaction;
}
void print() { Employee::print(); dept.print(); }
~Manager() {}
};
/////////////////////// class ExecutiveManager //////////////////////
// An ExecutiveManager supervises more than one department
class ExecutiveManager : public Manager {
short level;
vector<Department> departments;
public:
// Needed in the second example for type conversion
// from Manager to ExecutiveManager
ExecutiveManager()
: Manager( "", "", eUnknown ), level( 0 ) {}
ExecutiveManager( string name,
string address,
EducationLevel education,
short level )
: Manager( name,
address,
education ), level( level ) {
departments = vector<Department>();
}
void addDepartment( Department dept ) {
departments.push_back( dept );
}
void setLevel( int lvl ) { level = lvl; }
// overrides Manager's productivityGainYtoY():
double productivityGainYtoY(){ //(B)
double gain = 0.0;
vector<Department>::iterator iter = departments.begin();
while ( iter != departments.end() ) {
int lastProd = iter->getProductionLastYear();
int prevProd = iter->getProductionPreviousYear();
gain += ( lastProd - prevProd ) / prevProd;
}
return gain/departments.size();
}
void print() {
Employee::print();
cout << "Departments supervised: " << endl;
vector<Department>::iterator iter = departments.begin();
while ( iter != departments.end() )
iter++->print();
}
~ExecutiveManager(){}
};
/////////////////////// mixin class SalesType ///////////////////////
class SalesType {
protected:
virtual int getYearsInSales() = 0;
virtual double productivityGainYtoY() = 0;
};
///////////////////////// class SalesPerson /////////////////////////
class SalesPerson : public Employee, public SalesType {
int salesLastYear;
int salesPreviousYear;
protected:
int yearsInSales;
public:
SalesPerson( string name,
string address,
EducationLevel education )
: Employee( name,
address,
education,
Department( "Sales" )),
salesLastYear( 0 ),
salesPreviousYear( 0 ),
( run in 1.055 second using v1.01-cache-2.11-cpan-39bf76dae61 )