Saturday, June 7, 2008

Preparatory Lesson to Turbo C & Turbo C++ (FLOWCHARTING & ALGORITHM)



Programming
is a very challenging and simple task but it is easier if you prepare yourself by learning its logic and environment. Part of the preparation is to study flowcharting and algorithm.


FLOWCHARTING & ALGORITHM


Flowcharting in computer programming is a diagram that shows the sequence of actions representing the logical flow of operations in a process. It is the step-by-step progression through a procedure using connecting lines and a set of conventional symbols. It is also considered as the blueprint of the program and a schematic representation of an algorithm or a process.

Algorithm in computer programming is a finite set of instructions that shows the logical sequence of steps to be carried out in order to solve a specific problem, often written out as a flow chart that can be translated into a computer program.

FLOWCHARTING BASIC SYMBOLS

TERMINAL – marks the beginning and end of flowchart.


PREPARATION/INITIALIZATION – used to prepare data or select initial conditions.

INPUT/OUTPUT – display input (data read into computer memory by an input device) and output (data passed from computer memory by an output device)

PROCESSING – carry out any calculations that are to be done

DECISION – used when decisions are to be made by using alternatives execution


ON-PAGE CONNECTOR – used to connect one part of a flowchart to another within the page and it also shows the entry or exit point of the flowchart.

OFF-PAGE CONNECTOR – used to connect one part of a flowchart from one page to another page.

ARROW LINE - shows the process that is to be executed next



FLOWCHARTING BASIC CONTROL STRUCTURES

1. SEQUENCE – a control structure wherein the course of action is executed in a straightforward manner – See examples below:





























2. SELECTION (IF-THEN-ELSE) – a control structure wherein the course of action has a choice between two alternatives - See example below:

















3. REPETITION (LOOPING) – a control structure wherein the course of action has a repetitive execution of an operation as long as the condition is true, otherwise, control flows out of the structure. Also known as DO-WHILE structure.

EXAMPLE: Construct a flowchart that will count from 1 to 10 and print each number counted using the do-while repetition structure. Use A as variable for the number to be counted. Write its equivalent algorithm.




















OPERATORS COMMONLY USED IN FLOWCHARTING

OPERATORS MEANING

1. ARITHMETIC OPERATORS

+ addition

- subtraction

* multiplication

/ division


2. RELATIONAL OPERATORS

= equal

> greater than

< less than

< > not equal

> greater than or equal to

< less than or equal to


3. LOGICAL OPERATORS

&& AND

|| OR

! NOT


TEST YOURSELF


Applying the lessons you have learned in this site, do the following exercises:

1. Construct a flowchart that will convert an inputted number in Fahrenheit to its equivalent measure in Celsius. Use variable C for Celsius and F for Fahrenheit then Celsius for the output. Write its equivalent algorithm. (Clues: Formula: C=(5/9) x (F-32); use sequence control structure)

2. CBC Manufacturing Company plans to give a year-end bonus to each of its employee. Draw a flowchart which will compute the bonus of an employee. Consider the following conditions: If the employee’s monthly salary is less than 5,000 pesos, the bonus is 75% of the salary; for employees with salaries greater than 5, 000 pesos, the bonus is 2,500 pesos. Print the name and the corresponding bonus for each employee. Use variable B for bonus, S for salary, and N for name. Write each equivalent algorithm. (Clue: use selection control structure)

3. The initial value of the radius of a circle is equal to 1 unit and each succeeding radius is 1 unit greater than the value before it. Draw a flowchart to compute the Area of a circle starting with R = 1 up to R = 10, then print each radius and the corresponding area of a circle. Use variable R for radius and A for the area of the circle. Write the algorithm. (Clue: use repetition control structure)


NOTE: If you are not sure of your answer or if you have any question about the topic feel free to email me. Please check my profile for contact details.