meljun cortes flowcharting lecture notes

Post on 01-Feb-2015

5.097 Views

Category:

Technology

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

MELJUN CORTES Flowcharting Lecture Notes

TRANSCRIPT

Introduction to Computer

MELJUN CORTESMELJUN CORTES

Computer System

ELEMENTS OF COMPUTER SYSTEM

HARDWARE– PHYSICAL COMPONENT OF THE

COMPUTER SYSTEM– TANGIBLE PARTS

SOFTWARE– PROGRAMS THAT DIRECT THE

OPERATION OF THE COMPUTER PEOPLEWARE

– THE USERS OF THE COMPUTER

Computer Hardware

HARDWARE

INPUT HARWARE DEVICES

KEYBOARD SCANNERS POINT & DRAW

DEVICES(MOUSE,JOYSTICK,TRACKBALL, ETC)

PROCESS HARDWARE DEVICE

CPU MOTHERBOARD VIDEO CARD SOUND CARD EXPANSION SLOT

HARDWAREOUTPUT

HARDWARE DEVICE

MONITOR PRINTER PLOTTER ON-SCREEN

PROJECTOR

STORAGE HARDWARE DEVICE

MAGNETIC TAPE HARDDISK FLOPPY DISK COMPACT DISK DVD

HARDWARETELECOMMUNICATI

ON HARDWARE LAN CARDS TRANSMISSION

CABLES(COAXIAL CABLE,FIBER OPTIC,SATTELLITES)

OTHER HARDWARE UNINTERRUPTIBL

E POWER SUPPLY(UPS)

A STANDBY BATTERY POWERED SOURCE USE IN CASE OF POWER INTERRUPTIONS

Computer Software

Computer Software

GENERAL-PURPOSE SOFTWARE– PROVIDES THE FRAMEWORK FOR A GREAT

NUMBER OF BUSINESS,SCIENTIFIC, AND PERSONAL APPLICATIONS

APPLICATIONS SOFTWARE– DESIGNED AND WRITTEN TO PERFORM

SPECIFIC BUSINESS,SCIENTIFIC PROCESSING TASKS SUCH AS INVENTORY OR TAX PREPARATION

Computer Software

SYSTEM SOFTWARE– INDEPENDENT OF ANY GENERAL-

PURPOSE SOFTWARE PACKAGE OR ANY SPECIFIC APPLICATION AREA

– CONTROLS OR IN SOME WAY SUPPORTS SOFTWARE IN THE OTHER TWO CATEGORIES

EXAMPLES OF GENERAL-PURPOSE SOFTWARE

WORD PROCESSING SOFTWARE– MS WORD,AMI-PRO,WORDSTAR, ETC.

ELECTRONIC SPREADSHEETS– MS EXCEL,LOTUS 123,QUATTRO, ETC.

DESKTOP PUBLISHING– PAGEMAKER,VENTURA ETC.

EXAMPLES OF GENERAL PURPOSE SOFTWARE

GRAPHICS /PRESENTATION SOFTWARE– PHOTOSHOP,PAINT, COREL

DRAW,MS POWERPOINT, PRINTSHOP,BANNER MANIA,

DATABASE SOFTWARE– DBASE,FOXBASE,FOXPRO,CLIPPER

ETC.

EXAMPLES OF APPLICATION SOFTWARE

THESE ARE PROGRAMS OR SYSTEMS DEVELOPED THRU DIFFERENT PROGRAMMING LANGUAGES

INVENTORY SYSTEM, POINT-OF-SALE SYSTEM, ENROLLMENT SYSTEM, BILLING SYTEM, PAYROLL SYSTEM, SCHEDULING OR APPOINTMENT SYSTEM ETC.

TYPES OF SYSTEM SOFTWARE

OPERATING SYSTEM– DISK OPERATING SYSTEM(DOS) ,

WINDOWS OS & XENIX FOR MICRO COMPUTERS

