class 7 lecture notes

18
Class 7 – Intro to Notation, Flowcharts and Pseudocode

Upload: stephen-parsons

Post on 19-May-2015

4.619 views

Category:

Education


0 download

DESCRIPTION

PROG 1026 Logic and Problem-Solving: notes from Class 7, Notation, Flowcharts and Pseudocode

TRANSCRIPT

Page 1: Class 7 lecture notes

Class 7 – Intro to Notation, Flowcharts and Pseudocode

Page 2: Class 7 lecture notes

Agenda

Process development Algorithmic approaches to problem-

solving Pseudocode

Algorithm Structure Flowcharting Application

Project Development

Page 3: Class 7 lecture notes

What is a Process?

Discuss: what is a process? What are some examples of

processes you encounter in your day-to-day routine?

How can you describe a process What are the important criterion and

parameters of a process? Exercise 7-1: What is a Process?

Page 4: Class 7 lecture notes

Process Debrief

What issues occurred in developing your process?

What important considerations were necessary?

What elements are common to the various processes described?

What elements were unique?

Page 5: Class 7 lecture notes

Process as Problem-Solving

ALGORITHMIC SOLUTIONS some problems such as baking a cake, or

balancing a cheque book can be solved with a concise set of instructions or actions

HEURISITIC SOLUTIONS some problems aren’t so straight forward and

rely heavily on knowledge and experience; i.e. whether to expand a company; how to best buy stocks on the stock market, etc.

heavily reliant on the process of trial and error and cannot be reached by a series of direct steps

Page 6: Class 7 lecture notes

Algorithmic Solutions

An ALGORITHM is a set of precise steps that describe exactly the tasks to be performed, and the order in which they are to be carried out

It can be defined in programming terms as a set of detailed, unambiguous and ordered instructions, developed to describe the processes necessary to produce the desired output from a given input

Algorithms may be described in structured language or graphically

Page 7: Class 7 lecture notes

Algorithm Approaches

IPO Input Processing Output

Expanded IPO Includes Problem Statement Risk – certainty & uncertainty Approach Diagram Testing Options

Pseudo-code – structured syntax

Page 8: Class 7 lecture notes

Pseudocode

Pseudo-code is structured English that states the steps to the problem solution

1. Statements are written in simple English

2. Each instruction/step is written on a separate line

3. Keywords and indentation are used to signify particular control structures

4. Each set of instructions is written from top to bottom, with only one entry and one exit

Page 9: Class 7 lecture notes

Sample Pseudocode

# Start Program

# Prompt for Assignment Name

# Get Assignment Name and assign to variable

# Loop through Student 1-12

# prompt for grade

# get grade and assign to variable

# End Loop when 12 student grades are entered

# Calculate Average and assign to variable

# If the average is greater than 75%

# msg is “Well Done”

# Else

# msg is “Oh, oh!”

# End if

# Compose the output string

# Send the formatted output to the screen

# End Program

Page 10: Class 7 lecture notes

Structure Theorem

The theorem states that it is possible to write any computer program by using only three basic control structures

These control structures are: Sequence (order of steps) Selection, or conditional (if-else-

then) Repetition, or iteration (for-next)

Page 11: Class 7 lecture notes

IPO and Pseudocode

Page 12: Class 7 lecture notes

Practice Pseudocode

Exercise 7-2 Code an algorithm

using pseudocode using Ruby notation, and appropriate indentation

Exercise 7-3 If time allows

Page 13: Class 7 lecture notes

Flowcharting

A graphical representation of program logic using a series of geometric symbols and connecting lines

Flowcharts are relatively easy to learn and are intuitive

Help to identify flow of data Track variables through the life of

the application

Page 14: Class 7 lecture notes

Flow Chart Notation

Terminal symbol- indicates the starting or stopping point of logic:

Input/Output symbol- reading orwriting input/output:

Process Symbol- any single process, such as assigning a value or performinga calculation:

Decision Symbol- comparisons/ T or F decision:

Flowlines- connect symbols in the flowchart: arrow head suggests flow of data a straight line may be used to indicate a relationship

Page 15: Class 7 lecture notes

Sample FlowChart

Pseudocode Start Program Prompt for

assignment Loop through grades

Get student grade Increment counter

End loop Calculate Average Print Average End Program

start

end

Assignment name?

Set counter = 1

Counter>10?

Calculate Average

Print Average

Increment Counter

Student Grade? Ye

sNo

Page 16: Class 7 lecture notes

Flowchart Practice

Develop Flowchart for the last pseudocode exercise

Notes: Pseudocode often follows the development of

a flowchart Some applications are developed to generate

code or pseudocode based on a work flow or flow chart

Application flowcharts are often very complex Please ensure future Ruby solutions are

properly documented with pseudocode notation (# plus indentation)

Page 17: Class 7 lecture notes

Application

Project Work Begin to develop your project flowchart

and pseudocode

Page 18: Class 7 lecture notes

Summary

Process Algorithm and structure Notation

Pseudocode Flowchart

Next steps Refine your notation for Project 1