9.1 AS Loops

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

About the developer of this workbook

Inqilab Patel is an O & A Level Computer Teacher. Currently he is teaching A & O Level Computer Science
at The City School PAF Chapters, Hira Foundation School and Intellect. He has taught in many other
schools including Yaqeen Model School, Karachi Cadet School, KN Academy, Hexis A Level, Verge and
Nakhlah Boys Campus Society. Cambridge has selected him as a Member of Cambridge Editorial
Review Board. He is also associated with Aga Khan University Examination Board in the capacity of
Chief Examiner, Item Writer, E-Marker, Karachi Board of Secondary Education the capacity of
Deputy Head Examiner and Sindh Board of Technical Education.

His entire career path revolves around computer science; either he was a student or a teacher.
He got a chance to polish his skills of teaching and studying more about computers at various
levels which has given him great confidence in presenting himself for any senior level position of
transferring his knowledge to the youth.

He has not stopped; he is continuing with his education at the higher levels. It is his second
semester of MPhil computer studies from a well-known university of Pakistan; The Institute of
Business & Technology.

Inqilab Patel knows a lot of methods of teaching computers and has developed tutorial notes,
worksheets and assignments for my students. He also maintains a website
(www.inqilabpatel.com) which is specifically designed for the support of those who want to excel
in GCSE computer science. He also regularly contributes material to CIE teacher support website,
for which he receives appreciation from different people across the world.

He has also received various training in innovative and special methods of teaching this subject.

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Control Construct: Loop
Iteration is used to execute a set of instructions multiple times. It is also referred as LOOP or ITERATION.
In the following example statement number ii will be executed 10 times:
Problem: Print the name of Allah 10 times.

LOOPING STATEMENTS:
1. FOR TO NEXT: Count Controlled loop
2. REPEAT UNTIL : Post Condition loop
3. WHILE DO ENDWHILE: Pre-Condition Loop
Count-controlled (FOR) loops
a count-controlled loop that is executed a set number of time.
It is written as follows:

<statement(s)>
NEXT <identifier>
The identifier must be a variable of data type INTEGER, and the values should be expressions that
evaluate to integers.
The variable is assigned each of the integer values from value1 to value2 inclusive, running the
statements inside the FOR loop after each assignment. If value1 = value2 the statements will be
executed once, and if value1 > value2 the statements will not be executed.
It is good practice to repeat the identifier after NEXT, particularly with nested FOR loops. An
increment can be specified as follows:

<statement(s)>
NEXT <identifier>
The increment must be an expression that evaluates to an integer. In this case the identifier will be as
signed the values from value1 in successive increments of increment until it reaches value2. If it goes
past value2, the loop terminates. The increment can be negative.
Example – nested FOR loops

NEXT Column
OUTPUT "Total for Row ", Row, " is ", RowTotal

NEXT Row
OUTPUT "The grand total is ", Total

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Post-condition (REPEAT) loops
Post-condition loops are written as follows:
REPEAT
<Statement(s)>
UNTIL <condition>
The condition must be an expression that evaluates to a Boolean.
The statements in the loop will be executed at least once. The condition is tested after the statements
are executed and if it evaluates to TRUE the loop terminates, otherwise the statements are executed
again.
Example – REPEAT UNTIL statement
REPEAT
OUTPUT "Please enter the password"
INPUT Password
UNTIL Password = "Secret"
Pre-condition (WHILE) loops
WHILE is a pre-condition loop, that executes a block of statements repeatedly until given condition is
True. It is written as follows:
WHILE <condition>
<statement(s)>
ENDWHILE
The condition must be an expression that evaluates to a Boolean.
The condition is tested before the statements, and the statements will only be executed if the
condition evaluates to TRUE. After the statements have been executed the condition is tested again.
The loop terminates when the condition evaluates to FALSE.
The statements will not be executed if, on the first test, the condition evaluates to FALSE.

WHILE Number > 9


9
ENDWHILE

Problem: Input daily wages and number of day worked and output monthly pay for 100 employees.

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Problem: Input marks of a student in a class output result. Passing marks is 40

Problem: Input marks of 30 students in a class output result of each student. Passing marks is 40

Problem: Print name of Allah 10 times

Flowchart of pre-condition and post condition loops


Problem: Print name of Allah 10 times using all types of loops

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Pre-Condition Loop:
When condition to continue the loop is given

problem: To input and add a series of positive numbers in total. Continue this process for input of
positive numbers
WHILE

Problem: Input a number, calculate and output


sum of digits.

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Post-Condition
When condition is given at the end of loop

Problem: Input a series of numbers, calculate their total, stop input if total is more than 100
REPEAT UNTIL Loop

