11 - GCSE(Prog & Algorithms)Part1(Exam simulation)

 1. Describe what is meant by a variable. Please consider the key words we are looking for. Hint: M_____ location and a value that c_________. (2 marks)

 2. List the variabes in this program.
name="John Smith"
if age>13:
  print("Over 13")
  print("Under 13")





 3. In the above code, explain why the output of the program will be "Over 13" even though the age of John Smith is 11.

  The else statement should be removed and then it will work.

  The if statement is written incorrectly.

  Age has not been declared properly. It does not exist in memory.

  Age has been declared as a string. It needs casting (conversion) into an integer.

 4. State the most appropriate data type used to store employee_name, points and letter sent.
A company stores data about employees, the task
completed (denoted by a number) and points achieved.
It also records TRUE or FALSE to record if a letter
has been sent home to the employee. 

Employee Name    Task    Points    Letter Sent
Kristen           0       -2         FALSE
Bob               1        1         TRUE
Georgia           2        2         FALSE
Myles             3       -3         TRUE

  employee_name=Char;points=integer;letter sent=Char

  employee_name=String;points=integer;letter sent=Boolean

  employee_name=Integer;points=integer;letter sent=String

  employee_name=String;points=float;letter sent=String

 5. The data shown above is stored in a database table called Tasks. Write an SQL statement to select the EmployeeName field for all records that have negative Points.
Option 1
FROM table
WHERE Points < 0

Option 2
SELECT EmployeeName
FROM Tasks
WHERE Points < 0

Option 3
SELECT EmployeeName
WHERE Points > 0

  Option 1

  Option 2

  Option 3

  Option 1 and 2 are valid

 6. State the wildcard that can be used in SQL to show all fields from a table.

  Answer: @

  Answer: */ star / asterisk

  Answer: 'w'

  Answer: %

 7. The array is zero based, so _________________holds the value "Kristen".
A single record from this database table is 
read into a program that uses an array with 
the identifier employee_data.

An example of this array is shown below:

employee_data = 
["Kristen", "Task 0", "2", "FALSE"]





 8. In reference to the array and context above (of employees) what is the following code doing?
if employee_data[3] == "TRUE" then
   print "sent"
   print "not sent"
end if

  It identifies whether there are at least 3 employees in the array which have not been sent letters.

  It is checking to see if the data contained is valid and true (Verification).

  It identifies if 3 employees have had a letter sent out and outputs "sent" if so.

  It identifies whether the data in the employee_data array (in this case employee_data[3] ) has had a letter sent out, and outputs "sent" if so.

 9. If the values in the for loop below were changed to range(2,4), the code would print:2,3. What is the current output with (1,4)?
for k in range(1,4):





 10. What is the output of the following code? (note it is a single for loop)
for p in range(1,6):





 11. The following loop is called a: __________. Note that one loop is inside the other. The second loop runs five times (12,3,4,5,). (1 mark)
for k in range(1,4):
 for p in range(1,6):

 12. Analyse the following code. What are the first three numbers that are output? (Grade 8/9 question)
for k in range(1,4):
 for p in range(1,3):





 13. For the code above, state how many times line 3 will be executed if the algorithm runs through once.
