Você está na página 1de 17

IPO Charts 4.

1
To design a program, you must first identify the problem, find a solution and then test it. An IPO chart can show the
processes, inputs required and then outputs. An IPO chart should be used before starting codeing because when on
paper, you can plan out the program to be modular.
1. When we solve a problem, there are three steps we should follow. The first is to define the problem, the
second is to find a solution to the problem and the last is test the solution. One of the ways we can solve the
problem is to draw up an IPO chart which lists the process requires to produce the wanted output as well as the
input required.
2. Purpose and advantages of an IPO during software development cycle.
To see the flow of data in the program and the processes in place. Its just to plan the program before you
jump in and write it.
3. A subsystem is to calculate the postage on a parcel is calculated as being $2.00 + $1/kg or part of a kg. Draw
this IPO chart.
4. Describe in words:
A barcode is scanned and then an item is matched with it from the barcode master file. Then the update is
pushed to the transaction file and item displayed on screen and docket.
Abstraction and Refinement 4.2
Abstraction and refinement
The top down approach is the modulating of problems and parts of a program. Each module is written separately and
then brought together to make the larger program. Modular programs are easier to write and correct. Decomposition
or stepwise refinement is the name of this method. Advantages of this programming approach is that the logic of the
program can be tested and modified. Main program or algorithm is the driver module. You can use old modular parts
that are functioning well but not those that arent.
1. decompose, driver module, hierarchy, modules, stepwise refinement, top-down design
a. The process of breaking a problem into smaller problems is known as top-down design or step-wise
refinement.
b. A program containing modules allows the structure to be more clearly seen.
c. The numbers given to steps are used to show the hierarchy of the steps.
d. The programmer will decompose a problem into smaller problems.
e. The main algorithm is often known as the driver module.
2. Copy and complete
Computer programmers use a top-down design method to solve a problem. The term decomposition is also
used to describe this process. By breaking a problem into small,, more manageable parts, it becomes easier to
solve. The smaller parts are known as modules.
3. Decompose first module
Put washing powder in machine, plug washing machine in, open the lid
4. NA
5. Decompose another module from Q3
Select cycle, choose water temperature, choose spin speed, crease care, time save, rinse plus.
Data Representation 4.3
Data representation
Digital computers use the binary number system to represent data items. Media used to store these numbers are
electronic media (RAM), magnetic media (Hard disks) and optical media (Fibre optics).
1. Binary, bit, decimal, hexadecimal, octal.
a. The binary system of numbers is used to store values in a computer.
b. We normally count using the decimal number system
c. One digit in a binary number is called a bit
d. Binary numbers are difficult to work with so there is a system that is 0-7 called octal
e. The hexadecimal system uses 0-9 and then a-f.
2. Copy and complete
Digital computers store data as ones and zeros. Since there are only two digits in this system, it is known as the
binary number system. The binary number system is inconvenient for us to use, so the octal system based on
eight and the Hexadecimal number system based on sixteen are also used by programmers.
3. Convert digit from decimal to binary
a. 9 = 1001
b. 17 = 10001
c. 30 = 11110
d. 89 = 1011001
e. 248 = 11111000
4. Convert decimal to octal
a. 9 = 11
b. 17 = 21
c. 30 = 36
d. 89 = 131
e. 248 = 370
5. Convert decimal to hex.
a. 9 = 9
b. 17 = 11
c. 30 = 1E
d. 89 = 59
e. 248 = F8
6. Convert binary to decimal
a. 101
2
= 5
10
b. 1101
2
= 13
10
c. 1100 1011
2
= 203
10
Data Types 4.4
Data in computers are stored in binary strings of digits. THe program decides the meaning of the numbers. It is common
for each of the four bits of a byte to be stored on eight separate primary storage devices in the same location on each.
Abstract data types are beneficial to the programmer as the definition of their properties is independent of the computer
system being used. Abstract data structures can be classified as simple data type or structured data type. Simple data
type consists of Booleans, characters, integers etc. Structured data types are used to represent related data elements in
a form that is manageable by the programmer or thing making the physical representation within the computer system.
Most common structured type is array, record and file. Files are often databases.
SImple Data Types
Boolean
True or false
1 or 0
Character
Widely used and represents smallest
Gives maximum of 2
8
or 256 characters per set.
ASCII code
Integer
Stored as two bytes
2
16
or 65536 combinations. to cater for negative numbers numbers are stored in twos
complement
Two bytes, giving a range of -32768 to 32767
Floating point
Represents decimaly numbers
Dealt with as fractions
Stored in two parts
Exponent
Stored as one or more bytes and represents integer
Mantissa
Expressed as sum of binary digits and is stored as number of bytes.
Precision
Single precision
One byte for exponent and three for mantissa is common
Double precision
One byte for for exponent and seven for mantissa.
String
Represents sequence of characters but keeps as one data element.
Popular methods of storing strings
Use of one or more bytes at the beginning of the string to represent the size of a
string
Setting maximum size of the string when declaring the variable at the beginning of
a program module
Use of end of text character
Date
Formats
Separate bytes to store day, month and year.
Serial number which counts number of seconds from midnight 1 Jan 1900.
Currency
One byte to represent cents & two or three to represent dollars.
Structured Data Types
About them
Limited usefulness because must be accessed by unique identifier.
Arrays
number of separate storage locations arranged in a pattern
One-Dimensional array
SImplest
Records
Store multiple data items of same type
Consists of fields
File
Collection of data held in secondary storage device.
Usually collection of data held in records.
Structures
Sequential File
Allows record to be accessed if record before has been processed.
End is marked by End-of-file (EOF) mark.
1. Abstract, array, boolean, character, exponent, field, index, mantissa, physical, record, sequential, string
a. The physical structure of data is independent of the computer system in which it is stored.
b. The storage of data as a magnetic pattern on a disk is an example of the array
c. The Boolean data structure could be represented as one bit within a computer system.
d. Data of the same type can be represented a(n) array
e. Related data with different data types may be represented as a(n) record.
f. Each element within an array may be individually accessed by using an index.
g. A character is usually the smallest unit of data normally used by a person.
h. A file in which data items must be accesses in order is known as a sequential file.
i. A floating point number is often represented by two parts: an exponent and a mantissa.
j. A string can be pictured as a one-dimensional array of characters.
k. Each individual data item within a record is known as a field.
2. Copy and complete
A simple data type contains one data item per identifier. The most common of these types are Boolean,
character, integer, floating point and string. Two other special data types are date and currency. When related
data items are to be stored, we use a structured data type. The simplest of these data types are the array and
the record. Arrays contain related data items of the same data type and records contain related data items
which may be of a different data type.
3. N/A
4. Suitable data types for:
a. Height = integer
b. Birthday = Date
c. Address = String
d. Days taking of a shop = (list of profits?) currency
e. Number of L of fuel used by a truck each day of the month = array (integer)
f. Sex of animal = Boolean
g. Number of things sold from a van (ice-cream) = integer
h. Contact card = record(String, string, integer, integer)
5. -
6. Array vs record
Array is used for storing data types of the same type, where as records are used for storing logically related
data in fields of different data types. (Eg. List of phone numbers for telemarketing vs records containing phone
numbers and other relevant data about the phone number)
Structured Algorithms 4.5
An algorithm is a finite set of steps with a single beginning and end which solves a problem. An algorithm solves a
problem by breaking it into steps. Algorithms can be applied to everyday life and recipies. Eg:
To Make a Phone Call:
Pick up the phone.
Dial the number.
Deliver message.
Hang up the phone.
1. Copy and complete
a. An algorithm is a series of steps which when performed correctly will solve a problem in a finite time.
b. Algorithms can be used to describe simple steps that you do each day.
c. Algorithm description is commonly used in recipes, DIY manuals, and knitting manuals.
d. Each step in the algorithm must be detailed enough that it can be easily carried out.
e. For the algorithm to work in all situations, the steps must be performed in a particular order.
f. Before an algorithm can be written, the steps must be fully understood.
g. How you arrive at a solution depends very much on past steps.
h. After the algorithm has been written, it needs to be planned.
i. If the results are wrong the algorithm must be modified or discarded.
j. There is usually more than one type of algorithm.
2. Copy and complete
An algorithm consists of a fixed number of steps which, when followed, will solve a problem. An algorithm
must have a definite path and a single outcome. The steps of an algorithm must be performed in a particular
order for it to work.
3. -
4. -
5. -
6. Before writing the algorithm it must be planned
7. -
8. After the algorithm is written, it must be tested.
Methods of Algorithm Description 4.6
Pseudocode, flowcharts, English prose, structured English, Nassi-Schneiderman diagrams, HIPO, structure charts and
decision tables.
Pseudocode
Top to bottom
Keywords in capital letters or bold
Example:
Keyword Meaning
BEGIN
END
Terminal: start and finish
IF (condition)
THEN
ELSE
ENDIF
You know this...
WHILE (condition)
DO
ENDWHILE
You know this too...
REPEAT
DO
UNTIL
Kou know this too...
Flowcharts
Graphic method of describing the problem.
Top to bottom
Flowlines are lines
EG:
1. algorithm, decision, flowchart, flowlines, indentation, keywords, pseudocode, terminal, word processor
a. One method of algorithm description, involving the use of English, that relies on keywords and
indentation is pseudocode
b. Software application used to modify algorithms written in pseudocode is word processor.
c. Highlighted in capital letters of in bold type to indicate the type of action being performed is
keywords.
d. Used to show structure in pseudocode is indentation.
e. A pictorial or graphical method of describing an algorithm is flowchart.
f. Lines or arrows used in flowcharts to control the flow of control is flowlines.
g. A series of steps which, when performed correctly, will solve a problem in a finite time is algorithm.
h. A symbol used in a flow chart to indicate start and finish is terminal.
i. A selection is decision.
2. Copy and complete
Some methods of algorithm description used today are IPO Charts, Pseudocode, flowcharts, HIPO and Nassi-
schneiderman diagrams. Two methods approved for this course are IPO charts and pseudo code. The graphical
method is flowcharts. The method which uses English-like language is called pseudocode or prose. When
using flowcharts, we read them from the top to bottom and left to right, moving from step to step along
flowlines. Pseudo code is popular because its structures are close to those in programming languages.
3. -
4. -
5. The flow of control in pseudo code is in the indentation.
6. The keywords are highlighted in pseudocode to highlight the keywords.
7. The purpose of indentation in pseudocode is to show the structure of the code for visualisation.
8. -
9. -
10. -
11. -
12. Flow charts go from top to bottom
Standard Constructs 4.7-4.9
Sequence - 4.7
A set of instructions one after another.
Top to bottom
Note pseudocode
Starts and finishes with BEGIN/END or terminal symbol.
1. Copy & complete
The simplest control structure is the sequence. The direction of flow passes through all steps in this structure. In
pseudocode, a sequence will always be indented the same amount. As a flowchart, the sequence is identified
as a number of steps flowing down the flowchart.
2. Three control structures used in all algorithms
Sequence of instructions, selection between two or more courses and repetition of instructions.
3. What is sequence in an algorithm?
Sequence is a number of steps that are completed one after another.
4. How does algorithm of pseudocode start and finish?
BEGIN & END
5. What is the point of indenting pseudocode?
To see the structure visually and to avoid clutter. To see the purpose of the code.
6. How does flowchart start and finish?
Starts with terminal Begin and ends with terminal End.
7. What does the process symbol in a flowchart represent?
An action that is taken.
Selection - 4.8
Binary Selection
Pseudocode Flowchart
IF condition THEN
process
ELSE
process
ENDIF
Multiway Selection
Pseudocode Flowchart
CASEWHERE
choice1 : process_1
choice2 : process_2
choice3 : process_3
OTHERWISE
default_process
ENDCASE
1. Copy and complete
When a decision is to be made in an algorithm, we have the choice of two types: the binary and the multiway.
When there are only two options to choose from, we use a binary selection. In pseudocode, this selection is
identified by the keywords IF and ENDIF. When there are more than two options we have to use a multiway
selection. It is identified in pseudocode by the keywords CASEWHERE and ENDCASE. In this type of selection
we may also use the keyword ELSE to allow for other data items to lead to an outcome, Each data item
entering a statement should make only one of the choices available.
2. What standard constructs?
a. Binary selection
b. Sequence
c. Multiway selection
d. Binary selection with else
e. Multiway selection
f. Binary selection
g. BInary selection with else
h. Sequence
3. Binary vs multiway selection
Binary has only one or the other path. Multiway has multiple selection.
4. Keywords for binary selection in pseudocode.
IF, ELSE, ENDIF
Iteration - 4.9
Loops must contain a break.
Pre-test repetition (guarded loop)(WHILE)
Pseudocode Flowchart
WHILE condition
process
ENDWHILE
Post-test repetition (unguarded loop)(DO)
Pseudocode Flowchart
REPEAT
process
UNTIL condition
Counted loop (FOR)
Pseudocode Flowchart
set end to 10
FOR counter goes from 1 to end
print counter
NEXT counter
1. What standard constructs are shown?
a. Guarded loop
b. Unguarded loop
c. Unguarded loop
d. Guarded loop
2. Copy and complete
When a number of steps are to be executed more than once, a loop should be put in the algorithm. There are
two types of loop: the guarded and the unguarded loop. For convenience, we use a third type of loop called a
counted loop when we want the steps executed a fixed numbers of times. Its other name is a for loop. The test
in an unguarded loop comes at the end of the loop. For a guarded loop, the test is placed at the beginning. The
keywords used in pseudo code for the test loop are repeat and until.
3. Loop
4. Repetition must contain a condition otherwise it will never end everrr.
5. Pre-test: while loop, Post-test: do loop
6. Counted loops loop for a fixed number of times, set before the loop starts.
7. No
8. While, endwhile
Checking Algorithms - 4.10
Desk checking is checking the algorithm without the computer, on paper. Sample data used
is test data. Test data sets must test all aspects of the algorithm. We draw a desk check
table. As variables are changed, you cross out the previous values in the values box for the
var.
1. desk checking, input/output table, test data, tracing, variables
a. A listing of test data items with the expected outputs is knows as an IPO table.
b. Desk checking is the process of using a pen and paper to check an algorithm.
c. A process called tracing is used to keep track of variables and their values.
d. Data items chosen to check an algorithm are know as test data.
e. All variables must be listed before a desk check can take place.
Standard algorithms
Like the 45 45 90 and 30 60 90 triangles.
Swap two data items
Swap two variables around. (The data in them)
BEGIN swap items
set temp to item1
set item1 to item2
set item2 to temp
END swap items
Access elements of an array
Array processing
BEGIN process array
FOR count goes from first to last
process arrayitem(count)
NEXT count
END process array
Processing records from a sequential file
BEGIN process sequential file
set count to 1
WHILE recorditem(count).field <> setlinevalue
process recorditem(count).field
set count to count + 1
ENDWHILE
END process sequential file
1. -
2. -
3. -
4. -
5. -
6. -

Você também pode gostar