INTRODUCTION TO LOGIC AND DESIGN
THE PROGRAM DEVELOPMENT CYCLE
• Understand the problem
• Plan the logic
• Code the program
• Use software (a compiler or
interpreter) to translate the program
into machine language
• Test the program
• Put the program into production
• Maintain the program
These are the two most difficult steps.
SIMPLE PROGRAM LOGIC
ERRORS
• Syntax errors are errors with code
• These errors will not allow your
program to compile and run
• Logic Errors are errors that produce
incorrect results
• These are more difficult to find and fix
BASIC LOGIC – SUPPOSE YOU WANT TO BAKE A CAKE
Get a bowl
Stir
Add two eggs
Add a gallon of gasoline
Back a 350 degrees for 45
minutes
Add three cups of flower
Don’t do this when
baking a cake
This step is out of
order
TWO TRUTHS AND A LIE
1. Hardware is the equipment, or the devices associated with a computer.
Software is computer instructions
2. The grammar rules of a computer programming language are its syntax
3. You write programs using machine language, and translation software
converts the statements to programming language.
You write programs in a high level language like
java or python and a translator will convert the
statements to machine language
USING PSEUDOCODE AND FLOWCHARTS
• Programmers use two tools when planning the logic and flow of a program
• Pseudocode and Flowcharts
• Pseudocode is an English-like representation of the logical steps for solving a
problem
• A flowchart is a pictorial representation of the same thing.
PSEUDOCODE FOR A NUMBER DOUBLING PROBLEM
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
stop
Many programmers use begin and end
Some might write get myNumber or
calculate my answer
Some might say display myAnswer
The words used to dictate the logic are not as important as the logic itself.
Don’t get hung up on what to say, but make sure what you have written
works
DRAWING FLOWCHARTS
• In creating a flow chart you use geometric symbols connected by flow lines to
depict your logic
• A few basic symbols that every flow chart will have include:
• Terminal Symbols
• Input Symbol
• Processing Symbol
• Output Symbol
• Decision Symbol
Notice the input and output
symbols are the same. It is
often called the input/output
symbol or I/O symbol
THE NUMBER DOUBLING PROBLEM
TWO TRUTHS AND A LIE
1. When you draw a flowchart, you use a parallelogram to represent an input
operation
2. When you draw a flowchart, you use a parallelogram to represent a
processing operation
3. When you draw a flowchart, you use a parallelogram to represent an
output operation.
When you draw a flowchart, you use a rectangle
to represent processing operations
PRACTICE
• Draw a flow chart and write the pseudocode to represent the logic of a
program that allows the user to enter a value for the radius of a circle. The
program the calculates the diameter by multiplying the radius by 2 and then
calculates the circumference by multiplying the diameter by 3.14. The
program then should output both results.
HOMEWORK
• Write the process involved in creating a Peanut Butter and Jelly Sandwich.
• The directions need to be specific enough that someone who has never done
this or even seen a PB & J could perform this task.
Top Related