Practice Worksheet 1 Class IX
Practice Worksheet 1 Class IX
1. Write pseudocode to input ten positive numbers and find the total and the average.
2. Write pseudocode to input any number of positive numbers and find the total and the
average. The user should enter ‘-1’ when they have finished entering their list of positive
numbers.
3. Tickets are sold for a concert at $20 each. If 10 tickets are bought then the discount is
10%, if 20 tickets are bought the discount is 20%. No more than 25 tickets can be bought
in a single transaction.
a. Use pseudocode to write the algorithm to calculate the cost of buying a given
number of tickets.
b. Explain how you would test your algorithm.
4. A phone app is being developed to split the cost of a restaurant bill between a given
number of people. It is being designed to work for up to 12 diners and for bills from $10
to $500.
a. What validation checks should be used for the number of diners and the size of
the bill?
b. Provide two sets of normal data and their expected results.
c. Provide some abnormal/erroneous data.
d. Identify the boundary data required and the expected results.
5. An algorithm to checks the size of a consignment of ten parcels. The dimensions of
each parcel are input in centimetres. Length, breadth and total size needs to be within
30, 30 and 600 accordingly. Output how many are accepted and rejected.
a. Write the algorithm in pseudocode
b. Use this data and the following trace table to dry run the algorithm:
15, 10, 20, 17, 32, 10, 30, 35, 30, 15, 30, 28, 25, 25, 20, 15, 40, 20, 12, 10
c. State the processes included in this algorithm.
d. Identify the rules required to accept a parcel.
6. The following algorithm written in pseudocode adds up 10 positive numbers and outputs
the total. It contains several errors.
1
1. Counter ← 1
2. FOR Counter ← 1 TO 10
3. REPEAT
4. OUTPUT "Enter a positive whole number "
5. INPUT Number
6. UNTIL Number < 0
7. Total ← Total + Counter
8. Counter ← Counter + 1
9. OUTPUT Total
10. NEXT Number
b. Show how you could improve the algorithm written in pseudocode by writing an
alternative type of conditional statement in pseudocode.
2
Revision Guide
Previous content
Handout 3 Tasks
3
Practice Worksheet 1 Sample Solution of question 4 and 5
1. Solution:
2. Solution:
3. Solution:
4. Solution:
INPUT Bill
INPUT Diners
a) Diners – range check 2 to 12 inclusive, presence check and type check of integer
Bill – range check 10 to 500 inclusive, presence check and type check of real
b) Test data (sample – yours might be different):
• Normal data: 5 diners and a bill of $90.00 Expected result: $18.00
• Normal data: 8 diners and a bill of $69.00 Expected result: $8.63
c) Test data (sample – yours might be different):
• Abnormal data: 15 diners and a bill of $5.00 Expected result: both values rejected
d)
• Boundary data for lower bounds 1 diner and 2 diners and bills of $9.99 and $10.00
Expected result:
1 and $9.99 both values rejected
2 and $10.00 will OUTPUT $5.00
• Boundary data for upper bounds 12 diners and 13 diners and bills of $500.00 and
$500.01
Expected result:
13 and $500.01 both values rejected
12 and $500.00 will OUTPUT $41.67
4
5. Solution:
a) Pseudocode
accepted ← 0
rejected ← 0
FOR i ← 1 TO 10
OUTPUT "Enter dimensions for parcel " + i
INPUT length
INPUT breadth
INPUT height
b) Tracetable
Counter Length Breadth Volume Accepted Rejected Output
c) Process:
• input length and breadth of 10 parcels
• check length and breadth less than 30 for each parcel
• calculate size and check size less than 600 for each parcel
• increment the number of parcels accepted or the number of parcels rejected
• output number of parcels accepted and number of parcels rejected
d) Length and breadth must be less than or equal to 30. Size must be less than or equal to
600.
6. Solution:
7. Solution: