You are on page 1of 48

Module 2 Flowcharting and Pseudo-coding

Engr. J. Cansino
Information Technology Department

FEU EAST ASIA COLLEGE

Program Elements & Structure

Program Elements and Structure


1.) Constants Literal Value that does not change during program execution. It can be of the numeric or string type.

Numeric Constant - may be an integer (whole number) or a real number (with a decimal place). It may be preceded by a positive or negative sign. Examples: 10

-28

+3.4

-0.413

201

Note: No other characters must or can appear together with the constants. The following are examples of incorrect numeric constants: 10,000 $14.3 10mi/hr 1/2

String Constant A character or group of characters enclosed in double quotation marks ( ). The numbers 0-9, letters a-z or A-Z and all special characters like a space, % $ - _ & etc. may be included. Examples: J Jojo . 1225 J & J

Note: The entire string constant must always be enclosed in double quotation marks, one before the first character and one after the last character (no more no less). The following are examples of incorrect string constants:
Earl Jerald Cansino SMART Avenger Assemble

2.) Variables Is a portion of the computers main memory used to store a numeric or string constant. The value stored in the variable must be given a unique variable name but it can only hold one value at a given time.
Variable names must conform to the following requirements: a.) Must contain only letters, numbers and/or an underscore. b.) Must begin with a letter. c.) Must end either with a letter or a number. d.) Must be unique that is, not a name of another variable. e.) Must not be a keyword like ACCEPT, WHILE and the like.

A variable may be one of the following types: Numeric, String, Array Note: Variable names are not case sensitive in flowcharting and pseudo-coding, that is, upper and lower case letters are not differentiated. For example the variable TOTAL is the same as total. The following are example of incorrect variable name: Year code 10ctr #5 Total=

3.) Expressions is a group of program elements consisting of operands and operators. Operands can be a constant, variable, and or an array element. Operators can be arithmetic, logical, relational and/or string. Expressions always yield a value of a certain type depending on the type of expressions used. Arithmetic Expressions Hierarchy or Priority of Operators 1.) Expressions in parenthesis 2.) * / % 3.) + -

Examples:
1.) 10 + 4 * 8

3.)

20 / 4 * 9
5 45

32 42
2.) 50 % 6 5

2 -3

String Expressions
Examples: 1.) 2.)

3 + 4 = 34 Ja + red = Jared

Examples of incorrect usage of the + operator: 3 + 4 100 + Peso

Relational Expressions
Greater than Less than Greater than or equal to Less than or equal to Not equal Is equal to Examples: Ctr1 > 10 3 <= 5 Temp1 != Temp2 > < >= <= != ==

Examples of incorrect Relational Expressions: 30 <= X <= 40 43 > < 50

Logical Expressions
Hierarchy or Priority of Operators 1.) 2.) 3.) 4.) Expressions in parenthesis Not (!) And (&&) Or (||)

TRUTH TABLE FOR NOT(!) X FALSE TRUE !X TRUE FALSE

TRUTH TABLE FOR AND(&&) X FALSE FALSE TRUE TRUE Y FALSE TRUE FALSE TRUE X && Y FALSE FALSE FALSE TRUE

TRUTH TABLE FOR OR(||) X FALSE FALSE TRUE TRUE Y FALSE TRUE FALSE TRUE X || Y FALSE TRUE TRUE TRUE

Examples: 15 >= 10 && 15 <= 20 T && T T

4.) Statements are keywords, which perform which perform a predefined procedure. The following statements are available:
1.) 2.) 3.) 4.) 5.) DISPLAY Statement ACCEPT Statement IF Statement WHILE Statement FOR Statement

Assignment #1.1 Evaluate the following expression.


1.) 2.) 3.) 4.) 5.) 6.) 7.) 8.) 9.) 10.) 11 % 2 + 3 * 7 2 100 % 5 % 3 % 2 (45 / 9) * 6 + 4 (5 + 7) % (10 * 2 5) / (15 (8 6 % 4)) (8 + 21 % (18 5 * 3)) % (17 (6 + 13 % 5)) (12 == 12 % 2 * 2) && !(( 5 > 3) && (8<3)) (6 > 3) && (8 != 8) || !(10 <= 10) 15 / 3 == 15 % 3 5 != 11 / 2 (100 * 24)/12 + 45