– UNIX FOR MINICOMPUTER & MAINFRAME COMPUTERS

– IBM’S MVS & VM– DEC’S VMS– AT&T’S UNIX

TYPES OF SYSTEM SOFTWARE

PROGRAMMING LANGUAGES– COMPILERS & INTERPRETERS– 1ST GEN. OF PROGRAMMING

LANGUAGES(MACHINE LANGUAGE)– 2ND GEN. OF PROGRAMMING

LANGUAGES(ASSEMBLY LANGUAGE)– 3RD GEN. OF PROGRAMMING

LANGUAGES(PROCEDURE ORIENTED) COBOL,BASIC,PASCAL,C, ETC

PROGRAMMING LANGUAGES

4TH GEN. OF PROGRAMMING LANGUAGES(OBJECT-ORIENTED)– VISUAL BASIC,VISUAL FOXPRO,VISUAL C++,

ETC. 5TH GEN. OF PROGRAMMING LANGUAGES

– ARTIFICIAL INTELLIGENCE– NATURAL LANGUAGES

OTHER TYPES OF SYSTEM SOFTWARE

DATABASE MANAGEMENT SYSTEM SOFTWARE(DBMS)– SQL,INFORMIX,ORACLE, ETC.

UTILITY PROGRAMS– NORTON DISK DOCTOR(NDD),PC TOOLS

PERFORMANCE MONITORING SOFTWARE

COMMUNICATIONS SOFTWARE

OTHER SOFTWARE GAMES VIRUS

– BOOT-SECTOR,TROJAN HORSE,MACRO

ANTI-VIRUS PROGRAMS(VACCINES)

BROWSERS– NAVIGATOR, INTERNET EXPLORER

PEOPLE WARE

ORGANIZATION MANAGEMENT

– MIS HEAD,EDP HEAD, MIS PLANNER,CHIEF INFORMATION OFFICER(CIO)

– PLAN,ORGANIZE,CONTROL,STAFF,DIRECT,BUDGET ETC.

PEOPLEWARE ANALYSIS & DESIGN

– SYSTEM ANALYSTS PROGRAMMING

– PROGRAMMER(SYSTEM OR APPLICATION)– TRAINEE/JR./SR. PROGRAMMER

NETWORK ADMINISTRATION– NETWORK ADMINISTRATOR– DATA BASE ADMINISTRATOR

PEOPLE WARE

OPERATIONS– COMPUTER OPERATOR– COMPUTER LIBRARIAN– COMPUTER ENCODER ETC.

TECHNICAL SUPPORT– COMPUTER TECHNICIAN

EDUCATION & TRAINING– TRAINORS

Computer Languages

Programming Languages A programming

language is a set of rules that provides a way of telling a computer what operations to perform.

Generations ofProgramming Languages There are several generations of

programming languages: Machine Assembly High-level Very high-level Natural

Major Programming Languages

There are several languages with which to write your program:

• FORTRANFORTRAN• COBOLCOBOL• BASICBASIC• PascalPascal

• CC• C++ C++ • JavaJava• Object-OrientedObject-Oriented

Program Logic Formulation

Definition of Programming

Programming Computer process data under the

control of set of instructions.Programmer

Computer program guide the computer through orderly sets of actions by people.

Programming Cycle

The computer is basically a problem-solving tool. Once it is properly provided with a valid program, the computer becomes self-operational, that is, it requires no human intervention during processing. To use this tool effectively, the programmer usually have to perform the following set of well define steps.

Programming CycleDefining the Problem

One of making sure what was has to be done or what problem has to be solved. A careful analysis of that need should involved both prospective users of the information and one or more trained systems designers or programmers, who can perceive the full nature of the information need and how the computer can be used to respond to it.

Planning the SolutionThis is the next step, after the

problem has been defined, select the best method for solving the problem. This commonly involves determining the sequence of processing steps within individual programs.

To save on time and effort, the programmer refers to a pictorial representation, the program flow chart. The flow chart is an all-purpose tool and a program blueprint. The programmer constructs the flow chart to lay out the program logic.

