SlideShare a Scribd company logo
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
• The presentations cover the objectives found in the
opening of each chapter
• All chapter objectives are listed in the beginning of each
presentation
• You may customize the presentations to fit your class
needs
• Some figures from the chapters are included. A
complete set of images from the book can be found on
the Instructor companion Web site at
login.cengage.com
An Introduction to Programming with C++, Eighth Edition 1
About the Presentations
An Introduction to Programming with C++
Eighth Edition
Chapter 1:
An Introduction to Programming
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Chapter Objectives
• Define the terminology used in programming
• Explain the tasks performed by a programmer
• Understand the employment opportunities for
programmers and software engineers
• Explain the history of programming languages
• Explain the sequence, selection, and repetition
structures
• Write simple algorithms using the sequence, selection,
and repetition structures
An Introduction to Programming with C++, Eighth Edition 3
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Programming a Computer
It is important to understand the relationship between the
terms programs, programmers, and programming
languages.
Programs - The directions that humans give to computers
Programmers - The people who create these directions
Programming Languages - Special languages used by
programmers to communicate directions to a computer
An Introduction to Programming with C++, Eighth Edition 4
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Programmer’s Job
• Programmers help solve computer problems
• Employee or freelance
• Typical steps involved
– Meet with user to determine problem
– Convert the problem into a program
– Test the program
– Provide user manual
An Introduction to Programming with C++, Eighth Edition 5
© 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
What Traits Should a Software Developer
Possess?
• Analytical skills
• Communication skills
• Creativity
• Customer-service skills
• Detail oriented
• Problem-solving skills
• Teamwork
• Technical skills
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Employment Opportunities
• Computer software engineer: designs an appropriate
solution to a user’s problem
• Computer programmer: codes a computer solution
• Coding is the process of translating a computer solution
into a language a computer can understand
• Some positions call for both engineering and
programming
An Introduction to Programming with C++, Eighth Edition 7
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
A Brief History of Programming Languages
There are many different types of programming
languages. This chapter will discuss:
•Machine languages
•Assembly languages
•High-level procedure-oriented languages
•High-level object-oriented languages
An Introduction to Programming with C++, Eighth Edition 8
© 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
Machine Languages
• The first programmers had to write the program
instructions using only combinations of 0s and 1s
– Example: 0000 0101 1100 0000
• Instructions written in 0s and 1s are called machine
language or machine code
• Each type of machine has its own language
• Machine languages are the only way to communicate
directly with the computer
• Programming in machine language: tedious and error-
prone; requires highly trained programmers
© 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
Assembly Languages
• Assembly languages made writing code simpler than
using only 0s and 1s
• Mnemonics – symbols used to represent the actual
machine language instructions
Example: 00000101 vs. BALR
• Assembly programs require an assembler to convert
instructions into machine code
• Easier to write programs in assembly language
– But still tedious and requires highly trained programmers
© 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
High-Level Languages
• High-level languages allow programmers to use English-
like instructions
Example: taxAmount = total * taxRate
• Each high-level language instruction is equivalent to
more than one machine language instruction
• Compilers translate high-level instructions into 0s and 1s
(machine language)
• Interpreters translate the program line by line as the
program is running
© 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
High-Level Languages (cont.)
• When writing a procedure-oriented program, the
programmer concentrates on the major tasks that the
program needs to perform
– Examples: COBOL, BASIC, C
• An object-oriented program requires the programmer
to focus on the objects that the program can use to
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 than one program
© 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
Control Structures
All computer programs are written using one or more of
three basic control 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 be used.
© 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 Sequence Structure
• The sequence 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 a finite number of step-by-step
instructions that accomplish a task
• Example: steps to pump gas at a self-service pump
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Sequence Structure (cont.)
An Introduction to Programming with C++, Eighth Edition 15
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 16
The Selection Structure
• The selection structure directs the computer to make a
decision (evaluate a condition), and then take an
appropriate action based upon that decision
• The selection structure allows the programmer to
evaluate data, therefore properly controlling the logic
flow of the program
• Another name for the selection structure is the decision
structure
• Example: stopping or going at a signal light
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Selection Structure (cont.)
An Introduction to Programming with C++, Eighth Edition 17
Figure 1-2 An example of the selection structure
An Introduction to Programming with C++, Eighth Edition 18
The Selection Structure (cont.)
Figure 1-3 Another 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 19
The Repetition Structure
• The repetition structure, commonly called iteration or
looping, directs the computer to repeat one or more
program instructions until some condition is met
• This condition may be checked at the beginning or end
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 in once
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Repetition Structure (cont.)
An Introduction to Programming with C++, Eighth Edition 20
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.
Summary
• Programs are step-by-step instructions that tell a
computer how to perform a task
• Programmers use programming languages to
communicate with the computer
• First programming languages were machine language
using 0s and 1s
• Assembly languages followed, using mnemonics
• High-level languages can be used to created procedure-
oriented or object-oriented programs
An Introduction to Programming with C++, Eighth Edition 21
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Summary (cont.)
• An algorithm is a finite number of step-by-step
instructions that accomplish a task
• Algorithms utilize three basic control structures:
sequence, selection, and repetition
• The sequence structure directs the computer to process
the program instructions, one after another, in the
order in which they are listed
• The selection structure directs the computer to make a
decision (evaluate a condition), and then take an
appropriate action based upon that decision
An Introduction to Programming with C++, Eighth Edition 22
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Summary (cont.)
• The repetition structure, commonly called iteration or
looping, directs the computer to repeat one or more
program instructions until some condition is met
• The sequence structure is used in all programs
• Most programs also contain both the selection and
repetition structures
An Introduction to Programming with C++, Eighth Edition 23
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Lab 1-1: Stop and Analyze
Study the algorithm below and answer the questions.
• Which control structures are used in the algorithm?
• What will the algorithm print when the price of the TV is $2,100?
• How would you modify the algorithm so that it can be used for only the
first 10 customers buying a TV?
• How would you modify the algorithm so that it allows the user to also
enter the discount rate and then uses that rate to calculate the
discount?
An Introduction to Programming with C++, Eighth Edition 24
© 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 25
Lab 1-2: Plan and Create
The 10 salespeople at Harkins Company are paid a 10%
bonus when they sell more than $10,000 in product;
otherwise, they receive a 5% bonus. Create an
appropriate algorithm using only the instructions shown
below.
© 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 26
Lab 1-3: Modify
Modify the algorithm shown below so that it gives a 25%
discount to customers who are also employees of the
store; all other customers receive a 15% discount.
© 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 27
Lab 1-4: What’s Missing?
Harold wants to sit down on the park bench, but his cat Ginger may or may
not be already seated there. Put the instructions shown below in the
proper order, and then determine the one or more missing instructions.

