






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Polymorphism, Simple Payroll Application, Sample Payroll, Sample Output, Never Treat Arrays Polymorphically, Shape Hierarchy Revisited, DrawShapes(), Polymorphism and Arrays are the points you can learn in this object oriented programming subject.
Typology: Slides
1 / 30
This page cannot be seen from the preview
Don't miss anything!























Employee
SalariedEmp HourlyEmp CommEmp
getName calcSalary
sales commRate
hours hourlyRate
salary
calcSalary calcSalary
calcSalary
name taxRate
String
String operator = operator <<
pStr
class Employee {
private: String name; double taxRate; public: Employee( String&, double ); String getName(); virtual double calcSalary() = 0;
}
class SalariedEmp : public Employee
{
private:
double salary;
public:
SalariedEmp(String&,double,double); virtual double calcSalary();
}
SalariedEmp::SalariedEmp(String& n,
double tr, double sal) : Employee( n, tr ) { salary = sal;
}
double SalariedEmp::calcSalary() {
double tax = salary * taxRate; return salary – tax;
}
HourlyEmp ::HourlyEmp( String& n,
double tr, int h, double hr )
: Employee( n, tr ) { hours = h; hourlyRate = hr;
}
double HourlyEmp::calcSalary()
{
double grossPay, tax;
grossPay = hours * hourlyRate; tax = grossPay * taxRate;
return grossPay – tax;
}
CommEmp::CommEmp( String& n,
double tr, double s, double cr ) : Employee( n, tr ) {
sales = s; commRate = cr;
}
double CommEmp::calcSalary()
{
double grossPay = sales * commRate;
double tax = grossPay * taxRate;
return grossPay – tax;
}
void generatePayroll(Employee* emp[], int size) {
cout << “Name\tNet Salary\n\n”;
for (int i = 0; i < size; i++) { cout << emp[i]->getName() << ‘\t’ << emp[i]->calcSalary() << ‘\n’; }
}
class Shape {
…
public:
Shape(); virtual void draw(){ cout << “Shape\n”; } virtual int calcArea() { return 0; }
};