computer science: an overview tenth edition by j. glenn brookshear

17
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Computer Science: An Overview Tenth Edition by J. Glenn Brookshear Chapter 6: Programming Languages

Upload: mordecai-jasper

Post on 02-Jan-2016

140 views

Category:

Documents


29 download

DESCRIPTION

Chapter 6: Programming Languages. Computer Science: An Overview Tenth Edition by J. Glenn Brookshear. Chapter 6: Programming Languages. 6.1 Historical Perspective 6.2 Traditional Programming Concepts 6.4 Language Implementation. Figure 6.1 Generations of programming languages. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Computer Science: An OverviewTenth Edition

by J. Glenn Brookshear

Chapter 6:Programming Languages

Page 2: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-2

Chapter 6: Programming Languages

• 6.1 Historical Perspective• 6.2 Traditional Programming Concepts• 6.4 Language Implementation

Page 3: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-3

Figure 6.1 Generations of programming languages

Page 4: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-4

Second-generation:Assembly language

• A mnemonic system for representing machine instructions– Mnemonic names for op-codes– Identifiers: Descriptive names for memory

locations, chosen by the programmer

Page 5: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-5

Assembly Language Characteristics

• One-to-one correspondence between machine instructions and assembly instructions– Programmer must think like the machine

• Inherently machine-dependent• Converted to machine language by a

program called an assembler

Page 6: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-6

Program Example

Machine language

156C166D505630CEC000

Assembly language

LD R5, PriceLD R6, ShippingChargeADDI R0, R5 R6ST R0, TotalCostHLT

Page 7: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-7

Third Generation Language

• Uses high-level primitives– Similar to our pseudocode in Chapter 5

• Machine independent (mostly)• Examples: FORTRAN, COBOL• Each primitive corresponds to a sequence

of machine language instructions• Converted to machine language by a

program called a compiler

Turkish, German, English etc. are natural languages but programming languages are formal languages.

Page 8: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-8

Figure 6.2 The evolution of programming paradigms

Imperative (procedural) paradigm:Programming process is the development of a sequence of commands that, when followed, manipulate data to produce the desired result (i.e. find an algorithm to solve the problem).

Declarative paradigm: Asks programmer to describe the problem to be solved rather than an algorithm to be followed.

Programming (software development) paradigms: Alternative approaches to the programming (software development process) process.

Functional paradigm: A program is constructed by connecting smaller program units (i.e. predefined functions) so that each unit’s outputs are used as inputs to another unit in such a way that the desired overall input-to-output relationship is obtained.

Object-oriented paradigmSoftware system is a collection of units (called objects) each of which is capable of performing the actions that are related to itself and as well as requesting actions of other objects.

Agent-oriented paradigm (?)Autonomous, proactive and social objects (a.k.a. dynamic objects).

Page 9: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-9

Figure 6.3 A function for checkbook balancing constructed from simpler functionsIn LISP, (Find_diff (Find_sum (Old_balance Credits) Find_sum (Debits))

Page 10: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-10

Figure 6.4 The composition of a typical imperative program or program unit

Statement categories in imperative and object-oriented languages: Declarative statementsCustomized terminology that is used later in the program. E.g. Names of data items.

Imperative statementsDescription of steps in the underlying algorithms

CommentsStatements written into the code in any langugage in order to improve the human readability of the program.

Page 11: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-11

Data Types

• Integer: Whole numbers• Real (float): Numbers with fractions• Character: Symbols• Boolean: True/false

Variable: Descriptive names (rather than numeric addresses) that refer to main memory locations. Changing the values in such locations results in value changes for the variable.

Data type: Type of the associated variable. It encompasses both the manner in which the data item (named by its variable) is encoded and the operations that can be performed on that data (or in general the variable).

Page 12: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-12

Variable Declarations

float Length, Width;

int Price, Total, Tax;

char Symbol;

Page 13: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-13

Figure 6.5 A two-dimensional array with two rows and nine columns

Data structure: A conceptual arrangement of data.

Homogeneous array: A block of values of the same type such as one-dimensional list, two-dimensional list with rows and columns and higher dimensional tables.

Indices: Integer values that specify rows, columns etc. of the elements of a homogeneous array.

Page 14: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-14

Figure 6.6 The conceptual structure of the heterogeneous array Employee

Heterogeneous array: Block of data in which different elements can have different types.An example in C:

struct {char Name[25]; int Age; float SkillRating;} Employee;

Employee.Age = Employee.Age + 1;Employee.SkillRating = 72.5;

Declaration

part

Imperative

part

Page 15: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-15

Page 16: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-16

Page 17: Computer Science: An Overview Tenth Edition by  J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-17

Figure 6.7 The for loop structure and its representation in C++, C#, and Java

Comments: provide an easy understanding of program statements. They are explanatory statements inserted within program statements.

In C++, C# and Java,

/* This is a comment */// This is a comment