Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 46

CS1010 Introduction to Computing

Lecture
(Programming Languages)

1
Programming
• The process of telling the computer
what to do
Also known as coding

2
TYPES OF PROGRAMS
• Batch Program

• Event-Driven Program
BATCH PROGRAMS
These are typically started from a shell (or
automatically via a scheduler) and tend to
follow a pattern of:
– Initialize internal data
– Read input data
– Process that data
– Print or store results

Key feature: No user interaction with the


computer while the program is running
4
EXAMPLE?
• Suppose you are working in a company,
hundreds of people are working in that
company, at the end of the month you have to
pay salaries. You just give one command to
computer i.e. prepare the pay roll. No further
interaction with computer. The program
automatically fetch the data and print the check
or send advice to bank. In the whole process
when it started till its end. User have no
interaction with program.
EVENT-DRIVEN PROGRAMS
Examples?
Event driven program interact with user while the program is running, sometimes
instead of user they interact with sub-parts that generates events in computer.
The system sends events to the program and the
program responds to these as they arrive.

Events can include things a user does - like clicking


the mouse - or things that the system itself does - like
updating the clock.

These programs generally work as follows:


– Initialize the internal data
– Wait for events to arrive
– Identify an incoming event and react accordingly 6
A vocabulary and set of grammatical rules for
instructing a computer to perform specific tasks

7
ALL PROGRAMS CONSISTS OF:
1. Sequence of instructions
2. Conditionals
3. Loops

These may contain:


– Data (Text etc)
– Input/output (print, etc)
– Operations (add, divide, etc)

8
• Machine Language • Ada(1983)
• Assembly Language • C++ (1983-85)
(1956-63) • QBasic (1986)
• LISP (1956) • Perl (1987)
• Fortran (1957) • VisualBasic (1991)
• COBOL (1959) • PowerBuilder
• PL/1(1964) • Java (1995)
• BASIC (1964) • JavaScript
• Pascal (1970) • C# (2001)
• Smalltalk (1972)
• C (1972)
CLASSIFICATION OF PROGRAMMING
LANGUAGES
• Business Languages: COBOL having report writing
capabilities.

• Scientific Languages: FORTRAN and ALGOL

• Educational Languages: PASCAL & LOGO use


when teaching the principles of programming.
• System Programming: C has been developed to
write operating systems and associated system
programs.

• Object Oriented Programming: C++, DELPHI,


SMALLTALK, JAVA and EIFFEL.

• Artificial Intelligence: PROLOG has been


developed to implement these applications.
CLASSIFICATION OF
PROGRAMMING LANGUAGES
High level Programming Languages

Low Level Programming Languages

13
High-level programming languages, while
simple compared to human languages, are
more complex than the languages the uP
actually understands, called machine
languages

Each different type of microprocessors has


its own unique machine language

14
Lying between
machine languages
&
high-level languages
are languages called
assembly languages

15
Assembly languages are similar to machine languages, but are easier to program in as they allow a programmer to substitute names for numbers

An assembly language instruction has a mnemonic to describe the operation and allows the programmer to name memory location.

The assembly language instruction is converted into the machine code instruction by an assembler program.

Machine languages consist of numbers only

16
4th-generation languages

High-level languages

Assembly languages

Machine languages

17
• PowerBuilder is 4th generation language.

• More complex task can performed with one


statement.
Regardless of what language you use, you
eventually need to convert your program
into a language that the computer can
understand

Two ways for doing that:


compile the program or
interpret the program

19
Interpreter is a program that executes instructions written in a high-level language
An interpreter translates high-level instructions line by line into an intermediate form, which it then executes

In contrast, a Compiler translates high-level instructions directly into machine language

20
Compiled programs generally run faster than interpreted programs

The advantage of an interpreter, however, is that it does not need to go through the compilation stage during which the whole of the high-level code
is translated into machine instructions in one go. This process can be time-consuming if the program is long.

The interpreter can immediately execute high-level programs, without waiting for the completion of the translation process

21
Interpreters:
Immediate response,
but
execute code slowly

Compilers:
Takes longer to compile,
but
super-fast execution 22
Both interpreters and compilers are available for most high-level languages.

However, BASIC and LISP were especially designed to be executed by an interpreter

23
CLASSIFICATION OF
PROGRAMMING LANGUAGES
Procedural Languages

Non-Procedural Languages

25
PROCEDURAL LANGUAGES
• In procedural languages and programs used to
tell the computer exactly what to do, step by
step.