Assignment #1.2
Check if Valid (V) or Invalid (I) 1. Numeric Constant: 2. String Constant: 3. Arithmetic Expression: 4. Variable Name: 5. Relational Expression: 6. Logical Expression: 7. Variable Name: 8. String Constant: 9. Numeric Constant: 10. Logical Expression: 0.12345 HELLO_TRISHA (45.9)%(5*2%3) _J_A_R_E_D (5<=2*2) =10+1 (!(!(!(F&&T)))) J5R3D *&****hello## 1,000,000.98 (!T&&!F)||(!F)

Evaluate the Following expressions: 1. 12 % 6 + (2 + 12 * 3) ( 12 % 13) 2. (10 / 3 + (16 + 3) ) ((5 * 2 % 10) + 2) 3. (T || F) && (!(!F && (6 > 8) || (5< 10) || F) || !T) 4. (T || !F) || (!(!(!F || (3 < 15) || F) || !F) && T) 5. !(!T && !F) || (!T || (12 <= 12) || (T && F)|| F)

FLOWCHARTS
- A graphic form of an algorithm.

- A diagram of a sequence of steps that a program must perform to produce the desired output.
- Traditional tool of programmers which allow in terms of detail to be included. flexibility

TYPES OF FLOWCHARTS
1.) System Flowchart present the total picture without worrying about taking care of every detail. 2.) Program Flowcharts depicts a main segment of a complete computer program.

FLOWCHARTING GUIDELINES
1.) Always use the ANSI standard symbols.

2.) Construct your flowcharts to read from top to bottom and left to right.
3.) Do not crisscross flowlines (used labeled connectors and use arrowheads to indicate direction of the flow. 4.) Make the messages and labels in the flowchart symbol direct and descriptive. 5.) Strive for neatness, clarity and simplicity.

BASIC FLOWCHARTING SYMBOLS


Terminal Symbol

Preparation Symbol

Processing Symbol

Decision Symbol

Input/Output Symbol

Predefined Process Symbol


Onpage Connector

Offpage Connector Flow Direction Lines

Sequential Program Structure

For Flowchart, symbols used are the following:


Terminal symbol

I/O symbol

Preparation symbol

Direction lines

For Pseudocode, keywords used are the following: 1.) Accept

Syntax: Accept <variable>


Accept <variable1>, , <variableN> 2.) Display Syntax: Display <string> Display <variable> Display <variable1>, , <variableN>

Sequential structure
#1] Input a temperature in Celsius and output the corresponding temperature in Fahrenheit. The formula is a follows: Fahrenheit = 9 (Celsius) + 32 5

Pseudocode

Flowchart
Start

Variables Used: F, C are numeric

F=0
Input C

Begin F=0 Display Input temperature in Celsius:

F = (9.0/5.0) * C + 32

Accept C
F = (9.0 / 5.0) * C + 32 Display Equivalent temperature in Fahrenheit:, F End

Output F End

Sequential structure #2] Pepperoni++ Pizza House charges 10% service charge and 5% sales tax on the gross bill of the customer. Create a flowchart and a pseudocode that would input the gross bill of the customer and the amount given by the customer to the waiter. It must output the customers total bill and change (if theres any).

Flowchart
Start Variables Used:

Pseudocode

GBill, Amt, change, TBill are numeric

TBill = 0 change = 0
Input GBill, Amt

Begin TBill = 0 change = 0

Display Input Gross Bill and Amount Given:


TBill = Gbill + Gbill *0.1 + Gbill * 0.05 change = Amt - TBill

Accept GBill, Amt TBill = GBill + GBill * 0.1 + GBill * 0.05

Output TBill, change End

change = Amt - TBill Display Total Bill = , Tbill Display Change = , change

End

Assignment #1.2: Sequential structure #5] Using Visual Logic, Draw and execute a FCD for Workers at a particular company were given a 15.5% salary increase. Moreover, the increase was retroactive for 2 months, that is, effective two months ago. Create a flowchart and a pseudocode that takes the employees old salary as input and then output the amount of retroactive pay (balance) due the employee and his new salary as well.

SELECTION / CONDITIONAL PROGRAM STRUCTURE

