Pseudocode algorithms using sequence, selection and repetition

Slides:



Advertisements
Similar presentations
PROBLEM SOLVING TECHNIQUES
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)
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
Chapter 2- Visual Basic Schneider
ALGORITHMS Algorithm: Is an ordered set of unambiguous, executable steps defining a terminating process Unambiguous:during the execution of an algorithm,
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.
Pseudocode.
DCT 1123 Problem Solving & Algorithms
PYTHON PROGRAMMING Week 10 – Wednesday. TERMS – CHAPTER 1 Write down definitions for these terms:  Computation  Computability  Computing  Artificial.
Combination of Sequence, Selection and Repetition
Pseudocode algorithms using sequence, selection and repetition
DCT 1123 Problem Solving & Algorithms
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.
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
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.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
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.
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.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
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.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
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.
Starter What does the following code do?
ALGORITHMS AND FLOWCHARTS
REPETITION CONTROL STRUCTURE
while Repetition Structure
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Chapter 2: Input, Processing, and Output
Chapter 2- Visual Basic Schneider
PROGRAM CONTROL STRUCTURE
CHAPTER 5A Loop Structure
Introduction To Flowcharting
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Computer Science Faculty
CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
Program Design Introduction to Computer Programming By:
Pseudocode.
Chapter 2- Visual Basic Schneider
Chapter 2- Visual Basic Schneider
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
CHAPTER 4 Iterative Structure.
UMBC CMSC 104 – Section 01, Fall 2016
Algorithms, Part 3 of 3 Topics In-Class Project: Tip Calculator
REPETITION Why Repetition?
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