32
What is a Computer? - an electronic device capable of performing complex computations in a short time - a fast electronic calculating machine that accepts input information, processes it according to a list of internally stored instructions called a program, and produces the resultant output information. - A program is a set of instructions for a computer, telling it what to do or how to behave - Programming is the craft of implementing one or more interrelated abstract algorithms using a particular programming language to produce a concrete computer program. Components of a Computer Hardware – the physical equipment of a computer system, including the monitor, keyboard, central processing unit, and storage devices. Software – refers to one or more computer programs and data held in the storage of a computer for some purpose Hardware Concepts - Data representation: conversion of images, letters and sounds into electrical signals - Digital electronics: manipulation of “on” and “off” signals to perform complex tasks - A digital device works with discrete signals, such as 0 and 1. - An analog device works with continuous data. - As an analogy, a traditional light switch has two discrete states – on and off. A dimmer switch, on the other hand, has a rotating dial that controls a continuous range of brightness – from none (off) to full brightness. The first is therefore a digital device while the latter is an analog device. Digital Data Representation - The “0” and “1” are also known as bits or binary digits - A sequence of “0” and “1” could be written as 10011, this sequence may have significant value, for instance it may pertain to a certain character or number. How can a computer represent numbers using bits? - Numeric data like your age, salary, electricity bill are easily understood by humans. Then, how is it possible for a computer to show a number using only binary digits? - The computer uses the binary number system which uses only two digits: 0 and 1. There are no 2’s or 3’s. A series of 0’s and 1’s results in a particular number much in the same way we use the decimal number system. DIGITAL DATA REPRESENTATION This table shows how binary system works. Decimal ( Base 10 ) Binary ( Base 2 ) 0 0000 1 0001 2 0010 3 0011

Flowcharts

Embed Size (px)

DESCRIPTION

Flowchart study guide for prelims

Citation preview

Page 1: Flowcharts

What is a Computer?- an electronic device capable of performing complex computations in a short time- a fast electronic calculating machine that accepts input information, processes it according to a list of internally

stored instructions called a program, and produces the resultant output information.- A program is a set of instructions for a computer, telling it what to do or how to behave- Programming is the craft of implementing one or more interrelated abstract algorithms using a particular

programming language to produce a concrete computer program.

Components of a ComputerHardware – the physical equipment of a computer system, including the monitor, keyboard, central processing unit, and storage devices.Software – refers to one or more computer programs and data held in the storage of a computer for some purpose

Hardware Concepts- Data representation: conversion of images, letters and sounds into electrical signals- Digital electronics: manipulation of “on” and “off” signals to perform complex tasks- A digital device works with discrete signals, such as 0 and 1.- An analog device works with continuous data.- As an analogy, a traditional light switch has two discrete states – on and off. A dimmer switch, on the other hand,

has a rotating dial that controls a continuous range of brightness – from none (off) to full brightness. The first is therefore a digital device while the latter is an analog device.

Digital Data Representation- The “0” and “1” are also known as bits or binary digits- A sequence of “0” and “1” could be written as 10011, this sequence may have significant value, for instance it may

pertain to a certain character or number.How can a computer represent numbers using bits?

- Numeric data like your age, salary, electricity bill are easily understood by humans. Then, how is it possible for a computer to show a number using only binary digits?

- The computer uses the binary number system which uses only two digits: 0 and 1. There are no 2’s or 3’s. A series of 0’s and 1’s results in a particular number much in the same way we use the decimal number system.

DIGITAL DATA REPRESENTATION

This table shows how binary system works.

Decimal ( Base 10 ) Binary ( Base 2 )

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

9 1001

If the box contains 0, the value is turned “off”’. However if the box contains 1, the value of that box is turned “on” and will be added to the sum.

How can a computer represent words and letters using bits?

Much like representing numerical data, bits can also be used to represent character data. It is synonymous to using Morse code using the dashes and dots to represent letters in the alphabet. In this case, computers makes use of 0 and 1 as a replacement to dashes and dots.

Page 2: Flowcharts

Example: STI has a corresponding binary value.

S – 0101 0011T – 0101 0100I – 0100 1001

There are many ways on how the computer can represent characters and numbers. Some types of codes are:

ASCII (American Standard Code for Information Interchange) requires only seven bits for each character.

EBCDIC (Extended Binary Coded Decimal Interchange Code) is an alternative 8- bit code used by older IBM mainframe computers.

