Basics of Computer Programming
description
Transcript of Basics of Computer Programming
Basics of Computer ProgrammingWeb DesignSection 8-1
Computer Programs A computer program is nothing
more than a set of instructions that tells the computer what to do
A computer program is also a way to tell another human being what you want the computer to do Part of writing a computer program
is to include documentation Comments in the code, written
document, etc. Helps another human being
understand what you are trying to do
Building Blocks of a Program All computer programs are made
from simple ideas… A List of Instructions
Example: Beat eggs Mix in flour, sugar and shortening Pour into a pan Bake at 375 degrees for 45 minutes
This is called sequential processing
Building Blocks of a Program Ifs
If something is true do this, otherwise do that…
Example – If it is raining take an umbrella
This is called Conditional Processing Repeating Behavior
Examples: Stomp your foot five times While there are cookies on the plate,
keep eating cookies This is called Looping or Iteration
Building Blocks of a Program
Breaking Things Into Smaller Pieces Example:
To clean the house we will first clean the kitchen, then clean the bathroom, and then clean the bedrooms one at a time.
This is called problem decomposition, stepwise refinement or top-down design
It’s really just breaking a complicated task down into a list of simpler tasks and then doing all those simple tasks.
Building Blocks of a Program
Compute a Result Performing a sequence of tasks to
obtain a result that is the answer to a question
Examples: Look in the phone book and find the
number for Rebecca Smith (Question really is “What is Rebecca Smith’s phone number?)
Put this baby on the scale and tell me how many pounds she weighs. (How much does the baby weigh?)
The question is known as a function and asking the question to get a result is known as calling a function
Computer Programming Computer programming is just
using those ideas in various combinations.
Computers really only understand about 100 different instructions! The millions of programs that are
out there are simply different combinations of those 100 instructions.
Designing a Program The best way to design a
program or for someone else or to see the logical flow of your own program is by sketching the design on paper.
One way of doing this is a visual representation called a Flowchart
Flowcharts Flowcharts are constructed using
a set of basic symbols:
Terminal Input/Output
Processing
Call Decision
Flowcharting Along with the symbols certain
connectors are needed:
On PageConnector
Off PageConnector
Flowcharting Example This is a simple flowchart with no
connectors To follow the logic of a flow chart
you start at the top and read downward.
What does this program do?
Start
Read avalue
Multiply thevalue by 2 and
store in X
Display thevalue entered
and X
Stop
The Three Programming Control Structures.
All programs can be described by combining these 3 control structures:
Simple SequenceSimple Selection(IF-THEN-ELSE)
Simple Repitition(Loop)
Flowcharting This is a simple flowchart for taking a bath. Each of these processes can then be broken
down into the steps associated with that process
Note the Start and End! What is this program missing?
Flowcharting This is the flowchart for the
process “Fill the bathtub with water”
This process has decisions and loops! Note that lines coming out of a
decision are labeled with the answer
Friendship Algorithm
Summary A computer program is simply a set
of instructions which the computer must follow to solve a problem.
Computer programs are based on 5 simple ideas:
1. Sequential processing (a list of instructions)
2. Conditional Processing (Ifs)3. Looping or Iteration (repeating)4. Problem decomposition (Breaking
Things Into Smaller Pieces)5. Calling a function (Compute a Result)
Rest of Today Download 8-1 from the Hancock
Web Site On the first page on the homework
the arrows are in the correct places. Simply move the boxes and the text to complete the flowcharts.
For the second page you can use Word or draw the flowchart by hand.
When done print out the homework and turn it in.