Differences between
Pre-Condition Post Condition

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
3c 9618 S22 P23
1 (a) The following table contains pseudocode examples.
Each example may include all or part of:
• selection
• iteration (repetition)
• assignment.
Complete the table by placing one or more ticks ( ) in each row. [5]
Pseudocode example Selection Iteration Assignment
FOR Index 1 TO 3
Safe[Index] GetResult()
NEXT Index
OTHERWISE : OUTPUT "ERROR 1202"
REPEAT UNTIL Index = 27
INPUT MyName
IF Mark > 74 THEN
Grade 'A'
ENDIF

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


9618 Paper
(c) Write in pseudocode a post-condition loop to output all the odd numbers between 100 and 200.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]

9618 S21 P21


(c) A program will:
• input 50 unique integer values
• output the largest value
• output the average of the values excluding the largest value.
Draw a program flowchart to represent the algorithm. Variable declarations are not required.
It is not necessary to check that each input value is unique. [6]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Summer 21 P22
4 A teacher uses a paper-based system to store marks for a class test. The teacher requires a
program to assign grades based on these results.
The program will output the grades together with the average mark.
Write a detailed description of the algorithm that will be needed.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Winter 21 P22
2 (a) An algorithm will:
1. input an integer value
2. jump to step 6 if the value is zero
3. sum and count the positive values
4. sum and count the negative values
5. repeat from step 1
6. output the two sum values and the two count values.
Draw a program flowchart on the following page to represent the algorithm.
Note that variable declarations are not required in program flowcharts. [5]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/
COMPUTER SCIENCE WITH INQILAB PATEL
4 The following is a procedure design in pseudocode.
Line numbers are given for reference only.
10 PROCEDURE Check(InString : STRING)
11 DECLARE Odds, Evens, Index : INTEGER
12
13 Odds ← 0
14 Evens ← 0
15 Index ← 1
16
17 WHILE Index <= LENGTH(InString)
18 IF STR_TO_NUM(MID(InString, Index, 1)) MOD 2 <> 0 THEN
19 Odds ← Odds + 1
20 ELSE
21 Evens ← Evens + 1
22 ENDIF
23 Index ← Index + 1
24 ENDWHILE
25
26 CALL Result(Odds, Evens)
27 ENDPROCEDURE
(a) Complete the following table by giving the answers, using the given pseudocode. [5]
Answer
A line number containing a variable being incremented
The type of loop structure
The number of functions used
The number of parameters passed to STR_TO_NUM()
The name of a procedure other than Check()
(b) The pseudocode includes several features that make it easier to read and understand.
Identify three of these features.
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................ [3]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


(c) (i) The loop structure used in the pseudocode is not the most appropriate.
State a more appropriate loop structure and justify your choice.
Loop structure ...................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
........................................................................................................................................... [2]
(ii) The appropriate loop structure is now used. Two lines of pseudocode are changed and two lines
are removed.
Write the line numbers of the two lines that are removed.
...........................................................................................................................................
..................................................................................................................................... [1]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
4 An algorithm has been written in pseudo code to input 100 numbers and print out the sum.
A REPEAT UNTIL loop has been used.
Count 0
Sum 0
REPEAT
INPUT Number
Sum Sum + Number
Count Count + 1
UNTIL Count > 100
PRINT Sum

(a) Find the error in the pseudo code and suggest a correction.
Error 1 ................................................................................................................................................
Correction ...........................................................................................................................................
......................................................................................................................................................[2]
(b) Rewrite the correct algorithm using a more suitable loop structure.
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
.............................. [3]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


There are three different types of looping structures. Write pseudo code for each of following three problems
using different looping structure:
a) Input daily temperature for a month of 30 days, calculate and output their total and average.
............................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
.. [6]
Summer 2018 P22
b) Draw a flowchart for an algorithm to input numbers. Reject any numbers that are negative and count
how many numbers are positive. When the number zero is input, the process ends and the count of
positive numbers is output.
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
...................................................................................... [6]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Extracted from March 2018 P22 (India)
c) Input the weight in kilograms of a passenger stepping into a lift. The lift can take a maximum weight of
640 kilograms. Stop input when total weight is greater than or equal to maximum allowed weight and
display message Ready to Go
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
..........................................................................................................................................................................
................................................................... [6]

Q 9.6) Write an algorithm, using pseudo code and a FOR TO NEXT loop structure, to input 1000 numbers
into an array.
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
...................................................[2]
Summer 2015 P22

(b) Rewrite your algorithm using another loop structure.


................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
...............................[4]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
...................................................................................... [6]
Q 9.8b) Explain how you change your pseudo code to reject any item over 25 Kg.
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
...................................................................................... [6]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Control Constructs
Q 1) Write down different statements for following tasks
Input Output Selection Iteration