UNICODE uses 16 bits providing codes for 65000 characters and becoming popular.

Extended ASCII code makes use of a series of O’s and 1’s for it to symbolize the 256 characters (includes letters for uppercase and lowercase, number, and symbol).

BIT- An abbreviation of binary digit- Other abbreviation for bit is the lowercase “b”

BYTE- A collection of bits (8 to be exact)- Usually abbreviated as an uppercase “B”

PREFIX ABBREVIATION VALUEKilo K 210

Mega M 220

Giga G 230

Tera T 240

How are bits stored and transferred from one point to another?- Since most computers are electronic devices, bits take the form of electrical pulses traveling over the circuits. All

circuits, chips, and mechanical components forming a computer are designed to work with bits.

The basic parts of the computerINPUT DEVICES are machines that generate input for the computer, such as keyboard and mouse.

PROCESSOR or CPU (Central Processing Unit) is the central electronic chip that controls the processes in the computer. It determines the processing power of the computer.

OUTPUT DEVICES are machines that display information from the computer, such as monitor, speaker, and printer.

MEMORY is the part of the computer that stores applications, documents, and systems operating information.

SOFTWARE CONCEPTS

What is software?- Computer instructions or data- Anything that can be stored electronically- Computer programs, modules (support and data) working together providing computers with instructions and data

for certain task (e.g word processing, internet browsing)

Terminologies: COMPUTER PROGRAM (or “program”)- an organized list of instructions that, when executed, causes the computer to behave in the predetermined manner.

SUPPORT MODULE-an auxiliary set of instructions used in conjunction with the main software program

Page 3: Flowcharts

DATA MODULE-contains data (not supplied by the user) necessary for the execution of certain task.

DATA vs. SOFTWARE- Before, the term “software” is always associated to all non-hardware components of a computer.- However, modern definitions made it clear that all documents, spreadsheets and even downloaded materials from

the net are now classified as data.

Software Basics- Technically, the computer creates object code, which is the machine language representation of the source code,

and the linker creates the executable code.- The linker combines program object code, object code from library routines and any other required system code

into one addressable machine language file.

Application Software vs. System SoftwareSoftware are basically categorized into two: Application software and System software. Some people used the

term “software” to describe either application or system software.

Application software provides instructions to the computer depending on the use (application). The purpose of application software is to help automates common task (example: typing, accounting task, etc).

System software help the computer carry out its basic operating function. Under this type of software includes device driver, operating system, and other utilities.

What is SLDC?A common methodology for systems development in many organizations, featuring several phases that marks the progress of the system analysis and design effort.

An outline of a process that helps develops successful information system.

Is the process of developing information systems through investigation, analysis, design, implementation and maintenance. SDLC is also known as information system development or application development.

Also known as System Development Life Cycle

What is importance of SLDC?

In order to create systems that are in good in design we must take into consideration that it must involve several phases. You cant just create it in just one big attempt.

Furthermore, it would be very favorable for companies to have certain set of standardized steps that would serve as a guide in system development.

What are the 5 phase of SDLC?SDLC involves several phases. Each phase plays an important role to create a good system. The said phases are:

1. Planning2. Analysis3. Design4. Implementation5. Maintenance

Planning phasePlanning is also known as project identification and selection. This phase is involves identification for the need

or enhancement(s) of the current system being used.For larger companies that deal with complicated systems, it is vital that these requirements are properly identified

so that the development of the system may not be delayed or stray from the original objective.“The first phase of the SDLC an organization’s total information system are identified, analyzed,

prioritized, and arranged.”

Analysis phase

Page 4: Flowcharts

This phase requires the analyst to thoroughly study the current procedures or system used to execute tasks in an organization.

The main goal in this phase is to identify the requirements for a new system or simply change several aspects in the current working system. ”This phase studies the current system and produces proposed alternatives or replacements”

Design phase During this phase, the developer of the system translates the result of the previous phase into actual design or specifications of the system. Development of the system involves covering the input and output screens to reports, databases, and computer process.

Implementation Phase After the design phase, we must put the proposed system into the test. During this phase, implementing the

system will include several steps:1) Coding- creation of the actual program.2) Testing- both programmer and analyst submits the system to various “quality testing” to discover if there any bugs

within the system.3) Installation- after coding and testing is done, the actual system must be installed and slowly or completely

replaces the old system.

