You are on page 1of 75

Chapter 5: Flowcharts and Algorithms

Flowcharts and Algorithms

Flowchart

It is a diagram showing the step-by-step procedure of a specific task. It can also be used to
illustrate the existing process or the solution to a problem. Each symbol represents different
function. Using the flowchart makes it is possible to write computer programs in several computer
languages. The flowchart places importance on logic than specifics of the programming
language.

Flowchart Symbols

- Terminal Block. This symbol is used to mark the start and end of the list of
instructions. Start is used to mark the starting point and End is used to mark the
end of the flowchart.

- Input/Output Block. The parallelogram symbol is used for input and output
instructions. For input the instruction that can be used is Read or Input, followed
by a list of variables separated by a comma. For output the instruction that can
be used is Display or Print, followed by a list of variables and/or text that will be
displayed or printed.

Input. Data to be entered into the computer.

Output. Information that is displayed on the computer screen or is printed.

- Processing Block. This symbol is used to process calculations. Formulas are


usually entered in this section of the flowchart. Formulas include variables that
will be replaced by figures entered by the user. Activities that are to be performed
are also included.

Processing. It is where data is processed or manipulated into information.

- Decision Block. A diamond shaped symbol used to indicate decisions. Done in


question form and is answerable by yes or no. Uses logical relations such as
equal (=), not equal (≠), greater than (>), less than (<), greater than or equal to
(≥) and less than or equal to (≤).

- On-page Connectors. Flowcharts are written from top to bottom, left to right.
Once the bottom of the left side is reached continuation of the flowchart can be at
the right side on the same page.

- Off-page Connectors. This symbol is used if the flowchart is to be continued on


the next page.

- Flowlines. This shows the direction of the flowchart.

- Preparation. This symbol is used to initialize the value/s of the variable/s to be


used.

- Document. This represents a document or a printed output.

52
Chapter 5: Flowcharts and Algorithms

- Multidocument. This represents multiple documents to be printed.

- Stored Data. This corresponds to any data stored in a memory or storage unit.

- Manual Input. This denotes a manual entry of data.

- Display. This represents data to be displayed on a monitor or projector.

- Magnetic Disk. This symbol is used where data is to be stored.

- Manual Operation. For process flowcharts this will indicate manual operation to
be performed by an individual or group.

The above flowchart symbols are commonly used for programming or process flowcharting. A
flowchart is a diagram to illustrate a program or process. This book will concentrate on program
flowcharts. Flowcharts need not be complicated as the purpose of the flowchart is to illustrate the
solution to the problem. Some flowchart symbols can be used in place of other symbols.

Algorithm

Algorithm is writing a sequence of instructions in word form. It is close to writing a program but
not necessarily using a programming language. Best example of algorithm is recipes.

The purpose of flowcharts and algorithms is writing the instructions that can be adopted by
different programming language.

Application

Let us start first with the concept of designing programs. In designing programs always keep in
mind the input-process-output sequence. It means that without input the program cannot process
anything much more produce an output.

Looking at the sample flowchart the input section is asking the user to enter two (2) numbers to
be added. We start off by using the terminal block to start the flowchart. The preparation symbol
is used to initialize the value of the variables to be used in the computation.

Variables are used to represent a value. The value may be a number, letter or word. In algebra
we are used to variables x, y and z or a, b and c, sometimes using xy, xz and so on. But in
programming we use variables that are easy to understand by using the exact word or something
close to that. Thus, we use Num1 to represent the first number to be entered, Num2 for the
second number and Sum for the sum or total of the two numbers. You may consider using N1
and N2 for the two numbers and Total for the sum.

53
Chapter 5: Flowcharts and Algorithms

The format of the variables is in alphabet or word form or alpha-numeric (combination of alphabet
and numbers) with the alphabet/s at the front followed by the number/s. Numbers cannot be used
as variables as this will be read by the computer as a value. If two or more words are to be
combined to create a variable there is a proper way of doing this one is to use an underscore ( _ )
the other is simply combining the words. For example, for account title we may use acct_title or
accttitle. The use of hyphen (-) is not advisable since this may be treated as a mathematical
operation and the words being combined will be treated as variables.

Sample Flowchart

Start 1

Input Num2
Num1=0
Num2=0
Sum=0
Sum=Num1+Num2

Display “The sum of


Display “Enter the
the two numbers is: ”,
first number:”
Sum

Input Num1
End

Display “Enter the


second number:”

Display “Enter the first number:” may look like an output because of the word Display. It is
actually asking for an input from the user. Texts are enclosed in parenthesis (Enter the first
number: and Enter the second number:) whereas variables are not enclosed in parenthesis. The
parenthesis indicates that the words typed are not variables. “The sum of the two numbers is:” is
enclosed in parenthesis the variable Sum is separated by a comma. Most programming
languages use this style to display the amount, sum or total in the same line.

The numbers are then entered by the user for adding. The processing block contains the formula
to be used in the computation. Then the total is then displayed on the computer screen.

There is also an on-page connector that was used the continuation is on the same page the
reference points must be the same to avoid confusion. On-page and off-page connectors are
used since flowcharts top-to-bottom designs arrows are not allowed to go up to denote that the
continuation is on the right side of the page. This also makes the flowchart neat and easy to
understand.

Once the flowchart has been converted using a programming language it will look something like
this.

54
Chapter 5: Flowcharts and Algorithms

Enter the first number:


25
Enter the second number:
12
The sum of the two numbers is: 37

Let us start with an easy problem where there is no process portion. This is a problem on input
and output.

Problem 1:
Create a program design that will properly label the input of a person’s name, address and
telephone number. The program must print the same information together with the proper labels.

Flowchart:

Start 1

Input Phone_Num
Display “Name: ”

Print “Name: ”, Name


Input Name

Print “Address: ”, Add


Display “Address: ”

Print “Phone No.: ”,


Input Add
Phone_Num

Display “Phone No.: ”


End

The result of this design will look something like this.

Input:

Name:
Juan Dela Cruz
Address:
Anonas St., Quezon City
Phone No.:
223-5667

55
Chapter 5: Flowcharts and Algorithms

Printout:

Name: Juan Dela Cruz


Address: Anonas St., Quezon City
Phone No.: 223-5667

Algorithm:
1. Display “Name: ”.
2. Input Name.
3. Display “Address:”.
4. Input Add.
5. Display “Phone No.:”.
6. Input Phone_Num.
7. Print “Name: ”, Name.
8. Print “Address: ”, Add.
9. Print “Phone No.: ” Phone_Num.
10. End.

The algorithms are easy to convert to different programming languages. Avoid using a
programming language for algorithms this might not be compatible with other programming
languages.

Counters are used for a number of reasons like the number of records being maintained by the
system, number clients, etc. Counters are important especially if it is used as a statistical
reference.

Problem 2:
Create a program design that will count from 1 to 50 and display the progression of the counter.

Flowchart:

Start 1

Counter=0
Is No
2 Counter= 2
50?
Counter=Counter+1

Yes

Display Counter End

56
Chapter 5: Flowcharts and Algorithms

Algorithm:
1. Set Counter=0
2. Counter=Counter+1
3. Display Counter
4. If Counter=50, then go to the next step. If not go to step 2.
5. End

Aside from being a counter this is also exhibits a loop. Loops are performed until the terminating
condition is satisfied. In this case, the counter will keep adding one (1) to its total until it reaches
50. Once it reaches 50 the loop will stop.

The formula is simple for this counter, counter=counter+1. Where the initial value is 0 then when
added to 1 the value of the counter becomes 1. Comparing the value of the counter which is 1 to
50, it is not equal. Therefore, it will go back to the step after the preparation symbol. The value we
got will be added to 1 and counter will now be equal to 2. This cycle will repeat until counter is
equal to 50.

Moving on to the next problem, problem 3 is another example of counter. This let us include an
input.

Problem 3:
Create a program that can input 100 names.

Flowchart:

Start

Counter=0

Input Name

Counter=Counter+1

Is No
Counter=
100?

Yes

End

Algorithm:
1. Set Counter=0.
2. Input Name.
3. Counter=Counter+1.
4. If Counter=100, then go to the next step. If not go to step 2.

57
Chapter 5: Flowcharts and Algorithms

5. End.

In the previous two problems the termination of the program is done once the condition has been
met. This time let us give the option to the user for the program termination.

Problem 4:
Create a design that can enter student name, address, course, and age. Once the program is
terminated by the user, display the number of entries made.

Flowchart:

Start

Counter=0

Input stud_name,
add, course, age

Counter=Counter+1

Display “Enter
another set of
data? (Y or N): ”

Input Ans

Is Yes
Ans=’Y’?

No

Display Counter

End

58
Chapter 5: Flowcharts and Algorithms

Algorithm:
1. Set Counter=0.
2. Input stud_name.
3. Input add.
4. Input course.
5. Input age.
6. Counter=Counter+1.
7. Display “Enter another set of data? (Y or N): ”
8. Input Ans.
9. If Ans=’N’, then go to the next step. If not go to step 2.
10. Display Counter.
11. End.

In the “Enter another set of data? (Y or N):” we are asking the user for a response of Y or N (Yes
or No). The program terminates if the user enters N. Another way of writing the condition in the
decision block is:

Is No
Ans=’N’?

Yes

Display Counter

End

If the user enters ‘N’ the program terminates.

