Professional Documents
Culture Documents
3 What is a flowchart? Draw and explain the standard symbols used in flowchart.
Answer:
A flowchart diagrammatic representation of the steps required to complete a task and the order that
they are to be performed.
Standard flowchart symbols:
Begin/End
Terminator flowchart symbols are used at the beginning and end of each flowchart.
Process
Process flowchart symbols are used to show actions, for example, when values are assigned to
variables.
2
Decision
Decision flowchart symbols are used to decide which action is to be taken next.
Flow lines
Flowchart flow lines use arrows to show the direction of flow, which is usually, but not always, top to
bottom and left to right.
4 What is pseudocode? State different types of statements used in pseudocode and give example of
each.
Answer:
Pseudocode is a method of showing an algorithm that describes what the algorithm does by using
English key words that are very similar to those used in a high-level programming language.
Assignment statement
A value is assigned to an item/variable using the ← operator. The variable on the left of the ← is
assigned the value of the expression on the right.
Examples of pseudocode assignment statements:
Cost ← 10 Cost has the value 10
Price ← Cost * 2 Price has the value 20
Selection/conditional statement
There are two types of conditional statement:
(a) a condition that can be true or false such as: IF … THEN … ELSE … ENDIF
Example:
IF Age < 18
THEN
OUTPUT "Child"
ELSE
OUTPUT "Adult"
ENDIF
(b) a choice between several different values, such as: CASE OF … OTHERWISE … ENDCASE
Example:
CASE OF Grade
"A" : OUTPUT "Excellent"
"B" : OUTPUT "Good"
"C" : OUTPUT "Average"
OTHERWISE OUTPUT "Improvement is needed"
ENDCASE
Looping/iteration/repetition statement
Pseudocode includes these three different types of loop structure:
A set number of repetitions FOR … TO … NEXT
A repetition, where the number of repeats is not known, that is
REPEAT … UNTIL
completed at least once:
A repetition, where the number of repeats is not known, that may
WHILE … DO …ENDWHILE
never be completed:
6 Write an algorithm in the form of pseudocode that inputs 100 numbers and outputs the total of the
numbers.
Answer:
Total ← 0
FOR Counter ← 1 TO 100
INPUT Num
Total ← Total + Num
NEXT Counter
OUTPUT “Total of the numbers is:”, Total
7 Write an algorithm in the form of pseudocode that inputs 100 numbers and outputs the average of
the numbers.
Answer:
Total ← 0
FOR Counter ← 1 TO 100
INPUT Num
Total ← Total + Num
NEXT Counter
Avg ← Total / 100
OUTPUT “Average of the numbers is:”, Avg
8 Write an algorithm in the form of pseudocode that inputs 100 numbers and outputs the number of
positive numbers and the number of negative numbers.
Answer:
PosCount ← 0
NegCount ← 0
FOR Counter ← 1 TO 100
INPUT Num
IF Num > 0
THEN
PosCount ← PosCount + 1
ELSE
IF Num > 0
THEN
NegCount ← NegCount + 1
ENDIF
ENDIF
NEXT Counter
OUTPUT “Number of positive numbers is:”, PosCount
OUTPUT “Number of negaitive numbers is:”, NegCount