More Related Content

PPTX
Introduction to flowchart
PDF
Introduction to computer programming
PPT
Chapter 1 - An Introduction to Programming
PPTX
Algorithm and flowchart
PDF
Chapter 2 basic element of programming
PPT
Intro To Programming Concepts
PPTX
system software and application software
PPTX
Types of Programming Languages
Introduction to flowchart
Introduction to computer programming
Chapter 1 - An Introduction to Programming
Algorithm and flowchart
Chapter 2 basic element of programming
Intro To Programming Concepts
system software and application software
Types of Programming Languages

What's hot (20)

PPTX
Graphical User Interface
PPTX
ppt of flowchart
PPTX
MOUSE SKILLS FOR BEGINNERS.pptx
PPTX
Programming Fundamentals lecture 1
PDF
Solutions manual for c++ programming from problem analysis to program design ...
PPTX
Computer software
PPTX
Programming process and flowchart
PDF
Visual Basic IDE Introduction
PPT
PPTX
Flowchart and algorithm
PPT
Introduction to computer programming
PPTX
Unit 11. Graphics
PPTX
User controls
PPTX
Programming Fundamentals
PPTX
History of Programming Language
PPTX
introduction to programming languages
PPSX
Programming Fundamental Presentation
PDF
Programming language
PPT
Programming in c
PPTX
Algorithm and flowchart
Graphical User Interface
ppt of flowchart
MOUSE SKILLS FOR BEGINNERS.pptx
Programming Fundamentals lecture 1
Solutions manual for c++ programming from problem analysis to program design ...
Computer software
Programming process and flowchart
Visual Basic IDE Introduction
Flowchart and algorithm
Introduction to computer programming
Unit 11. Graphics
User controls
Programming Fundamentals
History of Programming Language
introduction to programming languages
Programming Fundamental Presentation
Programming language
Programming in c
Algorithm and flowchart
Ad

Similar to Lecture 1 programming fundamentals (PF) (20)

