Flowcharts Lecture 12.

Slides:



Advertisements
Similar presentations
Repetition Control Structures
Advertisements

Flow Charts, Loop Structures
Introduction to Flowcharting
Introduction to Flowcharting
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
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
Assistanship Assistant: Denny, TE 2002 Type: not compulsary, only when necessary Duration: once a week, not more than 2 hours. Time,place: ask assistant.
TEL 104 / MKK Fundamental Programming: Lecture 3
Chapter 2- Visual Basic Schneider
Nassi-Schneidermann Diagrams Lecture 13. Three basic control Structures.
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.
1 TEL 104 / MKK Fundamental Programming: Lecture 4.
Modularisation II Lecture 9. Communication between modules Also known as intermodule communication. The fewer and the simpler the communications, the.
Array Processing Lecture 7.
Repetition Control Structures
Pseudocode Algorithms Using Sequence, Selection, and Repetition.
Chapter 3 Planning Your Solution
Chapter 1 Pseudocode & Flowcharts
CSC103: Introduction to Computer and Programming
DCT 1123 Problem Solving & Algorithms
Sw development1 Software Development 1.Define the problem (Analysis) 2.Plan the solution 3.Code 4.Test and debug 5.Maintain and Document.
Combination of Sequence, Selection and Repetition
Pseudocode algorithms using sequence, selection and repetition
Looping While-continue.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Pseudocode Demo for Payroll.c
First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
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.
Array Processing.
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.
Visual Basic Programming
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Pseudocode Algorithms Using Sequence, Selection, and Repetition
EXERCISES for ALGORITHMS WRITING
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
1 Program Planning and Design Important stages before actual program is written.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into small parts (module)
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
Flowcharts. Symbol Terminal Symbol: indicates the starting or stopping pointin the logic. Input/Output Symbol: Represents an input or output process in.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
1 Introduction to Flowcharting Computer Science Principles ASFA.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
CIS 115 AID Peer Educator/cis115aid.com FOR MORE CLASSES VISIT
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
CIS 115 Slingshot Academy / cis115.com
ALGORITHMS AND FLOWCHARTS
1-1 Logic and Syntax A computer program is a solution to a problem.
Chapter 2- Visual Basic Schneider
Introduction to Flowcharting
CIS 115 Possible Is Everything/snaptutorial.com
CIS115 Education for Service-- snaptutorial.com
CIS 115 Teaching Effectively-- snaptutorial.com
Programming Right from the Start with Visual Basic .NET 1/e
Chapter 2- Visual Basic Schneider
Introduction to Flowcharting
Assistanship Assistant : Denny, TE 2002
Chapter 5 Desk Checking/Dry Running.
Introduction to Pseudocode
Presentation transcript:

Flowcharts Lecture 12

Symbol Terminal Symbol: indicates the starting or stopping pointin the logic. Input/Output Symbol: Represents an input or output process in an algorithm Process Symbol: Represents any single process in an algorithm Predefined Process Symbol: Decision Symbol: Represents a decision in the logic involving the comparison Of two values.

The three basic control structures

1. Sequence Statemement a Statemement b Statemement c

2. Selection Condition p? T F Statemement a Statemement b

Selection (2) Condition p? F T Statemement a

3. Repetition Condition p? F T Statemement block

Example 12.1 Add three numbers A program is required to read three numbers, add them together and print their total.

Defining diagram Input Processing Output Number1 Number2 Number3 Read three numbers Add number together Print total number total

Solution Algorithm Start Read Number1 Number2 number3 Add numbers to total Print total Stop

Example 12.2 Find average temperature A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, and calculate and display to the screen the average temperature, calculated by (maximum temperature + minimum temperature)/2.

Defining diagram Input Processing Output Max_temp Min_temp Prompt for temperatures Get temperatures Calculate average temperature Display average temperature Avg_temp

Solution Algorithm

Example 12.3 Compute mowing time A program is required to read from the screen the lenght and widht of a rectangular house block, and the lenght and width of the rectangular house that has been built on the block. The algorithm should then compute and display the mowing time required to cut the grass around the house, at the rate of two square metres per minute.

