Object-oriented programming (staff management, knowledge derived points inheritance, polymorphism, naming, bulk) ...

Object-oriented programming (staff management, knowledge derived points inheritance, polymorphism, naming, bulk)

1. Title Description:

A small company, we need the information store staff (including the number, grade, salary), and displays all the information.

Please a class Employee design, construction and destructor defined and uniform definition of the operation should personnel information.

Employee class, the data members include: number (4), level (an integer), monthly (floating point). Operation (i.e. function member) comprising: setting number and extraction, and the extraction level is calculated, and extraction is provided monthly.

In the main function of the three examples of the staff, and outputs the corresponding information is provided.

2. improvements:

There are four types of company staff: manager, sales manager, part-time technical staff, part-time salesman.

For the four categories of personnel information processing method is not identical:

Manager: fixed monthly salary of 8000 yuan

Part-time art: according to 100 / hour, calculated based on the number of work hours monthly

Part-time salesman: 4% monthly sales commission;

Sales Manager: a fixed monthly salary (5000) + Commission (the jurisdictions month sales of 5% of the total)

3. The development of requirements:

A description of the company's four categories of staff: manager, sales manager, part-time technical staff, part-time salesman. Now, the need to store the names of these persons, number, grade, salary, calculate and display the total monthly salary of employees all the information.

For the four categories of personnel information processing method are not identical (e.g., different methods of calculating monthly), and therefore can not be used to describe the same class, four categories can be considered design, describe these four persons. But there are all kinds of these four have a lot of members are the same, such as name, number, level, etc.; some member functions such as upgrading, calculated monthly, is each class need only implement different methods.

4. Code


7411425-3f28752ae0e39557.png
1 complete code

5. Run results


7411425-1dd13d671a96a4d9.png
Figure 2 operating results

Update

Code memory leak, the return 0; added before the delete [] pe; free memory.

Reproduced in: https: //www.jianshu.com/p/c54d4893be59

Guess you like

Origin blog.csdn.net/weixin_34319999/article/details/91252776