Problem 5 will be using two counters one to count for the number of male, the other the number
of females. The user will still have the option to terminate the program.

Problem 5:
Create a design that would input a person’s name and sex. The program must count the number
of males and females that were entered. The program must display the number of males and
females that were entered upon termination of the program.

Flowchart:

Start 1

M=0 Display “Name: “


F=0

D
A
1

59
Chapter 5: Flowcharts and Algorithms

Input Name

Display “Sex (‘M’ or


‘F’): ”

Input Sex

Is Sex=’M’or
Sex=’F’? No Display “Invalid sex
entered. Enter again. “

Yes

Is No
Sex= F=F+1
’M’?

Yes
M=M+1
C

Display “Enter another


set of data? (‘Y’ or
‘N’):”

Input Ans

60
Chapter 5: Flowcharts and Algorithms

Is No Display “Invalid answer


Ans=’Y’ or C
entered. Enter again. “
Ans=’N’?

Yes

Is Yes
Ans=’Y’? D

No

Display “Number of
Males:“, M

Display “Number of
Females:“, F

End

Algorithm:
1. Set M=0, F=0.
2. Display “Name: “
3. Input Name.
4. Display “Sex (‘M’ of ‘F’): “,
5. Input Sex.
6. If Sex=‘M’ or Sex=‘F’, then go to the next step. If not, display “Invalid sex entered. Enter
again.” and go to step 4.
7. If Sex=‘M’, compute M=M+1 and go to step 8. If not go to the next step.
8. F=F+1 and go to the next step.
9. Display “Enter another set of data? (‘Y’ or ‘N’):”
10. Input Ans.
11. If Ans=‘Y’ or Ans=‘N’ go to the next step. If not, “Invalid answer entered. Enter again.” And
go to step 8.
12. If Ans=‘Y’ go to step 2. If not go to the next step.
13. Display “Number of Males:”, M.
14. Display “Number of Females:”, F.
15. End.

We have place filters in entering the gender and entering the Y or N answer. Filters are useful as
this can minimize errors made by the user. The word is minimize not totally prevent. Computer

61
Chapter 5: Flowcharts and Algorithms

programs cannot prevent human errors but installing filters can minimize errors. There are more
examples of filters in next problems.

We can use and and or in the decision block or we can have separate decision blocks for this.
And, means both conditions must be satisfied, or, means either one of the conditions must be
satisfied to make it valid.

Logical operations are very important in programming. Equal denotes an exact value and not
equal is everything else that is not equivalent to a specific value or amount. Problem 6 is an
example of the logical operation equal (=).

Problem 6:
When entering student information regarding the year level the following information will printed:

INPUT OUTPUT

1 “Freshman”
2 “Sophomore”
3 “Junior”
4 “Senior”

Reject any invalid year level entered.

Flowchart:

Start

Level=0

Input Level

Is Yes
Print “Freshman”
Level=1?

No A

Is Yes
Print “Sophomore”
Level=2?

No
A

Is Yes
Print “Junior”
Level=3?

No A
B

62
Chapter 5: Flowcharts and Algorithms

No Display “Invalid year


Is level entered! Enter
Level=4? valid year level!”

Yes

Print “Senior” C

End

Algorithm:
1. Set Level=0.
2. Input Level.
3. If Level=1, then print “Freshman” and go to step 8. If not, go to the next step.
4. If Level=2, then print “Sophomore” and go to step 8. If not, go to the next step.
5. If Level=3, then print “Junior” and go to step 8. If not, go to the next step.
6. If Level=4, then print “Senior” and go to step 8. If not, go to the next step.
7. Display “Invalid year level entered! Enter year level again!” and go back to step 2.
8. End.

If an invalid entry is made it will check on all the conditions if there is no match with any of the
conditions it is considered and invalid entry. Problem 7 and 8 are a similar problems to problem 6
that you can try working on.

Problem 7:
When entering an elementary student’s grade level the following information must be printed:

Input Print/Output

1 “Grade 1”
2 “Grade 2”
3 “Grade 3”
4 “Grade 4”
5 “Grade 5”
6 “Grade 6”

Create a flowchart in such a way that it will reject any number other than the above input.

63
Chapter 5: Flowcharts and Algorithms

Flowchart:

Start

Level=0

Input Level

Is Yes
Print “Grade 1”
Level=1?

No
B

Is Yes
Print “Grade 2”
Level=2?

No
B

Is Yes
Print “Grade 3”
Level=3?

No B

Is Yes
Print “Grade 4”
Level=4?

No B

Is Yes
Print “Grade 5”
Level=5?

No B

No Display “Invalid year


Is level entered! Enter a
Level=6? valid year level!”

Yes
A
1

64
Chapter 5: Flowcharts and Algorithms

Print “Grade 6”

End

Algorithm:
1. Set Level=0.
2. Input Level.
3. If Level=1, then print “Grade 1” and go to step 10. If not, go to the next step.
4. If Level=2, then print “Grade 2” and go to step 10. If not, go to the next step.
5. If Level=3, then print “Grade 3” and go to step 10. If not, go to the next step.
6. If Level=4, then print “Grade 4” and go to step 10. If not, go to the next step.
7. If Level=5, then print “Grade 5” and go to step 10. If not, go to the next step.
8. If Level=6, then print “Grade 6” and go to step 10. If not, go to the next step.
9. Display “Invalid Grade Level entered! Enter level again.” and go back to step 2.
10. End.

Problem 8:
Enter the employee names, employee numbers, and level. The output must print the employee
names, employee numbers, and the corresponding level.

Input Output

1 “Board of Directors”
2 “Senior Management”
3 “Middle Management”
4 “Rank and File”

The flowchart must reject any invalid numbers entered and must ask if the user wants to enter
another record.

Flowchart:

Start

Num=0
Level=0

Input Name, Num,


Level

65
Chapter 5: Flowcharts and Algorithms

Is Yes Print Name, Num,


Level=1? “Board of Directors”

No
1

Is Print Name, Num,


Level=2? “Middle Management”

Is Yes Print Name, Num,


Level=3? “Middle Management”

No
1

Is No Display “Invalid entry!


Level=4? Enter again!”

Yes
B
Print Name, Num,
“Rank and File”

D 1

Display “Enter another?”

Input Ans

66
Chapter 5: Flowcharts and Algorithms

Is Ans=’Y’ No Display “Invalid entry! Enter


or again!”
Ans=’N’?

Yes D

Is Yes
Ans=’Y’? B

No

End

Algorithm:
1. Set Num=0, Level=0.
2. Input Name, Num, Level.
3. If Level=1, then print Name, Num, “Board of Directors” and go to step 7. If not go to the next
step.
4. If Level=2, then print Name, Num, “Senior Management” and go to step 7. If not go to the
next step.
5. If Level=3, then print Name, Num, “Middle Management” and go to step 7. If not go to the
next step.
6. If Level=4 then print Name, Num, “Rank and File” and go to step 7. If not display “Invalid
level entered! Enter data again!” and go to step 2.
7. Display “Enter another record? (‘Y’ or ‘N’): “
8. Input Ans
9. If Ans=’Y’ or Ans=’N’, then go to the next step. If not, display “Invalid entry! Enter again!”
10. If Ans=‘Y’, then go back to step 2. If not, if Ans=‘N’ go to the next step.
11. End.

Greater than (>) and less than (<) are conditions used to signify a range of numbers. For
example, x>72, this means all numbers above 72 satisfies this condition. Starting at
72.0000000000001 (to exaggerate it a bit) to an infinite number is included in the range. The
same applies for less than. For example, x<27, everything below the indicated number satisfies
the condition.

Problem 9:
Given the following conditions the corresponding output must be displayed.

Conditions Output

8 oC<Temperature<18oC “Do you live in Baguio?”


Temperature<26oC “The weather is cool.”
Temperature<30oC “The weather is warm.”
Temperature<37oC “It’s too hot!”

67
Chapter 5: Flowcharts and Algorithms

Flowchart:

Start

Temp=0

Input Temp

Is Temp>
8 and
Yes Display “Do you live in
Temp<18? Baguio?”

No 1

Is Yes
Display “The weather
Temp<
is cool.”
26?

No
1

Is Yes Display “The weather


Temp< is warm.”
30?

No
1

Is No
Temp< Display “The temperature entered
37? does not occur in our country.
Enter temperature again.”

Yes

Display “It’s too hot!”


2
1

End

68
Chapter 5: Flowcharts and Algorithms

Algorithm:
1. Set Temp=0.
2. Input Temp.
3. If Temp>8 and Temp<18, then display “Do you live in Baguio?” and go to step . If not,
proceed to the next step.
4. If Temp<26, then display “The weather is cool.” and go to step 7. If not, proceed to the next
step.
5. If Temp<30, then display “The weather is warm.” and go to step 7. If not, proceed to the next
step.
6. If Temp<37, then display “It’s too hot!” and go to step 7. If not, Display “The temperature
entered does not occur in our country. Enter temperature again.” And go to step 2.
7. End.

There are four categories in this problem:

1. 8.1oC to 17.9oC
2. 18.0 oC to 25.9 oC
3. 26.0 oC to 29.9 oC
4. 30.0 oC to 36.9 oC

