• No results found

Lecture 13

N/A
N/A
Protected

Academic year: 2020

Share "Lecture 13"

Copied!
78
0
0

Loading.... (view fulltext now)

Full text

(1)

1

CS1010 Introduction to Computing

Lecture 13

(Programming Languages)

(2)

2

The major part of computing is software. To

develop software, programming languages are used. To understand the role of programming languages in computing.

To understand the differences among low- &

high-level, interpreted & compiled, and

structured & object-oriented programming languages .

LEARNING GOALS FOR TODAY

(3)

3

Programming ?

(4)

4

The process of telling the computer what to do

Also known as coding

(5)

5

Types of

Programs?

(6)

TYPES OF PROGRAMS

Batch Program

Event-Driven Program

(7)

7

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

(8)

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.

(9)

9

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

(10)

10

Programming

Language ?

(11)

11

A vocabulary and set of grammatical rules for

instructing a computer to

perform specific tasks

(12)

12

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)

(13)

13

Examples of Programming

Language ?

(14)

Machine Language

Assembly Language (1956-63)

LISP (1956)

Fortran (1957)

COBOL (1959)

PL/1(1964)

BASIC (1964)

Pascal (1970)

Smalltalk (1972)

C (1972)

Ada(1983)

C++ (1983-85)

QBasic (1986)

Perl (1987)

VisualBasic (1991)

PowerBuilder

Java (1995)

JavaScript

C# (2001)

(15)

15

Is HTML a

programming

language ?

(16)

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.

(17)

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.

(18)

WHAT DOES PROGRAMMING LOOK LIKE?

Here are some examples of an instruction to print the word HELLO in different programming language.

Logo PR [HELLO]

JavaScript DOCUMENT.WRITE(“HELLO”);

FORTRAN PRINT “HELLO”

BASIC PRINT “HELLO”

COBOL DISPLAY ‘HELLO’

C printf(“HELLO”) C++ cout<<“HELLO”;

Pascal WRITELN(‘HELLO’);

Assembly XPRNT MESSAGE1 Language MESSAGE1 DC ‘HELLO’

PHP echo “Hello”;

(19)

19

Types of

Programming

Languages ?

(20)

CLASSIFICATION OF

PROGRAMMING LANGUAGES

(21)

21

High level Programming Languages

Low Level Programming Languages

(22)

22

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

(23)

23

Lying between

machine languages

&

high-level languages are languages called assembly languages

(24)

24

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

(25)

A SAMPLE ASSEMBLY LANGUAGE PROGRAM

A sample assembly language program for adding two numbers and storing the result.

START PROGRAM AT 0000 START DATA AT 1000

SET ASIDE AN ADDRESS FOR FRST SET ASIDE AN ADDRESS FOR SCND SET ASIDE AN ADDRESS FOR ANSR

CLA FRST ADD SCND STA ANSR HLT

(26)

Assembler

Assembly code

Object code

(27)

27

4th-generation languages High-level languages

Assembly languages

Machine languages

(28)

PowerBuilder is 4th generation language.

More complex task can performed with one statement.

(29)

29

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

(30)

30

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

(31)

31

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

(32)

32

Interpreters:

Immediate response, but

execute code slowly

Compilers:

Takes longer to compile, but

super-fast execution

(33)

33

Both interpreters and compilers are

available for most high-level languages.

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

(34)

CLASSIFICATION OF

PROGRAMMING LANGUAGES

(35)

35

Procedural Languages

Non-Procedural Languages

(36)

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…

(37)

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

(38)

38

Why are there so many different

programming

languages ?

(39)

39

What is the difference

between them ?

(40)

40

(41)

41

What are the advantages of

particular

languages ?

(42)

42

(43)

43

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

(44)

44

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

(45)

45

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

(46)

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.

(47)

A SAMPLE FORTRAN PROGRAM

A sample FORTRAN language program for compute and print the sum of 10 numbers.

C FORTRAN PROGRAM TO COMPUTE C THE SUM OF 10 NUMBERS

SUM = 0

DO 50 I = 1, 10 READ (5, 10) N SUM = SUM + N 50 CONTINUE

WRITE (6, 20) SUM 10 FORMAT (F6.2)

20 FORMAT (1X, ‘THE SUM OF GIVEN NUMBERS = ’, F10.2)

STOP END

(48)

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.

(49)

It has English-like commands.

COBOL 2002 is the latest version of COBOL standardized by ANSI.

(50)

50

A Sample COBOL program (1)

IDENTIFICATION DIVISION PROGRAM_ID SUMUP.

AUTHOR. P K SINHA.

* THIS PROGRAM COMPUTES AND PRINTS

* THE SUM OF GIVEN NUMBERS.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SOURCE_COMPUTER BURROUGHS_6700.

OBJECT_COMPUTER BURROUGHS_6700.

INPUT_OUTPUT SECTION.

FILE_CONTROL.

SELECT DATA_FILE ASSIGN TO DISK.

SELECT OUTPUT_FILE ASSIGN TO PRINTER.

To be Continue on next slide

(51)

51

A Sample COBOL program (2)

DATA DIVISION.

FILE SECTION.

FD DATA_FILE

RECORD CONTAINS 80 CHARACTERS LABEL RECORD IS OMITTED

DATA RECORD IS INPUT_DATA_RECORD.

01 INPUT_DATA_RECORD.

05 N PICTURE 9(6)V99.

05 FILLER PICTURE X(72).

FD OUTPUT_FILE

RECORD CONTAINS 132 CHARACTERS LABEL RECORD IS OMITTED

DATA RECORD IS OUTPUT_RECORD.

To be Continue on next slide

(52)

52

A Sample COBOL program (3)

01OUTPUT_RECORD.

