W05 Polymorphism
W05 Polymorphism
Week 05
Polymorphism
Cảm ơn thầy Trần Duy Quang đã cung cấp template cho môn học
1
Notes
Create a single solution/folder to store your source code in a week.
Then, create a project/sub-folder to store your source code of each assignment.
The source code in an assignment should have at least 3 files:
• A header file (.h): struct definition, function prototypes/definition.
• A source file (.cpp): function implementation.
• Another source file (.cpp): named YourID_Ex01.cpp, main function. Replace 01 by id of an
assignment.
Make sure your source code was built correctly. Use many test cases to check your code before
submitting to Moodle.
Name of your submission: StudentID_W05_YY.zip. YY: number of assignments you have done. YY:
00 – 99.
2
OOP W05 – Polymorphism
2
Content
In this lab, we will review the following topics:
1. Apply polymorphism to maintain a list of objects that have the same base class.
3
OOP W05 – Polymorphism
3
Assignments
A: YY: 01 (class diagram in png format, full of Assignment 1; source code in C++, half of
Assignment 1)
H: YY: 04
Draw a class diagram and implement in C++ for each of the following assignments.
Class diagram: https://en.wikipedia.org/wiki/Class_diagram
Use class string and class vector.
The system should store the following info for each employee: employ id, full name, hire date, address.
There are 2 types of employees in the company: Office employee and worker.
• Salary of an office employee in a month = number of his/her working days * pay rate per day
(300.000 VND/day)
• Salary of a worker in a month = number of items he/she produced in the month * rate pay per
item (20.000VND/item)
In this week exercise, you are asked to create 3 classes: Employee, OfficeEmployee and Worker.
OfficeEmployee and Worker extends/inherits from Employee.
Then you must define and implement the following methods for each Employee classes.
Then, define another class, Company, store all types of employees in a single array. And write the
following methods for class Company:
4
OOP W05 – Polymorphism
3.3. Assignment 3
Problem 1, ITEC Final Exam, 2017-2018