Intermodule communication was defined as the flow of information or
data between modules. Local and global variables were introduced,
along with the scope of a variable and the side effects of using only
global data.
The passing of parameters was introduced as a form of intermodule
communication, and the differences between formal and actual
parameters, and value and reference parameters, was explained.
The steps in modularization that a programmer must follow were listed.
These were: define the problem; group the activities into subtasks or
functions; construct a hierarchy chart; establish the logic of the mainline
using pseudocode; develop the pseudocode for each successive
module in the hierarchy chart; and desk check the solution algorithm.
Programming examples using these six steps in modularization were
then developed in pseudocode.
Programming problems
Construct a solution algorithm for the following programming problems. To
obtain your final solution, you should:
• define the problem
• group the activities into modules (also consider the data that each module
requires)
• construct a hierarchy chart
• establish the logic of the mainline using pseudocode
• develop the pseudocode for each successive module in the hierarchy
chart
• desk check the solution algorithm.
1. Design an algorithm that will prompt for and accept an employee's annual
salary, and calculate the annual income tax due on that salary. Income tax
is calculated according to the following table and is to be displayed on the
screen.
Portion of salary Income tax rate (%)
$0 to $4999.99 0
$5000 to $9999.99 6
$10000 to $19999.99 15
$20000 to $29999.99 20
17
Portion of salary Income tax rate (%)
$30000 to $39999.99 25
$40000 and above 30
Your program is to continue to process salaries until a salary of zero is
entered.
2. Design an algorithm that will prompt for and accept four numbers, sort
them into ascending sequence and display them to the screen. Your
algorithm is to include a module called Order _two_numbers that is to be
called from the mainline to sort two numbers at a time.
3. Design an algorithm that will prompt for and accept a four-digit
representation of the year (for example, 2003). Your program is to
determine if the year provided is a leap year and print a message to this
effect on the screen. Also print a message on the screen if the value
provided is not exactly four numeric digits. Continue processing until a
sentinel of 0000 is entered.
4. The members of the board of a small university are considering voting for a
pay increase for their 25 faculty members. They are considering a pay
increase of 8%. However, before doing so, they want to know how much
this pay increase will cost. Design an algorithm that will prompt for and
accept the current salary for each of the faculty members, then calculate
and display their individual pay increases. At the end of the algorithm, print
the total faculty payroll before and after the pay increase, and the total pay
increase involved.
5. Design an algorithm that will produce an employee payroll register from an
employee file. Each input employee record contains the employee number,
employee's gross pay, income tax, union dues, and other deductions. Your
program is to read the employee file and print a detail line for each
employee record showing employee number, gross pay, income tax, union
dues, other deductions and net pay. Net pay is calculated as gross pay –
income tax – union dues – other deductions. At the end of the report, print
the total net pay for all employees.
6. Design an algorithm that will produce an inventory report from an inventory
file. Each input inventory record contains the item number, open inventory
amount, amount purchased and amount sold. Your program is to read the
inventory file and print a detail line for each inventory record showing item
number, open inventory amount, amount purchased, amount sold and final
inventory amount. The final inventory amount is calculated as opening
inventory amount + purchases - sales. At the end of the report, print the
total open inventory amount, the total amount purchased, the total amount
sold and the total final inventory amount.
18
7. Design an algorithm that will produce a savings account balance report
from a customer savings account file. Each input savings account record
contains the account number, balance forward, deposits (sum of all
deposits), withdrawals (sum of all Withdrawals) and interest earned. Your
program is to read the savings account file and print a detail line for each
savings account record showing account number, balance forward,
deposits, withdrawals, interest earned end final account balance. The final
account balance is calculated as balance forward + deposits – withdrawals
+ interest. A heading is to appear at the top of each page and allowance is
to be made for 45 detail lines per page. At the end of the report, print the
total balances forward. total deposits, total withdrawals, total interest
earned and total final account balances.
8. Design an algorithm that will read a file of sales volume records and print a
report showing the sales commission owing to each salesperson. Each
input record contains salesperson number, name and that person's volume
of sales for the month. The commission rate varies according to sales
volume, as follows:
On sales volume ($) of Commision rate (%)
$0.00-$200.00 5
$200.01-$1000.00 8
$1000.01-$2000.00 10
$2000.01 and above 12
The calculated commission is an accumulated amount according to the
sales volume figure. For example, the commission owing for a sales
volume of $1200.00 would be calculated as follows:
Commission = (200 * 5%) + ((1000 - 200) * 8%) + ((1200 - 1000) * 10%))
Your program is to print the salesperson's number, name, volume of sales
and calculated commission, with the appropriate column headings.
9. Design an algorithm that will prompt for and receive your current cheque
book balance, followed by a number of financial transactions. Each
transaction consists of a transaction code and a transaction amount. The
transaction code can be a deposit ('0') or a cheque ('C'). Your program is
to add each deposit transaction amount to the balance and subtract each
cheque transaction amount. After each transaction is processed, a new
running balance is to be displayed on the screen, with a warning message
if the balance becomes negative. When there are no more transactions, a
'Q' is to be entered for transaction code to signify the end of the data. Your
algorithm is then to display the initial and final balances, along with a count
of the number of cheques and deposits processed.
19
10. At Olympic diving competition level, 10 diving judges award a single mark
(with one decimal place) for each dive attempted by a diving competitor.
This mark can range from a to 10. Design an algorithm that will receive a
score from the 10 judges and calculate the average score. The screen
should display the following output:
Judge 1 2 3 4 5 6 7 8 9 10
Mark 6.7 8.1 5.8 7.0 6.6 6.0 7.6 6.1 7.2 7.0
Score for the dive 6.81
20