An Introduction to Programming with C++
Eighth Edition
Chapter 1:
An Introduction to Programming
Chapter Objectives
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 2
• Define the terminology used inprogramming
• Explain the tasks performed by aprogrammer
• Understand the employment opportunities for
programmers and software engineers
• Explain the history of programminglanguages
• Explain the sequence, selection, andrepetition
structures
• Write simple algorithms using the sequence,selection,
and repetition structures
Programming a Computer
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 3
It is important to understand the relationship between the
terms programs, programmers, and programming
languages.
Programs- Thedirections that humans give to computers
Programmers - Thepeople who create these directions
Programming Languages- Special languages used by
programmers to communicate directions toacomputer
The Programmer’s Job
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 4
• Programmers help solve computer problems
• Employee or freelance
• Typical steps involved
– Meet with user todetermine problem
– Convert the problem into aprogram
– Testthe program
– Provide user manual
What Traits Should a Software Developer
Possess?
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 5
• Analytical skills
• Communication skills
• Creativity
• Customer-service skills
• Detail oriented
• Problem-solving skills
• Teamwork
• Technical skills
Employment Opportunities
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 6
• Computer software engineer: designs an appropriate
solution to auser’sproblem
• Computer programmer: codes acomputer solution
• Codingis the processof translating acomputer solution
into alanguage acomputer canunderstand
• Somepositions call for both engineeringand
programming
A Brief History of Programming Languages
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 7
There are many different types ofprogramming
languages. Thischapter will discuss:
• Machine languages
• Assemblylanguages
• High-level procedure-oriented languages
• High-level object-oriented languages
Machine Languages
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 8
• Thefirst programmers had to write the program
instructions using only combinations of 0sand1s
– Example: 0000 010111000000
• Instructions written in 0sand 1sare called machine
language or machinecode
• Eachtype of machine hasits ownlanguage
• Machine languages are the only way tocommunicate
directly with thecomputer
• Programming in machine language: tedious anderror-
prone; requires highly trained programmers
Assembly Languages
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 9
• Assembly languages made writing code simplerthan
using only 0sand 1s
• Mnemonics – symbols used to represent theactual
machine language instructions
Example: 00000101 vs. BALR
• Assembly programs require an assembler to convert
instructions into machinecode
• Easier to write programs inassemblylanguage
– But still tedious and requires highly trainedprogrammers
High-Level Languages
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 10
• High-level languages allow programmers to useEnglish-
like instructions
Example: taxAmount = total * taxRate
• Eachhigh-level language instruction is equivalent to
more than one machine languageinstruction
• Compilers translate high-level instructions into 0sand
1s(machine language)
• Interpreters translate the program line by lineasthe
program isrunning
High-Level Languages (cont.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 11
• When writing aprocedure-oriented program, the
programmer concentrates on the major tasks thatthe
program needs to perform
– Examples:COBOL,BASIC,C
• An object-oriented program requires the programmer
to focus on the objects that the program can useto
accomplish its goal
– Examples:C++,Visual Basic,Java, C#
• Object-oriented programs allow for an object to be
created that can be reused in more thanone program
Control Structures
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 12
All computer programs are written using one or more of
three basiccontrol structures: sequence,repetition, and
selection. Another term used for control structures are
logic structures, because they control the logic flow of the
program.
While in every program that is written the sequence
structure will be used, in most all programs all three
control structures will beused.
The Sequence Structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 13
• Thesequence structure directs the computer to
process the program instructions, one after another,in
the order in which they are listed in the program
• An algorithm is afinite number of step-by-step
instructions that accomplish atask
• Example: steps to pump gasat aself-service pump
The Sequence Structure (cont.)
Figure 1-1 An example of the sequence structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 14
The Selection Structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 15
• Theselectionstructure directs the computer to makea
decision (evaluate acondition), and then take an
appropriate action based upon that decision
• Theselection structure allows the programmer to
evaluate data, therefore properly controlling thelogic
flow of theprogram
• Another name for the selection structure is thedecision
structure
• Example: stopping or going at asignallight
The Selection Structure (cont.)
Figure 1-2 An example of the selection structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 16
An Introduction to Programming with C++, Eighth Edition 17
The Selection Structure (cont.)
Figure 1-3 Another example of the selection structure
The Repetition Structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 18
• Therepetition structure, commonly called iteration or
looping,directs the computer to repeat one or more
program instructions until some condition ismet
• Thiscondition may be checked at the beginning orend
of the set of instructions to be processed dependent
upon the language being used
• The repetition structure allows the programmer to
repeatedly process a set of instructions, while only
typing them inonce
The Repetition Structure (cont.)
Original algorithm and modified algorithm
showing the repetition structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 19
Summary
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 20
• Programs are step-by-step instructions that tella
computer how to performatask
• Programmersuse programming languages to
communicate with thecomputer
• First programming languages were machine language
using 0sand 1s
• Assembly languages followed, using mnemonics
• High-level languages can be used to created procedure-
oriented or object-orientedprograms
Summary (cont.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 21
• An algorithm is afinite number of step-by-step
instructions that accomplish atask
• Algorithms utilize three basic controlstructures:
sequence, selection, and repetition
• Thesequence structure directs the computer to process
the program instructions, one after another, in the
order in which they arelisted
• Theselection structure directs the computer tomake a
decision (evaluate acondition), and then take an
appropriate action based upon that decision
Summary (cont.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 22
• Therepetition structure, commonly called iteration or
looping, directs the computer to repeat one or more
program instructions until some condition ismet
• Thesequence structure is used in all programs
• Most programs also contain both the selectionand
repetition structures

Lesson 1 introduction to programming

  • 1.
    An Introduction toProgramming with C++ Eighth Edition Chapter 1: An Introduction to Programming
  • 2.
    Chapter Objectives © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 2 • Define the terminology used inprogramming • Explain the tasks performed by aprogrammer • Understand the employment opportunities for programmers and software engineers • Explain the history of programminglanguages • Explain the sequence, selection, andrepetition structures • Write simple algorithms using the sequence,selection, and repetition structures
  • 3.
    Programming a Computer ©2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 3 It is important to understand the relationship between the terms programs, programmers, and programming languages. Programs- Thedirections that humans give to computers Programmers - Thepeople who create these directions Programming Languages- Special languages used by programmers to communicate directions toacomputer
  • 4.
    The Programmer’s Job ©2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 4 • Programmers help solve computer problems • Employee or freelance • Typical steps involved – Meet with user todetermine problem – Convert the problem into aprogram – Testthe program – Provide user manual
  • 5.
    What Traits Shoulda Software Developer Possess? © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 5 • Analytical skills • Communication skills • Creativity • Customer-service skills • Detail oriented • Problem-solving skills • Teamwork • Technical skills
  • 6.
    Employment Opportunities © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 6 • Computer software engineer: designs an appropriate solution to auser’sproblem • Computer programmer: codes acomputer solution • Codingis the processof translating acomputer solution into alanguage acomputer canunderstand • Somepositions call for both engineeringand programming
  • 7.
    A Brief Historyof Programming Languages © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 7 There are many different types ofprogramming languages. Thischapter will discuss: • Machine languages • Assemblylanguages • High-level procedure-oriented languages • High-level object-oriented languages
  • 8.
    Machine Languages © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 8 • Thefirst programmers had to write the program instructions using only combinations of 0sand1s – Example: 0000 010111000000 • Instructions written in 0sand 1sare called machine language or machinecode • Eachtype of machine hasits ownlanguage • Machine languages are the only way tocommunicate directly with thecomputer • Programming in machine language: tedious anderror- prone; requires highly trained programmers
  • 9.
    Assembly Languages © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 9 • Assembly languages made writing code simplerthan using only 0sand 1s • Mnemonics – symbols used to represent theactual machine language instructions Example: 00000101 vs. BALR • Assembly programs require an assembler to convert instructions into machinecode • Easier to write programs inassemblylanguage – But still tedious and requires highly trainedprogrammers
  • 10.
    High-Level Languages © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 10 • High-level languages allow programmers to useEnglish- like instructions Example: taxAmount = total * taxRate • Eachhigh-level language instruction is equivalent to more than one machine languageinstruction • Compilers translate high-level instructions into 0sand 1s(machine language) • Interpreters translate the program line by lineasthe program isrunning
  • 11.
    High-Level Languages (cont.) ©2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 11 • When writing aprocedure-oriented program, the programmer concentrates on the major tasks thatthe program needs to perform – Examples:COBOL,BASIC,C • An object-oriented program requires the programmer to focus on the objects that the program can useto accomplish its goal – Examples:C++,Visual Basic,Java, C# • Object-oriented programs allow for an object to be created that can be reused in more thanone program
  • 12.
    Control Structures © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 12 All computer programs are written using one or more of three basiccontrol structures: sequence,repetition, and selection. Another term used for control structures are logic structures, because they control the logic flow of the program. While in every program that is written the sequence structure will be used, in most all programs all three control structures will beused.
  • 13.
    The Sequence Structure ©2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 13 • Thesequence structure directs the computer to process the program instructions, one after another,in the order in which they are listed in the program • An algorithm is afinite number of step-by-step instructions that accomplish atask • Example: steps to pump gasat aself-service pump
  • 14.
    The Sequence Structure(cont.) Figure 1-1 An example of the sequence structure © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 14
  • 15.
    The Selection Structure ©2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 15 • Theselectionstructure directs the computer to makea decision (evaluate acondition), and then take an appropriate action based upon that decision • Theselection structure allows the programmer to evaluate data, therefore properly controlling thelogic flow of theprogram • Another name for the selection structure is thedecision structure • Example: stopping or going at asignallight
  • 16.
    The Selection Structure(cont.) Figure 1-2 An example of the selection structure © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 16
  • 17.
    An Introduction toProgramming with C++, Eighth Edition 17 The Selection Structure (cont.) Figure 1-3 Another example of the selection structure
  • 18.
    The Repetition Structure ©2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 18 • Therepetition structure, commonly called iteration or looping,directs the computer to repeat one or more program instructions until some condition ismet • Thiscondition may be checked at the beginning orend of the set of instructions to be processed dependent upon the language being used • The repetition structure allows the programmer to repeatedly process a set of instructions, while only typing them inonce
  • 19.
    The Repetition Structure(cont.) Original algorithm and modified algorithm showing the repetition structure © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 19
  • 20.
    Summary © 2016 CengageLearning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 20 • Programs are step-by-step instructions that tella computer how to performatask • Programmersuse programming languages to communicate with thecomputer • First programming languages were machine language using 0sand 1s • Assembly languages followed, using mnemonics • High-level languages can be used to created procedure- oriented or object-orientedprograms
  • 21.
    Summary (cont.) © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 21 • An algorithm is afinite number of step-by-step instructions that accomplish atask • Algorithms utilize three basic controlstructures: sequence, selection, and repetition • Thesequence structure directs the computer to process the program instructions, one after another, in the order in which they arelisted • Theselection structure directs the computer tomake a decision (evaluate acondition), and then take an appropriate action based upon that decision
  • 22.
    Summary (cont.) © 2016Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 22 • Therepetition structure, commonly called iteration or looping, directs the computer to repeat one or more program instructions until some condition ismet • Thesequence structure is used in all programs • Most programs also contain both the selectionand repetition structures