introduction to programming lecture number:. what is programming programming is to instruct the...

19
Introduction to Programming Lecture Number:

Upload: egbert-howard

Post on 26-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Introduction to Programming

Lecture Number:

Page 2: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

What is Programming

Programming is to instruct the computer on what it has to do in a language that the computer understands.

Programming must be done in a programming language, most preferably it should be the binary language as computers work on 1’s and 0’s which is called machine or some times ‘object’ code.

Page 3: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Machine Code

An example machine code could be:

1011001101010101 (Add two numbers)

1111001100110101 (Subtract two numbers)

1111000011110000 (Multiply two numbers)

It clearly is not memorisable or understandable

by the human being so we need an alternative!

Page 4: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Assembly Language

As an alternative the binary sequences of numbers were represented by simple english keywords:

1011001101010101 (ADD)

1111001100110101 (SUB)

1111000011110000 (MUL)

This is relatively easier as compared to the machine language, however modern applications need much higher levels of abstraction.

Page 5: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

The need for High level languages

ADD,SUB, MUL etc are usually limited to a specific maximum number of bits, we need generic coding schemes where we can concentrate on the logic instead of memory constraints.

ADD might be SUM or ADDA in other machines, we needed a machine and platform independent solution so a single language could suffice for all machines.

Page 6: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

High-level Languages

High level languages came into being solving various glitches that machine and assembly languages had.

Examples of high-level languages are: C++, Java, Visual Basic, Visual C#, etc However, High level languages are not

understandable by the machines so we need an interpreter, also called a compiler.

Page 7: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Compiler

A compiler is a piece of software that translates high level language into machine or binary code.

Every language has a specific style or way, called its syntax, just like there’s grammar in human languages.

Compiler also checks for any syntax errors in our ‘code’.

Page 8: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

The Compile process

Programmer Writes High-level Code

Compiler checks for code validity

Translated to machine code

Page 9: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Examples of Compilers

Microsoft Visual Studio Borland C++ Bloodshed Dev C++

Page 10: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

What happens after compiling?

Once the object-code/Machine-code is generated, another process called ‘Linking’ is done, which means to link any pre-available libraries with our code.

A library is a collection of modules or functions made by other programmers for later reuse.

Different languages have different ways of expressing libraries, like in C++ they’re represented by .lib extension.

Page 11: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

What happens after Linking?

Loading! The program after linking is put into Main

Memory (RAM). Execution is the next step The RAM acts like a conveyer belt for the

processor which actually executes the code.

Page 12: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Definition of Algorithm

(after Al Kho-warizmi a 9th century Persian mathematician) - an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time 

Let's examine the four parts of this definition more closely an ordered sequence means that you can number the steps

(it's socks then shoes!) unambiguous and well-defined instructions means that each

instruction is clear, do-able, and can be done without difficulty performs some task halts in finite time (algorithms terminate!)

Page 13: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Building the Program Logic

Before writing a program, we need to plan the flow of the program

Pseudo-code and flow-charts are two general tools that help in planning for a program

Page 14: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Pseudo-code & Flow Charts

Pseudo-code– Informal language used to develop algorithms– Similar to a Natural Language– Not actually executed on computers – Allows us to “think out” a program before writing

the code– Easy to convert into a program

Page 15: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Computing Sales Tax

Example #1 - Pseudo-code the task of computing the

final price of an item after figuring in sales tax. Note the

three types of instructions: input (get),process/calculate

(=) and output (display) 1. get price of item 2.       get sales tax rate 3.       sales tax = price of time times sales tax rate 4        final prince = price of item plus sales tax 5.       display final price 6.       halt

Variables: price of item, sales tax rate, sales tax, final price

Page 16: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Pseudo-code & Flow Charts

Flow Charts– Flow Charts are a graphical representation,

usually considered more understandable– Drawn using certain special-purpose symbols, as

described next

Page 17: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Pseudo-code & Flow Charts

Oval symbol OR small circle– indicates beginning or end of a program,

or a section of code

Arrows called flow-lines– Indicate the flow of program

Page 18: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Pseudo-code & Flow Charts

Rectangle symbol (action symbol)– Indicates any type of action.

Diamond– Indicates Decision

add grade to total

grade >= 60

Page 19: Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer

Today we studied

What is Computer Programming? Machine, Assembly and High-Level language Compilers The program planning process