Object-Oriented Programming Laboratuvar 11

19.12.2017 Object-Oriented Programming Laboratuvar 11 We use abstract class Employee to represent the general concept of an employee. The classes that...
Author: Ahmet Arat
8 downloads 0 Views 473KB Size
19.12.2017 Object-Oriented Programming Laboratuvar 11 We use abstract class Employee to represent the general concept of an employee. The classes that derive directly from Employee are SalariedEmployee and CommissionEmployee. BasePlusCommissionEmployee is derived from CommissionEmployee and represents the last employee type. Write definitions of the four classes and the overridden methods (earnings and print) according to the table.

Employee

earnings = 0

SalariedEmployee

weeklySalary

CommissionEmployee

commissionRate* grossSales

BasePlusCommissionEmployee (commissionRate* grossSales)+ baseSalary

print firstName lastName social security number: SSN salaried employee: firstName lastName social security number: SSN weekly salary: weeklySalary commission employee: firstName lastName social security number: SSN gross sales: grossSales commission rate: commissionRate base-salaried commission employee: firstName lastName social security number: SSN gross sales: grossSales commissiton rate: commissionRate base salary: baseSalary

1. çokbiçimli Employee (Calisan) sınıfları Bir çalışanın genel temsilini yapmak için soyut (abstract) Employee sınıfını kullanılsın. Employee sınıfından SalariedEmployee (MaasliCalisan) ve CommissionEmployee (KomisyonluCalisan) sınıfları türetilsin. BasePlusCommissionEmployee (MaasliKomisyonlıCalisan), CommissionEmployee sınıfından türetilen diğer bir çalışan sınıfı olsun. Bu 4 sınıfı ve override edilmiş (earnings (kazanç) ve print) metotlarını tabloya göre tanımlayın. Örnek program: 3 farklı class’tan birer çalışan tanımlayın. 8 hafta sonra, her bir çalışana ödenen toplam ücreti ve çalışanlara ödenen toplam ücreti hesaplayın ve ekranda gösterin. Komisyonlu çalışanların o haftaki satış miktarını kullanıcıdan girmesini isteyebilirsiniz.

#ifndef EMPLOYEE_H #define EMPLOYEE_H #define NAME_LEN 32 #define SSN_LEN 10 class Employee { public: Employee(void); virtual double earnings(void) = 0; virtual void print(void) const; protected: char firstName[NAME_LEN+1]; // +1 is for NULL character. char lastName[NAME_LEN+1]; // +1 is for NULL character. char SSN[SSN_LEN+1]; // +1 is for NULL character. }; #endif // EMPLOYEE_H #include "Employee.h" #include #include using std::cin; using std::cout; using std::endl; Employee::Employee(void) { char buffer[128]; cout > buffer; strncpy(firstName, buffer, NAME_LEN); firstName[NAME_LEN] = '\0'; cout > buffer;

strncpy(lastName, buffer, NAME_LEN); lastName[NAME_LEN] = '\0'; cout > buffer; strncpy(SSN, buffer, SSN_LEN); SSN[SSN_LEN] = '\0'; }

void Employee::print(void) const { cout

Suggest Documents