Note that that the inner loop completes fully for each iteration of the outer loop. 

  3x2 = 6 (because the first loop runs the numbers 1,2,3 and the second runs 1,2)

  3x5 =15 (because the first loop runs three times and the second runs 4+1 times (5)

  4x7 =14. The first loop runs 4 times. The second runs 7 times.

  None of these answers are correct

 14. List the programming constructs (name three for 3 marks) you can spot in this code. (3 marks)
def main():
  while score>0:
    print("Well done")
    if score==100:
      print("Especially well done")

 15. Name the two logic gates shown in this diagram. (write your answers separated by commas) (2 marks)

 16. Refer to the image and truth table above. Which arrow (A, B, C or D) is indicating that the value filled in for the output Q is INCORRECT?

  Arrow A (the output here should be 1)

  Arrow C (the output here should be 0)

  Arrow D (the output here should be 1)

  Arrow B (the output here should be 0)

 17. What is the expression that relates to the logic gate diagram below? Note that "¬" is a NOT gate and a "V" is an OR gate.

  Q = A¬B (this is A NOT B)

  Q = AV¬B (this is A OR NOT B)

  Q = A¬BV (this is A NOT B OR)

  Q = AVB - A (this is A OR B minus B)

 18. Read the context below and fill in the blanks.
A library gives each book a code made from the 
first three letters of the book title in upper
 case, followed by the last two digits of the 
year the book was published.

For example, "Chronicles of Narnia", 
published in 1960 would be given the 
code _________.





 19. Consider the following pseudocode.Along with 'title' what is the other parameter that needs to be taken in on line 01, for the program to run.
01 function librarycode (title, …………………………)
02 parta = title.subString (0, ……………………………)
03 partb = year.subString (2, 2)
04 …………………    parta.upper + partb
05 endfunction




  book code

 20. What does line 03, in the above code, do?

  A variable 'partb' is created. The last two characters of the 'year' are placed in this variable (e.g. 19 for 2019)

  partb' is a function that is creating a year with two numbers: 2,2

  An error is generated as it is not possible to slice a string

  The first two letters and the last two letters of the year are put into 'partb'

 21. In the same context as above (book code generation), fill in the blanks for line 02 in this pseudocode.
01 function librarycode (title, …………………………)
02 parta = title.subString (0, ……………………………)
03 partb = year.subString (2, 2)
04 …………………    parta.upper + partb
05 endfunction





 22. Note that a function always returns a single value (while a procedure does not). What is likely to go in the blank on line 04?

 23. State four benefits to a programmer of using sub programs.

 24. The following example shows the first two passes of a bubble sort (one more pass is needed to complete the sort). Fill in the blanks for the third line in the second pass.
Bubble sort example
This algorithm could be used to sort the following list:

3, 2, 4, 1, 5

First pass
The first loop of the algorithm would produce:
3, 2, 4, 1, 5 (2<3 so the two values are swapped)
2, 3, 4, 1, 5 (3<4 so the two values are not swapped)
2, 3, 4, 1, 5 (1<4 so the two values are swapped)
2, 3, 1, 4, 5 (4<5 so the two values are not swapped)
2, 3, 1, 4, 5 (First pass completed)

Values were swapped so the algorithm needs to run again. 
The second loop of the algorithm would start with the final
list and run again as follows:

Second pass
2, 3, 1, 4, 5 (2<3 so the values are not swapped)
2, 3, 1, 4, 5 (1<3 so the values are swapped)
____________?(3<4 so the values are not swapped)
2, 1, 3, 4, 5 (4<5 so the values are not swapped)
2, 1, 3, 4, 5 (Second pass completed)

  2, 1, 3, 4, 5

  2, 3, 1, 4, 5

  1, 3, 2, 4, 5


 25. Refer to the following set of steps demonstrating a merge sort. Fill in the blanks for points 2 and 3 in the algorithm for Merge sort.
1. List split into individual elements (may be done over several steps or just to start)
2. Merge individual elements into sorted lists of ________
3. Merge lists of size 2 into sorted lists of _________
4. Merge lists of size 4 into final sorted list.  

  size 2 / size 4

  size 1 / size 3

  size 4 / size 2

  size 0 / size 2

 26. Convert the denary number 132 into an 8 bit binary number.




  1000 0100

 27. Convert the binary number 11000101 to its hexadecimal equivalent.





 28. Convert the binary number 00001111 to its hexadecimal equivalent.

 29. The following is an example of a ______________(not a while loop) that prints out the numbers _____________ in ascending order.
for i in range(1,11):

  count controlled / 0 to 11

  condition controlled / 1 to 11

  condition controlled / 0 to 9

  count controlled / 1 to 10

 30. State four tools or facilities that an IDE commonly provides. (4 marks)