PAPER 4

Cards (63)

  • Pseudocode is words used to plan or describe an algorithm that will later be written in an actual programming language like Python or Java
  • On the A-level exam, pseudocode takes on its own role as a programming language with a specific syntax
  • This tutorial is meant to teach pseudocode syntax, not programming concepts
  • Calculating the volume of a sphere
    1. Declare volume and radius variables
    2. Get radius input from user
    3. Calculate volume using formula
    4. Output volume
  • Declare
    Creating a variable without initializing it
  • Real
    Decimal data type
  • Input
    Simulating user input
  • Arrow (->)

    Assignment operator in pseudocode
  • Creating a calculator
    1. Declare first value, second value, and operation variables
    2. Get first value, operation, and second value input from user
    3. Use if/else or switch statements to perform calculation based on operation
    4. Output result
  • If/Else

    Conditional statements in pseudocode
  • Switch
    Compact way to handle multiple conditional cases
  • Grading system
    1. Get grade input from user
    2. Use switch statement to categorize grade range and output message
  • Function
    Allows getting parameters and outputting a result
  • This tutorial covers variables, conditionals, loops, 1D arrays, 2D arrays, custom data types, procedures, functions, strings, text files, and object-oriented programming in pseudocode
  • ise block and just say otherwise if you don't get that you are a failure this is an example of a different kind of switch statement um that basically allows us to handle uh numerical ranges
  • The last thing I said I would do is actually just create a function
  • Function
    Allows us to get some parameters and then output a resulting value
  • Creating a function called calculate
    1. Take a first parameter called first (real)
    2. Take a second parameter called op (string)
    3. Take a third parameter called second (real)
    4. Return a real value
  • We can use the result variable inside the function without declaring it again
  • If the op parameter is not one of the four valid symbols, we output 'invalid operation' and return 0
  • We initialize result to 0 to handle the case of an invalid operator
  • We're going to focus on loops next
  • Writing a while loop to output all odd numbers from 0 to 20
    1. Declare counter variable I=1
    2. While I < 20, output I, I=I+2
    3. End while
  • Writing a for loop to output all odd numbers from 0 to 20
    1. For counter=1 to 20 step 2, output counter
    2. Next
  • Writing a repeat loop to output all odd numbers from 0 to 20
    1. Declare counter J=1
    2. Repeat, output J, J=J+2
    3. Next while J < 20
  • The for loop is the most common loop construct used in the A-level exam
  • Creating a procedure called 'odd'
    1. No parameters
    2. Output odd numbers 0 to 20
    3. End procedure
  • To use the 'odd' procedure, we call it with 'call odd'
  • Array
    Similar to declaring a variable, but with a range of indices
  • Declaring Celsius temps array with indices 1 to 6 and each element a real
  • Declaring Fahrenheit temps array, same size as Celsius temps
  • Initializing values in Celsius temps array
    1. Celsius temps 1 = 21
    2. Celsius temps 2 = 21
    3. ... (6 elements)
  • Printing all values in Celsius temps array
    1. For i=1 to 6, output Celsius temps[i]
    2. Next
  • Converting Celsius to Fahrenheit and storing in Fahrenheit temps array
    1. For i=1 to 6, Fahrenheit = Celsius temps[i]*9/5 + 32, Fahrenheit temps[i] = Fahrenheit
    2. Next
  • Finding the maximum temperature in Fahrenheit temps array
    1. Declare Max temp = Fahrenheit temps[1]
    2. For i=1 to 6, if Fahrenheit temps[i] > Max temp, Max temp = Fahrenheit temps[i]
    3. Next
  • Finding the minimum temperature in Fahrenheit temps array
    1. Declare Min temp = Fahrenheit temps[1]
    2. For i=1 to 6, if Fahrenheit temps[i] < Min temp, Min temp = Fahrenheit temps[i]
    3. Next
  • We're going to work with 2D arrays next
  • s going to be Fahrenheit Temps so this way we're going to consistently have whatever the lowest temperature is being stored in Min temp and then just output that in it's really a very similar type of problem
  • this was dealing with 1D arrays we're going to have another example that's going to be dealing with 2D arrays
  • a lot of a level questions are going to be more complex than this but you are going to be doing a lot of work with if statements inside of for Loops particularly when you have this sort of um when you have a lot of code inside different blocks make sure to keep it well organized