Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 31

CS101 - PROBLEM SOLVING &

PROGRAMMING

Lecture 1 (online)
Introduction to Computers & Programming
Week 20-24 April 2020
Zoubeir Aungnoo
Lecture Aims

■ Definition of computer
■ What is Programming?
■ History and type of programming languages
Computers
■ A digital computer is an electronic programmable machine that can process
almost all kinds of data.
– A computer system: hardware + software.
■ Processes information according to instructions (software) given. Without
these instructions it doesn’t know what to do.
■ Instructions you give: called a program
■ Programming is the systematic way of writing computer programs

Hardware: Electronic Devices Software: Instructions and Computer Programs


Why learn programming?

■ Most people are users of computer programs! Not everyone writes program.

■ Users vs Programmers

■ Users often want to do things with computers which haven’t been done
before, and since we programmers get paid to do that, we are going to learn
how to program.
Why learn programming?

■ .
Why learn programming?

■ .
Types of computer programs

 Software refers to all the programs running on a computer.


 There are categories of software:
1. System Software:
I. Operating System
II. Library programs
III. Utility programs
IV. Programming languages
V. Translation programs (Compilers, Interpreters & Assemblers)

2. Application Software:
I. General purpose software (off the shelf, tailor made software)
II. Custom made (bespoke software)
Types of computer programs

3. Integrated software (software suits)


4. Embedded software

 What are the advantages and disadvantages of buying off-the-shelf


applications and custom made applications?
Data Processing

■ Computers are data processors.


■ Info. fed in > follow instructions specified in computer program (process) >
generate further info.

■ Computer unaware of the data it is processing.


■ It is only us people who actually give meaning to the data.
■ Garbage In Garbage Out (GIGO)
■ E.g. program to sum and calculate average student marks.
■ Can process different types of data: numeric, character, objects, ..
How to develop a program

 Computers need instructions to process the data.


 Instructions are entered, then stored and executed in computer’s memory.

 When a stored program is executed, the following things happen:


1. input data are entered into computer
2. Input data is processed to produce certain desired results
3. Results are known as output data (displayed to user)

 This three steps procedure can be repeated many times if desired, to process
large quantity of data.
 Note: these steps can be lengthy and complicated.
Programming & Programming
Languages
Overview
■ Programming is an Art. Watch ‘The Codebreakers’ – shows how the first
programmable computer, Colossus, was used to break the Enigma code.
■ Think of a programmer as a bit like a plumber!
Programming & Programming
Languages
 Once we have our algorithm in place; need to express our program in a
form that the computer can work with.

 You might ask the question "Why do we need programming languages,


why can’t we just use something like English?" There are two answers to
this one:
1. Computers cannot understand English.
2. English would make a lousy programming language.

 Programming languages get around both of these problems: simple for


computer to understand and reduce ambiguities.
Computer Language

■ Digital devices have two stable states, which


are referred to as zero and one by convention
■ The binary number system has two digits, 0
and 1. A single digit (0 or 1) is called a bit,
short for binary digit. A byte is made up of 8
bits.
■ Binary Language: Data and instructions
(numbers, characters, strings, etc.) are encoded
as binary numbers - a series of bits (one or
more bytes made up of zeros and ones)
Computer Language (cont.)

■ Encoding and decoding of data into binary is performed


automatically by the system based on the encoding scheme
■ Encoding schemes
– Numeric Data: Encoded as binary numbers
– Non-Numeric Data: Encoded as binary numbers using
representative code
■ ASCII – 1 byte per character
■ Unicode – 2 bytes per character
Binary Number System
■ Decimal
– Base 10, ten digits (0-9)
– The position (place) values are integral powers of 10:
100(ones), 101(tens), 102(hundreds), 103(thousands)…
– n decimal digits - 10n unique values
■ Binary
– Base 2, two digits (0-1)
– The position (place) values are integral powers of 2:
20(1), 21(2), 22(4), 23(8), 24(16), 25(32), 26(64)…
– n binary digits - 2n unique values
ASCII Table
Generations of Programming Languages

 There are a variety of computer languages and the one that is chosen for a