PDF
Lesson 1 introduction to programming
PPT
First draft programming c++
PPT
Chapter 5 - The Selection Structure
PDF
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
PDF
C Programming Program design including data structures 5ed. Edition Malik D.S.
PDF
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
PPT
Chapter 8 - More on the Repetition Structure
PDF
C Programming Program design including data structures 5ed. Edition Malik D.S.
DOCX
Comso c++
PDF
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
PDF
C programming from problem analysis to program design 4th ed Edition D S Malik
PDF
Lesson 8 more on repitition structure
PDF
Starting out with C from control structures through objects Eighth Edition To...
PDF
Starting out with C from control structures through objects Eighth Edition To...
PDF
X-CS-8.0 Programming in C Language 2022-2023.pdf
PDF
Starting out with C from control structures through objects Eighth Edition To...
PDF
Starting out with C from control structures through objects Eighth Edition To...
PDF
A Complete Guide to Programming in C 1st Edition Ulla Kirch-Prinz
PDF
Starting out with C from control structures through objects Eighth Edition To...
DOCX
C++ PROGRAMMINGPROGRAM DESIGN INCLUDING DATA STRUCTURES.docx
Lesson 1 introduction to programming
First draft programming c++
Chapter 5 - The Selection Structure
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
C Programming Program design including data structures 5ed. Edition Malik D.S.
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
Chapter 8 - More on the Repetition Structure
C Programming Program design including data structures 5ed. Edition Malik D.S.
Comso c++
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
C programming from problem analysis to program design 4th ed Edition D S Malik
Lesson 8 more on repitition structure
Starting out with C from control structures through objects Eighth Edition To...
Starting out with C from control structures through objects Eighth Edition To...
X-CS-8.0 Programming in C Language 2022-2023.pdf
Starting out with C from control structures through objects Eighth Edition To...
Starting out with C from control structures through objects Eighth Edition To...
A Complete Guide to Programming in C 1st Edition Ulla Kirch-Prinz
Starting out with C from control structures through objects Eighth Edition To...
C++ PROGRAMMINGPROGRAM DESIGN INCLUDING DATA STRUCTURES.docx
Ad

More from Kamran Zafar (12)

