You are on page 1of 3

Computer Programming

LECTURE: 05-28-2020
Introduction to Computer Programming
Objectives
 To relate programming to problem-solving
 To develop algorithms in solving problems
 To represent algorithms in a flowchart
 To discuss the rules and guidelines for drawing flowchart
 To discuss the advantages and limitations of using flowcharts

A. Programming and Problem-solving


Designing Programs to Solve Problems
Throughout your school years, you have accumulated techniques for solving a wide variety of problems. This time,
you will learn to translate these problem solving skills so you can use the computer to carry out the mechanical details of the
problem solving. This is the essence of computer programming: to describe a problem-solving technique in a series of steps
that a computer can carry out.
In describing a problem-solving technique for a computer, it is necessary to proceed in a very organized fashion.
Your description must include all the steps necessary to solve the problem, and the steps must be in the proper order.

Fundamental Steps to Program Design:


Step1. Analyze the Problem

In this step, you must:


a. Determine the data to be produced (output) as a solution of the problem. You should define the variables that will
represent the output
b. Determine the data (inputs) necessary to produce the outputs. You should also define variables that will represent
the inputs
c. Develop an algorithm for obtaining the outputs from the inputs in a finite number of steps. An algorithm is
defined as an organized sequence of operations for solving a problem in a finite number of steps.
*The main purpose of step1 is to make sure that you thoroughly understand the problem. We have the old saying
GIGO (Garbage in=Garbage out).

Step2. Outline the Program.


In this step, you outline the program using English-like sentences, called pseudo-code. Each sentence corresponds to
a simple program operation.

Step3. Implement the Program.


The final step in program design is to write the source code for the program. In this step, the pseudo-code for the
modules is translated into C statements. As part of the source code, you should include documentation in the form of
comments which describe what the various sections of the program do. In addition, the source code may include debugging
code to test the operation of the program and to allow you to track down programming errors (bugs).
a. Coding the Program
b. Testing and Debugging the Program
c. Documenting the Program

B. Software Development Method

C. Flowcharting

Flowchart is a diagram representing the logical sequence which is a combination of steps or operations to be performed. It
consists of labeled geometrical symbols that are interconnected to provide a pictorial representation of a data processing
procedure. A flowchart is simply a visual representation of an algorithm. It is the blueprint of the program.

Advantages:
1. Flowcharts are language independent
2. It enforces users to give attention to significant matters over the less significant ones.
3. Flowcharts provide an alternative to usual narrative description
4. Flowcharts are easier to understand

Limitations:
1. Flowcharts do not represent a programming language
2. Thinking in graphic terms is not normal
3. Certain details often require a long sequence of interconnected symbols
4. It does not convey why a given set of operations is made.
5. It does not highlight the important details

RJBO pg. 1
Computer Programming
Flowcharting Symbols
1. Input/Ouput (Parallelogram)- represents an instruction to an input or output device
2. Processing (Rectangle)- used to represent program instructions such as arithmetic operations
3. Decision (Diamond)- denotes a point in the program where more than one path can be taken. Based upon variable
conditions, alternative paths are possible. The particular path chosen depends on the test result.
4. Preparation (Hexagon)- used to represent instructions that will 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.
5. Terminal (Oval)- designates the beginning and end of a program
6. On- page Connector (Small Circle)- non-processing symbol which is used to connect one part of a flowchart to
another without drawing flow lines. It denotes an entry or exit from another part of the flowchart and also used to
change reading sequence of a flowchart on the same page.
7. Off-page Connector (Small Pentagon)- a connector used to designate entry to or exit from a page when a flowchart
requires more than one page.
8. Flow Direction Indicators (Arrowheads)- used to show the direction of processing or data flow.
9. Flow Lines (Horizontal/Vertical Lines)- used to show reading order or sequence in which flowcharts symbols are to be
read. Flow lines are sometimes drawn with arrowheads.

2 4
1 3 5