• In other words, what to do and how to do is


required.

• Example: Fortran, Cobol, C++ etc…


NON-PROCEDURAL LANGUAGES
• In non-procedural languages and programs is
where you tell computer, and it figures out how
to get it.

• Non-procedural languages is often used for


database manipulation.

• Example: Query Languages i.e. SQL


The question of which language is best
is one that consumes a lot of time and
energy among computer professionals

Every language has its strengths and


weaknesses

28
FORTRAN is a particularly good language for
processing numerical data, but it does not lend
itself very well to large business programs

Pascal is very good for writing well-structured and


readable programs, but it is not as flexible as the C
programming language

C++ embodies powerful object-oriented features,


but it is complex and difficult to learn

29
The choice of which language to use can also depend on the:

type of computer the program is to run on,

and the

expertise of the programmer

30
FORTRAN
• FORTAN stands for FORmula TRANslation.

• Developed by John Backus and his team at IBM.

• FORTAN language is oriented towards solving problem of


a mathematical nature.

• It has been designed as algebra-based programming


language.

• FORTAN 90 is the latest version of FORTRAN standardized


by ANSI.
COBOL
• COBOL stands for COmmon Business Oriented
Language.

• Developed by Grace Hoper and his team.

• It was developed for business data processing


language.

• Business data processing application deal with


corporate accounting information, automate
inventory control, billing and payroll.
• It has English-like commands.

• COBOL 2002 is the latest version of COBOL


standardized by ANSI.
BASIC
• BASIC stands for Beginners All-purpose Symbolic
Instruction Code.

• Developed by Prof. John Kemeny & Thomas Kurtz


at Darmouth College in USA.

• It was developed to use for both business &


scientific applications.

• Users of BASIC range from school students to


scientists & engineers to business managers.
• It was designed to use an interpreter as the
language translator (FORTRAN & COBOL use
compilers).

• BASIC has many dialects including BASICA, QBSIC


and Visual Basic.
PASCAL
• Named after, French mathematician, Blaise Pascal.

• Developed by Prof. Nicklaus Wirth of Federal


Institute of Technology in Zurich, Switzerland.

• It was develop for beginners to learn good problem


solving and programming practices.

• PASCAL was based on the concepts associated with


structured programming an object oriented version
of Pascal is also available.
• Hence, it is recognized as an educational
language, used to teach programming to
beginners.

• PASCAL is suitable for both scientific and business


applications.
DATA TYPES
• In a high-level language a constant or a variable
represents one or more memory locations where
data can be stored.
SIMPLE DATA TYPES
• Most languages offer some primitive data types such
as:

o Integer: to store whole numbers.

o Real: to store values that contain digits after the decimal


point.

o Character: to store a single character.

o Boolean: to store one of the two values, True or False.


COMPLEX DATA TYPES
• It is possible to use more complex data types:

o Array: a collection of items, each of which can be


accessed directly using a subscript, e.g. Table[5] refers
to the fifth item in the array.

o String: naturally an array of characters but sometimes


offered as a special type.
Array

An indexed list of elements

We said that a variable is a container that


holds a value.

Similarly, an Array can be considered a


container as well, but this one can hold
multiple values

41
Array
An indexed list of elements

Example: There are many ways of assigning


identifiers to the following fruit

strawberry orange apple watermelon


fruit1 fruit2 fruit3 fruit4
fruit[ 0 ] fruit[ 1 ] fruit[ 2 ] fruit[ 3 ]

42
Array
An indexed list of elements

• fruit[ 0 ], fruit[ 1 ], fruit[ 2 ], and fruit[ 3 ] are the


elements of an array

• ‘fruit’ is the identifier for that array

• The length of the ‘fruit’ array is 4, i.e. ‘fruit’ has


four elements

43
Array

fruit[0]

Square
Identifier Index
bracket

44
ABSTRACT DATA TYPES
• Abstract data types (ADTs) are complex data
types that have operations associated with them.

• To access an ADT ask it to perform some


operations, e.g. a stack that has the operations
Push and Pop. To add an item to the stack you
use Push and to remove an item from the stack
you would use Pop.
• Abstract data types include:

o Queue: a first in first out (FIFO) data structure. Items


are retrieved in the same sequence that they were
added.

o Stack: a last in first out (LIFO) data structure. Items


are retrieved in the reverse sequence

o Binary Search Tree: items are added in any sequence.


A useful structure that automatically sorts the data.

You might also like