An Introduction to Programming with C++ Fifth Edition Chapter 8 More on the Repetition Structure.

Slides:



Advertisements
Similar presentations
Chapter 6: The Repetition Structure
Advertisements

Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Programming Logic and Design Eighth Edition
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Repeating Actions While and For Loops
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 6 More on the Selection Structure.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Chapter 12: How Long Can This Go On?
CPS120 Introduction to Computer Science Iteration (Looping)
Programming Logic and Design Fifth Edition, Comprehensive
Programming Logic and Design Sixth Edition Chapter 5 Looping.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Chapter 6: The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Computer Programming TCP1224 Chapter 8 More On Repetition Structure.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
CPS120 Introduction to Computer Science Iteration (Looping)
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 14 Do It, Then Ask Permission.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Chapter 6 - Repetition. while Loop u Simplest loop u Two parts: test expression and loop body u Pre-tested loop –Execute loop body if test true –Bypass.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING For Loop.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Chapter 8: More on the Repetition Structure
Programming Logic and Design Fourth Edition, Comprehensive
The Selection Structure
1.
Chapter 5: Repetition Structures
An Introduction to Programming with C++ Fifth Edition
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Chapter 8: More on the Repetition Structure
Presentation transcript:

An Introduction to Programming with C++ Fifth Edition Chapter 8 More on the Repetition Structure

An Introduction to Programming with C++, Fifth Edition2 Objectives Include the posttest repetition structure in pseudocode Include the posttest repetition structure in a flowchart Code a posttest loop using the C++ do while statement Nest repetition structures

An Introduction to Programming with C++, Fifth Edition3 Concept Lesson Posttest Loops Coding the Posttest Loop Nested Repetition Structures

An Introduction to Programming with C++, Fifth Edition4 Posttest Loops Loops can be pretest or posttest Condition in a posttest loop is evaluated with each loop iteration –Evaluation occurs after instructions within loop are processed Also called bottom-driven loops

An Introduction to Programming with C++, Fifth Edition5 Posttest Loops (continued)

An Introduction to Programming with C++, Fifth Edition6 Flowcharting a Posttest Loop Flowcharts illustrate why loops are referred to as pretest and posttest loops –Repetition diamond appears at the top of a pretest loop, but at the bottom of a posttest loop

Flowcharting a Posttest Loop (continued) An Introduction to Programming with C++, Fifth Edition7

8 Flowcharting a Posttest Loop (continued)

An Introduction to Programming with C++, Fifth Edition9 Flowcharting a Posttest Loop (continued)

An Introduction to Programming with C++, Fifth Edition10 Coding the Posttest Loop Use the while statement or the for statement to code a pretest loop in C++ Use the do while statement to code a posttest loop in C++ –The loop condition must be a Boolean expression Can contain variables, constants, functions, and arithmetic/comparison/logical operators

An Introduction to Programming with C++, Fifth Edition11 Coding the Posttest Loop (continued)

An Introduction to Programming with C++, Fifth Edition12 Posttest Loop Example – O’Donnell Incorporated Program Problem description –In January of each year, O’Donnell Incorporated pays a 10% bonus to each of its salespeople –Bonus based on amount of sales made by salesperson during previous year –Payroll clerk wants a program that calculates and displays each salesperson’s bonus amount

An Introduction to Programming with C++, Fifth Edition13 Posttest Loop Example – O’Donnell Incorporated Program (continued)

An Introduction to Programming with C++, Fifth Edition14 Posttest Loop Example – O’Donnell Incorporated Program (continued)

An Introduction to Programming with C++, Fifth Edition15 Nested Repetition Structures In a nested repetition structure, one loop (inner loop) is placed entirely within another loop (outer loop)

Nested Repetition Structures (continued) An Introduction to Programming with C++, Fifth Edition16

An Introduction to Programming with C++, Fifth Edition17 Nested Loop Example – Max Beauty Supply Program Max Beauty Supply divides its sales territory into two regions: Region 1 and Region 2 Sales manager wants a program to enter the sales amounts for both regions, one region at a time –Program should calculate the total amount sold in the current region, and display that information

An Introduction to Programming with C++, Fifth Edition18 Nested Loop Example – Max Beauty Supply Program (continued)

An Introduction to Programming with C++, Fifth Edition19 Nested Loop Example – Max Beauty Supply Program (continued)

An Introduction to Programming with C++, Fifth Edition20 Nested Loop Example – Max Beauty Supply Program (continued)

An Introduction to Programming with C++, Fifth Edition21 Nested Loop Example – Max Beauty Supply Program (continued)

An Introduction to Programming with C++, Fifth Edition22 Summary A repetition structure can be a pretest or posttest loop –In a pretest loop, the loop condition is evaluated before the instructions in the loop body are processed Instructions may never be processed Use while or for statements –In a posttest loop, the loop condition is evaluated after the instructions in the loop body are processed Instructions are always processed at least once Use the do while statement You can nest repetition structures

An Introduction to Programming with C++, Fifth Edition23 Application Lesson: Using a Nested Repetition Structure in a C++ Program Lab 8.1: Stop and Analyze Lab 8.2 –Create a program that displays one or more multiplication tables for Mrs. Johnson students Lab 8.3 –Modify program so it uses a posttest loop (instead of a pretest loop) to display the multiplication tables Lab 8.4: Desk-Check Lab Lab 8.5: Debugging Lab