Download presentation
Presentation is loading. Please wait.
Published byRosemary Black Modified over 9 years ago
1
Chapter 1: An Introduction to Control Structures Introduction to Programming with C++ Fourth Edition
2
Introduction to Programming with C++, Fourth Edition 2 Objectives Explain the sequence, selection, and repetition structures Write simple algorithms using the sequence, selection, and repetition structures
3
Introduction to Programming with C++, Fourth Edition 3 Defining Control Structures All computer programs, no matter how simple or how complex, are written using one or more of three basic structures: –Sequence –Selection –Repetition
4
Introduction to Programming with C++, Fourth Edition 4 The Sequence Structure Directs the computer to process the program instructions, one after another, in the order listed in the program Rob, the mechanical man, has a limited instruction set (walk, turn, and sit)
5
Introduction to Programming with C++, Fourth Edition 5 The Sequence Structure
6
Introduction to Programming with C++, Fourth Edition 6 The Repetition Structure Makes a decision, then takes appropriate action based on that decision –Example: shampoo bottles typically include the repetition structure in the directions for washing your hair
7
Introduction to Programming with C++, Fourth Edition 7 The Repetition Structure
8
Introduction to Programming with C++, Fourth Edition 8 The Repetition Structure
9
Introduction to Programming with C++, Fourth Edition 9 Rob’s New Instruction Set
10
Introduction to Programming with C++, Fourth Edition 10 The Selection Structure Directs the computer to repeat one or more instructions until some condition is met, at which time the computer should stop repeating the instructions –Example: Selection structure is used every time you drive your car and approach an intersection
11
Introduction to Programming with C++, Fourth Edition 11 The Selection Structure (continued)
12
Introduction to Programming with C++, Fourth Edition 12 Summary Basic components of all algorithmic problem solutions: –Sequence Process instructions one after another –Selection Take an action based on a decision –Repetition Repeat a set of instructions until a condition is met Write simple algorithms using the sequence, selection, and repetition structures
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.