IB Diploma Programme Computer Science Past Paper 2014 PDF
Document Details
Uploaded by EffortlessLeaningTowerOfPisa6436
2014
IB
Tags
Related
- CP1 - Introduction To Computer Programming PDF
- Lecture-fundamental-concept-of-algorithm-Introduction-to-Computer-Science (1).docx
- COMP 8547 Advanced Computing Concepts Fall 2024 Lecture Notes PDF
- Data Structures and Algorithm Analysis in C++ 4th Edition PDF
- Computer Science I Lecture Notes PDF
- Class of 2025 CS Notes PDF
Summary
This document is an IB Diploma Programme Computer Science past paper from 2014. It features various exercises and explanations on problem-solving, algorithms, including conditional statements and loops, along with array handling.
Full Transcript
if-then-else if (Boolean condition) then (Consequent) else (Alternative) end if (Consequent) (Alternative) if-then-else // SAMPLE OUTP...
if-then-else if (Boolean condition) then (Consequent) else (Alternative) end if (Consequent) (Alternative) if-then-else // SAMPLE OUTPUT Input a number. // Popup Window 56 This number is positive. // IF-THEN-ELSE // SAMPLE OUTPUT X = input ("Input a number.") Input a number. // Popup Window 56 if (X > 0) then This number is positive. output "This number is positive." else output "This number is negative." end if if-then (Consequent) if-then-else if if (Boolean condition) then (Consequent) else if (Boolean condition) then (Consequent) else (Alternative) end if (Consequent) (Consequent) (Alternative) if-then-else if // SAMPLE OUTPUT Input a number. // Popup Window 56 This number is positive. Input a number. // Popup Window 0 This number is 0. // IF-THEN-ELSE IF // SAMPLE OUTPUT X = input ("Input a number.") Input a number. // Popup Window 56 if (X > 0) then This number is positive. output "This number is positive." else if (X = 0) then output "This number is 0." else output "This number is negative." end if if-then (Consequent) (Alternative) if (Boolean condition) then (Consequent) end if (Consequent) if- then if-then if- then // SAMPLE OUTPUT Input a number. // Popup Window 56 This number is positive. Input a number. // Popup Window 0 This number is 0. from/to while from/to loop COUNT from 0 to 5 from/to Do something. end loop while while loop while (COUNT < 5) Do something. COUNT = COUNT + 1 end loop loop from/to from/to // SAMPLE OUTPUT This message will display five times. This message will display five times. This message will display five times. This message will display five times. This message will display five times. // LOOP FROM/TO #1 // SAMPLE OUTPUT loop X from 1 to 5 This message will display five times. output "This message will display five times." This message will display five times. end loop This message will display five times. This message will display five times. This message will display five times. loop while while // SAMPLE OUTPUT This message will display five times. This message will display five times. This message will display five times. This message will display five times. This message will display five times. // LOOP WHILE #1 // SAMPLE OUTPUT X = 0 This message will display five times. This message will display five times. loop while (X < 5) This message will display five times. output "This message will display five times." This message will display five times. X = X + 1 This message will display five times. end loop loop from/to from/to // SAMPLE OUTPUT How many times do you want to repeat? // Popup Window 5 This message will repeat 5 times. This message will repeat 5 times. This message will repeat 5 times. This message will repeat 5 times. This message will repeat 5 times. // LOOP FROM/TO #2 // SAMPLE OUTPUT NUM = input("How many times do you want to repeat?") This message will display five times. This message will display five times. loop X from 1 to NUM This message will display five times. output "This message will display ", NUM, " times." This message will display five times. end loop This message will display five times. loop while while // SAMPLE OUTPUT How many times do you want to repeat? // Popup Window 5 This message will repeat 5 times. This message will repeat 5 times. This message will repeat 5 times. This message will repeat 5 times. This message will repeat 5 times. // LOOP WHILE #2 // SAMPLE OUTPUT X = 0 This message will display five times. This message will display five times. NUM = input("How many times do you want to repeat?") This message will display five times. This message will display five times. loop while (X < NUM) This message will display five times. output "This message will display ", NUM, " times." X = X + 1 end loop from/to while // SAMPLE OUTPUT Input a positive integer to count up to. // Popup Window 6 0 1 2 3 4 5 6 // COUNTING UP // SAMPLE OUTPUT N = input("Input a positive integer to count up to.") Input a positive integer to count up to. // Popup Window 6 loop X from 0 to N 0 output X 1 end loop 2 3 4 5 6 while from/to // SAMPLE OUTPUT Input a positive integer to count down from. // Popup Window 6 6 5 4 3 2 1 0 // COUNTING DOWN // SAMPLE OUTPUT N = input("Input a positive integer to count down from.") Input a positive integer to count down from. // Popup 6 loop while (N >= 0) 6 output N 5 N = N - 1 4 end loop 3 2 1 0 // SAMPLE OUTPUT Input a number. // Popup Window 4 The factorial is 24. while // FACTORIAL // SAMPLE OUTPUT N = input("Input a number.") Input a number. // Popup Window 4 FACTORIAL = 1 The factorial is 24. loop while (N > 1) FACTORIAL = FACTORIAL * N N = N - 1 end loop output "The factorial is ", FACTORIAL NUM X 1 3 2 3 3 1 4 8 5 8 3 2 4 13 5 13 6 1 NUM = 3 NUM X 2 output NUM 3 loop X from 1 to 2 4 NUM = NUM + 5 5 output NUM 6 end loop 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 4 NUM = NUM + 5 5 output NUM 6 end loop 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 5 output NUM 6 end loop 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 6 end loop 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 4 8 6 end loop 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 4 8 6 end loop 5 8 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 4 8 6 end loop 5 8 3 2 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 4 8 6 end loop 5 8 3 2 4 13 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 4 8 6 end loop 5 8 3 2 4 13 5 13 1 NUM = 3 NUM X 2 output NUM 1 3 3 loop X from 1 to 2 2 3 4 NUM = NUM + 5 3 1 5 output NUM 4 8 6 end loop 5 8 3 2 4 13 5 13 6 N = 4 FACTORIAL = 1 loop while (N > 1) FACTORIAL = FACTORIAL * N N = N - 1 end loop output FACTORIAL ARRAY_NAME ARRAY_NAME ARRAY_NAME = new Array(5) ARRAY_NAME = [0, 0, 0, 0, 0] ARRAY_NAME = 42 42 // SAMPLE OUTPUT 42 16 8 99 31 // OUTPUTTING AN ARRAY // SAMPLE OUTPUT MY_ARRAY = new Array(5) 42 MY_ARRAY = [42, 16, 8, 99, 31] 16 8 loop N from 0 to 4 99 output MY_ARRAY[N] 31 end loop // SAMPLE OUTPUT Input five numbers. // Popup Window 42 16 8 99 31 42 16 8 99 31 // INPUTTING TO AN ARRAY // SAMPLE OUTPUT MY_ARRAY = new Array(5) 42 16 loop N from 0 to 4 8 MY_ARRAY[N] = input("Input a number.") 99 end loop 31 loop N from 0 to 4 output MY_ARRAY[N] end loop // SEQUENTIAL SEARCH // SAMPLE OUTPUT // This algorithm shows an inefficient sequential search. 42 A = new Array(6) 16 A = [7, 5, 3, 8, 1, 6] 8 KEY = 8 // This is what we are searching for 99 FOUND = false 31 // Iterate through each item in the array loop N from 0 to 5 output "Index", N, "will be checked." // Test only if (A[N] = KEY) then FOUND = true output A[N], "was found at index", N end if end loop // After searching, tell if not found if (FOUND = false) then output KEY, "was not found." end if // MORE EFFICIENT SEQUENTIAL SEARCH // SAMPLE OUTPUT // This algorithm shows a better sequential search. 42 A = new Array(6) 16 A = [7, 5, 3, 8, 1, 6] 8 KEY = 8 // This is what we are searching for 99 FOUND = false 31 N = 0 // Iterate through each item in the array loop while (N