This is assuming the numbers entered are whole numbers. Looking at the first condition if the
temperature does not fall in this range it checks the second condition. There is no need to define
the lower limit of the second condition since this was taken care of by the first condition. It means
by default the lower limit is 18oC. If the temperature entered is not within the first two conditions it
will check the third condition. If the temperature entered does not fall within the third condition it
will check the fourth condition. If the temperature entered does not fall on the fourth condition it is
an invalid temperature.

Let us test the flowchart. If we enter 15 oC, it will display “Do you live in Baguio?” If we enter 24oC,
checking the first condition 24oC does fall within the first condition. It will now check if it is within
the second condition. 24oC falls within the second condition will therefore display “The weather is
cool.” Let us try 28oC, 28oC does not fall within the first condition or the second condition it will
now check the third condition. It does fall within the limits of the third condition, and will display
“The weather is warm.” Let us try 36oC, 36oC does not fall within the first three conditions it will
check the fourth. It falls within the range of the fourth condition and will therefore display “It’s too
hot!” Let us try 2oC, what will happen here is 2oC will be checked if it falls under any of the
conditions. It does not fall under any condition, and will therefore display “The temperature
entered does not occur in our country. Enter temperature again.”

Still using greater than (>) and less than (<) let us try problem 10.

Problem 10:
Enter three (3) numbers with the output printing the highest number.

Flowchart:

Start

69
Chapter 5: Flowcharts and Algorithms

Num1=0
Num2=0
Num3=0
High=0

Input Num1,
Num2, Num3

No Yes
Is Is
Num1> Num2> High=Num2
Num2? Num3?

Yes
No
No
Is
Num1> High=Num3
Num3?

Yes
High=Num1

Print High

End

Algorithm:
1. Set High=0, Num1=0, Num2=0, Num3=0.
2. If Num1>Num2. Then proceed to the next step. If not, proceed to step 4.
3. If Num1>Num3. Then High=Num1. If not, proceed to step 4.
4. If Num2>Num3. Then High=Num2. If not, High=Num3.
5. Print High.
6. Stop.

70
Chapter 5: Flowcharts and Algorithms

Let us test the flowchart. Entering three (3) numbers: 1 (Num1), 2 (Num2) and 3 (Num3). We
know that the third number, 3 is the highest number. Let us check if the third number will indeed
be printed. Num1 and Num2 will be compared Is 1>2? The answer is no. Since Num2 is higher
the Num1, Num2 will be compared to Num3. Is 2>3? The answer is no. Therefore, the highest
number is Num3.

Let us rearrange the entry. Entering three (3) numbers: 1 (Num1), 3 (Num2) and 2 (Num3). Num1
and Num2 will be compared. Is 1>3? Num2 is higher than Num1. Num2 will now be compared to
Num3. Is 3>2? The answer is yes. Therefore, Num2 is the highest number.

Let us rearrange again the entries. Entering three (3) numbers: 3 (Num1), 1 (Num2) and 2
(Num3). Num1 will be compared to Num2. Is 3>1? The answer is yes. Num1 will now be
compared to Num 3. Is 3>2? The answer is yes. Therefore, Num1 is the highest number.

Let us modify problem 10 a bit for problem 11.

Problem 11:
Enter three (3) numbers with the output printing the highest number, second highest then lowest.

Flowchart:

Start

Num1=0
Num2=0
Num3=0

Input Num1,
Num2, Num3

71
Chapter 5: Flowcharts and Algorithms

Yes Is No
Num1>
Num2?

Yes Is Yes Is No
Num1> Num2>
Num3? Num3?

No Yes Is
Num1>
Num3? Print Num3,
Print Num3, Num2, Num1
Num1, Num2

No
Print Num2,
Num1, Num3

Print Num2,
Num3, Num1

Is No
Num2> Print Num1,
Num3? Num2, Num3

Yes

Print Num1,
Num2, Num3

End

Algorithm:
1. Set Num1=0, Num2=0, Num3=0.
2. If Num1>Num2. Then, proceed to the next step. If not, proceed to step 5.
3. If Num1>Num3. Then, proceed to the next step. If not, print Num3, Num1, Num2 and proceed
to step 7.
4. If Num2>Num3. Then, print Num1, Num2, Num3 and proceed to step 7. If not, print Num1,
Num3, Num2 and proceed to step 7.

72
Chapter 5: Flowcharts and Algorithms

5. If Num2>Num3. Then, proceed to the next step. If not, print Num3, Num2, Num1 and proceed
to step 7.
6. If Num1>Num3. Then, print Num2, Num1, Num3 and proceed to the next step. In not, print
Num2, Num3, Num1 and proceed to the next step.
7. End.

Problem 10 was easier since we are looking for the highest number as compared to problem 11.
Problem 11 was also looking for the highest number together with the second highest and lowest
numbers. The output will have six possible combinations:

1. Num1, Num2, Num3


2. Num1, Num3, Num2
3. Num2, Num1, Num3
4. Num2, Num3, Num1
5. Num3, Num1, Num2
6. Num3, Num2, Num1

As a starting point we compare the first (Num1) and second (Num2) numbers. Another option is
to start comparing the first (Num1) and third (Num3) numbers or the second (Num2) and third
(Num3). Let us take one side of the flowchart. If Num1 is greater than Num2, check if Num1 is
greater than Num 3. If the answer is yes check if Num2 is greater than Num3, since we do not
know the second highest number and the lowest number. If Num2 is greater than Num3, the
output will be Num1, Num2, Num3. If Num3 is greater than Num2, then the output will be Num1,
Num3, Num2.

There are parts of the flowchart that only need two decision blocks to figure out the highest,
second highest and lowest numbers. If Num1 is greater than Num2, but Num3 is greater than
Num1. Num3 is the highest, Num1 is the second highest and Num2 is the lowest.

Greater than or equal to (≥) and less than or equal to (≤) involves a range of numbers similar to
greater than (>) and less than (<). For example, x≥10, the condition is satisfied when x falls within
10 to an infinite set of numbers.

Problem 12:
The grading system has a range from 80% - 100%. Enter or input the student’s grade displaying
the corresponding output.

Range Print/Output

98% - 100% “Excellent”


95% - 97% “Very Good”
92% - 94% “Good”
89% - 91% “Satisfactory”
85% - 88% “Fair/Pass”
80% - 84% “Failure”

Assume the grade to be entered is in whole numbers and the grade to be entered must not
accept less than 80% and more than 100%.

73
Chapter 5: Flowcharts and Algorithms

Flowchart:

Start

Grade=0

Display “Enter
Grade: ”

Input Grade

Is Grade≥80 Yes
and Display “Failure”
Grade≤84?

B
No

Is Grade≥85
and Yes
Display “Fair/Pass”
Grade≤88?

B
No

Is Grade≥89
Yes
and Display “Satisfactory”
Grade≤91?

B
No
A

74
Chapter 5: Flowcharts and Algorithms

Is Grade≥92
Yes
and Display “Good”
Grade≤94?

1
No

Is Grade≥95 Yes
and Display “Very Good”
Grade≤97?

No 1

Is Grade≥98 No Display “Invalid


and grade entered! Enter
Grade≤100 a valid grade!”
?

Yes
C
Display “Excellent”

B
1

Display “Enter
Another? (Y or N):”

Is Ans=’Y’ No Display “Invalid


or Ans=’N’? answer entered. Enter
Answer again.”

Yes
D 1

75
Chapter 5: Flowcharts and Algorithms

Is No
Ans=’Y’? C

Yes

End

Algorithm:
1. Set Grade=0.
2. Input Grade.
3. If Grade≥80% and Grade≤84%, then display “Failure” and go to step 10. If not, go to the next
step.
4. If Grade≥85% and Grade≤88%, then display “Fair/Pass” and go to step 10. If not, go to the
next step.
5. If Grade≥89% and Grade≤91%, then display “Satisfactory” and go to step 10. If not, go to the
next step.
6. If Grade≥92% and Grade≤94%, then display “Good” and go to step 10. If not, go to the next
step.
7. If Grade≥95% and Grade≤97%, then display “Very Good” and go to step 10. If not, go to the
next step.
8. If Grade≥98% and Grade≤100%, then display “Excellent” and go to step 10. If not, go to the
next step.
9. Display “Invalid Grade entered! Enter data again!” and go to step 2.
10. Display “Enter another? (Y or N):”
11. Input Ans
12. If Ans=’Y’ or Ans=’N’. Then go the next step. If not, display “Invalid answer entered. Enter
Answer again.” and proceed to step 10.
13. If Ans=’Y’. Then proceed to the next step. If not, go to step 2.
14. End.

Another way of writing the flowchart is

Is Grade≥80 Yes
and Display “Failure”
Grade≤84?

B
No
A

76
Chapter 5: Flowcharts and Algorithms

Is Yes
Grade≤88? Display “Fair/Pass”

No 1

Is Yes
Grade≤91? Display “Satisfactory”

No 1

Is Yes
Grade≤94? Display “Good”

No 1

Is Yes
Grade≤97? Display “Very Good”

No 1

Is Display “Invalid
No
Grade≤ grade entered! Enter
100? a valid grade!”

Yes

There are different ways of designing the flowchart as problems become more complex different
solutions can be done to achieve a specific output. Another way of writing the flowchart is to start
from the top.

77
Chapter 5: Flowcharts and Algorithms

Is Grade≥98
Yes
and Grade≤ Display “Excellent”
100?

No 1

Is Yes
Grade≥95? Display “Very Good”

