Programming – IGCSE Computer Science (0478)
270 questions · page 16 of 18 · Clear filters
Question text
3
Give an example of a pseudocode statement or statements to perform each of the following
functions.
A condition controlled loop …
…
…
A conditional statement …
…
…
Totalling …
…
…
[3]
Question text
4
This is a section of program code.
1 Total = 100.00
2 PRINT ′Enter the height of each member of your class, one at a
time, when prompted′
3 FOR Count = 1 TO 30
4
PRINT ′Enter a height in metres′
5
INPUT Height
6
Total = Total + Height
7
PRINT Total / 30
8
Count = Count + 1
9 NEXT Count
(a) There are three errors in this code.
State the line numbers that contain the errors and describe how to correct each error.
Error 1 …
…
…
Error 2 …
…
…
Error 3 …
…
…
[3]
(b) State the purpose of this program.
…
…
… [1]
Question text
5
The algorithm allows a number to be entered. It then calculates and outputs the next number in
the mathematical series.
1
Fib
0
Prev2
1
Prev1
INPUT Number
IF Number = 0
0
THEN Fib
ENDIF
WHILE Number > 2
Prev2 + Prev1
Fib
Prev1
Prev2
Fib
Prev1
Number - 1
Number
ENDWHILE
OUTPUT Fib
(a) Complete the trace table for the input data: 7
Fib
Prev2
Prev1
Number
OUTPUT
[4]
(b) Complete the trace table for the input data: 2
Fib
Prev2
Prev1
Number
OUTPUT
[2]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
You recorded information for the estimate of the cost of building a computer in Task 1.
Give a data structure that you created for Task 1, its name, data type and use.
Data structure …
Name …
Data type …
Use …
…
[4]
(ii)
Describe the data structures that you have used in Task 2 to record the customer details.
Include sample data in the description.
…
…
…
…
…
…
…
… [4]
(b) Explain how your program for Task 1 produces a unique estimate number.
…
…
…
… [2]
(c) Write an algorithm for part of Task 2 to check that the chosen processor and chosen RAM
are in stock, using either pseudocode, programming statements or a flowchart. Assume that
Task 1 has been completed. Do not check the other components or produce the order.
…
…
…
…
…
…
Question text
3
The global trade item number (GTIN-8) barcode has seven digits and a check digit.
This pseudocode algorithm inputs seven digits and calculates the eighth digit, then outputs the
GTIN-8.
DIV(X,Y), finds the number of divides in division for example DIV(23,10) is 2.
MOD(X,Y), finds the remainder in division for example MOD(23,10) is 3.
1 TO 7
FOR Count
INPUT Number
Number
Digit(Count)
NEXT
(Digit(1)+Digit(3)+Digit(5)+Digit(7))*3+Digit(2)+Digit(4)+Digit(6)
Sum
IF MOD(Sum,10) <> 0
DIV(Sum,10)*10 + 10 - Sum
THEN Digit(8)
0
ELSE Digit(8)
ENDIF
OUTPUT "GTIN-8"
1 TO 8
FOR Count
OUTPUT Digit(Count)
NEXT
(a) Complete the trace table for the input data: 5, 7, 0, 1, 2, 3, 4
Digit(1) Digit(2) Digit(3) Digit(4) Digit(5) Digit(6) Digit(7) Digit(8)
Sum
OUTPUT
Complete the trace table for the input data: 4, 3, 1, 0, 2, 3, 1
Digit(1) Digit(2) Digit(3) Digit(4) Digit(5) Digit(6) Digit(7) Digit(8)
Sum
OUTPUT
[5]
(b) Explain how you would change the algorithm to input eight digits (seven digits and the check
digit) and output if the check digit entered is correct or not.
…
…
…
…
…
…
… [3]
Question 4 starts on page 10.
Question text
5
Explain the difference between the programming concepts of counting and totalling.
Include an example of a programming statement for each concept in your explanation.
…
…
…
…
…
…
…
…
… [4]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
State the name, the data type and the use of two variables that you have used in Task 2.
Variable 1 name …
Data type …
Use …
Variable 2 name …
Data type …
Use …
[2]
(ii)
Describe, with the aid of some sample data, the data structures that you have used to
record the data for the cows in Task 1.
…
…
…
…
…
…
…
… [4]
(b) Explain how your program for Task 1 ensures that each 3-digit identity code is unique.
…
…
…
… [2]
(c) Write an algorithm for Task 2, using either pseudocode, programming statements or a
flowchart. Assume that Task 1 has been completed.
…
…
…
…
…
…
…
Question text
3
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.
INPUT
Number1, Number2, Sign
WHILE
Number1 <> 0
Number1 + Number2
ENDIF
IF
Sign = '+' THEN Answer
Number1 - Number2
ENDIF
IF
Sign = '-' THEN Answer
Number1 * Number2
ENDIF
IF
Sign = '*' THEN Answer
Number1 / Number2
ENDIF
IF
Sign = '/' THEN Answer
IF
Sign <> '/' AND Sign <> '*' AND Sign <> '-'
AND Sign <> '+'
0
THEN Answer
ENDIF
IF Answer <> 0 THEN OUTPUT Answer ENDIF
INPUT Number1, Number2, Sign
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
[3]
(b) Show how you could improve the algorithm written in pseudocode by writing an alternative
type of conditional statement in pseudocode.
…
…
…
…
…
…
…
…
…
… [3]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
State the name, data type and use of two arrays you created for Task 1.
Array 1 name …
Data type …
Use …
…
Array 2 name …
Data type …
Use …
…
[4]
(ii)
State the name, value and use of two constants you could have created for Task 3.
Constant 1 name …
Value …
Use …
…
Constant 2 name …
Value …
Use …
…
[4]
(b) Write an algorithm to perform the set up and ‘On Entry’ part of Task 1, using either pseudocode,
programming statements or a flowchart.
…
…
…
…
…
…
…
…
…
…
Question text
3
This section of program code reads the contents of the array, totals the numbers and prints out the
sum and average of the numbers. Assume the array is full.
Complete the four missing items by writing them in the spaces provided in this code.
1
Numbers[1:30]
2
Total = 0
… = 0
3
FOR Count = 1 TO …
4
5
Number = Numbers[Count]
Total = … + Number
6
7
Counter = Counter + 1
… Count
8
9
PRINT ′The sum of the numbers you entered is ′, Number
10 PRINT ′The average of the numbers you entered is ′, Number / Counter
[4]
Question text
1
(a) All identifiers should have meaningful names.
(i)
State the name and data structure that you have used to record student names in Task 1.
Name …
Data structure …
[2]
(ii)
State the name of one constant and the name of one variable that you could have used
in your programmed solution.
State the value that would be assigned to the constant. State the data type for the
variable. Explain what each one would be used for in your programmed solution.
Constant name …
Value …
Use …
…
Variable name …
Data type …
Use …
…
[6]
(b) Explain how you would change your program for Task 2 if the maximum group size for each
subject is increased to 25.
…
…
…
…
…
… [2]
(c) Write an algorithm to complete Task 1, using either pseudocode, programming statements
or a flowchart.
…
…
…
…
…
…
…
…
Question text
2
An algorithm has been written in pseudocode to input some numbers and print out any numbers
that are greater than or equal to 100. The number 999 stops the algorithm.
INPUT Number
WHILE NUMBERS <> 999 DO
IF Number > 100 THEN PRINT Number ENDIF
ENDWHILE
PRINT Number
(a) Find the four errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Show, using pseudocode, how you would change the corrected algorithm to print out any
numbers between 100 and 200 inclusive.
…
…
…
…
…
…
…
… [2]
Question text
5
Explain the difference between the programming concepts of sequence and selection. Include
an example of a programming statement for each concept in your explanation.
…
…
…
…
…
…
…
…
… [4]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
Declare suitable arrays for each of the planes to store time slots booked.
…
…
… [3]
(ii)
Name one variable and one constant you used for Task 1 and state the purpose of each
one.
Variable …
Purpose …
…
Constant …
Purpose …
…
[4]
(b) Write an algorithm to complete Task 1, using either pseudocode, programming statements
or a flowchart.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
..
Question text
2
This section of program code asks for 80 numbers between 100 and 1000 to be entered. It checks
that the numbers are in the correct range, and stores them in an array. It counts how many of the
numbers are larger than 500 and then outputs the result when the program is finished.
1 Count = 0
2 FOR Index = 1 TO 80
3
INPUT 'Enter a number between 100 and 1000', Number
4
WHILE Number = 99 AND Number = 1001
5
INPUT 'This is incorrect, please try again', Number
6
ENDWHILE
7
Num[80] = Number
8
IF Number > 500 THEN Count = Count + 1
9 UNTIL Index = 80
10 PRINT Index
11 PRINT ' numbers were larger than 500'
There are four lines of code that contain errors.
State the line number for each error and write the correct code for that line.
Error 1 Line Number …
Correct Code …
Error 2 Line Number …
Correct Code …
Error 3 Line Number …
Correct Code …
Error 4 Line Number …
Correct Code …
[4]