University of Macau
Faculty Of Business Administration
ISOM 3029 – Computer Programming Using C++
2020/2021 (First Semester)
Assignment 1
Due date: November 9, 2020 (in class)
Instructions:
• Read the Assignment Requirements posted in the UMMoodle before attempting to solve the following problems with C++ programs.
• Both the hardcopy and softcopy of your assignment should be submitted on time. All programs (.cpp files) are to be compressed and uploaded to the UMMoodle under the “Submit Assignment 1” button. The compressed file should be named with your student number such as “ba12345_Ass1.zip”.
Question 1: Reverse digits
Write a C++ program that outputs a greeting message at the beginning, then reads a positive three-digit integer and returns the integer with its digits reversed. For example, if the user inputs the number 123, the program should return 321. Your program should allow the user to choose to continue or not. It will also output a message to end the program.
Sample Input & Output: Welcome to the Reverse Program!
Please enter a positive three-digit number: 123
The reversed form of 123 is 321.
Would you like to continue (Y for Yes, N for No)? Y
++++++++++++++++++++++++++++++++++++++++++++++++++++
Please enter a positive three-digit number: 615
The reversed form of 615 is 516.
Would you like to continue (Y for Yes, N for No)? N
++++++++++++++++++++++++++++++++++++++++++++++++++++
Thank you very much!
Question 2: Personal loan
Suppose you are working in the bank as the manager who has to make decisions on granting personal loans to your customers. You will need a program to help you to check the duration of the loan. For example, if the customer wishes to borrow $100,000, with the annual interest rate 3.6% p.a., and he/she could afford to pay back $1,000 per month (principal plus interest) to the bank, you have to tell him/her the exact duration of the loan and the remaining balance to be repaid in the last month.
The interest is computed by multiplying the annual interest rate to the current value of the loan, divided by 12 months (e.g. for the first month, multiply $100,000 by 0.36, divided by 12, the interest for the first month will then be $300.) The repaid principal amount for the first month will then be $700 (which comes from the difference between the repayment amount $1,000 and the interest $300). This repaid principal amount $700 will be deducted from the current value of the loan monthly, leaving the loan to become less and less. Therefore, the current value of your loan for the second month will be $99,300, and the interest will be $297.90 (correct to 2 decimal places), leading to a repaid principal amount of $702.10 (correct to 2 decimal places).
Write a C++ program that will accept 3 values: the amount of the personal loan, the annual interest rate charged by the bank, and the monthly payment of the customer. The program should display a table listing all the monthly installments that your customer has to repay the bank, until the remaining balance is less than the monthly payment. It should also calculate the monthly current face value of the loan, the monthly interest payment and the repaid principal as shown below.
Sample Input & Output:
Welcome to the Personal Loan System
===================================
Please enter the loan amount: 100000
Please enter the annual interest rate(%): 3.6
Please enter the monthly payment: 1000
Month Current face value Interest Repaid Principal
==============================================================
1 $100,000.00 $300.00 $ 700.00
2 $ 99,300.00 $297.90 $ 702.10
3 $ 98,597.90 $295.79 $ 704.21
… … … … … … …
… … … … … … …
Remaining Balance in month 120 = $69.78
(Note: The remaining balance $69.78 with settled in the month 120!)
Question 3: Payroll
A good payroll system in the human resources department allows a company to record the compensation scheme properly. Suppose a company has to pay her employees in 4 different groups:
• managers (who receive a fixed monthly salary),
• hourly workers (who receive a fixed hourly wage for up to the first 100 hours they work and “time-and-a-half”, i.e., 1.5 hours their hourly wage – for overtime hours worked),
• commission workers (who receive $200 plus 15% of their gross monthly sales), and
• pieceworkers (who work on only one type of item and receive a fixed amount of money per item they produced).
You are required to compute the monthly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Code 1 for Managers, Code 2 for Hourly workers, Code 3 for Commission workers and Code 4 for Pieceworkers.
Write a C++ program to compute each employee’s monthly payroll according to that employee’s pay code entered by the user, who will also input the appropriate facts for your calculation. Set a sentinel value (e.g. enter 0) to stop the program. After processing all the employees’ data, a summary about each type of employee should be displayed as shown below.
Sample Input and Output:
Welcome to the Monthly Payroll Program
======================================
Employee Code:
1 = Manager, 2 = Hourly worker, 3 = Commission worker, 4 = Pieceworker
Please enter the code (0 to stop): 3
Commission worker selected!
Please enter the gross monthly sales: 5000
Commission worker’s pay is $950.00
Please enter the code (0 to stop): 2
Hourly worker selected!
Please enter the hourly salary: 5
Please enter the total hours worked: 120
Hourly worker’s pay is $650.00
Please enter the code (0 to stop): 1
Manager selected!
Please enter the monthly salary: 1000
Manager’s pay is $1000.00
Please enter the code (0 to stop): 4
Pieceworker selected!
Please enter the salary per piece ($): 10
Please enter the number of pieces: 50
Pieceworker’s pay is $500.00
Please enter the code (0 to stop): 0
Total number of employees Total payment
Managers 1 $1000.00
Hourly workers 1 $ 650.00
Commission workers 1 $ 950.00
Pieceworkers 1 $ 500.00
Total: 4 $3100.00
Sample Input and Output:
Welcome to the Monthly Payroll Program
======================================
Employee Code:
1 = Manager, 2 = Hourly worker, 3 = Commission worker, 4 = Pieceworker
Please enter the code (0 to stop): 3
Commission worker selected!
Please enter the gross monthly sales: 5000
Commission worker’s pay is $950.00
Please enter the code (0 to stop): 2
Hourly worker selected!
Please enter the hourly salary: 5
Please enter the total hours worked: 120
Hourly worker’s pay is $650.00
Please enter the code (0 to stop): 1
Manager selected!
Please enter the monthly salary: 1000
Manager’s pay is $1000.00
Please enter the code (0 to stop): 4
Pieceworker selected!
Please enter the salary per piece ($): 10
Please enter the number of pieces: 50
Pieceworker’s pay is $500.00
Please enter the code (0 to stop): 0
Total number of employees Total payment
Managers 1 $1000.00
Hourly workers 1 $ 650.00
Commission workers 1 $ 950.00
Pieceworkers 1 $ 500.00
Total: 4 $3100.00