No 1

Is Yes
Grade≥92? Display “Good”

No 1

Is Yes
Grade≥89? Display “Satisfactory”

No 1

Is Yes
Grade≤85? Display “Fair/Pass”

No 1

Is No Display “Invalid
Grade≤ grade entered! Enter
80? a valid grade!”

Yes

The next problem will include saving the data entered and using the saved data for printing. We
shall assume that the database table has been created for this problem and succeeding
problems.

Problem 13:
The grading system has a range from 80%-100%. Enter or input the student’s name and grade.
Save the data entered name, grade and the corresponding output. Print the name, grade and the
corresponding output.

78
Chapter 5: Flowcharts and Algorithms

Range Print/Output

98.00% - 100.00% “Excellent”


95.00% - 97.99% “Very Good”
92.00% - 94.99% “Good”
89.00% - 91.99% “Satisfactory”
85.00% - 88.99% “Fair/Pass”
80.00% - 84.99% “Failure”

The grade to be entered must not accept less than 80% and more than 100%. The grade/s to be
entered can accept decimal numbers.

Flowchart:

Start

Grade=0

Display “Enter
Name and Grade:”

Input Name, Grade

Is Grade≥98 Yes
and Cor_Grade=“Excellent”
Grade≤100?

B
No

Is Yes Cor_Grade=“Very Good”


Grade≥
95?

B
No
A

79
Chapter 5: Flowcharts and Algorithms

Is Yes Cor_Grade=“Good”
Grade≥
92?

B
No

Is Yes Cor_Grade=“Satisfactory”
Grade≥
89?

B
No

Is Yes Cor_Grade=“Fair/Pass”
Grade≥
85?

B
No

Is No Display “Invalid grade


Grade≥ entered! Enter data again!”
80?

Yes
C
Cor_Grade=“Failure”

Save Name,
Grade, Cor_Grade

Stud_Grade

80
Chapter 5: Flowcharts and Algorithms

D
B

Display “Input
another (Y or N)?”

Is No Display “Invalid answer


Ans=’Y’or entered! Enter a valid answer!”
Ans=’N’?

Yes

Is Yes
Ans=’Y’? C

No

Display “Do you want


to print the students’
grades (Y or N)?”

Is No Display “Invalid answer


Ans=’Y’or entered! Enter a valid answer!”
Ans=’N’?

Yes

Is No
Ans=’Y’? F

Yes
E

81
Chapter 5: Flowcharts and Algorithms

Stud_Grade

Print Name, Grade,


Cor_Grade

End

Algorithm:
1. Set Grade=0.
2. Display “Enter Name and Grade:”
3. Input Name, Grade.
4. If Grade≤100% and Grade≥98%, Cor_Grade=“Excellent” and go to step 12. If not, go to the
next step.
5. If Grade≥95%, Cor_Grade=“Very Good” and go to step 12. If not, go to the next step.
6. If Grade≥92%, Cor_Grade=“Good” and go to step 12. If not, go to the next step.
7. If Grade≥89%, Cor_Grade=“Satisfactory” and go to step 12. If not, go to the next step.
8. If Grade≥85%, Cor_Grade=“Fair/Pass” and go to step 12. If not, go to the next step.
9. If Grade≥80%, Cor_Grade=“Failure” and go to step 12. If not, display “Invalid grade entered!
Enter data again!”. and go to step 2.
10. Save Name, Grade, Cor_Grade
11. Store Stud_Grade in hard disk.
12. Display “Input another (Y or N)?”
13. Input Ans
14. If Ans=’Y’ or Ans=’N’? Then go to the next step. If not, display “Invalid answer entered! Enter
a valid answer!” and go back to step 10.
15. If Ans=’Y’. Then, and go to the step 2. If not, go to the next step.
16. Display “Do you want to print the students’ grades (Y or N)?”
17. Input Ans
18. If Ans=’Y’ or Ans=’N’? Then go to the next step. If not, display “Invalid answer entered! Enter
a valid answer!” and go back to step 14.
19. Retrieve the data Stud_Grade.
20. Print Name, Grade, Cor_Grade
21. End.

Note that saving the data in the hard disk is done automatically. Also, the design is becoming
more flexible by making the user decide on the activity to be performed.

Let us combine the different topics discussed already to create a more challenging problem. We
are going to make a flexible design that will give the user options on what activity to undertake.

Problem 14:
Create a program design that will enter the clients’ name, account number, and deposit balance
count the number of bank clients that fall under the different categories:

82
Chapter 5: Flowcharts and Algorithms

Deposit Balance

0.00 – 50,000.00
50,000.01 – 100,000.00
100,000.01 – 500,000.00
500,000.01 – 1,000,000.00
Above 1,000,000.00

The counter must also include clients that were previously entered in system. The user may or
may not enter any data. Limit the function of the design to data entry, counters and printing of
records.

Flowchart:

Start

Acctnum=0
Dep=0
Ctr_50K=0
Ctr_100K=0
Ctr_500K=0
Ctr_1M=0
Ctr_A1M=0

Display “Do you want


to enter data?”

Input Ans

Is Ans=’Y’ No Display “Invalid answer


or Ans=’N’? entered. Enter Answer
again.”

Yes
A

83
Chapter 5: Flowcharts and Algorithms

Is No Display “Do you want to


Ans=’Y’? display the number of clients
per category?”

E Yes

Display “Name: ”
Is Ans=’Y’ No
or Ans=’N’? D

Input Name
Yes
Client_data
Display “Account
Number: ”
C

Input Acctnum

Display “Deposit
Balance: ”

Input Dep

Is No Display “Invalid deposit


Dep≥0? amount entered. Enter
amount again”

Yes
Save Name,
Acctnum, Dep

84
Chapter 5: Flowcharts and Algorithms

Client_data

Display “Enter
another set of data?
(Y or N): ”

Input Ans

Is Ans=’Y’ No Display “Invalid answer


or Ans=’N’? entered. Enter Answer
again.”

Yes

Is Yes
Ans=’Y’? E

No
F

Is Dep≥0
Yes
and Dep≤ Ctr_50K=Ctr_50K+1
50,000.00?

H
No
G

85
Chapter 5: Flowcharts and Algorithms

Is Dep≤ Yes
100,000.00? Ctr_100K=Ctr_100K+1

No 1

Is Dep≤ Yes
500,000.00? Ctr_500K=Ctr_500K+1

No 1

Is Dep≤ Yes
1,000,000.00? Ctr_1M=Ctr_1M+1

No 1

Is Dep> No
1,000,000.00? 1

Yes
Ctr_A1M=Ctr_A1M+1
1
H

Display “Deposit Balance No.


of Clients ”

Display “0.00 – 50,000.00 ”,


Ctr_50K

86
Chapter 5: Flowcharts and Algorithms

I
I

Display “50,000.01 – 100,000.00


”, Ctr_100K

Display “100,000.01 – 500,000.00


”, Ctr_500K

Display “500,000.01 – 1,000,000.00


”, Ctr_1M

Display “Above 1,000,000.00


”, Ctr_A1M

Display “Do you want to print the


data? (Y or N): ”

Input Ans

Is Ans=’Y’ No Display “Invalid answer


or Ans=’N’? entered. Enter Answer
again.”

Yes

Is Yes
Ans=’Y’? J

No
K

87
Chapter 5: Flowcharts and Algorithms

Client_data

Print Acctnum, Name, Dep

End

Algorithm:
1. Set Acctnum (account number)=0, Dep (deposit)=0,Ctr_50K (0.00-50,000.00)=0, Ctr_100K
(50,000.01-100,000.00), Ctr_500K (100,000.01-500,000.00), Ctr_1M (500,000.00-
1,000,000.00), Ctr_A1M (above 1,000,000.00)=0.
2. Display “Do you want to enter data?”
3. Input Ans.
4. If Ans=’Y’ or Ans=’N’. Then, go to the next step. If not, display “Invalid answer entered. Enter
Answer again.” and go to step 2.
5. If Ans=’Y’. Then go to the next step. If not, display “Do you want to display the number of
clients per category?” and go to step 28.
6. Display “Name: ”
7. Input Name.
8. Display “Account Number: ”
9. Input Acctnum.
10. Display “Deposit Balance: ”
11. Input Dep.
12. If Dep≥0. Then, save to hard disk Name, Acctnum, Dep and go to next step. If not, display
“Invalid deposit amount entered. Enter amount again” and go to step 11.
13. Display “Enter another set of data? (Y or N): ”
14. Input Ans.
15. If Ans=’Y’ or Ans=’N’. Then, go to the next step. If not, display “Invalid answer entered. Enter
Answer again.” and go to step 2.
16. If Ans=’Y’. Then go to step 6. If not, go to step 5.
17. If Dep≥0 and Dep≤50,000.00. Then, Ctr_50K=Ctr_50K+1 and go to step 22. If not, go to the
next step.
18. Is Dep≤100,000.00. Then, Ctr_100K=Ctr_100K+1 and go to step 22. If not, go to the next
step.
19. Is Dep≤500,000.00. Then, Ctr_500K=Ctr_500K+1 and go to step 22. If not, go to the next
step.
20. Is Dep≤1,000,000.00. Then, Ctr_1M=Ctr_1M+1 and go to step 22. If not, go to the next step.
21. Is Dep>1,000,000.00. Then, Ctr_A1M=Ctr_A1M+1 and go to the next step. If not, go to the
next step.
22. Display “Deposit Balance No. of Clients ”
23. Display “0.00 – 50,000.00 ”, Ctr_50K
24. Display “50,000.01 – 100,000.00 ”, Ctr_100K
25. Display “100,000.01 – 500,000.00 ”, Ctr_500K
26. Display “500,000.01 – 1,000,000.00 ”, Ctr_1M
27. Display “Above 1,000,000.00 ”, Ctr_A1M
28. Display “Do you want to print the data? (Y or N): ”
29. Input Ans.

