Lesson 2. Read and Learn
Algorithm and Flowcharting
The Algorithm
-is a limited number of instructions that outline the steps to be taken in order to address a particular problem or set of related problems.
Criteria for Algorithm
Input – there is a data that needs to be processed.
Output – there is a report to be printed.
Definiteness – instructions must be clear and free from ambiguous.
Finiteness - If we follow an algorithm's steps step by step, in every scenario, the algorithm must end after a set number of steps.
Effectiveness - Each stage must be simple enough that it could theoretically be completed by a person using only paper and a pencil. Furthermore, every step must be both realistic and certain.
The Pseudocode
Is an outline of the logic of the program you will write. It is like doing a summary of the program before it is written. This expresses the logic of what you want the program to do.
The Flowchart
The "use of symbols and phrases to designate the logic of how a problem is solved" (SCHN95).
"A common method for defining the logical steps of flow within a program by using a series of symbols to identify the Input, Process, and Outputs(IPO's) function within a program" (TRA196).
A flowchart is a two-dimensional depiction of an algorithm that uses preset graphic symbols to show the various operations and the direction of control. (SWAZ89).
"A diagram showing the order in which a series of actions or procedures should be carried out. It serves as the program's blueprint. (LAPU86).
BASIC SYMBOLS USED IN FLOWCHARTING
SYMBOLS | EXPLANATION |

| Straight lines with optional arrows to depict the direction of data flow are used to represent flowlines. By leaving one block and entering another, it is utilized to connect them. |

| The beginning and ending of the module are denoted by flattened ellipses. The module name is used as an ellipse at the beginning. The top or Control module's word end or halt and all other modules' word exit serve as indicators of the end. Ends or exits have one flowline entering them but none exiting them, while starts have no flowlines entering them and only one exiting them. |

| carries out any calculations, file opening and closing, etc. There is just one exit and one entry per processing block. |

| Input and output from the computer's memory are represented by the parallelogram. It just has one exit and one entrance. |

| The diamond denotes a choice. Only two exits are available from the block, and there is only one entry. When the outcome is True, one exit represents the action to be taken; when the outcome is False, the other exit represents the action to be taken. |

| Module processing is indicated by rectangles with lines extending down either side. There is only one exit and one entry for them. |
Preparation / Initialization | The polygon represents data preparation. used to choose the initial circumstances used to denote a set of instructions or a group of instructions that will change or modify how a program runs. |

| Sections on the same page are connected by a circle, and flowcharts are connected by a home base plate across many pages. Programmers can enter characters or numbers inside of these two symbols. To identify where the adjoining connector is located, the on-page connector employs letters inside the circle. The next portion of the previous element of the flowchart is located on the page that the off-page connector uses. Consequently, the flowchart is simple for the reader to understand. There will be either an entry or an exit on on- and off-page connectors. |
Payroll System: A simple payroll system that compute for the total salary of an employee. There will be four different modules showing the algorithms, flowcharts and pseudocode that shows the order of processing a payroll.
Control Module: to control the processing of the solution.

Read Module: to enter the data needed in the solution. Two types of modules here for the salaried and hourly employee.
ALGORITHM | FLOWCHART | PSEUDOCODE |
Read Module
Read Hours, PayRate
Exit
| 
| Read Hours, PayRate
Exit |
Calculation Module: To process the data for each employee.
ALGORITHM | FLOWCHART | PSEUDOCODE |
Calc Module
Read Hours, PayRate
Exit
| 
| GrossPay = Hours + PayRate
Exit |
Print Module: To print the processed information.
ALGORITHM | FLOWCHART | PSEUDOCODE |
Print Module
Print Pay
Exit
| 
| Print Pay
Exit |
Figure 1.0 The algorithms, flowcharts and pseudocodes for a simple Payroll System.
Logic Structures
Sequence – Processes are carried out independently of one another in a clear way.

Examples:
Create a flowchart that can accept and display a number. Make the corresponding algorithms and pseudocode.
ALGORITHM | FLOWCHART | PSEUDOCODE |
Read in the value of N
Print the value of N
| 
| Read N
Print N
End |
Draw a flowchart that computes and shows the sum and product of two numbers. Write its equivalent algorithms and pseudo code.