particular depends on the job that is being done. One way of characterizing
them is by ‘generation’.

 1st Generation: Machine language


 2nd Generation: Assembly language
 3rd Generation: High-Level language

 Scripting Language
Machine Language – 1st Generation

 Most basic programming language is known as ‘Machine Code’.


 Consists of 1s and 0s, so, it’s directly understood by computer.
 All other languages must be translated into machine code before the
instructions can be carried out.
 Therefore, programs execute faster (no translations needed).
 E.g. Games, simulation programs, real-time applications are written in
machine code.

 Disadvantages:
1. Machine specific – program written for one type of machine won’t run on
another.
Machine Language – 1st Generation

 Disadvantages
2. Time consuming, laborious and cumbersome to work with.
3. Error prone.
4. Debugging is tedious.
Assembly Language – 2nd Generation

■ In the 50s, machine code gave way to assembly language.


■ Use of mnemonics (abbreviations that represent instructions in a more
memorable way) and numbers (0-9) instead of 0s and 1s. E.g. ADD, ADX,
SBX
■ Usage: apps where timing and storage space critical. Part of OS, device
drivers that control devices such as printer, CD ROM.

Advantage:
1. Easier for programmer to use – debugging is easier.
Assembly Language – 2nd Generation

■ Disadvantages:
1. Needs to be translated to machine code.
2. Machine specific.

■ Part of an assembly code program:


Machine Language vs Assembly
Language
■ .
High-Level Language – 3nd Generation

■ When the use of computer rose > needed error-free programming


languages.
■ High-level languages were developed – developed with programmer in
mind.
■ E.g: ALGOL (ALGOrithmic Language), FORTRAN (FORmula
TRANslation) & COBOL (Common Business Oriented Language).
■ Others followed: C, C++, C#, R, …
■ A single instruction in a high-level language usually translates into many
instructions in machine language.
High-Level Language – 3nd Generation

■ Advantages:
1. Independent of computer architecture
2. Simple instructions similar to English - easier to program with.
3. Debugging is not a hassle anymore!
History– 3nd Generation
Scripting Languages

■ It is difficult to characterize definitively the differences between


scripting languages like JavaScript and high-level programming
languages.
■ However, one important difference between the two types of
languages has to do with what happens when a program is run.
■ It may be more accurate to call a programming language a compiled
language.
■ Example:
– Some languages, such as Active Server Pages (ASP), PHP, and
Java Server Pages (JSP) are run on a user’s server. These are
server-side languages.
Translation Programs

■ Converts program into machine code for the computer to understand and
execute.

■ 3 Types:
1. Assembler
2. Compiler
3. Interpreter
Translation Programs

Assembler
 Translates assembly language into machine code.
 Translation is easy because one instruction in assembly language
corresponds to one machine code instruction.

Compiler
 Converts the whole of a program written in high level language into
machine code in one go.
 The programmer’s code is known as source code and the compiled code is
known as object code.
 Object code is used each time the program is run, i.e. no recompilation
needed.
Translation Programs

Compiler
■ If the program is altered, the original source code is altered and re
compiled. Large programs takes quite a long time to compile.

Interpreter
■ Also translates source code into object code but
■ Difference is that the interpreter translates one line at a time, executes it and
then proceed to the next.
■ No object code produced, so the program has to be interpreted each time it
is run.
Translation Programs

Relative advantages and disadvantages of compilers & interpreters


A compiler has many advantages over an interpreter:
■ Object code can be saved on disk and run whenever required without the
need to recompile. However, if error is discovered in program, the whole
program has to be recompiled.
■ Object code executes faster than interpreted code.
■ Object code produced by compiler can be distributed or executed without
having to have the compiler present.
■ Object code is more secure, as it cannot be read without a great deal of
‘reverse engineering’.
Translation Programs

Relative advantages and disadvantages of compilers & interpreters


An interpreter has some advantages over a compiler:
 Useful for program development - no need for lengthy recompilation each
time an error is discovered.
 It is easier to partially test and debug the program.

You might also like