88
Chapter 5: Flowcharts and Algorithms

30. If Ans=’Y’ or Ans=’N’. Then, go to the next step. If not, display “Invalid answer entered. Enter
Answer again.” and go to step 28.
31. If Ans=’Y’. Then, retrieve Client_data and go to the next step. If not, go to step 33.
32. Print Acctnum, Name, Dep.
33. End.

The variables used are the following:

Dep for Deposit


Acctnum for Account Number

Deposit Balance Variables

0.00 – 50,000.00 Ctr_50K (Counter for up to 50,000.00)


50,000.01 – 100,000.00 Ctr_100K (Counter for up to 100,000.00)
100,000.01 – 500,000.00 Ctr_500K (Counter for up to 500,000.00)
500,000.01 – 1,000,000.00 Ctr_1M (Counter for up to 1,000,000.00)
Above 1,000,000.00 Ctr_A1M (Counter for above 1,000,000.00)

The user is given choices regarding the activity to be performed. There are three (3) main
activities as mentioned in the problem. If the answer is no for all the activities the program is
terminated. If an activity is selected, the activity is performed.

The data entered is automatically saved. The counters will count for each of the categories until
the end of the file. Some programmers use EOF (End of File) in their programs. Each deposit
amount entered will be check and counted to the category it falls under. The same goes for
printing, it will print until the end of file.

One of the more difficult parts in designing and coding the program is the formulas to be used. A
counter is already a formula that we used but there are far more complex formulas than this. Let
us start of with an easy problem, a simple calculator problem.

Problem 15:
Create a design to allow the user to enter two numbers then select the operand to use. The
operands are: addition (+), subtraction (-), multiplication (x) and division (÷). The buttons are the
same as that of a calculator numbers and the four basic operations.

Flowchart:

Start

Num1=0
Num2=0
Total=0

89
Chapter 5: Flowcharts and Algorithms

Input Num1

Input Operand

Input Num2

Input Equal

Is Yes
Operand=’+’? Total=Num1+Num2

B
No

Is Yes
Operand=’-’? Total=Num1-Num2

B
No

Is Yes
Operand=’x’? Total=Num1*Num2

B
No

Is Yes
Operand=’÷’? Total=Num1/Num2

B
No
B

90
Chapter 5: Flowcharts and Algorithms

Display Total

End

Algorithm:
1. Set Num1=0, Num2=0, Total=0.
2. Input Num1.
3. Input Operand.
4. Input Num2.
5. Input Equal.
6. If Operand=’+’. Then, Total=Num1+Num2 and go to step 10. If not, proceed to the next step.
7. If Operand=’-’. Then, Total=Num1-Num2 and go to step 10. If not, proceed to the next step.
8. If Operand=’x’. Then, Total=Num1*Num2 and go to step 10. If not, proceed to the next step.
9. If Operand=’÷’. Then, Total=Num1/Num2 and go to the next step. If not, proceed to the next
step.
10. Display Total.
11. End.

The operand buttons of the calculator are defined this way but the actual program uses ‘*’ for
multiplication and ‘/’ for division. The equal is placed before the first decision block, since this
activates performance of the operation.

Problem 16 is simple but a long problem. This design will filter any negative number or characters
entered. It is a form of calculator that computes for the total amount of cash by multiplying the
quantity by the denomination.

Problem 16:
Create an algorithm and flowchart that will input the number of coins and bills. The program will
compute for the total amount of each denomination and will give the total of all the
denominations. It must display the number of each denomination, the total amount of each
denomination and the total amount of all the denominations.

Assume that the numbers entered are whole numbers

91
Chapter 5: Flowcharts and Algorithms

Flowchart:

Start

Five_c=0
Ten_c=0
Twentyfive_c=0
One_p=0
Five_p=0
Ten_p=0
Twenty_p=0
Fifty_p=0
One_hp=0
Two_hp=0
Five_hp=0
One_tp=0
Total_five_c=0
Total_ten_c=0
Total_twentyfive_c=0
Total_one_p=0
Total_five_p=0
Total_ten_p=0
Total_twenty_p=0
Total_fifty_p=0
Total_one_hp=0
Total_two_hp=0
Total_five_hp=0
Total_one_tp=0

Display “Number of
five centavo coins:”

92
Chapter 5: Flowcharts and Algorithms

Input Five_c

Is No Display “Invalid number of


Five_c≥0? five centavo coins entered.
Enter again.”

Yes
B
Display “Number of
ten centavo coins:”

Input Ten_c

Is No Display “Invalid number of


Ten_c≥0? ten centavo coins entered.
Enter again.”

Yes
D

Display “Number of
twenty-five centavo
coins:”

Input Twentyfive_c

93
Chapter 5: Flowcharts and Algorithms

Is No Display “Invalid number of


Twentyfive_c≥ twenty five centavo coins
0? entered. Enter again.”

Yes
D
Display “Number of
one peso coins:”

Input One_p

Is No Display “Invalid number of


One_p≥0? one peso coins entered.
Enter again.”

Yes

Display “Number of
five peso coins:”

Input Five_p

Is No Display “Invalid number of


Five_p≥0? five peso coins entered.
Enter again.”

Yes
E

94
Chapter 5: Flowcharts and Algorithms

Display “Number of
ten peso coins:”

Input ten_p

Is No Display “Invalid number of


Ten_p≥0? ten peso coins entered.
Enter again.”

Yes

Display “Number of
twenty peso bills:”

Input Twenty_p

Is No Display “Invalid number of


Twenty_p≥0? twenty peso bills entered.
Enter again.”

Yes
G

Display “Number of
fifty peso bills:”

Input Fifty_p

95
Chapter 5: Flowcharts and Algorithms

Is No Display “Invalid number of


Fifty_p≥0? fifty peso bills entered.
Enter again.”

Yes
G
Display “Number of
one hundred peso
bills:”

Input One_hp

Is No Display “Invalid number of


One_hp≥0? one hundred peso bills
entered. Enter again.”

Yes

Display “Number of
five hundred peso
bills:”

Input Five_hp

Is No Display “Invalid number of


Five_hp≥0? five hundred peso bills
entered. Enter again.”

Yes
H

96
Chapter 5: Flowcharts and Algorithms

Display “Number of
one thousand peso
bills:”

Input One_tp

Is No Display “Invalid number of


One_tp≥0? one thousand peso bills
entered. Enter again.”

Yes
Total_five_c=Five_c*.05

Total_ten_c=Ten_c*.1

Total_twentyfive_c=Twentyfive_c*.25

Total_one_p=One_p*1

Total_five_p=Five_p*5

Total_ten_p=Ten_p*10

Total_twenty_p=Twenty_p*20

97
Chapter 5: Flowcharts and Algorithms

I 1

Total_fifty_p=Fifty_p*50

Display “Twent-five
Centavos:”, Twenty_c,
Total_one_hp=One_hp*100 Total_twenty_c

Total_two_hp=Two_hp*200
Display “One Peso:”,
One_p, Total_one_p
Total_five_hp=Five_hp*500

Total_one_tp=One_tp*1,200 Display “Five Pesos:”,


Five_p, Total_five_p

Total=Total_five_c+Total_ten_c+
Total_twentyfive_c+Total_one_p+
Total_five_p+Total_ten_p+Total_
Display “Ten Pesos:”,
fifty_p+Total_one_hp+Total_two_hp
Ten_p, Total_ten_p
+Total_five_hp+Total_one_tp

Display Display “Twenty


“Denomination Pesos:”, Twenty_p,
Quantity Amount” Total_twenty_p

Display “Five
Centavos:”, Five_c, Display “Fifty Pesos:”,
Total_five_c Fifty_p, Total_fifty_p

Display “Ten I
Centavos:”, Ten_c,
Total_ten_c

98
Chapter 5: Flowcharts and Algorithms

I 2

Display “One Hundred Is Ans=’Y’


Pesos:”, One_hp, No
or
Total_one_hp Ans=’N’?

Display
Yes “Invalid entry!
Display “Two Hundred Enter again!”
Pesos:”, Two_hp,
Total_two_hp

Is Yes
Ans=’Y’? B

Display “Five Hundred No


Pesos:”, Five_hp,
Total_five_hp End

Display “One
Thousand Pesos:”,
One_tp, Total_one_tp

Display “Total
Amount:”, Total

Display “Enter
another? (‘Y’ or ‘N’):”

Input Ans

99
Chapter 5: Flowcharts and Algorithms

