programming recap. do you know these? low level 1 st generation: machine language (110011) 2 nd...

12
Programming recap

Upload: cassandra-collins

Post on 16-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Programming recap

Page 2: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Do you know these?LOW LEVEL1st generation: machine language

(110011)2nd generation: assembly language

(ADD, SUB)

HIGH LEVEL3rd / 4th generation:

E.g. Pascal, C++, Java

Page 3: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

How about these?Source code: original instructionsObject code: machine language

versionCompiling: converting from source

to objectLinking: bring all data together

before runningExecuting: running the programMaintaining: ensuring program

continues to run

Page 4: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Do these errors ring a bell?Syntax error: error with the use of the

language

Logic error: error when something is out of sequence or doesn’t make sense (e,g, sum = a * b)

Runtime error: error when program runs

Testing: checking for errors

Debugging: Fixing errors

Page 5: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Types of statementsAssignmentCalculationInputOutputLooping

Selection/condition

Program header

Vat:= 0.15Vat:=price * taxRead(age)Write(age)For age:= 1 to 5

doWhile age<65 do

If age > 65 thenProgram

OLDAGE;

Page 6: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Symbols symbols symbols; means end of

line{ } is used to

put comments that are not a part of the program

:= means equals. Means end of

program

> more than< less than<> not equal to= is equal to>= more than or

equal to

Page 7: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

What are datatypes?Integer – whole number (90)Real – decimal number (9.67)Char – single letter (n)String – word (nine)Array – a list

Page 8: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Declaring an arrayDeclare an array named class

that has 20 spaces and stores the names of persons

CLASS : array[1..20] of STRING;

Name of arrayNumber of spaces

datatype

Page 9: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Working with arraysOutput the fourth value in CLASS

◦Writlen(CLASS[4]);

Input a value into the 10th space in class◦Readln(CLASS[10]);

Input the name “george” into the 8th position in CLASS◦CLASS[8]:=“george”;

Page 10: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Tracing a program – Jan 2013, #9

a) Pascalb) Sequence. c) Outputd) The result is 12e) Set A = no error

Set B = runtime error. Because num1 is 2.5. This is a real number.

Page 11: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Boolean – ones and zeros!

AND

0 0 0

0 1 0

1 0 0

1 1 1

OR

0 0 0

0 1 11 0 11 1 1

AND

OR

Page 12: Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3

Documentation??External documentation

◦Use manuals◦Installation procedures◦Frequently asked questions

Internal documentation◦Comments in your program◦Indenting so your program is neat