11
Copyright © 2003 by Copyright © 2003 by Prentice Hall Prentice Hall Computers: Computers: Tools for an Tools for an Information Age Information Age Chapter 15 Chapter 15 Programming and Languages: Programming and Languages: Telling the Computer What to Do Telling the Computer What to Do

Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

Embed Size (px)

Citation preview

Page 1: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Computers:Computers:Tools for an Information AgeTools for an Information Age

Chapter 15Chapter 15Programming and Languages:Programming and Languages:

Telling the Computer What to DoTelling the Computer What to Do

Page 2: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

22 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

ObjectivesObjectives

Describe what programmers do and do not doDescribe what programmers do and do not doExplain how programmers define a problem, Explain how programmers define a problem, plan the solution, and then code, test, and plan the solution, and then code, test, and document the programdocument the programList and describe the levels of programming List and describe the levels of programming languages: machine, assembly, high level, very languages: machine, assembly, high level, very high level, and naturalhigh level, and naturalDescribe the major programming languages that Describe the major programming languages that are in use todayare in use todayExplain the concepts of object-oriented Explain the concepts of object-oriented programmingprogramming

Page 3: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

33 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

ProgrammingProgramming

Program – a set of detailed, step-by-step Program – a set of detailed, step-by-step instructions that directs the computer to do instructions that directs the computer to do what you want it to dowhat you want it to do

Programming language – a set of rules Programming language – a set of rules that provides a way of telling the computer that provides a way of telling the computer what operations to performwhat operations to perform

Page 4: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

44 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

The Programming ProcessThe Programming Process

Five main stepsFive main steps Defining the problemDefining the problem Planning the solutionPlanning the solution Coding the programCoding the program Testing the programTesting the program Documenting the programDocumenting the program

Page 5: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

1212 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Levels of LanguagesLevels of Languages

Lower-level languages – more like the 0s Lower-level languages – more like the 0s and 1s the computer itself usesand 1s the computer itself uses

Higher-level languages – more like the Higher-level languages – more like the languages people uselanguages people use

Divided into five generationsDivided into five generations

Page 6: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

1313 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Five Generations of LanguagesFive Generations of Languages

Machine languageMachine language

Assembly languagesAssembly languages

High-level languagesHigh-level languages

Very high-level languagesVery high-level languages

Natural languagesNatural languages

Page 7: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

1919 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Major Programming LanguagesMajor Programming Languages

FORTRANFORTRAN

COBOLCOBOL

BASICBASIC

RPGRPG

Visual BasicVisual Basic

CC

JavaJava

Page 8: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

2727 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Object-Oriented ProgrammingObject-Oriented Programming

Object – a self-contained unit that contains both Object – a self-contained unit that contains both data and its related functionsdata and its related functionsKey terms in object-oriented programmingKey terms in object-oriented programming Encapsulation – an object isolates both its data and Encapsulation – an object isolates both its data and

its related instructionsits related instructions Attributes – facts that describe the objectAttributes – facts that describe the object

Also called propertiesAlso called properties Methods – instructions that tell the object to do Methods – instructions that tell the object to do

somethingsomething Messages – an outside stimulus that results in the Messages – an outside stimulus that results in the

change of the state of an objectchange of the state of an object

Page 9: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

2828 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Using ObjectsUsing Objects

Programmers define classes of Programmers define classes of objectsobjects

The class contains all attributes that The class contains all attributes that are unique to objects of that classare unique to objects of that class

An object is an instance An object is an instance (occurrence) of a class(occurrence) of a class

Objects are arranged hierarchically Objects are arranged hierarchically in classes and subclassesin classes and subclasses

Subclasses are derived from classesSubclasses are derived from classes Inheritance – a subclass possesses Inheritance – a subclass possesses

all attributes of the class from which all attributes of the class from which it is derivedit is derived

Additional attributes can be coded in Additional attributes can be coded in the subclassesthe subclasses

Page 10: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

2929 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Activating the ObjectActivating the Object

A message is sent to the object, telling it to A message is sent to the object, telling it to do somethingdo something The object’s methods tell it how to do itThe object’s methods tell it how to do it

Polymorphism – each object has its own Polymorphism – each object has its own way to process the messageway to process the message For example, the class may have a Move For example, the class may have a Move

method, but each subclass implements that method, but each subclass implements that method differentlymethod differently

Page 11: Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do

3030 Copyright © 2003 by Prentice HallCopyright © 2003 by Prentice Hall

Object-Oriented LanguagesObject-Oriented Languages

C++C++

JavaJava

C#C#

Visual BasicVisual Basic