Beaconhouse School System
Jauhar Campus
Assignment
Subject: Computer Science 2210 Date: ____________________
Student Name: ____________________________ Class/Section: ___________
INSTRUCTIONS
• Answer all questions.
• Write your answers in the spaces provided.
• Use Cambridge pseudocode conventions where appropriate.
• Calculators are not permitted.
• The total mark for this paper is 75.
PSEUDOCODE REFERENCE
IF / ELSE IF condition THEN … ELSE … ENDIF
FOR loop FOR counter ← 1 TO n … NEXT counter
REPEAT loop REPEAT … UNTIL condition
WHILE loop WHILE condition DO … ENDWHILE
Input / Output INPUT variable, OUTPUT expression
Procedure PROCEDURE Name(parameters) …
ENDPROCEDURE
Function FUNCTION Name(parameters)
RETURNS Type … ENDFUNCTION
Array arrayName[index]
1. Identify and describe three stages of the program development life cycle.
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
2. Identify and describe the three methods you could use to design and construct a
solution to a problem.
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
3. A program is needed to input the names and ages of three students, then output
the name of the oldest student.
(a) Write pseudocode to:
1. Input the name and age for each student.
2. Determine the oldest student.
3. Output the name of the oldest student.
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
(b) Explain how your pseudocode could be modified to work for any number of
students entered by the user.
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
________________________________________________________________________________
4. A library system checks whether a member can borrow a book. A member may
borrow a book only if they have no overdue books and their membership is valid.
(a) Draw a flowchart to represent the following algorithm:
- Start
- Input HasOverdue and IsValidMember (TRUE/FALSE)
- If HasOverdue = TRUE then display “Cannot borrow”
- Else If IsValidMember = TRUE then display “Book issued”
- Else display “Membership invalid”
- Stop
5. A small shop stores product names and their prices in a one dimensional array.
(a) Write pseudocode to:
(i) Input ProductName and Price for 5 products into arrays.
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
(b) Sort the products by price in ascending order using a loop.
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
6. A teacher wants to store students’ scores in a file and calculate the average.
(a) Write a procedure SaveScores to save the scores of 5 students into a file called
[Link].
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
(b) Write a function CalculateAverage that reads the scores from [Link] and
returns the average.
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
7. (a) Explain the purpose of test data.
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
(b) (i) A program contains a validation function.
(i) The function will:
• take an integer value as a parameter
• return TRUE if the value is within the range 24 to 37, inclusive
• otherwise return FALSE.
Complete the table to define a test plan to thoroughly test the operation of the
function.
8. This pseudocode algorithm is intended to allow 1000 positive integers to be input
and stored in a one-dimensional (1D) array. The integers are added together as
they are input and the highest value is identified. At the end of the algorithm, the
highest number, the total and the average of the numbers are output.
01 DECLARE Numbers : ARRAY[1:1000] OF INTEGER
02 DECLARE Highest : STRING
03 DECLARE Count : INTEGER
04 DECLARE Total : INTEGER
05 Highest ← 1500
06 Total ← 0
07 FOR Count ← 1 TO 1000
08 INPUT Numbers[Count]
09 Total ← Total + Count
10 IF Numbers[Count] > Total
11 THEN
12 Highest ← Numbers[Count]
13 ENDIF
14 NEXT Count
15 OUTPUT "The highest number is ", Highest
16 OUTPUT "The total is ", Total
17 OUTPUT "The average is ", Average / 1000
(a) Identify the line numbers of five errors in the pseudocode and suggest a
correction for each error.
Error 1 line number ...............................................................................................................
Correction .............................................................................................................................
................................................................................................................................................
Error 2 line number ...............................................................................................................
Correction ............................................................................................................................
................................................................................................................................................
Error 3 line number ..............................................................................................................
Correction ...........................................................................................................................
...............................................................................................................................................
Error 4 line number ...............................................................................................................
Correction .............................................................................................................................
................................................................................................................................................
Error 5 line number ...............................................................................................................
Correction ............................................................................................................................
(b) Write the pseudocode statement to output the average of the numbers,
rounded to two decimal places.
..................................................................................................................................................
..................................................................................................................................................
(c) Explain how you could change the corrected algorithm so that it also finds the
smallest number that was input and outputs its value at the end.
Any code used must be fully explained.
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
9. This flowchart represents an algorithm to find the average value of a number of
sales.
10. (a)
(c)
11. A program is being developed to help the manager of a shop control the stock.
(a) An identifier table has been used during the design stage. Complete the
identifier table:
(b) A module Sales() is part of the stock control program.
The table contains pseudocode extracts from the module Sales()
Each extract may include all or part of:
• assignment • selection • iteration (repetition).
Complete the table by placing one or more ticks (✓) in each row:
(c) Decomposition has been used to design the program to help the shop manager
control the stock. Describe decomposition.
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
12. A student has been asked to create a simple guessing game program. This
program will generate a random integer value between 1 and 100. It will then
repeatedly prompt the user to input an integer value until they input the randomly
generated value.
Each time when user input a guess number, a procedure CheckNumber () will be
called to:
– output an appropriate message if the value input was too high; then repeat from
step 2 step 4
– output an appropriate message if the value input was too low; then repeat from
step 2 step 5
– output an appropriate message if the value input was the same value that was
randomly generated; then end the program.
Write an algorithm using pseudocode or flowchart to complete the above given
task. Assume no input validation is needed.
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
13. A program is being developed for the management of a sports centre.
(a) The programmer developing the software decides to use modules (procedures
or functions)
and local variables. They also decide not to use global variables.
(i) State two reasons why the programmer decides to use modules.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
(ii) State one difference between local and global variables.
...........................................................................................................................................
...........................................................................................................................................
(iii) State two benefits of using local variables.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
14. A database table, MajorCity, stores some details about a number of cities from
around the world.
(b) Identify the field in the database table that is most suitable to be the primary
key and give one reason for your choice.
Primary key fiel.......................................................................................................................
Reason ...................................................................................................................................
.................................................................................................................................................
(c) Give the output from the structured query language (SQL) statement:
SELECT City, Country, Population
FROM MajorCity
WHERE Continent = "South America"
ORDER BY Population;
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
(d) Write the SQL statement to count the capital cities.
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
(e) Write the SQL statement to find the total population of Asia.
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
..................................................................................................................................................
16. Write an algorithm that meets the following requirements:
• input a new customer’s name, room length and room width
• calculate the area of the room by multiplying together the length of the room
and the width of the room
• input the choice of wood and find its price per square metre
• calculate the price of the wood needed
• output the name of the customer, the choice of wood and the calculated price
of the wood required
• continue to accept the next customer.
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................
.................................................................................................................................................