Lesson aim:

To be able to:

·  explain the 3 main programming constructs

·  give example of different programming constructs

·  apply programming construct to practise

Starter (12)

I wanted to go over this particular set of questions that are focusing on logic gates and truth tables because everyone got these wrong.

Many electronic circuits have to make decisions. They look at two or more inputs and use these to determine the outputs from the circuit. The process of doing this uses electronic logic, which is based on digital switches called gates.

Electronic logic: digital and analogue signals

Logic gates allow an electronic system to make a decision based on a number on its inputs. They are digital electronic devices. Digital means that each input and output of the gates must be one of two states:

high, also known as 1 or 'on'

low, also known as 2 or 'off'

Source: BBC

Task 1

Find a picture of an AND gate, OR gate, NOT gate.

Explain how each circuit functions.

If you are not sure how each circuit functions, use the link below to help you:

Some excellent websites to look through:

http://www.bbc.co.uk/schools/gcsebitesize/design/electronics/logicrev2.shtml

OR

http://education.cambridge.org/media/577240/cambridge_igcse_computer_studies__revision_guide___cambridge_education___cambridge_university_press_samples.pdf

Task 2 (15 minutes)

Complete the truth table for an AND gate

A / B / A and B
0 / 0
0 / 1
1 / 0
1 / 1

[1 mark]

OR gate

A / B / A OR B
0 / 0
0 / 1
1 / 0
1 / 1

[1 mark]

NOT

A / B / Not A
0 / 0
0 / 1
1 / 0
1 / 1


NOT (A AND B)

A / B / A and B / Not (A and B)
0 / 0 / 0
0 / 1 / 0
1 / 0 / 0
1 / 1 / 1

Challenge: have a go at this:

A / B / C


Programming constructs (20 minutes)

There are 3 main programming constructs. This is sequence, selection and iteration assignment.

For each construct, explain what it is used for and give example of some python code to help you better understand it.

If you are not sure, you can use the link below or find others online using Google.

http://www.teach-ict.com/gcse_computing/ocr/216_programming/control_flow/miniweb/pg2.htm

https://cgi.csc.liv.ac.uk/~frans/OldLectures/2CS45/progCons/progCons.html#sequences


Programming construct challenge: (20 minutes)

You should now be comfortable answering the questions below. We will also go through them as a group.

Question 6)

Julie is writing a computer game that simulates a 100 m race. Each time the space bar is pressed,

the position of the player moves up by 1. When the position reaches 100, the player has won.

Here is Julie's algorithm for the program

CONST PlayerKey = " "

Position = 0

REPEAT

INPUT KeyPressed

If KeyPressed = PlayerKey THEN

Position = Position + 1

END IF

UNTIL Position = 100

(a) State an example of a constant and a variable in the algorithm above.

Constant:

Variable:

[2 marks]

b) State what is meant by selection and iteration using examples from Julie's algorithm.

Selection

Example

Iteration

Example

Note: You need to explain what selection is then give example. Repeat for iteration as well.

[4 marks]


Programming challenge

Complete the following without using Python first.

10 An isosceles triangle is a triangle that has at least two equal sides. The diagram below shows examples of isosceles triangles. In each diagram the marked sides are equal.

Write an algorithm for a computer program that determines whether a triangle is an isosceles triangle.

• The user inputs the lengths of the three sides as Length1, Length2 and Length3

• If any two sides have the same length the program outputs "Isosceles"

• Otherwise the program outputs "Not Isosceles"

Extension:

Work on developing your program that writes and reads from files. Make sure it is using functions.

See if you can develop a simple quiz that will read the questions from the text file.

Have a look at:

http://stackoverflow.com/questions/10393176/is-there-a-way-to-read-a-txt-file-and-store-each-line-to-memory

http://stackoverflow.com/questions/18412179/reading-a-file-and-storing-values-into-variables-in-python