Basics of Computer Programming

18
Basics of Computer Programming Web Design Section 8-1

description

Basics of Computer Programming. Web Design Section 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 - PowerPoint PPT Presentation

Transcript of Basics of Computer Programming

Page 1: Basics of Computer Programming

Basics of Computer ProgrammingWeb DesignSection 8-1

Page 2: Basics of Computer Programming

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

Page 3: Basics of Computer Programming

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

Page 4: Basics of Computer Programming

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

Page 5: Basics of Computer Programming

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.

Page 6: Basics of Computer Programming

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

Page 7: Basics of Computer Programming

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.

Page 8: Basics of Computer Programming

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

Page 9: Basics of Computer Programming

Flowcharts Flowcharts are constructed using

a set of basic symbols:

Terminal Input/Output

Processing

Call Decision

Page 10: Basics of Computer Programming

Flowcharting Along with the symbols certain

connectors are needed:

On PageConnector

Off PageConnector

Page 11: Basics of Computer Programming

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

Page 12: Basics of Computer Programming

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)

Page 13: Basics of Computer Programming

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?

Page 14: Basics of Computer Programming

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

Page 15: Basics of Computer Programming
Page 16: Basics of Computer Programming

Friendship Algorithm

Page 17: Basics of Computer Programming

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)

Page 18: Basics of Computer Programming

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.