Algorithm:
1. Set Five_c=0, Ten_c=0, Twentyfive_c=0, One_p=0, Five_p=0, Ten_p=0, Twenty_p=0,
Fifty_p=0, One_hp=0, Two_hp=0, Five_hp=0, One_tp=0, Total_five_c=0, Total_ten_c=0,
Total_twentyfive_c=0, Total_one_p=0, Total_five_p=0, Total_ten_p=0, Total_ten_p=0,
Total_twenty_p=0, Total_fifty_p=0, Total_one_hp=0, Total_two_hp=0, Total_five_hp=0,
Total_one_tp=0, Total=0.
2. Display “Number of five centavos coins:”.
3. Input Five_c.
4. If Five_c≥0, then go to the next step. If not, display “Invalid number of five centavo coins
entered. Enter again.” and go to step 2.
5. Display “Number of ten centavos coins:”.
6. Input Ten_c.
7. If Ten_c≥0, then go to the next step. If not, display “Invalid number of ten centavo coins
entered. Enter again.” and go to step 5.
8. Display “Number of twenty-five centavos coins:”.
9. Input Twentyfive_c.
10. If Twentyfive_c≥0, then go to the next step. If not, display “Invalid number of twenty-five
centavo coins entered. Enter again.” go to step 8.
11. Display “Number of one peso coins:”.
12. Input One_p.
13. If One_p≥0, then go to the next step. If not, display “Invalid number of one peso coins
entered. Enter again.” and go to step 11.
14. Display “Number of five peso coins:”.
15. Input Five_p.
16. If Five_p≥0, then go to the next step. If not, display “Invalid number of five peso coins
entered. Enter again.” and go to step 14.
17. Display “Number of ten peso coins:”.
18. Input Ten_p.
19. If Ten_p≥0, then go to the next step. If not, display “Invalid number of ten peso coins entered.
Enter again.” and go to step 17.
20. Display “Number of twenty peso bills:”.
21. Input Twenty_p.
22. If Twenty_p≥0, then go to the next step. If not, display “Invalid number of twenty peso bills
entered. Enter again.” and go to step 20.
23. Display “Number of fifty peso bills:”.
24. Input Fifty_p.
25. If Fifty_p≥0, then go to the next step. If not, display “Invalid number of fifty peso bills entered.
Enter again.” and go to step 23.
26. Display “Number of one hundred peso bills:”.
27. Input One_hp.
28. If One_hp≥0, then go to the next step. If not, display “Invalid number of one hundred peso
bills entered. Enter again.” and go to step 26.
29. Display “Number of two hundred peso bills:”.
30. Input Two_hp.
31. If Two_hp≥0, then go to the next step. If not, display “Invalid number of two hundred peso
bills entered. Enter again.” and go to step 29.
32. Display “Number of five hundred peso bills:”.
33. Input Five_hp.
34. If Five_hp≥0, then go to the next step. If not, display “Invalid number of five hundred peso
bills entered. Enter again.” and go to step 32.
35. Display “Number of one thousand peso bills:”.
36. Input One_tp.
37. If One_tp≥0, then go to the next step. If not, display “Invalid number of one thousand peso
bills entered. Enter again.” go to step 35.
38. Total_five_c=Five_c*0.05.
39. Total_ten_c=Ten_c*0.1.

100
Chapter 5: Flowcharts and Algorithms

40. Total_twentyfive_c=Twentyfive_c*0.25.
41. Total_one_p=One_p*1.
42. Total_five_p=Five_p*5.
43. Total_ten_p=Ten_p*10.
44. Total_twenty_p=Twenty_p*20.
45. Total_fifty_p=Fifty_p*50.
46. Total_one_hp=One_hp*100.
47. Total_two_hp=Two_hp*200
48. Total_five_hp=Five_hp*500.
49. Total_one_tp=One_tp*1,000.
50. Total=Total_five_c+Total_ten_c+Total_twentyfive_c+Total_one_p+Total_five_p+Total_ten_p
+Total_twenty_p+Total_fifty_p+Total_one_hp+Total_two_hp+Total_five_hp+Total_one_tp.
51. Display “Denomination Quantity Amount”.
52. Display “Five Centavos:”, Five_c, Total_five_c.
53. Display “Ten Centavos:”, Ten_c, Total_ten_c.
54. Display “Twenty-five Centavos:”, Twentyfive_c, Total_twentyfive_c.
55. Display “One Peso:”, One_p, Total_one_p.
56. Display “Five Pesos:”, Five_p, Total_five_p.
57. Display “Ten Peso Coin:”, Ten_pc, Total_ten_p.
58. Display “Twenty Pesos:”, Twenty_p, Total_twenty_p.
59. Display “Fifty Pesos:”, Fifty_p, Total_fifty_p.
60. Display “One Hundred Pesos:”, One_hp, Total_one_hp.
61. Display “Two Hundred Pesos:”, Two_hp, Total_two_hp.
62. Display “Five Hundred Pesos:”, Five_hp, Total_five_hp.
63. Display “One Thousand Pesos:”, One_tp, Total_one_tp.
64. Display “Total Amount:”, Total
65. Display “Enter another set of data? (‘Y’ or ‘N’):”.
66. Input Answer, call it Ans.
67. If Ans equals ‘Y’ or ‘N’ then go to the next step. If not, display “Invalid answer entered. Enter
again.” and go to the step 65.
68. If Ans equals ‘Y’ then go to the step 2. If not go to the next step.
69. End.

The next problem reflects the reality that the salary increase of an employee is dependent on the
performance for the year. Problem 17 is a sample of how rating affects the salary of an employee.
The computation of the rate of increase is relatively easy and is applicable in other situations as
well.

Problem 17:
Create an algorithm and flowchart that will input the employee name, department where the
employee is under, current salary, and performance rating. The program must compute for the
new salary with the rate of increase dependent on the performance rating.

Performance Rating Rate of Increase

92% - 100% 12%


84% - 91% 10%
76% - 83% 8%
68% - 75% 5%
60% - 67% 0%

It must have an output printing the new employee name, department, performance rating, and
new salary. It must reject any performance rating of more than 100% and less than 60%.

101
Chapter 5: Flowcharts and Algorithms

Flowchart:

Start

Rating=0
Sal=0
Nsal=0

Display “Employee
Name:”

Input Name

Display “Department:”

Input Dept

Display “Current
Salary:”

Input Sal

Display “Rating:”

Input Rating

102
Chapter 5: Flowcharts and Algorithms

Is Rating≥92 Yes
and Nsal=Sal+(Sal*0.12)
Rating≤100?

B
No

Is Yes
Rating≥84? Nsal=Sal+(Sal*0.10)

B
No

Is Yes
Rating≥76? Nsal=Sal+(Sal*0.8)

B
No

Is Yes
Rating≥68? Nsal=Sal+(Sal*0.05)

B
No

Is No Display “Invalid
Rating≥60? performance rating
entered! Enter data again!”

Yes
B C

103
Chapter 5: Flowcharts and Algorithms

Save Name, Dept,


Rating, Sal, Nsal

Employee_Rec

Display “Enter
another set of
data? (‘Y’ or ‘N’):”

Input Ans

Is Ans=’Y’ Yes Display “Invalid entry! Enter


or again!”
Ans=’N’?

Yes

Is Yes
Ans=’Y’? C

No E

Display “Do you


want to print the
data? (‘Y’ or ‘N’):”

104
Chapter 5: Flowcharts and Algorithms

Is Ans=’Y’ Yes Display “Invalid entry! Enter


or
again!”
Ans=’N’?

Is Yes Employee_Rec
Ans=’Y’?

No

End
Print “Employee
Name:”, Name,
“Department:”, Dept,
“Rating:”, Rating, “New
Salary:”, Nsal

Algorithm:
1. Set Rating=0, Current Sal=0, and Nsal=0.
2. Display “Employee Name:”.
3. Input Employee Name, call it Name.
4. Display “Department:”.
5. Input Department, call it Dept.
6. Display “Current Salary:”.
7. Input Sal.
8. If Sal is greater than 0, go to the next step. If not go to step 6.
9. Display “Rating:”
10. Input Rating.
11. If Rating≤100% and Rating≥92%, then compute Nsal=Sal+(Sal*0.12) and go to step 16. If
not go to the next step.
12. If Rating≥84%, then compute Nsal=Sal+(Sal*0.10) and go to step 16. If not go to the next
step.
13. If Rating≥76%, then compute Nsal=Sal+(Sal*0.08) and go to step 16. If not go to the next
step.
14. If Rating≥68%, then compute Nsal=Sal+(Sal*0.05) and go to step 16. If not go to the next
step.
15. If Rating≥60%, then and go to the next step. If not display “Invalid performance rating
entered! Enter again!” and go to step 2.
16. Save to hard disk Name, Dept, Rating, Sal, NSal as Employee_Rec.
17. Display “Enter another set of data? (‘Y’ or ‘N’):”
18. Input Answer, Ans.
19. If Ans=’Y’ or Ans=’N’, then go to the next step. If not, display “Invalid entry! Enter again!”.
20. If Ans=‘Y’, then go back to step 2. If not, go to the next step.

105
Chapter 5: Flowcharts and Algorithms

21. Display “Do you want to print the data? (‘Y’ or ‘N’):”
22. Input Answer, Ans.
23. If Ans=’Y’ or Ans=’N’, then go to the next step. If not, display “Invalid entry! Enter again!”.
24. If Ans=‘Y’, then go to the next step. If not go to step 27.
25. Retrieve Employee_Rec from hard disk.
26. Print “Employee Name:”, Name, “Department:”, Dept, “Rating:”, Rating, “New Salary:”, Nsal.
27. End.

