0% found this document useful (0 votes)
10 views5 pages

Practice Worksheet 1 Class IX

The document is a practice worksheet for a Computer Science final term exam, containing various pseudocode exercises and algorithm-related questions. It includes tasks such as calculating totals and averages, validating input for a restaurant bill splitter app, and checking parcel dimensions. Additionally, it provides sample solutions and guidance for testing algorithms and handling different types of data.

Uploaded by

yiyadok303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Practice Worksheet 1 Class IX

The document is a practice worksheet for a Computer Science final term exam, containing various pseudocode exercises and algorithm-related questions. It includes tasks such as calculating totals and averages, validating input for a restaurant bill splitter app, and checking parcel dimensions. Additionally, it provides sample solutions and guidance for testing algorithms and handling different types of data.

Uploaded by

yiyadok303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practice Worksheet 1 Final Term (2024-2025)

Name: Class: Roll: Section:


Subject: Computer Science Teachers: Md. Shahinur Alam Shadhin Date:

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

a. Identify all the errors in the algorithm.


b. Rewrite the algorithm so that it is effective and error free.
c. Set up a trace table and some test data to dry run your rewritten
algorithm.
d. Identify which items of your test data are normal, erroneous and extreme.
7. This pseudocode algorithm inputs two non-zero numbers and a sign, and then performs
the calculation shown by the sign. An input of zero for the first number terminates the
process.

1. INPUT Number1, Number2, Sign


2. WHILE Number <> 0
3. IF Sign = '+' THEN Answer ← Number1 + Number2 ENDIF
4. IF Sign = '-' THEN Answer ← Number1 - Number2 ENDIF
5. IF Sign = '*' THEN Answer ← Number1 * Number2 ENDIF
6. IF Sign = '/' THEN Answer ← Number1 / Number2 ENDIF
7. IF Sign <> '/' AND Sign <> '*' AND Sign <> '-' AND Sign <> '+'
8. THEN Answer ← 0
9. ENDIF
10. IF Answer <> 0 THEN OUTPUT Answer ENDIF
11. INPUT Number1, Number2, Sign
12. ENDWHILE

a. Complete the trace table for the input data: 5, 7, +, 6, 2, -, 4, 3, *, 7, 8, ?, 0, 0, /


Number1 Number2 Sign Answer OUTPUT

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

1. Practice basic pseudocode and flowchart


a. Try to solve 7 algorithms (marked home work from HY)
It covers basics of algorithm (Variable, Condition, calculation)
b. Go through validation check pseudocode from page 276 and following pages.
2. Practice Loop and array
a. Go through Handout 1
b. Solve the tasks in the Handout 1
3. Practice Standard method of solutions
a. Go through Handout 3
b. Try to solve Handout 3 Tasks given in this document
New content
Try to solve Practice Worksheet 1 without looking at the solution first

Handout 3 Tasks

1. Write an algorithm to take 5 product prices store it in an array. (Fixed)


2. Write an algorithm for a shop, first input no of items user wants to enter, then take each
item’s prices and store it in an array. (User-defined)
3. Write an algorithm for a shop take product item’s prices as input until the user provide -1
and store it in an array. ( Sentinel)
4. You have a product prices array, calculate Total and average price. (total, average)
5. You have a product prices array find Minimum and maximum price. (min-max)
6. You have a product prices array calculate how many products are below $20.00 (Count)
7. You have a product prices array find if is there any product priced $10.50 (Search)

3
Practice Worksheet 1 Sample Solution of question 4 and 5

1. Solution:
2. Solution:
3. Solution:
4. Solution:

INPUT Bill
INPUT Diners

IF Bill < 10 OR Bill > 500 THEN


OUTPUT "Error: Bill must be between $10 and $500"
ELSE
IF Diners < 2 OR Diners > 12 THEN
OUTPUT "Error: Diners must be between 2 and 12"
ELSE
costPerPerson ← Bill ÷ Diners
OUTPUT "Each person should pay $" + costPerPerson
ENDIF
ENDIF

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

totalSize ← length + breadth + height

IF length ≤ 30 AND breadth ≤ 30 AND totalSize ≤ 600 THEN


accepted ← accepted + 1
ELSE
rejected ← rejected + 1
ENDIF
NEXT i

OUTPUT "Accepted parcels: " + accepted


OUTPUT "Rejected parcels: " + rejected

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:

You might also like