Q 2) Show what type of programming construct each statement represents.


Complete the table by putting a tick ( ) in the appropriate column for each item.

Item Statement Selection Iteration Assignment


1 MyScore = 65
2 FOR IndexVal = 0 TO 99
3 MyArray[3] = MID(MyString,3,2)
4 IF MyScore>= 70 THEN
5 ENDWHILE
6 ELSE Message = "Error"

Q 3) Show what type of programming construct each statement represents.

Complete the table by putting a tick ( ) in the appropriate column for each item.

Item Statement Selection Iteration Assignment


1 WHILE DegF> 37.5
2 MyName = "Gordon"
3 DegF = INT(DegF)
4 ENDIF
5 CASE OF MyFavourite
6 UNTIL x = 5

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


1 (a) The following table contains statements written in pseudocode.
Show what type of programming construct each statement represents.
Put a tick (3) in the appropriate column for each statement. [6]
Repetition
Statement Selection Assignment
(Iteration)
WHILE Count < 20
Count Count + 1
IF MyGrade<> 'C' THEN
Mark[Count] GetMark(StudentID)
ELSE OUTPUT "Fail"
NEXT

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
1 (a) The following table contains statements written in pseudocode.
Show the type of programming construct each statement represents.
Put a tick (3) in the appropriate column for each statement. [6]
Repetition
Statement Selection Assignment
(Iteration)
Index Index + 5
FOR Count 1 TO 100
TempValue[Index] ReadValue(SensorID)
IF Index < 30
UNTIL DayNumber> 7
OTHERWISE OUTPUT "ERROR"

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Summer 2019 P21
1 (a) (i) Algorithms may be expressed using four basic constructs. One construct is sequence.
Complete the following table for two other constructs. [4]
Construct Pseudocode example

..................................................................................................................
......................... ..................................................................................................................
..................................................................................................................
..................................................................................................................

..................................................................................................................
......................... ..................................................................................................................
..................................................................................................................
..................................................................................................................
(ii) Simple algorithms usually consist of input, process and output.

[4]
Pseudocode statement Input Process Output
Temp SensorValue * Factor
WRITEFILE "LogFile.txt", TextLine
WRITEFILE "LogFile.txt", MyName&MyIDNumber
READFILE "AddressBook.txt", NextLine

(c) White-box and black-box are two types of testing. In white-box testing, data are chosen to
test every possible path through the program.
Explain how data are chosen in black-box testing.
...................................................................................................................................................
............................................................................................................................................. [2]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Winter 16 P21 The program design is to be amended. The value input by the user for the ticket type
is to be validated. Part of the amended flowchart is shown below.

Write pseudocode to use a pre-condition loop for this validation.


.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
............................................................................................................................................................[3]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


The programmer amends the design to validate the value of player game grade that the user
inputs. The amended part of the flowchart is shown below.

Write the equivalent pseudocode using a pre-condition loop, for this part of the amended
flowchart.

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Radhika was interviewed for the job. Part of the interview process was to study some program
code written in language ABC.
11 settype($TimesTable, Integer);
12 settype($upTo, Integer);
13 settype($Posn, Integer);
14 settype($Product, Integer);
15 $TimesTable = 7;
16 $UpTo = 10;
17
18 $Posn = 1
19 While ($Posn< $UpTo + 1)
20 {
21 $Product = $Posn * $TimesTable;
22 Echo $Posn . ' X' . $TimesTable . ' = ' . $Product . "<br>";
23 $Posn = $Posn + 1;
24 }

Answer the following questions taken from the interview.


(i) State what the settype keyword does in this language. [1]
(ii) Name one variable that the code uses. [1]
(iii) Give a line number for an assignment statement. [1]
(iv) Line 19 is the start of a pre-condition loop.
State the syntax that language ABC uses to indicate which statements must be executed inside a
loop. [1]
(b) (i) Describe what is meant by a transferable skill. [2]
(ii) Give two examples which suggest that programming in a high-level language is a
transferrable skill.
1 .......................................................................................................................................
...........................................................................................................................................
2 .......................................................................................................................................
...................................................................................................................................... [2]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


