An Introduction to Control Structures - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

An Introduction to Control Structures

Description:

Write simple algorithms using the sequence, selection, and ... Rob and the Flower Bed. An Introduction to Programming with C . 20. Running the Application ... – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 31
Provided by: www2Pie
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to Control Structures


1
An Introduction to Control Structures
  • Tutorial 1

2
Objectives
  • Explain the sequence, selection, and repetition
    structures
  • Write simple algorithms using the sequence,
    selection, and repetition structures

3
Concept Lesson
4
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

5
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 limited instruction set (walk, turn, and sit)

6
The Sequence Structure
7
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

8
The Repetition Structure
9
The Repetition Structure
10
Robs New Instruction Set
11
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

12
The Selection Structure
13
Application Lesson
14
Programming Rob the Mechanical Man
  • To install the Rob the Mechanical Man files on
    your computers hard disk
  • Click the Start button on the taskbar, and then
    click Run to open the Run dialog box
  • Click the Browse button to open the Browse dialog
    box. Open the Rob Installation Files folder,
    which is located in the CppNet folder on your
    computers hard disk

15
Programming Rob the Mechanical Man
  • Click Setup (Setup.exe) in the list of filenames,
    and then click the Open button to return to the
    Run dialog box
  • Click the OK button in the Run dialog box. A
    message box appears and indicates that seven
    files are being copied to your computers hard
    disk
  • Read the message in the dialog box. If necessary,
    close any open files, then click the OK button in
    the dialog box

16
Installation Message
17
Programming Rob the Mechanical Man(Cont.)
  • As the dialog box indicates, the files will be
    installed in the Program Files\Rob directory
    (folder) on your computers hard disk. You can
    use the Change Directory button to install the
    files in another directory
  • If desired, change the default installation
    directory to one of your choosing

18
Programming Rob the Mechanical Man(Cont.)
  • Click the Click here to begin setup button in the
    dialog box. The Rob the Mechanical Man Choose
    Program Group dialog box opens and shows Rob the
    Mechanical Man selected in the list of groups
  • Click the Continue button. When the message Rob
    the Mechanical Man Setup was completed
    successfully appears, click the OK button

19
Rob and the Flower Bed
20
Running the Application
  • To run the application that you will use to
    create Robs algorithm
  • Click the Start button on the taskbar, and then
    point to All Programs on the Start menu
  • Point to Rob the Mechanical Man on the All
    Programs menu, and then click Application Lesson.
    The Rob the Mechanical Man application shown in
    Figure 1-13 appears on your screen

21
Rob the Mechanical Man Application
22
Initial Algorithm for Rob
23
Initial Algorithm for Rob (Cont.)
24
Final Algorithm for Rob
25
Entering the Algorithm
  • To enter the algorithm shown in Figure 1-15, and
    then verify that it works correctly
  • Scroll down the Instruction Set list box until
    you see the repeat 6 times instruction.
    Double-click repeat 6 times in the Instruction
    Set list box
  • Double-click if the flower is red, then do this
    (inside loop) to copy this instruction to the
    Algorithm list box
  • Double-click pick up the flower with your right
    hand (inside loopselection) to copy this
    instruction to the Algorithm list box
  • Double-click otherwise, do this (inside loop),
    then double-click pick up the flower with your
    left hand (inside loopselection)

26
Entering the Algorithm (Cont.)
  • Scroll down the Instruction Set list box, if
    necessary, until you locate the walk (inside
    loopselection) instruction, then double-click
    walk (inside loopselection)
  • Double-click walk (outside loopselection)
  • Click the Verify Algorithm button. The Verify
    message box opens and displays the Great job!
    message. Click the OK button to close the message
    box
  • Click the Exit button to close the application

27
First Instruction
28
Completed Algorithm
29
Uninstalling Rob the Mechanical Man
  • Click the Start button, and then click Control
    Panel on the Start menu
  • Click Add or Remove Programs to open the Add or
    Remove Programs window
  • Scroll down the list of currently installed
    programs, if necessary, then click Rob the
    Mechanical Man in the list. Click the
    Change/Remove button. When you are asked if you
    are sure you want to remove Rob the Mechanical
    Man and all of its components, click the Yes
    button
  • When the Program installation removed message
    appears, click the OK button
  • Click the Close button to close the Add or Remove
    Programs window, then close the Control Panel
    window

30
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
Write a Comment
User Comments (0)
About PowerShow.com