


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Chapter-
class Point {
//implementation };
class Circle:public Point {
//implementation };
void main(void){
Point *p = new Circle(3,3,2.5);
}
Above code is correct. Is there any problem?
YES: If we call Display function through p then which function will execute
Case Study: Payroll System Using
Polymorphism
SalariedEmployee CommissionEmployee HourlyEmployee
BasePlusCommissionEmployee
Employee::Employee(const char *first, const char *last) { firstName = new char[ strlen(first) + 1 ]; strcpy(firstName, first); lastName = new char[ strlen(last) + 1 ]; strcpy(lastName, last); } // Destructor deallocates dynamically allocated memory Employee::~Employee() { delete [] firstName; delete [] lastName; } // Return a pointer to the first name char *Employee::getFirstName() const { return firstName; // caller must delete memory } char *Employee::getLastName() const { return lastName; // caller must delete memory }
CommissionWorker::CommissionWorker(const char *first, const char *last, float c, unsigned q) : Employee(first, last) // call base-class constructor { commission = c > 0? c : 0; quantity = q > 0? q : 0; } void CommissionWorker::setCommission(float c) { commission = c > 0? c : 0; } void CommissionWorker::setQuantity(unsigned q) { quantity = q > 0? q : 0; } float CommissionWorker::earnings() const { return commission * quantity; } void CommissionWorker::print() const { cout << endl << "Commission worker: " << getFirstName() << ' ' << getLastName(); } docsity.com