6 7
8&9
GUIDELINES IN FLOWCHARTING
1. All operations (tasks) should be listed out in a logical order according to the flow of operations. The flowchart must be
clear, simple and neat, to avoid vagueness and confusion.
2. Declare all variables (or labels/legends) needed in the flowchart and must be written anywhere near the flowchart, but it is
better to write it before the flowchart or at the right side of it. Example. let: num1 = first input number
num2 = second input number
sum = sum of the two input numbers
3. A flowchart must always begin and end with a terminal symbol. There should only be one start and one end for every
flowchart. In addition, a Start must have only flowline coming out and an End/Stop must have only flowline coming in.
4. In using the process symbol, input/output symbol, and the preparation symbol, there should only be one flowline coming
out but it may have one or more flowlines coming in.
5. In using the preparation symbol, you assign numeric values equal to zero(0) while characters(or string) variables equal to”
“(null value). Sometimes, due to many variables to be declared, this symbol will just have Clear to tell that all variables are
initialized.
6. The decision symbol must have two flowlines coming out(one for true and one for false condition) and must have only one
flowline coming in.
7. In using the on-page/off-page connector, it must be going out and in of the symbol. There should be the same label of
connector to show continuity or flow of the flowchart. Note: use on-page when connection is within the same page and use off-
page when you show connection of separate pages.
8. Connectors are better to be used when the flowchart is complex and contains many operations. Using connectors is better
than intersecting flowlines which may give confusion to the reader. Note therefore that intersections should be avoided.

9. The usual direction of the flow of the flowchart is from left to right or from top to bottom.
10. It is good to try assigning values to variables and go through the flowchart to test the validity and correctness of the
flowchart.
11. Use the flowchart appropriately according to its purpose.
Today there are many software that can be used to prepare a flowchart. Software that can be used in preparing flowcharts is
classified as computer-aided software engineering (CASE) tools since it helps in the preparation of an analysis of the
problem. Microsoft Visio and Edraw are some CASE software that can be used. Some may be downloaded free in the
Internet. Microsoft Word can be an alternative software in preparing flowcharts.

RJBO pg. 2
Computer Programming
Problems:
1. Draw a flowchart that computes the area of a rectangle whose dimensions are specified by the user.

START
A

L=0
W=0
Print L,
A= 0
W and A

Read L
and W END

A=L*W

2. The radius of a circle is equal to one unit. Draw a flowchart to compute the corresponding area of the circle and print
out the value of the radius and the area.
3. Given three numbers A, B, C. Draw a flowchart to compute and print out the sum, average and the product of these
values.
4. The ABC Manufacturing Company plans to give a year-end bonus to each of its employees. Draw a flowchart which
will compute the bonus of an employee. Consider the following criteria: If the employee’s monthly salary is less than
10,000, the bonus is 50% of the salary; for employees with salaries greater than 10,000, the bonus is 10,000. Print out
the name and corresponding bonus of the employee
5. Given two numbers, X and Y. Draw a flowchart that determines the higher number. Print out the higher number.
6. 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+2Y; and if X-Y is positive, compute R=X*Y. Print out the values of
X, Y and R.
7. A metric ton is 35,273.92 ounces. Draw a flowchart that will read the weight of a package in ounces and outputs the
weight in metric tons. It should allow the user to repeat this calculation as often as the user wishes.
8. The volume of a rectangular box is given by the formula:
Volume = Length*Width*Height
Draw a flowchart to calculate the volume of a box whose dimensions are specified by the user. Print out the
volume and the dimensions.
9. The volume of a sphere is given by the formula:
Volume = 4/3*Pi*R3
Draw a flowchart to calculate the volume of a sphere with the radius given by the user. Print out the volume
and the radius.
10. Given a number. Draw a flowchart that determines if the number is positive or negative. Print out the number
which is either positive or negative

ASSIGNMENT#1: Prepare the flowchart of the following:


1. The program should allow the user to input the name of the student, class standing, average quiz and periodic test. The
grade is computed by getting the average of CS, AQ and PT. The program should be able to print the computed grade
of the student.(5pts)
2. Salary computation: The program must accept the name of a fast food chain crew, the number of hours worked, rate
per hour and allowance per day. Compute for the basic salary by multiplying number of hours worked and rate per
hour and the Total Allowance by multiplying allowance per day by 12.50 and the gross pay by adding basic salary and
total allowance. Print all the computed values.(5pts)
Unit of measurement for weight and height: the program must accept the weight in pounds(lbs) and height in feet(ft).
Convert the inputted weight in kilogram(kg) and height in meters(m). print the converted values of weight and height.
(5pts)

RJBO pg. 3

You might also like