1
flight. Two types of ticket are available for a flight:
economy class (coded E)
standard class (coded S)
Each ticket type has a baggage weight allowance as shown below. The airline makes a charge if the
weight exceeds the allowance.
Ticket type Baggage allowance(kg) Charge rate per additional kg($)
'E' 16 3.50
'S' 20 5.75
(a) A program flowchart will document the program. The flowchart will contain the following
statements:
Statement no. Statement
1 Charge 0
2 INPUT BaggageWeight
3 Charge ExcessWeight * ChargeRate
4 Is ExcessWeight>0 ?
5 INPUT TicketType
6 ExcessWeight BaggageWeight - BaggageAllowance
7 BaggageAllowance 16
8 ChargeRate 3.5
9 OUTPUT Charge
10 ChargeRate 5.75
11 BaggageAllowance 20
12 Is TicketType = 'E' ?

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Complete the flowchart by putting the appropriate statement number in each flowchart symbol.
Statement 5 has been done for you. [6]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


(b) The programmer needs data to test the flowchart.
Complete the table of test data below to show five tests. [5]
Expected
TicketType BaggageWeight Explanation
output

E 15 .................................................................
.................................................................

.................................................................
.................................................................
.................................................................

.................................................................
.................................................................
.................................................................

.................................................................
.................................................................
.................................................................

.................................................................
.................................................................
.................................................................

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
(c) The program design is to be amended. The value input by the user for the ticket type is to be
validated. Part of the amended flowchart is shown below.

Write pseudocode to use a pre-condition loop for this validation.


.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
............................................................................................................................................................[3]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


1 (a) (i) Show what type of programming construct each statement represents.

Complete the table by putting a tick ( ) in the appropriate column for each item. [6]

Item Statement Selection Iteration Assignment


1 MyScore = 65
2 FOR IndexVal = 0 TO 99
MyArray[3] =
3
MID(MyString,3,2)
4 IF MyScore>= 70 THEN
5 ENDWHILE
6 ELSE Message = "Error"

(ii) State the purpose of each statement in the table in part (a)(i).
Do not use mathematical symbols in your descriptions. [6]
Item Purpose of statement

1 ...............................................................................................................................................
...............................................................................................................................................

2 ...............................................................................................................................................
...............................................................................................................................................

3 ...............................................................................................................................................
...............................................................................................................................................

4 ...............................................................................................................................................
...............................................................................................................................................

5 ...............................................................................................................................................
...............................................................................................................................................

6 ...............................................................................................................................................
...............................................................................................................................................

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
(iii) Evaluate the following expressions when MyString has the value "AdaptiveMaintenance".[2]
Expression Result
'D' & RIGHT(MyString, 4)
LEFT(RIGHT(MyString, 7), 3)

1 (a) Complete this definition of the term algorithm.


An algorithm is a solution to a problem expressed as ..............................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) A program design includes the use of subroutines (functions and procedures).
Give three advantages of using subroutines in a program.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
................................................................................................................................................... [3]
(c) Draw lines on the following diagram to connect each computing term with the appropriate description. [3]
Term Description

Checking that a program performs as


Selection
expected

A method for increasing the level of detail of


Black-box testing
an algorithm

To test a condition to determine the path of


Stepwise refinement
program execution

A method of executing certain lines of code


Iteration
more than once

1 (a) (i) Programming languages can support different data types.


Complete the table by naming three different data types together with an example data value for each. [6]
Data type Example data value

(ii) Identify the type of programming statement that assigns a data type to a variable.
..................................................................................................................................... [1]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


(b) As part of the development of an algorithm, a programmer may construct an identifier table.
Describe what an identifier table contains.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
[2]

(c) (i) Simple algorithms usually consist of three different stages.


Complete the table below. Write each example statement in program code.
The second stage has already been given.
[5]
Stage Example statement

Process

(ii) Write a single statement in program code that contains two of the stages. Do not repeat any of
the statements from part (c)(i).
..................................................................................................................................... [1]

(d) A software developer is writing a program and includes several features to make it easier to
read and understand. One of these features is the use of indentation.
State three other features.
Feature 1 ..................................................................................................................................
Feature 2 ..................................................................................................................................
Feature 3 .................................................................................................................................. [3]
(e) A trace table is often used during program testing.
Identify the type of testing that includes the use of a trace table.
............................................................................................................................................. [1]

2 (a) (i) Two types of loop that may be found in an algorithm are the ‘pre-condition’ and ‘post
condition’ loop.
Identify one other type of loop. Explain when it should be used.
Type ..................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
.................................................................................................................................... [2]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
(ii) Part of a program flowchart is shown.

Implement the flowchart in pseudocode using a post-condition loop.


...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


(a) (i) This pseudocode lacks features that would make it easier to read and understand.
State three such features.
Feature 1 ...........................................................................................................................
Feature 2 ...........................................................................................................................
Feature 3 ........................................................................................................................... [3]
(ii) Draw a program flowchart to represent the algorithm implemented in the pseudocode.
Variable declarations are not required in program flowcharts. [5]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/

You might also like