Coding the SolutionOnce the programmer is satisfied that all

processing steps have been identified and all alternatives and exceptions provided for, the program is then made. The program flow chart serves as a guide in coding.

Checking out the ProgramExperience will prove that a program seldom

executes successfully the first time. Even the simplest programs contain errors, and even experienced programmers make mistakes.

DocumentationAfter a program has been fully tested

and implemented, the programmer must write up the full specifications for all users. The technical documentation package should include:

1. Complete statement of the problem.2. Description of the program logic and copies of the flow charts.3.Final source listing

4. List and description or error tests along with the disposition of these error.

5. Operating instructions, including program and data structures, and test data used.

6. Input and output specifications.

7. Schedules to be maintained.

If all the pertinent data is contained within the documentation package, then the program can be run and modified without requiring the original programmer’s assistance.

DEFINING THE

PROBLEM

PLANNING THE

SOLUTION

CODING THE

SOLUTION

CHECKING OUT THE PROGRAM

DOCUMENTATION

The Programming Cycle

Defining what has to be done or what problem has to be solved

Select the best method for solving the problem

Prepare the set of instructions for the computer to execute

Perform debugging and testing the program, using representatives input data

Write up the full specifications for other program users

Program Design Tools:

A flowchart is a pictorial representation of a step-by-step solution to a part of a problem.

Flowchart

Flowchart Basics A flowchart

consists of arrows to represent direction the program takes and boxes and symbols to represent actions.

Pseudocode Pseudocode is an English-like

nonstandard language. It allows programmers to focus on the

program logiclogic without being concerned about the particulars of a formal programming language.

Algorithms

An algorithm is a logical sequence of steps leading to the solution of ONE TASK in a bigger problem

– Define expected OUTPUT

– Describe desired INPUT

– Determine PROCESSING needed to produce desired output from expected input

Sample ProblemWhat tasks need to be

done? Add Number 1 and

Number 2– Inputs/Outputs?– Process?

Subtract Number 2 from Number 1– Inputs/Outputs?– Process?

Use Modularity for Design Break the problem into separate tasks For EACH task

– What are the inputs (if any)?– What are the outputs (if any)?– What process must be done?

Construct pseudocode or flowchart

Flowcharting

Types of Flowcharts

1. Program Flowchart

It describes graphically in detail the logical

operations and steps within a program and the

sequence in which these steps are to be executed for

the transformation of data to produce the needed

output.

2. System Flowchart

It is a graphically representation of the

procedures involved in converting data on input media

to data in output form. It illustrates which data is used

or produced at various points in a sequence of

operation.

It portray the interaction among data,

hardware, and personnel.

Flowchart Symbols

Process

Start/StopInput/Output

Decision

Connector

Flow Lines

Preparation

Flow Direction Indicators

Flowcharting SymbolsInput/Output

• It represents an instruction to an input or an output device.

• This symbol is used to represent a group of program instructions that perform a processing function of the program such as to perform arithmetic operations, or to compare, sort, etc.

Parallelogram

Process Rectangle

Flowcharting Symbols

• It denotes a point in the program where more than one path can be taken. It is used to document points in the program where, based upon variable conditions, a branch to alternative path is possible. The particular path that is chosen depends on the answer to a question or the result of a test which is inserted in the symbols.

DiamondDecision

Flowcharting Symbols

• This symbols used to represent an instruction or group in instructions that will alter, or modify a program’s course of execution. It is commonly used to specify operations such as control, index register, initialization, switch setting, and in indicating loops.

HexagonPreparatio

n

Flowcharting Symbols

• It is used to designated the beginning and the end of a program, or a point of interruptions.

OvalStart/Stop

Connector

• This is a nonprocessing symbols which is used to connect one part of a flowchart to another without drawing flow lines. It denotes an entry or an exit from another part of the flowchart and also used to change the reading sequence of a flowchart on the same page.

