Tải bản đầy đủ (.pdf) (2 trang)

Lập trình hướng đối tượng: Workshop 10

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (66.57 KB, 2 trang )

<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>

<b>Workshop 10</b>


<i><b>Task 1: Employee</b></i>



Design and code a class named <b>Employee</b> that holds information for an employee. Upon
instantiation, an Employee object may receive an <b>integer</b> identifying the employee and a <b>double </b>


holding the employee’s <b>salary</b>. If the object does not receive any data, or receives invalid data,
the object adopts a <b>safe empty state</b>.


Your Employee class includes the following member functions:


• <b>void display() const</b>


o Displays the employee number followed by the salary in (NNNN) - $$$$$$$$$$
format, where NNNN denotes the employee’s number and $$$$$$$$$$ denotes
the employee’s salary.


o Displays the employee number in a field of 4 and the salary in a field of 10 to 2
decimal places.


• <b>bool valid() const</b>


o Returns true if the object holds valid data, false otherwise.


Your Employee class is supported by an <b>extraction operator</b>. For the purpose of this workshop,
you may assume that the user will input the data correctly.


<i><b>Task 2: Manager</b></i>



Derive a class named <b>Manager</b> from <b>Employee</b> that holds information for a manager. Upon
instantiation, a Manager object may receive an <b>integer</b> identifying the <b>number of employees</b> for


which the manager is responsible, an <b>integer</b> identifying the <b>manager’s</b> <b>employee number</b> and
a <b>double</b> holding the manager’s <b>salary</b>. If the object does not receive any data or receives invalid
data, the object adopts a <b>safe empty state</b>.


Your Manager class includes the following member functions:


• <b>void display() const</b>


o Displays the employee information for the object followed by the number of
employees for which the manager is responsible in (NNNN) - $$$$$$$$$$ -
(RRR) format, where NNNN - $$$$$$$$$$ denotes employee information and
RRR denotes the number of employees.


• <b>bool valid() const</b>


</div>
<span class='text_page_counter'>(2)</span><div class='page_container' data-page=2>

o Returns true if the object holds valid data, false otherwise.


Your Manager class is supported by an <b>extraction operator</b>. For the purpose of this workshop,
you may assume that the user will input the data correctly.


<i><b>Note:</b></i>



The main program that uses your class is The output from your program looks
something like:


</div>

<!--links-->

×