Pseudocode algorithms using sequence, selection and repetition

Slides:



Advertisements
Similar presentations
Repetition There are three different ways that a set of instructions can be repeated, and each way is determined by where the decision to repeat is.
Advertisements

Repetition Control Structures
Repetition control structures
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Fundamentals of Algorithms MCS - 2 Lecture # 4
Program Design Tool. 6 Basic Computer Operations Receive information Put out information Perform arithmetic Assign a value to variable (memory location)
Selection control structures
Repetition Control Structure
TEL 104 / MKK Fundamental Programming: Lecture 3
Chapter 2- Visual Basic Schneider
Steps in Program Development
Chapter 4 Repetitive Execution. 2 Types of Repetition There are two basic types of repetition: 1) Repetition controlled by a counter; The body of the.
Logic and Algorithm. Developing an algorithm To help the initial analysis, the problem should be divided into 3 separate components: 1.Input: a list of.
ALGORITHMS Algorithm: Is an ordered set of unambiguous, executable steps defining a terminating process Unambiguous:during the execution of an algorithm,
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Program Design and Development
Repetition Control Structures
Pseudocode.
Pseudocode Algorithms Using Sequence, Selection, and Repetition.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Pseudocode.
Adapted from slides by Marie desJardins
DCT 1123 Problem Solving & Algorithms
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Combination of Sequence, Selection and Repetition
DCT 1123 Problem Solving & Algorithms
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.
Developing an Algorithm
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
Chapter 7 Array processing. Objectives To introduce arrays and the uses of arrays To develop pseudocode algorithms for common operations on arrays To.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Developing an Algorithm
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Pseudocode Algorithms Using Sequence, Selection, and Repetition
Repetition Control Structures Simple Program Design Third Edition A Step-by-Step Approach 5.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
EXERCISES for ALGORITHMS WRITING
Pseudocode Algorithms Using Sequence, Selection, and Repetition Simple Program Design Third Edition A Step-by-Step Approach 6.
Developing an Algorithm. Simple Program Design, Fourth Edition Chapter 3 2 Objectives In this chapter you will be able to: Introduce methods of analyzing.
Chapter 8 First steps in modularisation. Objectives To introduce modularisation as a means of dividing a problem into subtasks To present hierarchy charts.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into small parts (module)
Fundamental Programming Fundamental Programming More on Repetition.
Flowcharts. Symbol Terminal Symbol: indicates the starting or stopping pointin the logic. Input/Output Symbol: Represents an input or output process in.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
PROGRAM CONTROL STRUCTURE
Computer Science Faculty
CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
Program Design Introduction to Computer Programming By:
Pseudocode.
Pseudocode algorithms using sequence, selection and repetition
Chapter 2- Visual Basic Schneider
CHAPTER 4 Iterative Structure.
UMBC CMSC 104 – Section 01, Fall 2016
Introduction to Pseudocode
Presentation transcript:

Pseudocode algorithms using sequence, selection and repetition Chapter 6 Pseudocode algorithms using sequence, selection and repetition

Objectives To develop solution algorithms to eight typical programming problems using sequence, selection and repetition constructs

Eight solution algorithms 6.1 Eight solution algorithms

Eight solution algorithms Each programming problem will be defined, the control structures required will be determined and a solution algorithm will be devised

Eight solution algorithms Defining the problem Divide the problem into its three components Input Output Processing The processing component should list the task to be performed – what need to be done, NOT how. Underline the verbs in each problem to help identify the actions to be performed

Eight solution algorithms The control structures required Once the problem has been defined, write down the control structures (sequence, selection and repetition) that may be needed, as well as any extra variables that the solution may require

Eight solution algorithms The solution algorithm Devise a solution algorithm and represent it using pseudocode Desk checking Desk check each of the algorithm with two or more test cases

Example 6.1 Process number pairs Design an algorithm that will prompt for and receive pairs of numbers from an operator at a terminal and display their sum, product and average on the screen. If the calculated sum is over 200, an asterisk is to be displayed beside the sum. The program is to terminate when a pair of zero values is entered.

Example 6.1 Process number pairs Defining Diagram Input Processing Output number1 number2 Prompt for numbers Get numbers Calculate sum Calculate product Calculate average Display sum, product, average Display ‘*’ Sum Product Average ‘*’

Example 6.1 Process number pairs Control structures required A DOWHILE loop to control the repetition An IF statement to determine if an asterisk is to be displayed Note the use of the NOT operand with the AND logical operator

Example 6.1 Process number pairs Solution algorithm Process_numbers_pairs Set sum to zero Prompt for number1, number2 Get number1, number2 DOWHILE NOT (number1 = 0 AND number2 = 0) sum = number1 + number2 product = number1 * number2 average = sum / 2 IF sum > 200 THEN Display sum, ‘*’, product, average

Example 6.1 Process number pairs ELSE Display sum, product, average ENDIF Prompt for number1, number2 Get number1, number2 ENDDO END

Summary This chapter developed solutions to eight programming problems. The approach to the problems followed the same pattern: The problem was defined using a defining diagram. The control structures required were written down, along with any extra variables required. The solution algorithm was produced, using pseudocode and the three basic control structures: sequence, selection and repetition.

Summary It was noted that the solution algorithms followed the same basic pattern, although the statements within the pattern were different Process_sequential_file Initial processing Read first record DOWHILE more records exist Process this record Read next record ENDDO Final processing END