Small Circle

Flowcharting Symbols

• Used to show the direction of processing or data flow. These are added to flow lines of a flowchart appears confusing in its layout.

Arrowheads

Flowcharting Symbols

• It is used to show reading order or sequence in which flowchart symbols are to be read.

Horizontal/ Vertical Lines

Advantage and Disadvantage of Flowcharts

Advantage of Flowcharts

1. Since flowcharts are language-independent, they

can be learned and applied without formal knowledge

of a programming language.

2. It enforces users to give attention to significant

matters over the less significant ones.

3. Being graphically portrayed, flowcharts

provide an alternative to the usual narrative

description of a system or a program.

4. Flowcharts are easier to understand than a

program written in a particular programming

language.

Disadvantage of Flowcharts

1. Flowcharts do not represent a programming and

are more of a person-to person than a person-to-

computer means of communication. A computer

cannot accept a program describe in flowcharting.

2. Since thinking in graphic term is not normal,

flowchart cannot be viewed as a natural means of

communication.

5. Flowcharts do not highlight the important

details since each step receives as much attention in a

flowchart as any other.

3. Certain details often require long sequence of

interconnected symbols which could easily be

described in just a few lines of explanation.

4. It does not convey why a given set of

operations is made. Flowcharts only portray how.

Two flowcharts neededStartStart

GetGetNumber 1Number 1

Display ResultDisplay Result

Result = Result = Number 1 + Number 2Number 1 + Number 2

EndEnd

GetGetNumber 2Number 2

StartStart

GetGetNumber 1Number 1

Display ResultDisplay Result

Result = Result = Number 1 - Number 2Number 1 - Number 2

EndEnd

GetGetNumber 2Number 2

InputsInputs

ProcessProcess

OutputsOutputs

Task 1Task 1 Task 2Task 2

Sample Problem

Example 1 - Algorithms

Algorithms for changing a flat tire

1. Jack up the car2. Unscrew the lugs3. Remove the wheel4. Put on the Spare5. Screw the lugs6. Jack the car down

Flowchart for changing a flat tire.

Example 1 - Flowchart

A

AStart

Jack up the Car

Unscrew the lugs

Remove the wheel

Put on the spare

Screw on the lugs

Jack the Car down

End

Given the three numbers A, B, C. Draw a flowcharts to compute and print out the sum, the average, and the product of these values.

Example 2

Example 2 - Algorithms1. Read in the values of A, B, C.2. Determine the sum of the three values

read.3. Compute the average by dividing the

sum by 3.4. Multiply the first value by the second

value then by the third value to determine the product of the three values.

5. Print out the computed values (sum, average, and the product).

Example 2 - Flowchart

Start

Print Sum Ave, Prod

Prod = A*B*C

Ave = Sum/3

A

A

Sum = A+B+C

Read A, B, C

End

Decision Making – Sample Problem

Example 3 The ABC Manufacturing Company plans

to give a year-end bonus to each of its employees. Make an algorithms which will compute the bonus of an employee. Consider the following criteria: If the employee’s monthly salary is less than 1,000.00 pesos, the bonus is 50% of the salary; for the employees with salaries greater than 1,000.00 pesos, the bonus is 1,000.00. Print out the name and corresponding bonus of the employee.

Example 3 - Algorithms

1. Read in the employee’s name and salary

2. Test if the employee’s salary is less than 1,000.00

3. If the salary is less than 1,000.00 pesos, the bonus is 50% of the employee’s salary. However, if the salary is more than 1,000.00 pesos, the bonus is 1,000.00 pesos.

4. Print out the employee’s name and bonus.

Example 3 - Flowchart

Start

Print Name. Bonus

Bonus = .5 - Salary

Bonus = 1000

A

A

Read Name, Salary

End

Is Salary < 1000

B

B

Y N

Example 4

Given two numbers X and Y. Draw a flowchart to determine the difference between X and Y. If X-Y is negative, compute R=X+Y, if X-Y is zero, compute R=2X+XY; and if X-Y is positive, compute R=X*Y. Print out the values of X, Y, and R.

Example 4 - Algorithms

1. Read in the values of X and Y

2. Subtract Y from X

3. If the difference between X-Y is negative, compute R=X+Y, if zero, compute R=2X+XY; and if X-Y is positive, compute R=X*Y.

4. Print out the values of X, Y and R.

Example 4 - Flowchart

Start

Print X, Y, R

Diff = X - Y

R = X*Y

A

A

Read X, Y

End

If Diff

B

R = X+Y

R = 2X+2Y

<0 >0

=0B

B

Example 5

Create a Flowchart and algorithms that would input five values of numbers and compute for the average. If the average is below 75, the remarks is failed, if not remark is passed. Print the average, remarks.

Example 5 - Algorithms

1. Read in the values of n1, n2, n3, n4, and n5

2. Compute the average of the five values read.

3. If the the average is below 75, the remark is failed, if not the remark is passed

4. Print out the average and the remarks.

Example 5 - Flowchart

Start

ave = (n1+n2+n3+n4+

n5)/5

A

A

Read n1, n2, n3, n4, n5

End

Is

average <75

Y NRem = Failed

Rem = Failed

Print Ave, Rem

Loop and Counter

Steps in Control Loop Initialization - the value of a counter used is initially

set equal to zero ( or one ). This process is always done outside the loop.

Test for Limit Conditions - before logic flows gets out of a loop, a loop-terminating condition must first be satisfied. The process of testing is usually found either at the beginning or at the end of a loop.

Incrementation - after each loop is executed, 1 is added to the counter. Thus the counter reflects the number of times the operation has been performed. Note that process of incrementation is always done within the loop.

Looping - is used when it is desired to make the same calculation on more than one set of data. - it consists of repeating a program, or a section of a program, and substituting new data for each repetition.

Counters- is set up in a program loop to keep track of the number of times the program segment is repeated.- the program can then be terminated after the completion of a predetermined number of passes. - Prior to the execution of counting, all counters should be initialized ( usually to zero) before the loop is executed.

- For instance, if a program is supposed to read and print five data values, a counter may be set up in the program which counts the number of data values; after a data value is read and printed, the counter is increased by one. Before a new data value is allowed to be read, a conditional transfer may be used to determined whether or not the desired amount of data has been reached. If it has, the program is terminated; otherwise an unconditional transfer causes the computer to repeat the input/output and other processing operations.

Example 1

The initial value of the radius of a circle is equal to one unit and each succeeding radius is one unit greater than the value before it. Draw a flowchart to compute the area of the circle starting with R=1.0 up to R=5.0, then print out each radius and the corresponding area of the circle.

Example 1 - Algorithms

1. Initialized the value of R to 1 and the value of PI to 3.1416

2. Compute area by multiplying PI by the square of R.

3. Print out the value of R and the square of R.4. Increment the value of R by 1.5. Test if R is less than or equal to 56. If R is less than than or equal to 5, loop back

and repeat step 2 through 5. However, if R is greater than 5, stop processing.

Example 1 - Flowchart

Start

Print R, AREA

R = 1.0

PI = 3.1416

R = R + 1.0

A

A EndIs R < =

5.0 ?

BAREA =

PI *R*R

B Y N

Example 2

Given a set of 5 numbers that include both positive and negative data values. Draw a flowchart to read in these values one at a time and count the number of positive values (including zero values) and the number of negative values found in the set. After the required values are determined, print out these counted values.

Example 2 - Algorithms1. Set up two counters and initialized their

values to zero (one counter, NNEG, is used for counting the number of negative values and the other, NPOS, for counting positive values).

2. Input the first data value, NO.3. Test and determine if the the value read is

positive or negative (The decision symbol is used and in it is written the question, NO<0?)

4. If the value of NO is negative ( or less than zero), increment the NNEG counter by one. However, if it is positive ( or equal to or greater than zero), increment the NPOS counter.

Example 2 - Algorithms5. Determine the number of values

encountered (NVAL) by adding the two counters (NNEG and NPOS).

6. Test if NVAL is equal to 5

7. If the value of NVAL is not equal to 5, repeat steps 2 through 5. However, if it is equal to 5, print out the current value stored in these counters (NNEG and NPOS)

Example 2- FlowchartStart

NNEG = 0

NPOS = 0

A

A

B

Y

Read NO

Is NO < 0

NNEG = NNEG + 1

NVAL = NNEG + NPOS

NPOS = NPOS + 1

N

Is NVAL

= 5?B N Y

NNEG,

NPOS

End

Example 3

Draw a flowchart and algorithms which will read and print the names and individual scores of 100 students for a particular examination. Also, determine their average and score, and print it out.

Example 3 - Algorithms1. Initialize the counter (CTR) and accumulator

(sum) to zero.2. Read in the student’s name and score.3. Print out the student’s name and score.4. Accumulate the data value (SCORE) into the

sum.5. Test if the desired amount of data (100) has

been reached.6. If the value of counter (CTR) is less than 100,

repeat the steps 2 through 5. However, if the desired amount of data has been reached (100), compute the average score by dividing the sum by the value of counter.

Example 3 - Algorithms

7. Print out the average scores.

Example 3 - FlowchartStart

Print Ave

CTR = 0

SUM = 0

CTR = CTR + 1

A

A

B

Y NRead Name, SCORE

Is CTR = 100?

Ave = SUM/CTR

SUM = SUM + SCORE

End

B

Example 4 Given the lengths of 3 sides (a, b, and c)

of a triangle. Prepare a flowchart to read these values, compute the perimeter and the value of S, and determine the area of the triangle using Hero’s formula (Hint: Per = a + b + c; S=Per/2; and the AREA=[s(s-a) (s-b) (s-c)]2. Then print out the given and computed values.

Example 4 - FlowchartStart

CTR = 0

A

A

YRead

a, b, c

Is

Per < 0?

Perimeter = a + b + c

C

Print CTR

1

Example 4 - Flowchart

1

N

S = Per/2

Area = s(s-a) (s-b) (s-c)

B

B

Is

Area = 0 ?EndPrint

a, b, c Per, S, Area

CTR = CTR + 1

C

Loop and Accumulator

•AccumulatorThe variable used is thereby

continuously accumulating the numerical quantities

Example 1

Draw a flowchart to compute and print the sum of the squares of positive integers from 1 to 100.

Example 1 – Flowchart-Sol 1- K<=100

Start

K = 1

Sum = 0B

K = k + 1Is

k<=100?BY N

Print sum

A

End

Sum = Sum + 1

A

Example 1 – Flowchart-Sol 2 – K=100

Start

K = 1

Sum = 0

B

Sum = Sum + K2

Is

K =100?

B

Y NPrint sum

A

End

K = K + 1

Example 1 – Flowchart-Sol 3 – K>100

Start

K = 1

Sum = 0

B

K = k + 1

Is

K > 100?

B

Y

N

Print sum

AEnd

A

Sum = Sum + K2

Example 2

Make a flowchart that will display the numbers from 1 – 5.

Example 2 - FlowchartStart

Print A

A = 1

A

A

FIf A < = 10 ?

A = A + 1End

BT

B

Example 3

Draw a flowchart to compute and print the sum of the square of positive integer from 1 - 5

Example 3 - FlowchartStart

Print SumSum = Sum +

(A * A)

A

A

FIf A < = 5 ?

End

B

T

B

X = 1

Sum = 0

A = A + 1

Example 4

Create a flowchart that will print the product numbers from 1 - 5

Example 4 - FlowchartStart

Print Prod

A = A + 1

B

A

FIf A < = 5 ?

End

B

T

A

A = 1

Prod = 0

Prod = A * Prod

top related