Another way of writing the formula for problem 17 is Nsal=Sal*1.12 for a salary increase of 12%,
Nsal=Sal*1.10 for a salary increase of 10% and so on. This will yield the same answer.

Problem 18 is the opposite of problem 17. We are to compute for the discount. But in this case
the printing is not optional anymore. Upon purchase the discount and the amount to be paid is
computed and printed right away.

Problem 18:
Create a program design that will input the customer, date, and the amount of purchase. Below
are the range of amount and the corresponding discount.

Amount Discount

P100,000.00 and above 20%


80,000.00 – 99,999.99 16%
60,000.00 – 79,999.99 12%
40,000.00 – 59,999.99 9%
20,000.00 – 39,999.99 5%
0.00 – 19,999.99 0%

The program must compute the amount of discount and the amount to be paid by the customer.
It must print the name, date, amount of purchase, discount, and the amount to be paid.

Flowchart:

Start

Purchase=0
Disc=0
Amount=0

Display “Customer:”

Input Name

106
Chapter 5: Flowcharts and Algorithms

Display “Date:”

Input Date

Display “Amount of
Purchase:”

Input Purchase

Is Purchase>0 .00 Yes


and Purchase< Disc=0
20,000.00?

C
No

Is Purchase Yes
<40,000.00? Disc=Purchase*0.05

No C

Is Purchase< Yes
60,000.00? Disc=Purchase*0.09

Is Purchase Yes
<80,000.00? Disc=Purchase*0.12

No C

107
Chapter 5: Flowcharts and Algorithms

B
No

Is Purchase< Yes
100,000.00? Disc=Purchase*0.16

No 1

Is Purchase≥ No
Display “Invalid
100,000.00?
amount of purchase
entered! Enter again!”
Yes
Disc=Purchase*0.2
C 1 D

Amount=Purchase-Disc

Save Date, Name,


Purchase, Disc, Amount

Transaction

Print “Date:”, Date

Print “Customer:”, Name

Print “Amount of
Purchase:”, Purchase

Print “Discount:”, Disc

108
Chapter 5: Flowcharts and Algorithms

Print “Amount to be
Paid:”, Amount

Display “Enter
another set of
data? (‘Y’ or ‘N’):”

Input Ans

Is Ans=’Y’ No Display “Invalid


or answer entered!
Ans=’N’? Enter again!”

Yes

Yes
Is
Ans=’Y’? D

No

End

Algorithm:
1. Set Purchase=0, Disc=0, Amount=0.
2. Display “Customer:”.
3. Input Name.
4. Display “Date:”.
5. Input Date.
6. Display “Amount of Purchase:”.
7. Input Purchase.
8. If Purchase>0 and Purchase<20,000, then Disc=0 and go to step 15. If not go to the next
step.
9. If Purchase<40,000, then Disc= Purchase*0.05 and go to step 15. If not go to the next step.
10. If Purchase<60,000, then Disc= Purchase*0.09 and go to step 15. If not go to the next step.
11. If Purchase<80,000, then Disc= Purchase*0.12 and go to step 15. If not go to the next step.
12. If Purchase<100,000, then Disc= Purchase*0.16 and go to step 15. If not go to the next step.
13. If Purchase≥100,000, then Disc= Purchase*0.2 and go to step 15. If not, go to the next step.
14. Display “Invalid amount of purchase entered! Enter data again!” and go to step 2.

109
Chapter 5: Flowcharts and Algorithms

15. Amount= Purchase-Disc


16. Save Date, Name, Purchase, Disc, Amount to hard disk as Transaction.
17. Print “Date:”, Date.
18. Print “Customer:”, Name.
19. Print “Amount of Purchase:”, Purchase.
20. Print “Discount:”, Disc.
21. Print “Amount to be Paid:”, Amount.
22. Display “Enter another set of data? (‘Y’ or ‘N’):”
23. Input Answer, call it Ans.
24. If Ans=‘Y’ or Ans=‘N’, then go to the next step. If not, display “Invalid answer entered. Enter
again.” go to step 21.
25. If Ans=‘Y’ go to step 2. If not go to the next step.
26. End.

The next problem is combining the different types of formula that have been taken up so far.
Problem 19 is similar to problem 19.

Problem 19:
Create a program design for a hospital that will input the date, patient’s name, address, room
classification, length of stay of the patient (in days), doctor’s fee, Philhealth deduction and
medical bill. The program must compute for the hospital bill. The room classification and
corresponding rates are given below:

Room Classification Room Rates (per day)

1 1,200
2 900
3 650
4 450
5 200

The program will print the patient’s name, address, room bill, doctor’s fee, medical bill, philhealth
deduction and hospital bill. Assume that there will be no changes in room classification of the
patient and there will only be on doctor to attend to the patient.

Flowchart:

Start 1
G

Display “Patient
Room=0 Name:”
Days=0
Rbill=0
Dfee=0
Mbill=0 Input Name
Phealth=0
Hbill=0
A

110
Chapter 5: Flowcharts and Algorithms

Display “Address:”

Input Add

Display “Room
Classification:”

Input Room

Is Yes
Rbill=1,200*Days
Room=1?

No C

Is Yes Rbill=900*Days
Room=2?

No C

Is Yes
Rbill=650*Days
Room=3?

No C

Is Yes Rbill=450*Days
Room=4?

No C
B

111
Chapter 5: Flowcharts and Algorithms

Is No Display “Invalid room


Room=5? entered. Enter again.”

Yes
Rbill=200*Days 2

Display “Length of
Stay:”

Input Days

No
Is Display “Invalid number of
Days≥1? days entered. Enter again.”

Yes

Display “Doctor’s
Fee:”

Input Dfee

Is No
Dfee≥0? Display “Invalid doctor’s fee
entered. Enter again.”

Yes E

Display “Medical Bill:”

112
Chapter 5: Flowcharts and Algorithms

Input Mbill

Is No Display “Invalid medical bill


Mbill≥0? entered. Enter again.”

Yes
E
Display “Philhealth
Deduction:”, Philhealth

Is Display “Invalid Philhealth


Philhealth≥0? deduction entered. Enter
again.”

Hbill=Rbill+Dfee+Mbill-Philhealth

Print “Date:”, Date

Print “Name:”, Name

Print “Address:”, Add

Print “Room Bill:”, Rbill

Print “Doctor’s Fee:”, Dfee

113
Chapter 5: Flowcharts and Algorithms

Print “Medical Bill:”, Mbill

Print “Philhealth Deduction:”,


Philhealth

Print “Hospital Bill:”, Hbill

Save Date, Name, Address, Rbill,


Dfee, Mbill, Philhealth, Hbill

Hosp_Rec

Display “Enter another


set of data? (‘Y’ or ‘N’):”

Input Ans

Is Ans=’Y’ Display “Invalid entry! Enter


No
or again!”
Ans=’N’?

Yes

Is Yes
Ans=’Y’? G

No
End

114
Chapter 5: Flowcharts and Algorithms

Algorithm:
1. Set Room=0, Days=0, Rbill=0, Dfee=0, Mbill=0, Philhealth=0, Hbill=0.
2. Display “Patient Name:”.
3. Input Patient’s Name, call it Name.
4. Display “Address:”.
5. Input Address, call it Add.
6. Display “Room Classification:”.
7. Input Room.
8. If Room=1, then Rbill=1,200*Days and go to step 13. If not, go to the next step.
9. If Room=2, then Rbill=900*Days and go to step 13. If not, go to the next step.
10. If Room=3, then Rbill=650*Days and go to step 13. If not, go to the next step.
11. If Room=4, then Rbill=450*Days and go to step 13. If not, go to the next step.
12. If Room=5, then Rbill=200*Days and go to the next step. If not display “Invalid room
classification entered! Enter data again!” and go to step 6.
13. Display “Length of Stay (in Days):”.
14. Input Days.
15. If Days≥1 then go to the next step. If not, display “Invalid number of days entered. Enter
again.” and go to step 13.
16. Display “Doctor’s Fee:”.
17. Input Dfee.
18. If Dfee≥0, then go to the next step. If not, display “Invalid number of days entered. Enter
again.” and go to step 16.
19. Display Medical Bill:”.
20. Input Mbill.
21. If Mbill≥0, then go to the next step. If not, display “Invalid number of days entered. Enter
again.” and go to step 19.
22. Display Philhealth Duduction:”.
23. Input Philhealth.
24. If Philhealth≥0, then go to the next step. If not, display “Invalid number of days entered. Enter
again.” and go to step 22.
25. Hbill=Rbill+Dfee+Mbill-Philhealth
26. Print “Date:”, Date
27. Print “Name:”, Name.
28. Print “Address:”, Add.
29. Print “Room Bill:”, Rbill.
30. Print “Doctor’s Fee:”, Dfee.
31. Print “Medical Bill:”, Mbill.
32. Print “Philhealth Deduction:”, Philhealth.
33. Print “Hospital Bill:”, Hbill.
34. Save Date, Name, Address, Rbill, Dfee, Mbill, Philhealth, Hbill to Hosp_Rec
35. Display “Enter another set of data? (‘Y’ or ‘N’):”
36. Input Ans.
37. If Ans=‘Y’ or Ans=‘N’ then go to the next step. If not, display “Invalid entry! Enter again!” go
to step 35.
38. If Ans=‘Y’ then go to the step 2. If not go to the next step.
39. End.

