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
Program Design Tool. 6 Basic Computer Operations Receive information Put out information Perform arithmetic Assign a value to variable (memory location)
 Control structures  Algorithm & flowchart  If statements  While statements.
Selection control structures
Repetition Control Structure
Program Design and Development
Repetition Control Structures
Pseudocode.
General Algorithms for Common Business Problems
Chapter 1 Program Design
Pseudocode Algorithms Using Sequence, Selection, and Repetition.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Pseudocode.
Chapter 5: Control Structures II (Repetition)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 5: Control Structures II (Repetition)
DCT 1123 Problem Solving & Algorithms
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
Combination of Sequence, Selection and Repetition
Pseudocode algorithms using sequence, selection and repetition
DCT 1123 Problem Solving & Algorithms
Simple Program Design Third Edition A Step-by-Step Approach
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection)
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.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Chapter 7 Array processing. Objectives To introduce arrays and the uses of arrays To develop pseudocode algorithms for common operations on arrays To.
Array Processing.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
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
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
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.
General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10.
Cs413_design04.ppt Design and Software Development Design : to create a functional interface that has high usability Development : an organized approach.
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.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Developing an Algorithm. Simple Program Design, Fourth Edition Chapter 3 2 Objectives In this chapter you will be able to: Introduce methods of analyzing.
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.
Intermediate 2 Computing Unit 2 - Software Development.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition)
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
Chapter 5: Control Structures II (Repetition)
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Control Structures II (Repetition)
Program Design Introduction to Computer Programming By:
Pseudocode algorithms using sequence, selection and repetition
For Wednesday No new reading No quiz.
CHAPTER 4 Iterative Structure.
Chapter 5: Control Structures II (Repetition)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Presentation transcript:

Pseudocode Algorithms Using Sequence, Selection, and Repetition

Simple Program Design, Fourth Edition Chapter 6 Objectives In this chapter you will be able to: Develop solution algorithms to eight typical programming problems using sequence, selection, and repetition constructs Simple Program Design, Fourth Edition Chapter 6

Eight Solution Algorithms This chapter develops solution algorithms to eight programming problems of increasing complexity All the algorithms will use a combination of sequence, selection, and repetition constructs The algorithms have been designed to be interactive or to process sequential files Simple Program Design, Fourth Edition Chapter 6

Simple Program Design, Fourth Edition Chapter 6 1 Defining the Problem It is important that you divide the problem into its three components: Input Output Processing Simple Program Design, Fourth Edition Chapter 6

2 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 Simple Program Design, Fourth Edition Chapter 6

3 The Solution Algorithm Having defined the problem and determined the required control structures, devise a solution algorithm and represent it using pseudocode Simple Program Design, Fourth Edition Chapter 6

Simple Program Design, Fourth Edition Chapter 6 4 Desk Checking You will need to desk check each of the developed algorithms with two or more test cases Simple Program Design, Fourth Edition Chapter 6

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 A Defining diagram (shown on page 74) Simple Program Design, Fourth Edition Chapter 6

Example 6.1 Process Number Pairs B 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 operator with the AND logical operator C Solution algorithm Refer to the code of the solution algorithm on page 74 of the textbook Simple Program Design, Fourth Edition Chapter 6

Example 6.2 Print Student Records A file of student records consists of ‘S’ records and ‘U’ records. An ‘S’ record contains the student’s number, name, age, gender, address, and attendance pattern; full-time (F/T) or part-time (P/T). A ‘U’ record contains the number and name of the unit or units in which the student has enrolled. There may be more than one ‘U’ record for each ‘S’ record. Design a solution algorithm that will read the file of student records and print only the student’s number, name, and address on a ‘STUDENT LIST’. A Defining Diagram (shown on page 75 of the text) Simple Program Design, Fourth Edition Chapter 6

Example 6.2 Print Student Records B Control Structures Required A DOWHILE loop to control the repetition An IF statement to select ‘S’ records C Solution algorithm Examine the pseudocode illustrated on page 75 of the textbook Simple Program Design, Fourth Edition Chapter 6

Example 6.3 Print Selected Students Design a solution algorithm that will read the same student file as in Example 6.2, and produce a report of all female students who are enrolled part-time. The report is to be headed ‘PART TIME FEMALE STUDENTS’ and is to show the student’s number, name, address, and age A Defining Diagram (shown on page 76) Simple Program Design, Fourth Edition Chapter 6