Maintenance Phase

With every phase being comleted, perhaps the maintenance phase would be the most prevalent phase of all. There are some bugs in the system which can’t be properly indentified without putting the system into actual use. The maintenance phase is used to make necessary patches to remove found errors.

This is were the system is systematically repaired and improved based on errors or possible new requirements found.

SOFTWARE DEVELOPMENT LIFE CYCLEWaterfall SDLC

The waterfall SDLC suggests that prior to proceeding to next phase, the current phase should be finished first. But applying this strategy in the real world would be unfeasible since it would be impossible to modularize system development.

Modified Waterfall and Iterative SDLCThis version of the SDLC is more flexible compared to the traditional SDLC model. Since, nature of developing a

system is unpredictable using this model will allow the developer to adjust to certain situations. (Example: unforeseen requirement or additional features that are highly needed in the system.

The modified waterfall SDLC allows overlap between phases.The iterative SDLC allows phases to repeat, if necessary.

Programming Cycle- Problem Definition- Problem Analysis

o Inputo Output

- Algorithm Developmento Processo Pseudocodes and Flowcharts

- Coding and Debugging

Algorithm- a step by step problem-solving procedure, especially an established, recursive computational procedure for

solving a problem in a finite number of steps- finite sequence of steps for solving a logical or mathematical problem- a specific set of well-defined, simple mathematical and logical procedures that can be followed to solve a problem

in a finite number of steps

Example

Page 5: Flowcharts

1. Baking of chocolate cake2. Computing for average grade3. Going from one location to another

These characteristics will serve as guide or determiner to have good algorithms.1. Specify each step or instruction exactly. There must be no ambiguity. The instructions must be clear.2. There must be a finite number of steps. The algorithm must terminate. There must be a stopping point.3. There must be an output. The algorithm must produce the correct result.

Pseudocodes- generic way of describing an algorithm without use of any specific programming language syntax- it cannot be executed on a real computer, but it models and resembles real programming code, and is written at

roughly the same level of detail

Flowchart- a chart that contains symbols referring to computer operations, describing how the program performs- a graphic map of the path of control or data through the operations in a program or an information-handling

system- symbols such as squares, diamonds, and ovals represent various operations- these symbols are connected by lines and arrows to indicate the flow of data or control from one point to another

Flowchart Symbols

Terminal Block

Process Block

Input/Output Block

Decision Block

Initialization Block

Connector

Flow Lines

Page 6: Flowcharts

Flow Lines - indicated by straight lines with arrows to show the direction of data flow- the arrowhead is sometimes not shown when the direction of flow is clear- used to connect blocks by exiting from one and entering another

Terminal Block- ovals or rounded rectangles are used to indicate the start and the end of a module or

program- an oval is labeled with the name of the module at the start - the end is indicated by the word end or stop for the top or Control Module- a start has no flow lines entering it and only one exiting it; an end or exit has one flow line

entering but none exiting it

Initialization box - is used for declaring/initialing variables needed to solve a certain process. Take note: you can only use variables that are placed inside the initialization box

Declaration Binding of an identifier to the information that relates to it. Set a variable name to be used.

Initialization To set a starting value of variable.

START

STOP

X=10 Y=25

Page 7: Flowcharts

Process Box – The rectangle indicates a processing block, for such, things as calculations, opening and closing files, and so forth. A processing block has one entrance and one exit.

Input/Output Box - The parallelogram indicates input to and output from the computer memory. An I/O block has one entrance and only one exit.

Decision Box – The diamond indicates a decision. It has one entrance and two and only two exits from the block. One exit is the action when the resultant is TRUE and the other exit is the action when resultant is FALSE.

Action when Action when TRUE FALSE

Connectors – The connector block is used as a connection between two sections of a flowchart that is not adjacent or closely located to each other. Note: These connectors should be used as little as possible. They should be used to enhance readability. Overuse decreases readability and produces a cluttered effect.

CONVENTION

TRUE FALSE

T F

YES NO

Y N

X = Y + ZA = 18

B = A - 2

Enter X Display X

ConditionT F

Page 8: Flowcharts

Flowchart Case Study: Flowchart Case Study: Create a flowchart having a variable Create a flowchart having 3 variables. that is initialized to your current age. Two of the variables are used to initialize Your flowchart should be able to show the Birth Year and Current Year. your age 5 years from now Your variable is used to compute

for the current age. Your flowchart should display the age value.

A

A

Age = 18

Age = Age + 5

Display Age

STOP

START

Age = 0Cyr = 2007Byr = 1990

Age = Cyr - Byr

Display Age

STOP

START

Page 9: Flowcharts

Create a flowchart that will increase the value of the number by 5 if it is greater

than 10 and display the result; otherwise do nothing.

Start

x = 0

Get x

X > 10?

Yes Nox = x + 5Display x Stop

Create a flowchart that computes for the circumference of a circle. Assume that the value for radius is 7.23. Your flowchart should be able to show the value of the circumference.

Additional facts:The pi value is 3.1416, which is constant and should never be changed. You can compute the circumference by using this formula 2Πr.

Circ = 0 Rad = 7.23 Pi = 3.1416

Circ= 2 * Pi * Rad

Display Circ

START

STOP

Page 10: Flowcharts

CONDITIONAL OPERATORS

What is a Condition?

Conditions are statements that result to a Boolean value. The Boolean value may either be a TRUE or FALSE, 0 or 1 value. Conditions are categorized into two:

LOGICAL OPERATORS RELATIONAL OPERATORS

In programming, there are three basic logic operators that you could use for conditional statements. They are the following:

LOGICAL OPERATORS: AND OR

Page 11: Flowcharts

NOT

The commonly used logical operators are AND and OR, while NOT is a logical operator that negates the result of the Boolean value.

AND/OR truth table

NOT truth table

True = T or 1 False = F or 0

The NOT logic operator reverses the logic or result of a certain condition

Condition A!A

0 1

1 0

Try this

Condition A

Condition B

Condition C

A AND B B OR C

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

Condition A Condition B AND OR

0 0 0 0

0 1 0 1

1 0 0 1

1 1 1 1

Page 12: Flowcharts

1 1 1

Relational Operators

Relational Operators are used in order to get the Boolean result of certain conditions.

Boolean Result: The result may be a TRUE or FALSE value, depending on the condition that is being evaluated.

The relational Operator may be the following:

< Less than != not equal

> Greater than <> not equal

<= Less than equal

>= Greater than equal

== Is equal to

Page 13: Flowcharts

Assume that you have a variable called X and Y. What would be the results of the conditions if we were to compare them with different values and different relational operators?

X Y < > <= >= == !=5 1718 412 1230 31

More on Decision Box

We said that the diamond box is used for decision making within your flowchart.It should be noted that what you place inside the diamond box are conditions.Conditions that either results to TRUE or FALSE. NOTE: You don’t place conditions that are in essay form, you must be able to represent it in a mathematical form.

Question: How do you know if X is less than 20?

Single Alternative Selection Structure

A decision box may not necessarily have to do something for both the TRUE path and the FALSE path. You may opt to skip one part if need be.

Dual Alternative Selection Structure

X<20 Is variable X less than 20?

F T

STOP

TF

Page 14: Flowcharts

The dual alternative selection structure performs two different things when the condition evaluates to true or to false.

CONDITIONAL STATEMENTSFlowchart Case Study 1:

Draw a flowchart that will let the

User enter a number, increase the

Value of a number by 5 if it is greater

10 and display the result, otherwise

do nothing.

FT

Start

X=0

Enter X

X >10

X = X + 5

Display X

Stop

TRUE FALSE

Page 15: Flowcharts

Flowchart Case Study 2:

Draw a flowchart that will let the user enter a number, increase the value of the number by 5 if it is

greater than 10, and display the result; otherwise multiply the value by 5 and display the result.

X=0

Enter X

X>10

X=X+5 X=X*5

Display X

START

STOP

TRUE FALSE

Page 16: Flowcharts

Flowchart Case Study 3:

Draw a flowchart for a college’s admissions office. Create variables to store a student’s numeric high school grade point average and an admissions test score. Print the message “Accept” if the student has a grade point average of 3.0 or above and an admission test score of at least 60. If the student does not meet either of the qualification criteria, print the message “Reject”.

Multiple Decision box

Not all the times multiple decision box can be combined in one box. There are times that you have to be very specific with the conditions that you have to put in.

Ave = 0.0

Test = 0

Enter Ave, Test

Start

Ave>=3.0

TRUE FALSE

Test>=60

Display “Accept”

Display “Reject”

Stop

TRUE FALSE

Page 17: Flowcharts

Flowchart Case Study:

Let the user enter a number from 1 – 3. If the user inputs a ‘1’, print “Hello”, if the user inputs a ‘2’,

print “Hi”, and if the user inputs a ‘3’, then print “Bye”. Otherwise print “Invalid Number”

Using Decision box with ranges

Business programs often need to make selections based on a variable falling within a range of values. To perform a range check, use either the lowest or highest value in each range of values you are using to make your selections.

Start

Enter x

X= =1

Display “Hello”

X = 0

TRUE

FALSE

X= =2

Display “Hi”

TRUE

FALSE

X= =3

Display “Bye”

TRUE

FALSE

Display “Invalid number”

STOP

Page 18: Flowcharts

Example: Create a flowchart that would print the name of the supervisor under a certain department number.

Department Number Supervisor 1-3 Mr. X 4-7 Mr. Y

8-9 Mr. Z

2nd solution

START

Dept = 0

Enter Dept

X<=3 Display

“Mr. X”

X<=7 Display

“Mr. Y”

Display

“Mr. Z”

STOP

TRUE

TRUE

FALSE

FALSE

START

Dept = 0

Enter Dept

X>=8 Display

“Mr. Z”

X>=4 Display

“Mr. Y”

Display

“Mr. X”

STOP

TRUE

TRUE

FALSE

FALSE

Page 19: Flowcharts

LOOPING CONSTRUCT

What is a loop?

Page 20: Flowcharts

In programming, a set of program instructions that executes repeatedly until a condition is satisfied.

In the flowchart segment, the question - “is x < y?” is asked. If the answer is ‘Yes’ then Process A is performed. The question “is x < y?” is asked again. Process A is repeated as long as the question (condition) evaluates to True. When x is no longer less than y, the question (condition then evaluates to False, the repetition stops and the structure is exited.

LOOPLOOP

RUNRUN

TRUETRUE

CONDITIONCONDITION

VARIABLEVARIABLE

STOPSTOP

FALSEFALSE

INITIALIZATIONINITIALIZATION

USER INPUTUSER INPUT

START

X < y

Process ATRUE

FALSE

Page 21: Flowcharts

The Action Performed by a repetitionstructure must eventually cause theloop to terminate. Otherwise, aninfinite loop is created.

In this flowchart segment, x is neverchanged. Once the loop starts, itwill never end.

QUESTION: How can this flowchart be modifiedso it is no longer an infinite loop?

ANSWER: By adding an action within the repetitionThat changes the value of x.

Pre-test Repetition Structure:

This type of structure is known as a Pre-Test Repetition structure. The condition is tested BEFORE any actions are performed.

In a pre-test repetition structure, if the condition does not exist, the loop will never begin.

Post-test Repetition Structure:

Display X

X=X+1

X<Y

TRUE

FALSE

X<Y

Display X

TRUE

FALSE

DISP X X=X+1X<Y

TRUE

FALSE

Page 22: Flowcharts

This flowchart segment shows a Post-TestRepetition structure.

The condition is tested AFTER the actions are performed.

A Post-Test repetition structure always performits action at least once.

FLOWCHART CASE STUDY:

Create a flowchart that will display the following result:(assume that the variable is initialized to 5)

Output:

54321Done

X=5

X>0

Display X

X=X-1Display “Done”

START

STOP

TRUE

FALSE

Page 23: Flowcharts

FLOWCHART CASE STUDY:

Create a flowchart that will print aseries of numbers, based on whatwas entered by the user.

FLOWCHART CASE STUDY:

Number Entered:

4

Output:

12 34

X=0Y=0

Enter Y

X<Y

Display “Done”

X = X+1

Display X

START

STOP

TRUE

FALSE

Page 24: Flowcharts

Create a flowchart that will print the sum of all odd numbers from 1-100

NESTED LOOPS:

It is possible to have a loop within a loop. In case of multiple loops, it is critical to determine what condition will terminate the whole flowchart.

START

sum = 1

ctr = 1

ctr<100

ctr = ctr+2

sum = sum + ctr

Display sum

STOP

TRUE

FALSE

This condition will cause the loop to

stop.

Page 25: Flowcharts

Multiple loops are useful if there is a need to perform repetitive tasks, in other words, repeating tasks. Aside from that, nested loops are also useful for user input validations. For example, suppose you will let the user enter a number but you don’t allow a 0 or a negative number