Tutorial Week 5 - Nested IFs & Compound Conditions


Home


For the following problems, work through steps 1 (Understanding) through 5 (Desk Checking) of the Steps in Program Development discussed in lectures.

Question 1

Problem Description

Write a program to display the letter Grade (A, B, C, D or N) for a student based on their numeric mark for a subject. A numeric mark is always a whole number. Where: A is 80 to 100, B is 70 to 79, C is 60 to 69, D is 50 to 59 and N is 0 to 49.

Example Runs

Run
Mark (0 to 100) ? 79
Grade = B

Run
Mark (0 to 100) ? 80
Grade = A

Run
Mark (0 to 100) ? 49
Grade = N

Run
Mark (0 to 100) ? 59
Grade = D

Run
Mark (0 to 100) ? 69
Grade = C

Question 2

Problem Description

Write a program to calculate an employees salary. Employees normally work between 30 and 50 hours per week. Employees are paid differing rates per hour. The first 40 hours worked per week are paid at the standard rate. Overtime hours (over 40 hours) are paid at 50% above an employees normal hourly rate. Display a warning message if the hours worked is less than 30 or more than 50.

Example Runs

Run
Hours worked ? 40
Hourly Rate ($) ? 20
Salary = $800

Run
Hours worked ? 30
Hourly Rate ($) ? 50
Salary = $1500

Run
Hours worked ? 50
Hourly Rate ($) ? 20
Base Salary = $800
Overtime (10 hours) = $300  
Salary = $1100

Run
Hours worked ? 20
Warning: hours worked should be between 30 and 50 hours (inclusive)
Hourly Rate ($) ? 20
Salary = $400

Run
Hours worked ? 60
Warning: hours worked should be between 30 and 50 hours (inclusive)
Hourly Rate ($) ? 20
Base Salary = $800
Overtime (20 hours) = $600  
Salary = $1400

Question 3

What could be improved in the above problem? Why?


Written by Tim Whitfort.