Module 2 - Preparation
Assignment 2.04

Objectives: After studying the Module 2 Preparation Chip, you will be able to:

  1. Define the following terms: pseudocode, flowchart, terminal symbol, processing symbol, and input/output symbol.
  2. Explain why programmers use flowcharts to represent algorithms.
  3. Explain what the oval, rectangle, and parallelogram are used for in flowcharts.
  4. Interpret an algorithm defined by a simple flowchart.
  5. Demonstrate that you can read a flowchart. and create a pseudocode

 

YOUR LESSON

Introduction

boy reading a flowchart (2_4_a.gif)

 

There are many ways to write an algorithm. You can write it as a list of statements or draw a picture. You have probably heard many people say that a picture is worth a thousand words. In some cases, the solution to a problem is more evident from a picture than from a list of instructions. Programmers use flowcharts to represent an algorithm graphically; however, a flowchart is not a program.

Flowcharts are useful during the planning step of a program.

Flowcharting

Flowcharts are a series of boxes of various shapes connected by lines with arrows showing the sequence of instructions to be followed.

The three most common flowchart symbols are the oval, the parallelogram, and the rectangle. They are also referred to as the terminal symbol, the input/output symbol, and the processing symbol, respectively.

An oval is used for a terminal symbol. 2_4_m.jpg

Terminal Symbol
An oval shows where a program begins and ends.

A parallelogram is used for Input/Output symbols. 2_4_n.jpg

Input/Output Symbol
A parallelogram indicates that information will be printed.

A rectangle is used as the processing symbol. 2_4_o.jpg Processing Symbol
A rectangle depicts a calculation and shows the formula to be used.

INPUT - PROCESSING - OUTPUT

The programs you have written so far in this course have contained only output. The programs used PRINT to display information for the user to read. As you continue working in the course your programs will often be divided into three sections: INPUT - > PROCESSING -> OUTPUT

Before we define these sections in program terms, let's look at an everyday example.

Have you ever made a sandwich? How about a peanut butter sandwich? Stop for a minute and think about the steps you took to create that sandwich.

Flowchart
Pseudocode
A simple flowchart. 2_4_p.jpg

On the left is a flowchart

Here's the flowchart: a series of boxes of various shapes connected by lines with arrows showing the order to perform the various instructions.

The terminal symbols indicate where to begin and end.
The processing symbol shows the calculation to be performed.
The input/output symbol shows what to print.

As a general rule, the flow should be shown from top to bottom and from left to right. Always make sure the arrows point in the correct direction.

On the right is Pseudocode.

Pseudocode (pronounced Sue - doe - code) means "false" code. When writing pseudocode, you will write notes telling what should happen in each section of the program. From these notes, you can write the program. Notice the pseudocode is in plain words, not program code and no graphics are used.

INPUT

Collect Ingredients

  • peanut butter
  • bread
  • spreader

PROCESSING

Spread peanut butter on bread and cover with the other piece of bread

OUTPUT

You have a peanut butter sandwich

Were the instructions clear? Would you be able to create a sandwich by following them? When you develop algorithms for your programs, the steps will need to be clear to help you write your program.

Notice how the order of the steps matter. You can't have OUTPUT before the INPUT and PROCESSING have been completed. The same will be true for your programs.

Also note, listing the instructions for making a sandwich is not the same as physically making the sandwich. The same is true of flowcharts and programs. Developing the flowchart is not the same as coding the program. Knowledge of how to write an algorithm does not imply knowledge of how to write a program. When given a problem, you are the one who must come up with the program that the computer must follow in order to solve the problem.

From Algorithm to Program Code

The Problem

A man went to the mall to purchase CD's. The price for a CD was $10. He purchased 8.

Write a program that will calculate how much is spent for the CD's.

Display how many CD's were bought and how much it cost in sentence format.

Don't forget to use "good programming practices".

Pseudocode

INPUT

The price for a CD was $10 each.
(price1)

He purchased 8 CD's.
(quantity1)

PROCESSING

total cost equals price times the quantity
(totalcost1)

OUTPUT

Display how many CD's were bought and the total cost in sentence format.

Graphic Flow Chart

CD flowchart. 2_4_q.jpg

Once pseudocode or a flowchart depicting an algorithm is created, it is fairly easy to write a program. To the right is a QBASIC program to go along with the sample flowchart. Please note the following:

REM, CLS and COLOR are not in the flowchart but need to be in your program.

Stop is used in the flowchart, but END is used in the program. There is no corresponding keyword for Start.

We used meaningful variable names and there was a number at the end of the variable names. You may be asking, "What is a variable?" You will learn about variables soon!

Translating the rest of the flowchart to a program is pretty straightforward. LET (which you will learn about later in this Module) is represented by the Processing symbol and PRINT is represented by the INPUT/OUTPUT symbol.

REM CD COSTS
REM Programmer: Ada Ross
REM 04/28/07
'
COLOR 15,1
CLS

REM INPUT (assigning variables)
LET price1 = 10
LET quantity1 = 8

REM PROCESSING (calculations)
LET totalcost1 = price1 * quantity1

REM OUTPUT (the display)
PRINT "The cost of ";quantity1; " CDs is: $"; totalcost1
END

Now it's your turn. Open QBASIC and type the program above. Run it a few times and study how it works. When it runs, you should see a sentence on the OUTPUT screen telling the quantity and cost of the CDs purchased. Try changing the value for the price of a CD or the quantity purchased and run the program again. Notice how the output changed.

 

Extra Practice with Input, Processing and Output

Reading a problem and identifying the key elements as Input, Processing, or Output is a skill.

IPO Practice Icon

A text version is also available.

 

Writing an Algorithm

You will be creating either Pseudocode or Flowcharts throughout this course. There are many ways to do this. Let's look at two options.

Pseudocode

  • Use Notepad to organize the instructions into the INPUT, PROCESSING and OUTPUT sections.
    1. Instructions about Data such as numbers or names which should be saved as variables should be pasted in the INPUT section because that is where Numeric and String data are assigned as variables.
    2. Instructions mentioning calculations, formulas or variables which are created as the result of calculations or other types of processing should be pasted into the PROCESSING section
    3. Instructions about what the program is supposed to look like in the display should be pasted into the OUTPUT section
  • When you submit pseudocode, copy the text and then paste into the Student Comments section of the Assignment document.

Flowcharts

  • If you have MS Word, the easiest thing to do is select View from the menu bar, then select Toolbars, and then select Drawing. This will add a tool bar at the bottom of the screen. Select AutoShapes and you will see an option that will let you design flowcharts.
  • Paint programs can also be used to create flowcharts. You can use the paint program that comes with Windows or any other paint program that you have. Please save these files in either bmp, gif, or jpg format.
  • A program called Inspiration is very useful for creating flowcharts. Some of you may already have that if you are taking other online courses.
  • It is also possible to draw flowcharts by hand and then scan them. If you do this, buy an inexpensive plastic flowchart template so your drawings will look nice.
  • If you have more than one file, please do not zip them. (Throughout the course you will see instructions asking you to zip files. You do NOT need to use Zip.) To submit more than one file, go to your Gradebook. Submit the first file, then click the Assessment again and submit the next file. Your instructor will see both when she grades your assessment.

CB Character: Check Your Understanding.
A flowchart and a program are the same thing.


True
False

YOUR ASSIGNMENT

Your assignment for this lesson has two parts.

  1. Download the following worksheet (Flowchart Worksheet) and review the concepts presented in this lesson. Several of the questions on the Worksheet will appear on the Quiz.
  2. When you have completed the Worksheet, take the Quiz for Assignment 02.04 - Preparation.

A QBasic Review

Before moving on to the next assignment, be sure that you can do the following:

  1. Define the following terms: pseudocode, flowchart, terminal symbol, processing symbol, and input/output symbol.
  2. Explain why programmers use flowcharts to represent algorithms.
  3. Explain what the oval, rectangle, and parallelogram are used for in flowcharts.
  4. Interpret an algorithm defined by a simple flowchart.
  5. Demonstrate that you can create a pseudocode and read a flowchart.

Pseudocode is a useful technique to organize the instructions into an algorithm which can be used as a "check list" of tasks to be completed during the development of the code for a program.

Flowcharting is a more formal technique for showing a "picture" of an algorithm. It is a technique also used in many other situations. You will gain a practice reading flowcharting in this course.

preparation key After you have completed the Quiz for Assignment 02.04, please move on to the next assignment.
previousnext