PPTX
DFA Assignment solution.pptx
PPTX
TOA_WEEK 14.pptx
PPTX
Drones in agri. by eskill india
PDF
exercise 3.3 solution /class 12th/ mathcity
PPTX
Lec 1 number systems converted
PDF
Lecture 5 binary_codes
PPT
Lecture java continued 1
PPT
Lecture java continued
PPT
digital systems and information
PDF
02 computing magazine september 2012
PDF
Binary search tree operations
DOCX
Learn microsoft word from tayyab riaz
DFA Assignment solution.pptx
TOA_WEEK 14.pptx
Drones in agri. by eskill india
exercise 3.3 solution /class 12th/ mathcity
Lec 1 number systems converted
Lecture 5 binary_codes
Lecture java continued 1
Lecture java continued
digital systems and information
02 computing magazine september 2012
Binary search tree operations
Learn microsoft word from tayyab riaz

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Business Ethics Teaching Materials for college
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Business Ethics Teaching Materials for college
Week 4 Term 3 Study Techniques revisited.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Renaissance Architecture: A Journey from Faith to Humanism
Introduction and Scope of Bichemistry.pptx
Cell Structure & Organelles in detailed.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
The Final Stretch: How to Release a Game and Not Die in the Process.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
NOI Hackathon - Summer Edition - GreenThumber.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
Microbial disease of the cardiovascular and lymphatic systems
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Lecture 1 programming fundamentals (PF)

  • 1. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. • The presentations cover the objectives found in the opening of each chapter • All chapter objectives are listed in the beginning of each presentation • You may customize the presentations to fit your class needs • Some figures from the chapters are included. A complete set of images from the book can be found on the Instructor companion Web site at login.cengage.com An Introduction to Programming with C++, Eighth Edition 1 About the Presentations
  • 2. An Introduction to Programming with C++ Eighth Edition Chapter 1: An Introduction to Programming
  • 3. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Chapter Objectives • Define the terminology used in programming • Explain the tasks performed by a programmer • Understand the employment opportunities for programmers and software engineers • Explain the history of programming languages • Explain the sequence, selection, and repetition structures • Write simple algorithms using the sequence, selection, and repetition structures An Introduction to Programming with C++, Eighth Edition 3
  • 4. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Programming a Computer It is important to understand the relationship between the terms programs, programmers, and programming languages. Programs - The directions that humans give to computers Programmers - The people who create these directions Programming Languages - Special languages used by programmers to communicate directions to a computer An Introduction to Programming with C++, Eighth Edition 4
  • 5. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Programmer’s Job • Programmers help solve computer problems • Employee or freelance • Typical steps involved – Meet with user to determine problem – Convert the problem into a program – Test the program – Provide user manual An Introduction to Programming with C++, Eighth Edition 5
  • 6. © 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 What Traits Should a Software Developer Possess? • Analytical skills • Communication skills • Creativity • Customer-service skills • Detail oriented • Problem-solving skills • Teamwork • Technical skills
  • 7. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Employment Opportunities • Computer software engineer: designs an appropriate solution to a user’s problem • Computer programmer: codes a computer solution • Coding is the process of translating a computer solution into a language a computer can understand • Some positions call for both engineering and programming An Introduction to Programming with C++, Eighth Edition 7
  • 8. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. A Brief History of Programming Languages There are many different types of programming languages. This chapter will discuss: •Machine languages •Assembly languages •High-level procedure-oriented languages •High-level object-oriented languages An Introduction to Programming with C++, Eighth Edition 8
  • 9. © 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 Machine Languages • The first programmers had to write the program instructions using only combinations of 0s and 1s – Example: 0000 0101 1100 0000 • Instructions written in 0s and 1s are called machine language or machine code • Each type of machine has its own language • Machine languages are the only way to communicate directly with the computer • Programming in machine language: tedious and error- prone; requires highly trained programmers
  • 10. © 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 Assembly Languages • Assembly languages made writing code simpler than using only 0s and 1s • Mnemonics – symbols used to represent the actual machine language instructions Example: 00000101 vs. BALR • Assembly programs require an assembler to convert instructions into machine code • Easier to write programs in assembly language – But still tedious and requires highly trained programmers
  • 11. © 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 High-Level Languages • High-level languages allow programmers to use English- like instructions Example: taxAmount = total * taxRate • Each high-level language instruction is equivalent to more than one machine language instruction • Compilers translate high-level instructions into 0s and 1s (machine language) • Interpreters translate the program line by line as the program is running
  • 12. © 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 High-Level Languages (cont.) • When writing a procedure-oriented program, the programmer concentrates on the major tasks that the program needs to perform – Examples: COBOL, BASIC, C • An object-oriented program requires the programmer to focus on the objects that the program can use to 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 than one program
  • 13. © 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 Control Structures All computer programs are written using one or more of three basic control 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 be used.
  • 14. © 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 Sequence Structure • The sequence 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 a finite number of step-by-step instructions that accomplish a task • Example: steps to pump gas at a self-service pump
  • 15. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Sequence Structure (cont.) An Introduction to Programming with C++, Eighth Edition 15 Figure 1-1 An example of the sequence structure
  • 16. © 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 The Selection Structure • The selection structure directs the computer to make a decision (evaluate a condition), and then take an appropriate action based upon that decision • The selection structure allows the programmer to evaluate data, therefore properly controlling the logic flow of the program • Another name for the selection structure is the decision structure • Example: stopping or going at a signal light
  • 17. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Selection Structure (cont.) An Introduction to Programming with C++, Eighth Edition 17 Figure 1-2 An example of the selection structure
  • 18. An Introduction to Programming with C++, Eighth Edition 18 The Selection Structure (cont.) Figure 1-3 Another example of the selection structure
  • 19. © 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 The Repetition Structure • The repetition structure, commonly called iteration or looping, directs the computer to repeat one or more program instructions until some condition is met • This condition may be checked at the beginning or end 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 in once
  • 20. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Repetition Structure (cont.) An Introduction to Programming with C++, Eighth Edition 20 Original algorithm and modified algorithm showing the repetition structure
  • 21. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary • Programs are step-by-step instructions that tell a computer how to perform a task • Programmers use programming languages to communicate with the computer • First programming languages were machine language using 0s and 1s • Assembly languages followed, using mnemonics • High-level languages can be used to created procedure- oriented or object-oriented programs An Introduction to Programming with C++, Eighth Edition 21
  • 22. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (cont.) • An algorithm is a finite number of step-by-step instructions that accomplish a task • Algorithms utilize three basic control structures: sequence, selection, and repetition • The sequence structure directs the computer to process the program instructions, one after another, in the order in which they are listed • The selection structure directs the computer to make a decision (evaluate a condition), and then take an appropriate action based upon that decision An Introduction to Programming with C++, Eighth Edition 22
  • 23. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (cont.) • The repetition structure, commonly called iteration or looping, directs the computer to repeat one or more program instructions until some condition is met • The sequence structure is used in all programs • Most programs also contain both the selection and repetition structures An Introduction to Programming with C++, Eighth Edition 23
  • 24. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Lab 1-1: Stop and Analyze Study the algorithm below and answer the questions. • Which control structures are used in the algorithm? • What will the algorithm print when the price of the TV is $2,100? • How would you modify the algorithm so that it can be used for only the first 10 customers buying a TV? • How would you modify the algorithm so that it allows the user to also enter the discount rate and then uses that rate to calculate the discount? An Introduction to Programming with C++, Eighth Edition 24
  • 25. © 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 25 Lab 1-2: Plan and Create The 10 salespeople at Harkins Company are paid a 10% bonus when they sell more than $10,000 in product; otherwise, they receive a 5% bonus. Create an appropriate algorithm using only the instructions shown below.
  • 26. © 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 26 Lab 1-3: Modify Modify the algorithm shown below so that it gives a 25% discount to customers who are also employees of the store; all other customers receive a 15% discount.
  • 27. © 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 27 Lab 1-4: What’s Missing? Harold wants to sit down on the park bench, but his cat Ginger may or may not be already seated there. Put the instructions shown below in the proper order, and then determine the one or more missing instructions.