Defining diagram Input Processing Output Block_lenght Block_width House_lenght House_width Prompt for block measurements Get block measurements Prompt for house measurements Get house measurements Calculate mowing area Calculate mowing time Mowing_time

Solution Algorithm

Flowchart and the selection control structure

Simple IF statement Account_ balance < $300? T F Service_charge = $5 Service_charge = $2

Null ELSE statement Student_ attendance = F P/T? T Increment part_time_count

Female_part_time_count Combined IF statement Student = P/T AND Gender = F ? F T Increment Female_part_time_count

Nested IF statement T F F T F T Increment Counter_A Increment Record Code =`A‘ ? F F T Record Code =`A‘ ? Increment Counter_A Record Code =`A‘ ? F Increment Counter_B T Increment Error_counter Increment Counter_C

Example 12.4 Read three characters Design an algorithm that will prompt a terminal operator for three characters, accept those characters as input, sort them into ascending sequence and output them to the screen.

Defining diagram Input Processing Output Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Output three characters

Solution Algorithm ?

Case Structure Case Of variable Statement_a Statement_b Statement_c Value 2 Value 3 Value 4 Value 1 Statement_a Statement_b Statement_c Statement_d

Flowchart and Array Design a program that will prompt for and receive 18 examination scores from a mathematics test, compute the class average, and display all the scores and the class average to the screen.

Defining diagram Input Processing Output 18 exam scores Prompt the scores Get scores Compute class average Display scores Display class average Class_average

Control Structures required An array to store the exam scores – called ´scores´ An index to identify each element in the array A DO loop to accept the scores Another DO loop to display the scores to the screen.

Solution Algorithm T F T F Start Calculate average Display average Total_score = zero I = 1 I = 1 Stop Prompt and get Scores (I) Display Scores (I) Add scores(I) to Total score I = I + 1 T I = I + 1 I <= 18 ? F T I <= 18 ? F

Flowchart and Module Design a solution algorithm that will prompt a terminal operator for three characters, accept those characters as input, sort them into ascending sequence and output them to the screen. The algorithm is to continue to read characters until ´XXX`is entered.

Defining diagram Input Processing Output Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Output three characters

Hierarchy chart Process_three_ characters Sort_three_ characters

Process_three_characters Start Sort_ Three_ characters Prompt For characters Outpur characters Get characters Prompt For characters Characters NOT = xxx ? F Stop Get characters T

Sort_three_characters Start T Char_1 > Char_2 ? F Swap Char_1, Char_2 Char_2 > Char_3 ? T F Swap Char_2, Char_3 Char_1 > Char_2 ? T F Swap Char_1, Char_2 Stop

Assignment: Calculate Employee‘s pay A program is required by a company to read an employee‘s number, pay rate and the number of hours worked in a week. The program is then to validate the pay rate and the hours worked fields and, if valid, compute the employee‘s weekly pay and print it along with the input data.

Assignment (cont‘) Validation: According to the company‘s rules, the maximum hours an emplooye can work per week is 60 hours, and the maximum hourly rate is $25.00 per hour. If the hours worked field or the hourly rate field is out of range, the input data and an appropriate message is to be printed and the emplooye‘s weekly pay is not to be calculated. Weekly pay calculation: Weekly pay is calculated as hours worked times pay rate. If more than 35 hours are worked, payment for the overtime hours worked is calculated at time-and half.

Defining diagram Input Processing Output Emp_no Pay_rate Hrs_worked Read employee details Validate input fields Calculate employee pay Print employee details Emp_weekly_pay Error_message

Compute_employee_pay Hierarchy chart Compute_employee_pay Employee_details Valid_input_ fields Read_employee_ details Validate_input_ fields Calculate_ Employee_pay Print_employee_ details

Solution Algorithm

Compute_employee_pay Fields Valid? Start Read_ Employee_ details Calculate_ Employee_ pay More Recods? Print_ Employee_ details Validate_ Input: fields Stop Read_ Employee_ details

Validate_input_fields Start Hours_ Worked > 60 Valid_input_ fields = T Print Error message Pay_rate > $ 25 Print Error message Valid_ Input_ Fields = T Valid_ Input_ Fields = F Stop