Part A

A mathematical conjecture states that if we start with any positive number, we can get to the value 1 by repeating 2 steps depending on the value of the current number.

If the current value is even, we divide the number by 2 and reapply the steps again (number / 2).

If the number is odd, we multiply the current number by 3 and add 1 to the result and reply the previous steps again (number * 3 + 1).

If we keep repeating the two possible alternative steps, we will eventually get to the value 1 at which point we are finished.

Write a recursive function to test the conjecture. The function should return the number of times we had to recur through the function and the highest number that we generated by the use of the two possible steps during the process. Your solution will need to handle large numbers for processing. Do not use global variables in your solution.

Sample run capture from the function

Starting with 9 it took 19 steps; the highest number achieved 52.
Starting with 27 it took 111 steps; the highest number achieved 9232.
Starting with 837791 it took 162 steps; the highest number achieved 122288020.
Starting with 837799 it took 524 steps; the highest number achieved 2974984576.

Part B

For this exercise you may create other methods and functions to help you write the application. Some of the functions/methods in the specifications need to be implemented. Some processes described may require other support or helper function. Any function implemented have to be self-contained and perform a single well-defined task. Polymorphic solution is preferred.

Task Description

Design and write a base class employee and derived classes hourlyEmployee and salariedEmployee.

employee class (base class)

Every employee has an EmpID, name, salary rate and hours worked and other methods (instance functions/methods) that may be needed to access and manage the properties (private variables).

All employees can receive a pay rise by calling the function payRise(int percent) which will increase the employee salary by that percentage amount.

hourlyEmployee class

An hourlyEmployee inherits from employee class and gets paid the hourly wage for the actual number of hours worked, where hours is at most 40. If the hourly employee worked more than 40 hours, the excess (hours over 40) are paid at time and a half.

salaryEmployee class

A salaryEmployee gets paid a fixed salary per week. On top of the fixed salary they also receive a performance bonus every week.

Other Methods

A virtual method computePay() is used to calculate and return the total pay that the employee type will earn. For the employee class the value will be the recorded salary, the hourleyEmployee will be calculation based on the hours worked (plus any penalty rates for more than 40 hour of work), the salaryEmployee the pay is the weekly salary plus any performance bonuses.

A virtual method totalPay() returns the base salary pay for each type of employee. For employee and hourlyEmployee classes this is the salary and the number of hours worked minus 33% tax, while for salaryEmployee the returned result will be the salary plus any performance bonuses minus the 45% tax rate.

An overloaded plus '+' operator is to add the salary of two employees. The method returns the calculation from calling the totalPay() method. The method will be used to sum up values in the classes for totals. How to do this is up to you to design.

An overloaded greater than '>' operator is to compare two same type of employees (comparing hourlyEmployee class with hourleyEmployee class, salaryEmployee with salaryEmployee). The method returns a Boolean result of comparing the totalPay() calculation.

Process

The program is to read the file employee.txt and create a class instance depending on the first digit of the employee ID. salaryEmployee are identified by the first digit on their employee ID number is 1 while hourlyEmployee are all the other possible number combinations. (For example, EmpID 101 for salaryEmployee while other combinations which don't start with 1 are hourlyEmployee).

Once the classes have been created read the work.txt file which contains the number of hours each employee worked for a week or the performance bonus for salaried Employee. For each employee find the employee id and update the hours worked for the week or their salary bonus.

a)Execute the function reportPayHourly( .. ) which takes an array of hourlyEmployee and generates a report which calculates the pay for each employee without any tax taken out. At the end of the report show the total cost of the salary for the hourlyEmployee.

Sample output

Hourly Employee Pay Report
EmpID Name Pay Per Hour Hours Worked Pay for Week
201 Sam $35.00 47 $1,645.00
202 Ann $27.00 38 $1,026.00
… … … … …

Total Pay Bill $12,900.75

b)Do the same process by passing the array containing the salaryEmployee the function called reportPaySalary(..) which reports the salary without tax taken out.

Sample output

Salary Employee Pay Report
EmpID Name Salary Perf Bonus Pay for week
109 Chia $1,200.00 $600.00 $1,800.00
108 Silvia $3,400.00 $1,200.00 $4,600.00
… … … ... …
Total Pay Bill $22,800.00

c)Write a function called topPerformers(..) which takes in the hourlyEmployee array and prints the employee ID, name and earnings for the top 3 hourly Employees. Report on the details of the top performers at the bottom of the report.

d)Write a function that uses the overloaded '+' operator to calculate the amount of taxes that needs to be paid for the hourlyEmployee. Execute the function and display the results at the bottom of the report.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.