4.3 – Introduction to programming

4.3.1 – State the fundamental operations of a computer

  • All CPU’s have a set of instructions.
  • These are called fundamental operations
  • These enable commands to be processed

The most fundamental operations are

  • ADD
  • COMPARE
  • RETRIEVE (or LOAD)
  • STORE (or SAVE)

4.3.2 – Distinguish between fundamental and compound operations of a computer

A fundamental operation could be something like add two numbers, store a number, move a number to another location in RAM etc.

A compound operation is an operation that involves a number of stages/other operations. Think of it as a group of operations that combine together to form an operation.

An example of fundamental instructions: 

  • Load Register 32ab
  • Add 29
  • Store Result
  • Compare Result to register 4

Examples of compound/complex instructions:

  • Find the biggest number in an array
  • Sort the names alphabetically 

4.3.3 – Explain the essential features of a computer language

There are different types of langauge

  • Human Language
  • Computer Language

Within computing there are different languages such as

High Level Languages

  • Java
  • Python
  • C#

Low Level Langauges

  • Assembly
  • Machine Code

The essential features of a computer language are

  • Fixed vocabulary – There are fixed terms that are used in specific languages (int = integer, str = String)
  • Unambiguous meaning – One term cannot have several meanings
  • Consistent grammar & syntax – The syntax and grammar of the language has to be preserved, otherwise the computer will not understand the code (why we always get syntax errors!!

4.4.4 – Explain the need for higher level languages

As we require far more from computers than we did say 10 years ago, it would take a huge amount of time to created such complex programs in machine code.

Higher Level Languages are much more similar to the human language (English)

Machine Code

Python

4.4.5- Outline the need for a translation process from a higher level language to machine executable code

What is a translator?

“A translator is a computer program/ software that translates a program written in a given programming language into a functionally equivalent program in a different language.”

The most common example would be a program that is written in say JAVA or C# (high level language) needs to run on the CPU and therefore needs translating into the machine code (low level language)  that the CPU understands. 

The main types of translators are:

  • Compiler – If the translator translates a high level language into a lower level language (Java) 
  • Interpreter – the translator translates a high level language into an intermediate code which will be immediately executed by the CPU (Python)
  • Assembler – the translator translates assembly language to machine code

4.3.6 – Define the terms: variable, constant, operator, object

Variable

A variable is used to store a single data element of a program which can be changed during the execution of the program

Constant

Constants represent elements that cannot be changed during the execution of a program, un-changeable variables if you wish.

Operators

Operators are used to manipulate and change operands

Image result for pseudocode operators

So for example 600+300

  • 600, 300 would be the operands
  • + would be the operator

Objects

An object is a software bundle of variables and related methods.

Essentially objects contain both data (states) and actions (behaviours).

Data is used to store the current state of the object whilst methods are typically used to change or access this data.

4.3.7 – Define Various Operators

There are many different types of operators

Image result for pseudocode operators

4.3.8 – Analyse the use of variables, constants and operators in algorithms

Most of this is pretty self explanatory.

When you are designing a program consider why has a particular variable been used?

Is the value ever going to change ? Could it not be a constant?

Why is div needed instead of / ?

4.3.9 – Construct algorithms using loops, branching

This is all down to practice and something we do a lot of in class.

Loops

  • For
  • While

Branching

  • If /Else

4.3.10 – Describe the characteristics and applications of a collection

Defined as “a collection is a grouping of some variable number of data items (possibly zero) that have some shared significance to the problem being solved and need to be operated upon together in some controlled fashion”

Fixed-size arrays (or tables) are usually not considered a collection because they hold a fixed number of data items

Very useful for when you do not know how many items you will be needing which is the opposite to an Array when you set the size in stone before execution.

4.3.11 – Construct algorithms using the access methods of a collection

4.3.12 – Discuss the need for sub-programmes and collections within programmed solutions

A sub program is a section or block that contains a sequence of computer instructions that perform a specific task

This means that this sub program can be called multiple times and promotes code reuse

It also means that programmers can take advantage of solutions developed by other programmers which in turn speeds up the workflow

  • One ready good example is using software libraries which contain many different sub programs which can be used for a variety of different projects.

Other advantages include:

  • Updates/ Maintenance are much easier as you only have to update the block/module rather than the whole program
  • Many people can be working on the same project at once programming their own modules
  • Modules can be used in future projects
  • Makes program organization/planning much easier.

4.3.13 – Construct algorithms using predefined sub-programmes, one-dimensional arrays and/or collections

This is all down to practice.

The following examples are taken from the IB Pseudocode Booklet