Example 6.3 Print Selected Students B Control Structures Required A DOWHILE loop to control the repetition An IF statement or statements to select ‘S’, female, and part- time (P/T) students C Solution Algorithm Several algorithms for this problem will be presented, and all are equally correct The algorithms only differ in the way the IF statement is expressed, as shown in the code on pages 76 and in Solution 2 on page 77 of the textbook Simple Program Design, Fourth Edition Chapter 6

Example 6.4 Print and Total Selected Students Design a solution algorithm that will read the same student file as in Example 6.3 and produce the same ‘PART TIME FEMALE STUDENTS’ report. In addition, you are to print at the end of the report the number of students who have been selected and listed, and the total number of students on the file A Defining Diagram (shown on page 78) Simple Program Design, Fourth Edition Chapter 6

Example 6.4 Print and Total Selected Students B Control Structures Required A DOWHILE loop to control the repetition IF statements to select ‘S’, female, and P/T students Accumulators for total_selected_students and total_students C Solution Algorithm Examine the code listed on page 78 of the textbook Simple Program Design, Fourth Edition Chapter 6

Example 6.5 Print Student Report Design an algorithm that will read the same student file as in Example 6.4 and for each student, print the name, number, and attendance pattern from the ‘S’ records (student records) and the unit number and unit name from the ‘U’ records (enrolled units records) as shown on page 79 of the textbook. At the end of the report, print the total number of students enrolled A Defining Diagram (shown on page 79) Simple Program Design, Fourth Edition Chapter 6

Example 6.5 Print Student Report B Control Structures Required A DOWHILE loop to control the repetition An IF statement to select ‘S’ or ‘U’ records An accumulator for total_students C Solution Algorithm Examine the code illustrated on page 80 of the textbook for this program problem Simple Program Design, Fourth Edition Chapter 6

Example 6.6 Produce Sales Report Design a program that will read a file of sales records and produce a sales report. Each record in the file contains a customer’s number, name, a sales amount, and a tax code. The tax code is to be applied to the sales amount to determine the sales tax due for that sale, as shown in the table on page 80 of the textbook. The report is to print a heading ‘SALES REPORT’, and detail lines listing the customer number, name, sales amount, sales tax, and the total amount owed A Defining Diagram (shown on page 81) Simple Program Design, Fourth Edition Chapter 6

Example 6.6 Produce Sales Report B Control Structures Required A DOWHILE loop to control the repetition A case statement to calculate the sales_tax C Solution Algorithm Examine the code illustrated on page 81 which is the solution for this program problem Simple Program Design, Fourth Edition Chapter 6

Example 6.7 Student Test Results Design a solution algorithm that will read a file of student test results and produce a student test grades report. Each test record contains the student number, name, and test score (out of 50). The program is to calculate for each student the test score as a percentage and to print the student’s number, name, test score (out of 50), and letter grade on the report. The letter grade is determined using the listing on page 81 of the text A Defining Diagram (shown on page 82) Simple Program Design, Fourth Edition Chapter 6

Example 6.7 Student Test Results B Control Structures Required A DOWHILE loop to control the repetition A formula to calculate the percentage A linear nested IF statement to calculate the grade. (The case construct cannot be used here, as CASE is not designed to cater for a range of values.) C Solution Algorithm Refer to the code shown on page 82 of the textbook Simple Program Design, Fourth Edition Chapter 6

Example 6.8 Gas Supply Billing Refer to the background of the Domestic Gas Supply company on page 83 of the text. Design a solution algorithm that will read the customer usage file, calculate the amount owing for gas usage for each customer, and print a report listing each customer’s number, name, address, gas usage, and the amount owing. Read the remainder of the problem specification on page 83 and at the end of the report, print the total number of customers and the total amount owed to the company A Defining Diagram (shown on page 83) Simple Program Design, Fourth Edition Chapter 6

Example 6.8 Gas Supply Billing B Control Structures Required A DOWHILE loop to control the repetition An IF statement to calculate the amount_owing Accumulators for total_customers and total_amount_owing C Solution Algorithm Examine the code shown on page 84 of the textbook, which shows the pseudocode for this problem Simple Program Design, Fourth Edition Chapter 6

Simple Program Design, Fourth Edition Chapter 6 Summary This chapter developed solution algorithms to eight typical programming problems The approach to all eight 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 Simple Program Design, Fourth Edition Chapter 6