2019 New Spec

From AQA Computer Science
Jump to: navigation, search

The algorithm, represented using pseudo-code, in Figure 2 outputs a numeric result. The numeric result depends upon the value entered by the user.

Figure 2

OUTPUT "Enter a positive whole number: "
INPUT NumberIn
NumberOut ← 0
Count ← 0
WHILE NumberIn > 0
   Count ← Count + 1
   PartValue ← NumberIn MOD 2
   NumberIn ← NumberIn DIV 2
   FOR i ← 1 TO Count – 1
      PartValue ← PartValue * 10
   ENDFOR
   NumberOut ← NumberOut + PartValue
ENDWHILE
OUTPUT "The result is: " NumberOut

Table 2 lists the MOD and DIV operators for each of the available programming languages. You should refer to the row for your programming language.

Table 2

Programming language MOD DIV
C#  % /
Java  % /
Pascal mod div
Python  % //
VB.Net Mod

What you need to do:

Task 1

Write a program to implement the algorithm in Figure 2.

Task 2

Test that your program works:

  • run your program, then enter the number 22
  • run your program, then enter the number 29
  • run your program, then enter the number -1