1.Do the planning and write an algorithm to solve the following problem. Prepare test data for the example to test all possibilities and draw a trace table.


Sam works at a coffee company where all the employees receive a bonus of R700, except the employees in the coffee department 3, who receive a bonus of R850. Enter his gross salary and his personal department number. Calculate the total income of Sam. Subtract 25% of the gross income for tax. Determine and display Sam’s net income on the screen

My Work:
CalcTotaincome
~ Calculate the total income
~ Input
display “ Sam’s gross income”, Salary ~ Display on new line
~ intermediate
display “Subtract gross income for tax”, tax ~ Display on new line
~ Processing
Totalincome = Gross income - (gross income * tax)
~ Test how much amount Sam receive as a netIncome
If salary = 700
~ Calculate if salary = R850
~ Output
display “Sam’s net income”, netIncome ~ Display on new line
end

To solve the problem, you can follow this algorithm:

1. Start the program.

2. Prompt the user to enter Sam's gross salary.

3. Prompt the user to enter Sam's personal department number.

4. Calculate the total income by subtracting 25% of the gross income for tax. Store this value in a variable called Totalincome.

5. Use an if statement to determine if Sam's personal department number is 3. If it is, add R850 to the total income. Otherwise, add R700 to the total income.

6. Calculate Sam's net income by subtracting the total income for tax deduction. Store this value in a variable called netIncome.

7. Display Sam's net income on the screen.

8. End the program.

To prepare test data for the example, you can consider the following cases:

Test Case 1:
- Sam's gross salary: R5000
- Sam's personal department number: 3
- Expected total income: (R5000 - (R5000 * 0.25)) + R850 = R3995
- Expected net income: R3995 - (R3995 * 0.25) = R2996.25

Test Case 2:
- Sam's gross salary: R4000
- Sam's personal department number: 2
- Expected total income: (R4000 - (R4000 * 0.25)) + R700 = R3200
- Expected net income: R3200 - (R3200 * 0.25) = R2400

You can use a trace table to organize the steps and values involved in the algorithm's execution. The trace table would look something like this:

| Step | Variable | Value |
|------------|-----------------|--------------|
| 1 | | |
| 2 | Salary | R5000 |
| 3 | DeptNumber | 3 |
| 4 | Totalincome | R3995 |
| 5 | | |
| 6 | netIncome | R2996.25 |
| 7 | | |
| 8 | | |

You can fill in the trace table with the actual values obtained during the execution of the algorithm for each test case.