Programming Problems SU 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Programming problems

Construct a solution algorithm for the following programming problems. Your solution should
contain:
 a defining diagram
 a pseudocode algorithm
 a desk check of the algorithm.

1 Design an algorithm that will receive two integer items from a terminal operator, and
display to the screen their sum, difference, product and quotient. Note that the quotient
calculation (first integer divided by second integer) is only to be performed if the
second integer does not equal zero.

2 Design an algorithm that will read two numbers and an integer code from the screen.
The value of the integer code should be 1, 2, 3 or 4. If the value of the code is 1,
compute the sum of the two numbers. If the code is 2, compute the difference (first
minus second). If the code is 3, compute the product of the two numbers. If the code is
4, and the second number is not zero, compute the quotient (first divided by second). If
the code is not equal to 1, 2, 3 or 4, display an error message. The program is then to
display the two numbers, the integer code and the computed result to the screen.

3 Design an algorithm that will prompt the user for a student number and the student's
exam mark out of 100. Your program is then to match the exam mark to a letter grade
and print the student number and grade on the screen. Calculate the letter grade as
follows:

Exam score Assigned grade


90 and above A
80-89 B
70-79 C
60-69 D
below 60 F

4 Design an algorithm that will receive the weight of a parcel and determine the delivery
charge for that parcel. Calculate the charges as follows:

Parcel weight (kg) Cost per kg (R)


<2.5 kg 83.50 per kg
2.5-5 kg R2.85 per kg
>5 kg R2.45 per kg

5 Design an algorithm that will prompt a terminal operator for the price of an article and a
pricing code. Your program is then to calculate a discount rate according to the pricing
code and print to the screen the original price of the article, the discount amount and
the new discounted price. Calculate the pricing code and accompanying discount
amount as follows:

Pricing code Discount rate


H 50%
F 40%
T 33%
Q 25%
Z 0%

if the pricing code is Z, the words 'No discount' are to be printed on the screen. If the
pricing code is not H, F, T, Q or Z, the words 'Invalid pricing code' are to be printed.

6 An architect's fee is calculated as a percentage of the cost of a building. The fee is


made up as follows:

8% of the first R5000.00 of the cost of a building and


3% on the remainder if the remainder is less than or equal to R80000.00 or
2% on the remainder if the remainder is more than R80000.00.

Design an algorithm that will accept the cost of a building and calculate and display
the architect's fee.

7 A home mortgage authority requires a deposit on a home loan according to the


following schedule:

Loan (R) Deposit


less than R25 000 5% of loan value
R25 000-S49 999 R1250 + 10% of loan over R25 000
R50 000-R100 000 R5000 + 25% of loan over R50 000

Loans in excess of R100000 are not allowed. Design an algorithm that will read a
loan amount and compute and print the required deposit.

8 Design an algorithm that will receive a date in the format dd/mm/yyyy (for example,
21/07/2003) and validate it as follows:

i the month must be in the range 1-12, and


ii the day must be in the range of 1 -31 and acceptable for the corresponding month.
(Don't forget a leap year check for February.)

9 The tax payable on taxable incomes for employees in a certain country is set out in the
following table:

Taxable income Tax payable


From R1.00-R4461.99 Nil
From R4462.00-R17893.99 Nil plus 30 cents for each R in excess of R4462.00

From R17894.00-R29499.99 R4119.00 plus 35 cents for each R in excess of R17894.00

From R29 500. 00-R45 787.99 R8656.00 plus 46 cents for each R in excess of R29500.00

R45 788. 00 and over R11179.00 plus 60 cents for each R in excess of
R45788.00
Design an algorithm that will read as input the taxable income amount and calculate
and print the tax payable on that amount.

10 A transaction record on a sales commission file contains the retail price of an item sold,
a transaction code that indicates the sales commission category to which an item can
belong, and the employee number of the person who sold the item. The transaction
code can contain the values S, M or L, which indicate that the percentage commission
will be 5%, 7% or 10%, respectively. Construct an algorithm that will read a record on
the file, calculate the commission owing for that record, and print the retail price,
commission and employee number.

You might also like