05 FILLER PICTURE X.

05 TITLE PICTURE X(25).

05 SUM PICTURE 9(10)V99.

05 FILLER PICTURE X(94).

WORKING_STORAGE SECTION 77 MESSAGE PICTURE X(25)

VALUES IS “THE SUM OF GIVEN NO.”

PROCEDURE DIVISION.

OPEN_FILES.

OPEN INPUT DATA_FILE

OPEN OUTPUT OUTPUT_FILE

To be Continue on next slide

(53)

53

A Sample COBOL program (4)

INITIALIZATION.

MOVE SPACES TO OUTPUT_RECORD MOVE ZERO TO SUM.

PROCESS_LOOP.

READ DATA_FILE AT END GO TO PRINT_PARA.

ADD N TO SUM.

GO TO PROCESS_LOOP.

PRINT_PARA.

MOVE MESSAGE TO TITLE.

WRITE OUTPUT_RECORD.

END_OF_JOB.

CLOSE DATA_FILE.

CLOSE OUTPUT_FILE.

STOP RUN.

(54)

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.

(55)

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.

(56)

56

A Sample BASIC program

A sample BASIC program.

5 REM PROGRAM TO COMPUTE 6 REM THE SUM OF 10 NUMBERS 10 LET S = 0

20 FOR I = 1 TO 10 30 READ N

40 LET S = S + N 50 NEXT I

60 PRINT “THE SUM OF GIVEN NUMBERS = ”; S 70 DATA 4, 20, 15, 32, 48

80 DATA 12, 3, 9, 14, 44 90 END;

(57)

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.

(58)

Hence, it is recognized as an educational language, used to teach programming to beginners.

PASCAL is suitable for both scientific and business applications.

(59)

59

A Sample PASCAL program

PROGRAM SUMNUMS (INPUT, OUTPUT);

(* PROGRAM TO COMPUTE THE SUM OF 10 NUMBERS *) (* DECLARATION OF VARIABLES*)

VARSUM, N : REAL;

VARI : INTEGER;

(* MAIN PROGRAM LOGIC STARTS HERE*) BEGIN

SUM := 0;

FOR I := 1 TO 10 DO BEGIN

READ (N);

SUM := SUM + N;

END;

WRITELN (‘THE SUM OF GIVEN NUMBERS=’, SUM);

END;

(60)

DATA TYPES

In a high-level language a constant or a variable represents one or more memory locations where data can be stored.

(61)

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.

(62)

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.

(63)

63

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

(64)

64

Array

An indexed list of elements

Example: There are many ways of assigning identifiers to the following fruit

strawberry fruit1

fruit[ 0 ]

orange fruit2

fruit[ 1 ]

apple fruit3

fruit[ 2 ]

watermelon fruit4

fruit[ 3 ]

(65)

65

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

(66)

66

Array fruit[0]

Identifier Square

bracket Index

(67)

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.

(68)

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.

(69)

?

69

Programming

SW Development

(70)

70

SW Design

Methodology ?

(71)

71

The set of (often flexible) rules and

guidelines a team of developers follow to construct reasonably complex SW systems

(72)

72

Object Oriented Design (1)

OO SW is all about objects: a black box which receives messages & responds with those of its own

An object has 2 aspects:

State, also termed as properties, data

Example: For the bicycle: color, speed, pressure

Behaviors, also termed as methods, instructions

Example: For the same object: accelerate(), inflate()

In traditional design, these 2 aspects have been kept apart

(73)

73

Object Oriented Design (2)

The designer starts with any component (object) of the system; designs it as an independent,

self-contained system, and then moves to the design of some other component

The over-all system is put together by fitting together a collection of these components

Key feature: Details of the design of the

component are kept independent of the over-all system

Benefit: It can be easily re-used in other systems:

design once; use multiple times

(74)

74

Structured Design (1)

Also called top-down design

The designer starts by first conceiving a skeleton high-level design of the system, and then starts defining features of that over-all design in an ever-increasing detail

Making small changes in the functionality of the systems sometimes leads to major re-design

exercise

(75)

75

Structured Design (2)

Structured design emphasizes separating a program's data from its functionality

Separating data from functionality typically leads to SW that is difficult to maintain &

understand - especially for large SW systems

(76)

76

Object-Oriented Languages

Programming languages specifically

designed to make it easy to implement object-oriented designs

Examples: Smalltalk, C++, Java

(77)

77

Reading Material

Programming Languages

http://www.wikipedia.com/wiki/Programming_language

What is Object-Oriented Software?

http://catalog.com/softinfo/objects.html VisualBasic: Taming the Wooly Mammoth

http://computer.org/software/so2000/pdf/s3016.pdf

(78)

References

Related documents

Implementation level: A specific representation of the structure to hold the data items, and the coding of the operations in a programming language. This is how we

Key words: High-level programming languages, Out-of-core algorithms, Program synthesis, Memory and storage hierarchies, Query processing, Generative programming, Optimizing

6.2 High Level Programming Languages for Process Automation 6.3 Programming Programmable Logic Controllers (PLC) (PLC) 6.4 Real-time Programming Language Ada 95.. 6.5 The

Collaboration can be on initial level (simple) or can be very high level, complex as when employees of the downstream company actually work in the facility of

Most previous work on program verication has focused on proving the correctness of programs written in high-level programming languages.. Why study program proving at the

It is an open source set of libraries for various high level programming languages that give programmers programming languages that give programmers tools to easily control how

Answer: High level languages or 3rd generation languages use English like statements to code computer instructions.. These are programmers' friendly since these languages

I So, translation from high-level language code to machine code is necessary I Strategies:.. I Interpretation: a program “interprets” the high-level code and carries out the