Problem 20 will be branching out into two (2) categories the old and the new students. This is a
computation regarding the tuition fees where the increase in tuition fee is different from old
students and new students.

Problem 20:
Enter the student’s name, year level of the current school year and entry status (O = old students,
N = new students or transferees). The program must compute for the new tuition fee using 10%
increase for old and 12% increase for new/transferee students. The output will print the name,
year level and new tuition fee.

115
Chapter 5: Flowcharts and Algorithms

Year Level Current Tuition Fee

1 10,000
2 9,000
3 8,000
4 7,000
5 6,000

Miscellaneous fee is P1,500.00 and Laboratory fee is P1,000.00 for all students. Reject any
invalid year level and entry status entered. And ask if the user wants to enter additional data.

Flowchart:

Start

Level=0
Nfee=0

Input Name,
Status, Level,

Is
Status=’N’ or No Display “Invalid entry!
Status=’O’? Enter again!”

Yes

Is No
Status= B
’New’?

Yes
A

116
Chapter 5: Flowcharts and Algorithms

Is Yes
Level=1? Nfee=(10,000*0.10)+10,000+1,500+1,000

No C

Is Yes
Level=2? Nfee=(9,000*0.10)+9,000+1,500+1,000

No C

Is Yes
Level=3? Nfee=(8,000*0.10)+8,000+1,500+1,000

C
No

Is Yes
Level=4? Nfee=(7,000*0.10)+7,000+1,500+1,000

C
No

Is Yes
Level=5? Nfee=(6,000*0.10)+6,000+1,500+1,000

C
No
D

Is Yes
Level=1? Nfee=(10,000*0.12)+10,000+1,500+1,000

No C

117
Chapter 5: Flowcharts and Algorithms

Is Yes
Level=2? Nfee=(9,000*0.12)+9,000+1,500+1,000

C
No

Is Yes
Level=3? Nfee=(8,000*0.12)+8,000+1,500+1,000

C
No

Is Yes
Level=4? Nfee=(7,000*0.12)+7,000+1,500+1,000

C
No D

Is No Display “Invalid year level


Level=5? entered! Enter again!”

Yes
F
Nfee=(6,000*0.12)+6,000+1,500+1,000

C
Save Name, Status,
Level, Nfee

Student_Tuition
Display “Enter another
set of data? (‘Y’ or ‘N’):”

Print “Name:”, Name,

Print “Year Level:”,


Level

118
Chapter 5: Flowcharts and Algorithms

Print “Tuition Fee:”,


Nfee

Display “Enter
another? (‘Y’ or ‘N’): ”

Input Ans

Is Ans=’Y’ No Display “Invalid entry! Enter


or again!”
Ans=’N’?

Yes

Is Yes
Ans=’Y’? F

No

End

The above solution is simple but long it is also not flexible in the sense that the miscellaneous
and laboratory fees have been included in the formula but nevertheless it still works. The design
should be flexible to minimize reprogramming the system for large programs especially. Another
way of presenting the solution is:

119
Chapter 5: Flowcharts and Algorithms

Start 1

Display “Enter Tuition


Level=0,Level1=0 for Fourth Year:”
Level2=0, Level3=0
Level4=0, Level5=0
Misc=0, Lab=0
Nfee=0, N_Rate=0
O_Rate=0, Rate=0 Input Level4

Display “Enter Tuition


for Fifth Year:”
Display “Enter Tuition
for First Year:”

Input Level5
Input Level1

Display “Enter
Miscellaneous Fee:”
Display “Enter Tuition
for Second Year:”

Input Misc
Input Level2

Display “Enter
Laboratory Fee:”
Display “Enter Tuition
for Third Year:”

Input Lab
Input Level3

Display “Enter Rate for


1 Old Students:”

120
Chapter 5: Flowcharts and Algorithms

Input O_Rate

Display “Enter Rate for


New Students:”

Input N_Rate

Save Level1, Level2, Level3, Level4,


Level5, Misc, Lab, O_Rate, N_Rate

Fees

Display “Enter Name:”

Input Name

Display “Enter Year Level:”

Input Level

Display “Enter Status


(N=New or O=Old:”

Input Status

121
Chapter 5: Flowcharts and Algorithms

Is
Status=’N’ or No Display “Invalid entry!
Status=’O’? Enter again!”

Yes C

Is No
Ans=’N’? Rate=O_Rate

Yes
Rate=N_Rate

Is Yes
Level=1? Nfee=(Level1*Rate)+Level1+Misc+Lab

E
No

Is Yes
Level=2? Nfee=(Level2*Rate)+Level2+Misc+Lab

E
No

Is Yes
Level=3? Nfee=(Level3*Rate)+Level3+Misc+Lab

E
No

Is Yes
Level=4? Nfee=(Level4*Rate)+Level4+Misc+Lab

E
No
D

122
Chapter 5: Flowcharts and Algorithms

Is No Display “Invalid entry!


Level=5? Enter again!”

Yes
F
Nfee=(Level5*Rate)+Level5+Misc+Lab
E
Save Name, Level, Status,
Nfee

Student_Fees

Print “Name:”, Name

Print “Year Level:”, Level

Print “Tuition Fee:”,


Nfee

Display “Enter
another? (‘Y’ or ‘N’): ”

Input Ans

123
Chapter 5: Flowcharts and Algorithms

Is Ans=’Y’ No Display “Invalid entry! Enter


or again!”
Ans=’N’?

Yes H

Is Yes
Ans=’Y’? F

No

End

Algorithm:
1. Set Level=0, Level1=0, Level2=0, Level3=0, Level4=0, Level5=0, Misc=0, Lab=0, Nfee=0,
N_Rate=0, O_Rate=0, Rate=0.
2. Display “Enter Tuition for First Year:”
3. Input Level 1.
4. Display “Enter Tuition for Second Year:”
5. Input Level2.
6. Display “Enter Tuition for Third Year:”
7. Input Level3.
8. Display “Enter Tuition for Fourth Year:”
9. Input Level4.
10. Display “Enter Tuition for Fifth Year:”
11. Input Level5.
12. Display “Enter Miscellaneous Fee:”
13. Input Misc
14. Display “Enter Laboratory Fee:”
15. Input Lab
16. Display “Enter Rate for Old Students:”
17. Input O_Rate.
18. Display “Enter Rate for New Students:”
19. Input N_Rate.
20. Save to hard disk Level1, Level2, Level3, Level4, Level5, Misc, Lab, O_Rate, N_Rate as
Fees.
21. Display “Enter Name:”
22. Input Name.
23. Display “Enter Year Level:”
24. Input Level.
25. Display “Enter Status (N=New or O=Old:”
26. Input Status.
27. If Status=’N’ or Status=’O’. Then, go to the next step. If not, display “Invalid entry! Enter
again!” and go to step 25.
28. If Ans=’N’. Then, Rate=N_Rate. If not, Rate=O_Rate.

124
Chapter 5: Flowcharts and Algorithms

29. If Level=1. Then, Nfee=(Level1*Rate)+Level1+Misc+Lab and go to step 34. If not, go to the


next step.
30. If Level=2. Then, Nfee=(Level2*Rate)+Level2+Misc+Lab and go to step 34. If not, go to the
next step.
31. If Level=3. Then, Nfee=(Level3*Rate)+Level3+Misc+Lab and go to step 34. If not, go to the
next step.
32. If Level=4. Then, Nfee=(Level4*Rate)+Level4+Misc+Lab and go to step 34. If not, go to the
next step.
33. If Level=5. Then, Nfee=(Level1*Rate)+Level5+Misc+Lab and go to the next step. If not,
display “Invalid entry! Enter again!” go to 21.
34. Save to hard disk Name, Level, Status, Nfee as Student_Fees.
35. Print “Name:”, Name.
36. Print “Year Level:”, Level.
37. Print “Tuition Fee:”, Nfee.
38. Display “Enter another? (‘Y’ or ‘N’): “.
39. If Ans=‘Y’ or Ans=’N’, then go to the next step. If not, display “Invalid entry! Enter again!” and
go to step 38.
40. If Ans=‘Y’, then go to step 21. If not, go to the next step.
41. End.

Enter first the data that will be used over-and-over like the rate (for old and new students), tuition
fee for the different year levels, miscellaneous and laboratory fees. For future use the user can
input a different set of fees to use for the following school year. The rate of increase can also be
changed if desired. Then the data is saved in a file called Fees. Then the entries are made for
name, year level and status. The rate can pick up either of the two rate of increase. We substitute
one of them to use in the formula.

Problem 21:
Create a design that will input the temperature in degrees Celsius (oC) or degrees Fahrenheit (oF)
and display the converted equivalent of the temperature.

Start 1
B

Temp=0
Cel=0 Display “Enter ‘C’ for
Fah=0 Celsius or ‘F’ for
Conv=0 Fahrenheit:”

Display “Enter
Temperature to convert:” Input Unit

A
Input Temp

125
Chapter 5: Flowcharts and Algorithms

Is Unit=’C’ No Display “Invalid entry! Enter


or
again!”
Unit=’F’?

Yes
B

Is No
Unit= Cel=(Temp*9/5)+32
’C’?

Conv=Cel
Yes
Fah=(Temp-32)*5/9

Conv=Fah

Display “The equivalent


temperature of ”, Temp, “o”,
Unit, “is:”, Conv

End

126

You might also like