1 of 59

Topic 4

Programming

IB Computer Science

The British International School, Istanbul

2 of 59

What We Will Cover

  • Trace Tables
  • Flow Charts
  • IB Programming Problems
  • Pseudocode Conventions

The British International School, Istanbul

3 of 59

What We Will Not Cover

  • Sorting Methods
  • Searching Methods
  • Gantt Charts
  • Basic Programming Concepts (See ‘Intro to Python’ playlist)

The British International School, Istanbul

4 of 59

Topic 4 Difficulties

  • Pseudocode Guides mediocre
  • No real curriculum
  • Questions unclear
  • Mark Schemes have slight differences in style
  • No official textbook

The British International School, Istanbul

5 of 59

What is Pseudocode?

  • Pseudocode is any method that can be used to represent programming concepts
  • Used to plan algorithms
  • Cannot be executed
  • IB mandates that you use their own made up pseudocode language, regardless of what programming language you know
  • Heavily based on Java
  • Older markschemes explicitly say that answers can be written in Java
  • Syntax and keywords must be memorized

The British International School, Istanbul

6 of 59

Fundamental Programming Tasks for the IB Exam

  • Iterate through an array
  • Find the maximum and minimum in an array
  • Calculate the sum and average of values in an array
  • Search an array for certain values or ranges of values in an array
  • Find the common elements between arrays
  • All of the above, except with collections
  • Transfer data between both data structures
  • Understand and be able to use methods (functions)
  • Be able to read and analyze problems (the most important)
  • Solve problems with mod and div
  • Validation

The British International School, Istanbul

7 of 59

Arrays

  • Fixed length
  • Pre-initialized and pre-created in IB
  • Length can be accessed using .length property
  • Array locations contiguously located in memory
  • Allows for empty data locations, not always efficient

The British International School, Istanbul

8 of 59

Basic Array Tasks

  • Iterate through an array
  • Find the maximum and minimum in an array
  • Calculate the sum and average of values in an array
  • Search an array for certain values or ranges of values in an array
  • Find the common elements between arrays

The British International School, Istanbul

9 of 59

Collections

  • No fixed length
  • Items can be added dynamically
  • Each location “points” to the next using a “pointer”
  • Can only be traversed using collection methods
  • Represents a type of object

The British International School, Istanbul

10 of 59

Basic Collection Tasks

  • Iterate through a collection
  • Find the maximum and minimum in a collection
  • Calculate the sum and average of values in a collection
  • Search an array for certain values or ranges of values in a collection
  • Find the common elements between collections
  • Transfer data from arrays to collections
  • Transfer data from collections to arrays

The British International School, Istanbul

11 of 59

mod and div

  • mod operator is used to figure out the remainder when two integers are divided by each other
  • mod is most often used to test for divisibility
  • div operator can be viewed in two ways
    • Rounding up the result when two numbers are divided by each other
    • Finding out how many times one number “fits into” another

The British International School, Istanbul

12 of 59

IB-style mod and div Question

Write a program that takes an input of up to 99 cents. Based on the amount of cents entered by the user, calculate the minimum number of coins of the given types necessary to represent the amount. You can use 4 types of coins, but remember, you must calculate the fewest number of coins possible:

  • quarter - 25 cents
  • dime - 10 cents
  • nickel - 5 cents
  • penny - 1 cent

For example, if the user enters 97 cents, your output should be “3 quarters, 2 dimes, 2 pennies” as this is the minimum number of coins, with types, required to represent 97 cents.

The British International School, Istanbul

13 of 59

Validation

  • Makes sure user input fits certain parameters
  • Uses a while loop
  • “Traps” user in the loop until they enter a valid value

The British International School, Istanbul

14 of 59

Methods

  • Also referred to as “functions”
  • You need to be able to write and call functions in pseudocode
  • Typically methods are used to simplify an existing problem
  • See slide 37 for a great example of a problem involving methods

The British International School, Istanbul

15 of 59

The British International School, Istanbul

16 of 59

The British International School, Istanbul

17 of 59

The British International School, Istanbul

18 of 59

The British International School, Istanbul

19 of 59

The British International School, Istanbul

20 of 59

The British International School, Istanbul

21 of 59

The British International School, Istanbul

22 of 59

The British International School, Istanbul

23 of 59

The British International School, Istanbul

24 of 59

The British International School, Istanbul

25 of 59

The British International School, Istanbul

26 of 59

The British International School, Istanbul

27 of 59

The British International School, Istanbul

28 of 59

The British International School, Istanbul

29 of 59

The British International School, Istanbul

30 of 59

The British International School, Istanbul

31 of 59

The British International School, Istanbul

32 of 59

The British International School, Istanbul

33 of 59

The British International School, Istanbul

34 of 59

The British International School, Istanbul

35 of 59

The British International School, Istanbul

36 of 59

The British International School, Istanbul

37 of 59

The British International School, Istanbul

38 of 59

The British International School, Istanbul

39 of 59

The British International School, Istanbul

40 of 59

The British International School, Istanbul

41 of 59

The British International School, Istanbul

42 of 59

The British International School, Istanbul

43 of 59

The British International School, Istanbul

44 of 59

The British International School, Istanbul

45 of 59

The British International School, Istanbul

46 of 59

The British International School, Istanbul

47 of 59

The British International School, Istanbul

48 of 59

The British International School, Istanbul

49 of 59

The British International School, Istanbul

50 of 59

The British International School, Istanbul

51 of 59

The British International School, Istanbul

52 of 59

The British International School, Istanbul

53 of 59

The British International School, Istanbul

54 of 59

The British International School, Istanbul

55 of 59

The British International School, Istanbul

56 of 59

The British International School, Istanbul

57 of 59

The British International School, Istanbul

58 of 59

The British International School, Istanbul

59 of 59

The British International School, Istanbul