For Flowchart, symbols used are the following: Terminal symbol I/O symbol Preparation symbol

Flow Direction lines

Decision symbol

For Pseudocode, keywords used are the following:


1.) Accept

Syntax: Accept <variable>


Accept <variable1>, , <variableN>

2.) Display
Syntax: Display <string> Display <variable> Display <variable1>, , <variableN>

3.)

if-then-else
begin statements . . . end

Syntax #1: if <condition> then

else
begin statements . . . end

Syntax #2: if <condition1> then begin statements end else if <condition2> then begin statements end else if <conditionN> then begin statements end else begin statements end

Selection/Conditional Structure #1] Using Visual Logic, create a flowchart and a pseudo-code that will prompt the user to input two number and output the highest number entered.

Flowchart

Start

Input N1, N2
Y If N1 > N2 N Output N2 A End Output N1 A

Pseudocode
Variables Used: N1, N2 are numeric

Begin
Display Input two numbers: Accept N1, N2 if (N1 > N2) then Display N1 else Display N2 End

Assignment # 1 .3 Selection Structure


#1] The fine for an over-speeding violation depends on the speed of the erring driver, as follows: 60 to 75 mph = Php 2000.00 76 mph and above = Php 4000.00 Create a flowchart and a pseudocode to input the cars speed and then output the fine, if any.
#2] In the game of JACK N POY each of the two player choose either a scissors (code X), paper (code P), or stone (code S). If one chooses scissors and the other chooses stone then stone wins. If one chooses paper and the other stone then paper wins. If one chooses paper and the other scissors then scissors wins. If they both choose the same then the result is a tie. Create a flowchart or a pseudocode that will input two character codes corresponding to the object selected and then output either the message PLAYER 1 WINS or PLAYER 2 WINS

#3] Bongga Ka Day Inc. gives additional performance bonuses to its employees every year. The amount is dependent on the number of years of service of the employee as follows:

Years of Service

Amount of Bonus

5 years and below


6 years to 10 years 11 years to 25 years

50% of monthly salary


100% of monthly salary Php 30,000.00 or twice the monthly salary, whichever is higher.

ITERATIVE/ LOOPING PROGRAM STRUCTURE

For Flowchart, symbols used are the following:


Terminal symbol I/O symbol

Preparation symbol Flow Direction lines

Decision symbol

For Pseudo code, keywords used are the following: 1.) Accept 2.) Display 3.) if-then, if-then-else 4.) while-do Syntax:

while <condition> do
begin statements;
. . .

end

Iterative Program Structure


#1] Create a flowchart/pseudo code that will generate the following number series:

10, 5, 9, 10, 8, 15, 7, 20, 6, and 25

Start

Flowchart

X = 10 Y=5
Output X, Y X=X1 Y=Y+5 Y N End

If X >= 6

Pseudo code
Variables Used: X, Y are numeric

Begin
X = 10 Y=5 while (X >= 6) do begin Display X, Y X=X1 Y=Y+5 end End

Iterative Program Structure


#2] Create a flowchart/pseudo code that will generate the following number series:

1, 1, 2, 3, 5, 8, 13, 21, 34, and 55

Start
X=0 Y=1 Sum = 1

Flowchart

Output Sum Sum = X + Y X=Y Y = Sum Y

If Sum <= 55

End

Pseudo code
Variables Used: X, Y, Sum are numeric Begin X=0 Y=1 Sum = 1 while (Sum <= 55) do begin Display Sum Sum = X + Y X=Y Y = Sum end End

Assignment #1.4 Iterative Program Structure Using Visual Logic: #1] Create a flowchart/pseudo code that will input five numbers and output how many of the numbers entered are odd or even. #2] Create a flowchart/pseudo code that will input five numbers and output how many of the numbers entered are positive or negative.

Assignment #1.3 Iterative Program Structure


#3] Create a flowchart/pseudo code that will input 10 alphabetic characters and output how many of the characters entered were vowels and consonants. Disregard characters that are not alphabetic.
Create a flowchart/pseudo code that will input 5 numbers and output the highest number entered. Create a flowchart/pseudo code that will input 6 score for quizzes (0-100). Eliminate the lowest quiz and compute and output the average of the five remaining quizzes.

#4] #5]

You might also like