Vous êtes sur la page 1sur 4

MODULE NAME: Structured Programming

TOPIC: Introduction to Programming

LECTURE 3

Algorithm
An algorithm is a step-by-step procedure to solve a problem. A computer has no
intelligence of its own. For this reason, any algorithm that we use to direct it must be set
up to identify all aspects of a processing situation and to present, in detail, all steps to be
performed.

The algorithm must meet the following requirements:


 Use operations from only a given set of basic operations
 Produce the problem solution, or answer, in a finite number of such
operations.

Pseudocode
Pseudocode is an artificial and informal language that helps programmers develops
algorithms. It is helpful for developing algorithms that will be converted to a high level
programming language e.g. C programs. Pseudocode is similar to every day English; it is
convenient and user friendly although it is not an actual computer programming language
(it is an informal program development aid).

All business applications involve some form of paperwork e.g. accounting procedures,
inventory, sales etc. The term information processing is a series of planned actions and
operations upon data to achieve a desired result. The methods and devices that achieve
the result form an information processing system. All information-processing systems
involve at least three basic elements:
 The source data, or input, entering the system
 The orderly, planned processing within the system
 The end result, or output, from the system

The basic elements of a program are input, processing and output.

Data Hierarchy
Some terms associated with the structure of the data processes by algorithms includes:
File – A collection of related data or fact. E.g. payroll facts for all employees in a
company from a payroll file.
Record- A collection of data, or facts about a single entity in the file e.g. payroll facts for
a single employee in a company form a payroll record.
Field – Any single piece of data, or fact, about a single entity (record) in a file e.g.
employee number represents a filed.
Character – A letter (A-Z, a-z) a number (0-9), or a special character (?,%,&)

1
System Flowchart
A system flowchart is often created to show general information about the application. It
illustrates the basic inputs, processes and outputs. Although a system flowchart is very
helpful in showing inputs, major processing functions and outputs of an information
processing system, it gives only a limited amount of detail about how the computer
performs the specific processing steps.

The following system flowchart shows that a program for computing a weekly sales
report is to be written and executed.
WEEKLY
SALES WEKLY SALES
DATA SALES REPORT
PROGRAM

The system flowchart does not know which mathematical operations must be performed.
To provide this detailed information we construct a program flowchart. A program
flowchart may also be called a Block diagram of logic diagram.

A representative sequence of instructions to solve the payroll problem is:


1. Input the two weekly sales totals for any employee.
2. Compute the sales commission by multiplying the regular sales by an amount of 6
percent.
3. Compute the sales commission by multiplying the reduced sales amount by 3 percent.
4. Computer the total pay due: $200.00 (base pay) + regular commission + sales
commission.
5. Output the total pay on the payroll report

We get this data into the computer in an input step. This is almost always one of the first
steps in an algorithm. Typically, the word READ is used to indicate input, but a word
such as ENTER, GET, or INPUT can also be used.

START

PRINT “Enter
Regular sales and
sales” 1

READ REGSALES,
SALESSALES
2

3 4 5 6
SALESCOM = PAY = WRITE
REGCOM = SALESSALES REGCOM + PAY STOP
REGSALES * *0.03 SALESCOM
0.06 + 200

2
In step 1 the word READ is followed by the words REGSALES and SALESSALES.
These words are names for variables. Variables are data items whose values may change,
or vary, during processing. We create variable names to represent, or refer to, these data
items. One common mistake is to put specific data right in the program as follows:

READ
$1000,
$3000

These numbers, although correct for one employee, are likely to need changing each time
the program is run because each employee sales data is likely to differ. This problem is
handled by the se of variables.

When a variable is used in conjunction with a READ statement, we assume that the value
of the variable is now known to the computer; this is called a defined value. The use of
variables helps ensure that the program is data independent, which means the program
will perform the required processing steps on any set of input data.

The following figure is called a memory diagram. On the left is a list of all the variable
names referenced in the algorithm. The boxes on the right represent the actual values that
these variable names refer to in the computer’s memory.

REGSALES 1000

SALESALES 3000
REGCOM
SALESCOM
PAY

In step the assignment statement is used. This step is commonly used when describing
computer processing. As assignment statement must adhere to the following rules of
formation:
1. Only a single variable name may appear to the left of the assignment symbol ( = ).
2. Only a single variable name, constant, or expression may appear to the right of the =.
3. Everything to the right of the = must be known (defined) to the computer.

Step 2 uses an assignment statement to compute the commission on the regular sales.
Because the percentage is always 6 percent, the 0.06 can be used in the statement. The
0.06 is an example of a constant, a value that never changes.

In step 5 the I/O (general input/output) symbol is used again, with the word WRITE
indicating output. Words such as OUTPUT, PRINT, or DISPLAY can also be used.
Note that the START and STOP SYMBOLS indicated by the ellipsis symbols is
sometimes called terminal interrupt symbols.

3
Design Verification
The solution to an algorithm should be verified. The objective is to prevent errors from
occurring or if some have already occurred to detect and eliminate them as soon as
possible.

One approach of verification of design is where the design documentation is distributed


to selected reviewers, who are asked to study it and respond within a set time. Each
reviewer is directed to note, individually, any required changes, additions and deletions.
This approach is known as an informal design review.

Another approach is the use of structured walkthroughs. This walkthrough is a formal


design review. The documentation is made available to several people selected to serve
as a member of a review team. After preparing the reviewers meet together with the
program designer and a moderator for an established period. Each reviewer is expected to
study and document the completeness, accuracy and general quality of the program
design. Then the moderator “walks” the group through each step of the documentation,
covering any points raised by the review team.

Pretending to be the computer is called simulation, procedure execution, or desk


checking.

Practice Questions
1. Draw a program flowchart and write the pseudocode for a program that will compute
the area and perimeter of a rectangle. The input will contain the length and the width
of the rectangle. The output will contain the length, width, area, and perimeter of the
rectangle.

2. Draw a program flowchart for a program that will accept one number as input.
Assume this number represents some amount of yards. Compute the corresponding
values of feet and inches, and output all three values, i.e., yards, feet and inches.

3. Draw a program flowchart for a program and write the corresponding psuedocode
that will compute the average of five grades. Input the five grades and output the
average.

4. Draw a program flowchart to find the area and circumference of a circle. Assume that
one value, the diameter of the circle, is provided as input. Output the diameter, area,
and circumference of the circle.

5. Write a program flowchart and a corresponding pseudocode to prepare a tuition bill.


The input will contain the student name, NIS number, and total number of credits for
which the student has enrolled. The bill will contain the student name, NIS number and
computed tuition. Total credits of 10 or more indicate that the student is full time. Full-
time students pay a flat rate of $1000.00 for tuition. Total credits of less than 10 indicate
that the student is part-time. Part-time students pay $100.00 per credit for tuition.

Vous aimerez peut-être aussi