Create a flowchart that will convert an inputted number in Fahrenheit to its equivalent measure in Celsius. Formula: C = (5/9) x (F-32)

Selection (IF-Then- Else) – There is a choice between two options.

Examples:
Create a flowchart that accept values for A and B. Compare the two values inputted and print which is higher with qualifier “Higher” on the printed page. Write the equivalent algorithm and pseudocode.

Create a flowchart that will input a grade of student and determine whether the grade is passed or failed. Print the name, grade, remarks of student. Write its equivalent algorithm and pseudocode.

ABC Consultancy plans to give a year-end bonus to each of its employee. Draw a flowchart which will compute the bonus for every employee. Employee’s salary over 2,000 will get 1,500 bonus and less than 2,000 will get 50% bonus. Print the name and the corresponding bonus for each employee. Write each equivalent algorithms and pseudocode.
ALGORITHM | FLOWCHART | PSEUDOCODE |
Initialize Bonus to 0. Read in employee’s name and salary. Test if employee’s salary is less than 2,000. If salary < 2,000 then
Bonus=salary=50% Else Bonus=1,500 Print employee’s name and bonus End
| 
| Bonus = 0 Read Employee Name, Salary Salary < 2,000 Bonus=Salary*50% Salary > 2,000 Bonus=1,500 Print Employee Name, Bonus End |
Construct a flowchart that will accept the evaluation grade of student and determine its equivalent remarks. Print the name of the student and the remarks obtained. Remarks are based on the following criteria: Write its equivalent algorithms and pseudocode.
1.0 – 3.0 Passed
3.01 – 3.5 Conditional
3.51 – 4.0 Failed
Above 4.0 Dropped
ALGORITHM | PSEUDOCODE |
Initialize Remarks into space or blanks. Read in student’s name and grade. Test the grade if it is less than or equal to 3.0, Remarks is Passed. However, if the grade is greater than 3.0, do step 4. Test the score if it is less than or equal to 3.5, Remarks is Conditional. However if the grade is greater than 3.5, do step 5. Test the score if it is less than or equal to 4.0, Remarks is Failed. However if the grade is greater than 4.0, Remarks is Dropped. Print the Name and Remarks. End
| Remarks= “” Read Name, Grade Grade<=3.0 Remarks=Passed Grade<=3.5 Remarks=Conditional Grade<=4.0 Remarks=Failed Grade>4.0 Remarks=Dropped Print Student Name, Remarks End |

Repetition Structure (Iteration Statements)
Do – While
The repetitive execution of an operation or routing when the condition is true is made possible by this structure. Before running any process statement, the condition is assessed. Control flows out of the structure if the condition is false, otherwise the process is carried out.

Examples:
Construct a flowchart that will count from 1 to 10 and print each number counted using the do-while –repetition structure. Write its equivalent algorithm.

Quiz #5
Identify the following terms.
Algorithm
Flowchart
Pseudocode
Program
Give what is asked.
Criteria for algorithm:
Six Steps in Problem Solving
Activity 5
Create a flowchart that will accept three numbers and display the highest and lowest numbers inputted.
Draw a flowchart that will determine the voter is qualified to vote or not. Age must be eighteen (18) and above.
Create a flowchart that convert and display an inputted number from hours to its equivalent minutes. 1 hour = 60 minutes.
Draw a flowchart that will determine if the user is an authorized user of the system. Password is pass.
Create a flowchart that will compute and display the sum of 3 inputted numbers.
Construct a flowchart that will accept 10 numbers and display the positive and negative numbers inputted.
Create a flowchart that will swap the values of two inputted numbers as A and B respectively.
Module 2 References
Workbook in C programming : computer programming 1 / Paulion H. Gatpandan and Azenith M. Rollan.
Kernighan, Brian W. and Ritchie, Dennis M. The C Programming Language 2nd Edition
Schildt, Herbert. Turbo C/C++ The Complete Reference 2nd Edition
Sellapan, P. C++ Through Examples Includes Object-Oriented Programming
Uckan, Yuksel. Program Solving Using C
http://www.cprogramming.com
http://www.cplusplus.com
http://www.cplusplus.com/doc/tutorial
http://www.stroustrup.com
http://www.research.att.com/~bs/homepage.html
http://halls-of-vahalla.org/
http://creativecommons.org/
http://www.tutorialspoint.com