© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 17 – Payroll Application: Introducing Inheritance.

Slides:



Advertisements
Similar presentations
2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 16 – Shopping List Application: Introducing.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 11 – Fundraiser Application: Introducing Scope.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
C++ Inheritance Systems Programming.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
 2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Abstract Classes. Lecture Objectives To learn about abstract classes To understand how to inherit abstract classes To understand how to override abstract.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
 2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
CS102--Object Oriented Programming Lecture 7: – Inheritance Copyright © 2008 Xiaoyan Li.
 2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 15 – Digital Clock Application: Building Your.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
C++ Polymorphism Systems Programming. Systems Programming: Polymorphism 2   Polymorphism Examples   Relationships Among Objects in an Inheritance.
Object-Oriented Programming: Inheritance Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
Chapter 12: Adding Functionality to Your Classes.
 Simple payroll application that polymorphically calculates the weekly pay of several different types of employees using each employee’s Earnings method.
Cpt S 122 – Data Structures Polymorphism
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Object Oriented Concepts
CISC6795: Spring Object-Oriented Programming: Polymorphism.
 2009 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 10 – Enhancing the Wage Calculator Application:
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
 2006 Pearson Education, Inc. All rights reserved Polymorphism, Interfaces & Operator Overloading.
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Inheritance  Virtual Function.
Object Oriented Programming
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 15 Inheritance.
Object-Oriented Programming: Inheritance and Polymorphism.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
C++ How to Program, 7/e. © by Pearson Education, Inc. All Rights Reserved.2.
C++ How to Program, 7/e.  There are cases in which it’s useful to define classes from which you never intend to instantiate any objects.  Such classes.
Part -1 © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Inheritance
Inheritance, Polymorphism, and Virtual Functions
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Polymorphism
Chapter 14 Inheritance Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Object-Oriented Programming: Polymorphism
Chapter 9 Object-Oriented Programming: Inheritance
Lecture 22 Inheritance Richard Gesick.
Object-Oriented Programming: Polymorphism
Fundaments of Game Design
Recitation Course 0610 Speaker: Liu Yu-Jiun.
Presentation transcript:

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 17 – Payroll Application: Introducing Inheritance and Polymorphism Outline 17.1 Test-Driving the Payroll Application 17.2 Inheritance Overview 17.3 Creating the Payroll Application 17.4 Using a Derived Class in the Payroll Application 17.5 Using Multiple Derived Classes in the Payroll Application 17.6 Polymorphism 17.7 Completing the Payroll Application 17.8 Wrap-Up Files Payroll.cpp <- Applicaton Employee.h, Employee.cpp <- Base Class Salaried.h, Salaried.cpp <- Derived Class Payroll.h, Payroll.cpp <- Derived Class Commission.h, Commission.cpp <- Derived Class

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Objectives In this tutorial, you will learn to: –Understand inheritance. –Form new classes quickly from existing classes using inheritance. –Use polymorphism to create an application that conveniently processes related objects as though they are the same.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Payroll Application

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Payroll Application (Cont.) Figure 17.1 Running the completed Payroll application. Figure 17.2 Entering employee information in the Payroll application.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Payroll Application (Cont.) Figure 17.3 Entering salary information in the Payroll application. Figure 17.4 Entering a second employee’s information into the Payroll application.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Payroll Application (Cont.) Figure 17.5 Entering a third employee’s information into the Payroll application. Figure 17.6 Displaying the payroll.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Inheritance Overview Inheritance –A derived class absorbs data members from its base class The derived class normally adds its own data members and member functions A derived class is typically more specialized than its base class –Is a relationship An object of the derived class is an object of the base class –Class Hierarchy Defines inheritance relationships among classes Direct base classes are one level above their derived classes Indirect base classes are two or more levels above their derived classes

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Inheritance Overview (Cont.)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Inheritance Overview (Cont.) Figure 17.8 Inheritance hierarchy for university students.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Inheritance Overview (Cont.) Figure 17.9 Inheritance hierarchy for university CommunityMembers.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Inheritance Overview (Cont.) public inheritance –Use a colon, the public keyword and the base class name –Non private members retain their original member access –private members are also inherited, but are not directly accessible in the derived class The derived class must use the base class’s get and set functions –Base classes can redefine the functions that they inherit

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Inheritance Overview (Cont.) Figure Inheritance hierarchy for Shapes.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application /* Later in the tutorial we will add Hourly and Commission based Employees. */

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application (Cont.) Figure Employee class definition.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application (Cont.) Figure Including the base-class definition. Including the Employee.h header file

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application (Cont.) Figure Defining class SalariedEmployee. SalariedEmployee inherits from Employee Creating a data member for the weekly salary Default arguments The default value is assigned to the argument if the function call does not specify that argument

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application (Cont.) Figure SalariedEmployee constructor definition. Defining the SalariedEmployee class’s constructor Base-class initializer syntax Call base-class constructor with a member initializer Member initializer list initializes a class’s data members Comma-separated list, separated from parameter list by a colon

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application (Cont.) Figure Set and get functions for the data member weeklySalary. Defining get and set functions for the weeklySalary data member

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Creating the Payroll Application (Cont.) Figure Redefining the print function. Displaying SalariedEmployee information Redefine (do not override) base class print method. Calling a base-class function from a derived class Use the base class’s name and the binary scope resolution operator before the function name

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Derived Class in the Payroll Application Figure Including the SalariedEmployee class definition. Including the Salaried.h header file Figure Creating an array of pointers to SalariedEmployee objects. Defining employees to store 10 pointers to SalariedEmployee objects

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Derived Class in the Payroll Application (Cont.) Figure Payroll application’s createEmployee function. Defining variables to store user input Prompting the user for and inputting an employee’s name, social security number and salary

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Derived Class in the Payroll Application (Cont.) Figure Creating a new SalariedEmployee object. Creating a new SalariedEmployee object

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Derived Class in the Payroll Application (Cont.) Figure Displaying information and wages for each SalariedEmployee. Repeating for each SalariedEmployee pointer in the array Displaying the name, social security number and employee type Displaying the weekly salaryAdding the salary to the total Displaying the total payroll

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Derived Class in the Payroll Application (Cont.) Figure Deleting each SalariedEmployee object. Deleting each SalariedEmployee object Figure Entering information for the Payroll application using SalariedEmployee.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Derived Class in the Payroll Application (Cont.) Figure Displaying the payroll in the Payroll application using SalariedEmployee.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application Figure UML class diagram for the Employee inheritance hierarchy in the Payroll application. /* We will now add Hourly and Commission based Employees. This section demonstrates the redefining a function no longer works when there is more than one derived class. */

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Declaring the earnings function in the Employee class. Declaring the earnings function Figure earnings function definition for the Employee class. Defining the Employee class function earnings

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure HourlyEmployee Class definition. HourlyEmployee class definition

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure earnings and print function definitions in the Employee class. Redefining the earnings function in the HourlyEmployee class Redefining the print function in the HourlyEmployee class /* Here is where the errors are introduced. The why question answered shortly. */

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Including the CommissionEmployee and HourlyEmployee class definitions. Including the Commission.h and Hourly.h header files

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Creating an array of pointers to Employee objects. employee stores ARRAY_SIZE (10) pointers to Employee objects /* An array can not store pointers to objects of different types. However, with inheritance, each of our objects (Salary, Commission, Hourly) is an Employee. As a result we can store pointers to the derived classes as pointers to the base class Instances of all our derived classes (Salary, Commission, Hourly) are now saved as pointers of the base class type, but NOT pointing to the base class. */

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Viewing the modified createEmployee function. Prompting the user for and inputting the employee name and social security Displaying a menu that prompts the user for the employee type Prompting the user for and inputting the employee’s salary and creating a new SalariedEmployee object

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Creating a new CommissionEmployee object. Creating a new CommissionEmployee object

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Creating a new HourlyEmployee object. Creating a new HourlyEmployee object

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Displaying information and wages for each Employee. Display the earnings Adding the earnings to the total

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Entering hourly employee information in the Payroll application. Entering earnings information for an hourly employee

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Entering salaried employee information in the Payroll application. Entering earnings information for a salaried employee

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) Figure Payroll application displaying incorrect output. Application does not display employee type and displays incorrect earnings information /* Redefining both earnings and print have failed.*/

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using Multiple Derived Classes in the Payroll Application (Cont.) C++ uses the type of the pointer to an object, not the type of the object, to determine which function to call when a derived class redefines a base class function /* Here is the problem. The answer to the why question.*/

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Polymorphism Polymorphism allows a function call to act differently depending on the type of the object invoking it –Polymorphism means “many forms” virtual functions –Use the type of the object being pointed to determine which version of the virtual function to call –virtual functions are overridden by derived classes –To declare a function virtual precede its declaration with the virtual keyword /* Here is the solution. Virtual functions come in two flavors (normal and pure).*/

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Polymorphism (Cont.) Abstract classes are too general to be instantiated –Make a class abstract by declaring a pure virtual function A pure virtual function has virtual before and = 0 after its declaration A pure virtual function cannot be defined –Abstract classes can be used to define pointers The pointers can then be pointed to objects of any concrete class derived from the abstract class Concrete classes are classes that can be instantiated –A concrete class must override all pure virtual functions it inherits from its base class (if that base class is abstract)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Completing the Payroll Application Figure Declaring a virtual function and a pure virtual function in the Employee class. Declaring functions as virtual so that they can be overridden Declaring function as pure virtual. Figure Updating comments in the displayEmployees function.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Completing the Payroll Application (Cont.) Figure Entering employee information in the completed Payroll application.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Completing the Payroll Application (Cont.) Figure Payroll application using virtual functions to access objects polymorphically. Displaying employee type and correct earnings

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Employee.h (1 of 2)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Employee.h (2 of 2) Declare functions as virtual so that they can be processed polymorphically

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Employee.cpp (1 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Employee.cpp (2 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Employee.cpp (3 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Employee.cpp (4 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Salaried.h Overridden virtual functions

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Salaried.cpp (1 of 3)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Salaried.cpp (2 of 3)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Salaried.cpp (3 of 3) earnings function definition in the SalariedEmployee class print function definition in the SalariedEmployee class

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.h (1 of 2)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.h (2 of 2) Overridden virtual functions

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.cpp (1 of 5)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.cpp (2 of 5)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.cpp (3 of 5)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.cpp (4 of 5) earnings function definition in the HourlyEmployee class

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Hourly.cpp (5 of 5) print function definition in the HourlyEmployee class

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Commission.h (1 of 2)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Commission.h (2 of 2) Overridden virtual functions

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Commission.cpp (1 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Commission.cpp (2 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Commission.cpp (3 of 4)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Commission.cpp (4 of 4) earnings function definition in the CommissionEmployee class print function definition in the CommissionEmployee class

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (1 of 9) Including header files for classes derived from Employee Function prototypes declaring parameters using an array of Employee pointers

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (2 of 9) Array of pointers to Employee s that enables the application to process employees polymorphically

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (3 of 9)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (4 of 9) Use delete to destroy each object referenced by a pointer in the employees array

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (5 of 9) Switch based on the selected employee type Begin the case for a salaried employee Prompt the user for and input the employee type

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (6 of 9) Use new to create a new SalariedEmployee object and store a pointer to it in the employees array Begin the case for a commissioned employee Use new to create a new CommissionEmployee object and store a pointer to it in the employees array

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (7 of 9) Begin the case for an hourly employee Use new to create a new HourlyEmployee object and store a pointer to it in the employees array

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (8 of 9) Process each object derived from Employee polymorphically; the overridden earnings function defined by each subclass is called Add earnings to total Display each employee’s name and type using polymorphism

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Payroll.cpp (9 of 9) Display total earnings

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Lab and Homework Assignment Tutorial 17 − Payroll Application. Turn in annotated source file with your own comments for Exercise or if you did not complete Answer and Turn-in Tutorial 17 Questions 17.1 to Note: The author defines “synonym” on page 371. Always write the question followed by the answer. Remember to highlight the answer. Exercises and For both exercises start from your completed Tutorial. Due next Wednesday