67% found this document useful (3 votes)
1K views

Computer Science A Level Paper 2 Revisio PDF

Uploaded by

Shahid Akhtar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
1K views

Computer Science A Level Paper 2 Revisio PDF

Uploaded by

Shahid Akhtar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

COMPUTER SCIENCE

Paper-2
Article # 252
A LEVEL NOTES SERIES
CIE SYLLABUS CODE 9608
2017 – 18 Edition

Fawad Khan

Visiting teacher at:


Green Hall Academy
Alpha DHA
Beaconhouse School System
City Ravi

GULBERG | JOHAR TOWN | WAPDA TOWN | SADDAR CANTT | DHA PHASE-I | DHA PHASE-IV
For Books Order: 0336-531-4141
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted,
in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior
written permission of the Publisher.

Title A-Level Computer Science P-2 Teacher’s Notes


Author Fawad Khan
Cell: +92 321 6386013

Published by Read & Write Publications


Printed by Sadaat Printers, Urdu Bazar, Lahore.
Composed Department Sharjeel Khan, Salman Buksh, Hayat, Shahab, Waqas, M. Awais
Graphics Department Rashid Mehmood, Raja Naveed Mumtaz
Legal Advisor Mian Tariq Ahmad (Advocate Supreme Court)
Room No. 10, 11, 12 Al-Majeed Centre
1-Mozang Road, Lahore.
Tel: 042-37236145, Fax: 042-37241367

Edition: 2016 – 18 Edition

Price Rs. 400/-


For Books Order Call Or SMS: 0336-5314141

DISTRIBUTORS
LAHORE KARACHI
 BOOK WISE  BURHANI BOOK CENTRE
12-Urdu Bazar, Lahore Shop # 6 Hashmi Trust Building Rotson Road
Tel 042-37112265, 042-37361468 New Urdu Bazar Karachi
Tel 021-32212640
 BOOKLAND
16-Urdu Bazar, Lahore  MARYAM ACADEMY
Tel 042-37124656, 042-37223210 Mool Chand DiyaRaam Building Sindh
Karachi.
 NATIONAL BOOK SERVICE Tel: 021-32214243 , 021-32634243
22. Urdu bazar lahore.
Ph. 042-37247310, 042-37355262 RAWALPINDI / ISLAMABAD
 BOOK VALLEY
 BURHANI BOOK CENTRE Shop No. A-P-4,China market 5 Brothers
Shop # 7, Mian Market, Ghazni Street,Urdu Plaza College Road Rawalpindi
Bazar Lahore. Tel: 051-35770894, 051-35551630
Ph:042-37312
PREFACE
This is a comprehensive and carefully balanced compilation of all the relevant topics
that need to be essentially covered and understood by any O Level candidate who
wishes to ace his Chemistry paper. We have managed to adopt a purely focused
and goal oriented approach in this context that would enable students not only to
grasp the content but also assist them in analysing and evaluating individual
components.

Fawad Khan

Cell: +92 321 6386013


Computer Science P-2 1 Contents

Contents
Unit 1: Teacher’s Guide ...................................................................................................... 4
1.1 Context ................................................................................................................... 4
1.2 Outline .................................................................................................................... 4
1.3 Teaching time ......................................................................................................... 4
1.4 Programming languages ......................................................................................... 4
1.5 VB.Net Resources .................................................................................................. 4
Unit 2: Algorithms ............................................................................................................... 6
2.1 Pseudocode ............................................................................................................ 7
2.2 Program Flowcharts .............................................................................................. 17
Unit-3: Procedural high-level programming languages ................................................. 24
3.1 Program statements.............................................................................................. 24
3.2 Programming terms .............................................................................................. 24
3.3 Writing maintainable programs.............................................................................. 25
3.4 Matching Pseudocode and VB codes ................................................................... 26
3.5 Sample illustrations + VB Practical on basic programming constructs ................... 28
3.6 Further exercises on VB basic programming constructs ....................................... 39
Unit-4: Structure program development .......................................................................... 42
4.1 Modular/top down approach/design or stepwise refinement .................................. 42
4.2 Top down design/Structure/Jackson diagram........................................................ 46
Unit-5: Subroutines ........................................................................................................... 50
5.1 Procedure ............................................................................................................. 50
5.2 Function ................................................................................................................ 51
5.3 Parameters and local and global variables ............................................................ 53
5.4 Samples illustrations + VB practical on procedures, function, parameter (known as
formal parameters) and arguments (known as actual parameters) .................................. 61
5.5 Further exercises on functions and procedures ..................................................... 65
Unit-6: Structure Chart ..................................................................................................... 70
6.1 Symbols used in structure chart ............................................................................ 70
6.2 Structure chart representation of sequence code .................................................. 71
6.3 Structure chart representation for selection code .................................................. 74
6.4 Structure chart representation of Iteration code .................................................... 75
6.5 Combination of sequence, selection and iteration code ........................................ 77
6.6 Further exercises on structure chart ...................................................................... 79
Unit-7: VB in Built Functions............................................................................................ 82
Computer Science P-2 2 Contents

7.1 Maths functions..................................................................................................... 82


7.2 Random Number generation ................................................................................. 84
7.3 String handling functions ....................................................................................... 88
Unit-8: Arrays .................................................................................................................... 94
8.1 Array - One dimensional ....................................................................................... 94
8.2 Sample illustrations + VB practical on 10 arrays ................................................... 97
8.3 Arrays – Multidimensional ................................................................................... 101
8.4 Sample illustration of using 2D array: .................................................................. 103
Unit-9: Sorting ................................................................................................................. 106
9.1 Bubble sort ......................................................................................................... 106
Unit-10: Files ................................................................................................................... 114
10.1 Keys terms associate with files ........................................................................ 114
10.2 Types of files ................................................................................................... 114
10.3 File manipulation ............................................................................................. 118
10.4 File extensions ................................................................................................ 118
10.5 Pseudocode structures for file handling ........................................................... 118
10.6 Sample illustration of manipulating serial files ................................................. 120
10.7 Sample illustration of manipulating sequential files .......................................... 125
Unit-11: Identifier Table .................................................................................................. 129
Unit-12: Software Development ..................................................................................... 132
12.1 Stages of program development life cycle (PDLC) .......................................... 132
12.2 System maintenance ....................................................................................... 133
12.3 Program testing ............................................................................................... 134
12.4 Testing strategies ............................................................................................ 135
12.5 Features found in a typical Integrated Development Environment (IDE) .......... 139
Computer Science P-2 3 Unit-1: Teacher’s Guide

Topics
Unit-1
– Context

– Outline

– Teaching time

– Programming languages

Teacher’s – VB.Net Resources

Guide

A Level

Computer
Science
P-2 NOTES

Fawad Khan
Cell: 0321-6386013
[email protected]

| Gulberg | Johar Town | Wapda Town |


| DHA Phase-1 | DHA Phase-4 | Saddar Cantt |
Computer Science P-2 4 Unit-1: Teacher’s Guide

Unit 1: Teacher’s Guide

1.1 Context
– Paper 2 should be completed prior to starting Paper 4.
– It is recommended that this paper be taught in a practical way with learners having
access to a computer that supports VB.Net (console mode).
– Learners should be encouraged to write their own programs, debug and execute them
using a computer with the assistance of their teacher

1.2 Outline
Paper 2 provides learners with knowledge and understanding of the following core aspects of
problem-solving and programming:
– Algorithm design
– Data representation
– Programming
– Software development

1.3 Teaching time


– It is recommended to spend about 90 hours on Paper 2.

1.4 Programming languages


– VB.Net (console mode) has been chosen as programming language for this book
because it is procedural and supports object oriented programming.

1.5 VB.Net Resources


– www.homeandlearn.co.uk/net/vbnet.html
– http://www.tutorialspoint.com/vb.net/
– http://howtostartprogramming.com/vb-netJ
– http://www.microsoftvirtualacademy.com/training-courses/vbfundamentals-for-
absolute-beginners
– http://www.studyvb.com/
Computer Science P-2 5 Unit-2: Algorithms

Topics
Unit-2

 Pseudocode

 Program Flowcharts

Alogrithms

A Level

Computer
Science
P-2 NOTES

Fawad Khan
Cell: 0321-6386013
[email protected]

| Gulberg | Johar Town | Wapda Town |


| DHA Phase-1 | DHA Phase-4 | Saddar Cantt |
Computer Science P-2 6 Unit-2: Algorithms

Unit 2: Algorithms

An algorithm is a set of instructions that either solves a problem or informs the user that there
is no solution.
Representing algorithms
There are two main ways of representing algorithms using:
– Pseudocode
– Flowchart
Common keywords used when writing algorithms
Several keywords are often used to indicate common input, output, and processing operations.
(i) Keywords used to take data from a user
– INPUT, READ, OBTAIN, GET
– Example: Input radius
(ii) Keywords used to give information to a user
(iii) Keywords used for processing data
– COMPUTE, CALCULATE, DETERMINE, DO
– Example: Calculate volume
(iv) Keywords used for declaring variables
– INITIALISE, SET
– Example: Set count to 0 (Le. count = 0)
(v) Keywords used to increase a variable value
– ADD, INCREMENT
– Example: Add 1 to count (i.e. count = count + 1)
(vi) Keywords used to decrease a variable value
– SUB, DECREMENT
– Example: Decrement count by 1 (i.e., count = count -1)
Case Study: Consider the movement of an electronic toy
An electronic toy can move over the floor according to commands that it is given through a
keypad. As it moves, it draws a line. It can obey the instructions shown in table below:
Instruction Meaning
Forward n Move forward n cm
Backward n Move backwards n cm
Left n Turn left n degrees
Right n Turn right n degrees
Repeat n Repeat the instruction which follows n times
Computer Science P-2 7 Unit-2: Algorithms

Class Activity 1:
Write an algorithm for the toy to draw the diagram shown below:

10 cm

25 cm

Start

5 cm

2.1 Pseudocode
Pseudocode is the language that combines programming terminology or high-level
programming language terms (e.g. if, while, repeat etc.) and ordinary English (nouns and
verbs: number, total, set count to 0 etc.). It is a halfway house (i.e. combines two features)
between written English and the program code for the problem.
The idea is that, once the pseudocode is written, a programmer using any high-level language
(e.g. VB, Java, C ++ etc.) should be able to write the program code from the pseudocode
design.
Pseudocode and programming constructs/structures
Algorithms and programs are expressed using 4 basic structures/constructs:
– Assignment construct (Le. assigning values to identifiers)
– Sequence construct (i.e. instructions which are executed one after the other)
– Selection construct (Le. if statements or select case statements}
– Iteration construct (i.e. loops)
Computer Science P-2 8 Unit-2: Algorithms

2.1.1 Assignment constructs


<variable> = value Or <constant> = value

Example: Declare a variable Name with initial value Fawad and another variable Pie with
initial value 3. 142
Name  " Fawad "
Pie  3.142

Class Activity 2:
Write a pseudocode that declares two variables (Mark1 and Mark2) that stores initial values
40 and 90 respectively.
2.1.2 Sequence construct
This means a two or more statements are going to be executed one after the other.

Example: Using pseudocode, write an algorithm that calculates the sum of two numbers
input by a user.
Input num1
Input num2
Print num1 + num2
Note: The pseudocode below is an example where instructions are not executed in sequence
1. Input num1
2. Goto line 4
3. Print num1 + num2
4. Input num2
5. Goto line 3

Class Activity 3:
Write the Pseudocode that will allow a user to calculate volume of a cylinder using formula.
V = pie * radius * radius * height.
2.1.3 Selection constructs
It is used when a decision or comparison has to be made in the form of a condition. If the
condition is true, it will execute certain instructions else if it is false, it will execute another set
of instructions.
Testing a condition
In selection or condition statements comparisons can be tested using the following operators:
– = (Equals)
– > (Greater than)
Computer Science P-2 9 Unit-2: Algorithms

– < (less than)


– >= (greater than or equal to)
– <= (less or equal to)
– <> (is not equal to)
Types of selection constructs
We can have two types of selection construct:

 IF construct

 CASE construct
(i) IF construct
There are different types or variations of IF construct/structures including:

 IF structure without 'ELSE' clause

 IF structure with 'ELSE' clause

 Nested IF structure
1. IF structure without 'ELSE' clause
IF <condition> THEN
<statement>
ENDIF

Example: Using pseudocode, write an algorithm that takes a mark from a user and output
pass if the mark is above 60.
Input mark
If mark> 60 Then
Print "Pass"
End IF

Class Activity 4:
Write the pseudocode that take a mark from a user and output fail if the mark is below
40

Class Activity 5:
(i) Write the pseudocode to input an examination mark and output the grade awarded.
The maximum mark is 100. The table below shows the grades that correspond to the marks
gained.
Computer Science P-2 10 Unit-2: Algorithms

Mark Grade
0-59 U
60-69 E
70-74 D
75-79 C
80-84 B
85-89 A
90-100 A*

2. IF structure with 'ELSE' clause


IF <condition> THEN
<statement>
ELSE
<statement>
ENDIF

Example: Using pseudocode, write an algorithm that takes a mark from a user and output
pass if the mark is above 59 and fail if it is below 59
Input mark
If mark> 59 Then
Print "Pass"
Else
Print "fail"
End IF

Class Activity 6:
Write the pseudocode that take a temperature from a user and output high if the temperature
is above 40, else output low.
3. Nested IF structure
IF <condition> THEN
<Statement>
IF <condition> THEN
<Statement>
ELSE
< Statement >
END IF
< Statement >
ELSE
< Statement >
END IF
Computer Science P-2 11 Unit-2: Algorithms

An example is illustrated below:

If Mark < 0 Then


Print "Mark below accepted range!"
Else
If Mark <= 100 Then
If Mark < 40 Then
Print "Fail"
Else
Print "Pass"
End If
Else
Print "Mark above accepted range!"
End If
End If

This is called a nested IF structure. It has one IF statement nested (sitting inside) another.
Note: Nested selection
A nested structure (such as an IF statement) is contained inside another similar structure (e.g.
IF statement). This is emphasised by indenting the code to show how the statements are
nested.

Class Activity 7:
Which algorithm is the more efficient (If structure v/s nested IF structure)?

Example: Using pseudocode, write an algorithm take an age from a user, first check if the
age is valid (must be between 0 and 100), if so, print young if the age is below 40 or print
old if the age is above 39.
Input age
If age> 0 and age <=100
If age < 40 Then
Print "young"
Else
Print "old"
End If
End If
Computer Science P-2 12 Unit-2: Algorithms

Class Activity 8:
Write pseudocode for a program that takes a mark from a user. Firstly, check that the mark is
above 39 and if so, check if the mark is above 90 and below 101, then print "Excellent Mark",
else print "Pass Mark". If the mark is below 60, print "fail mark".
(ii) Case construct
Case construct is used when there are multiple options from which to choose.
There are different types or variations of Case structures including:

 Case structure without 'otherwise' clause

 Case structure with 'otherwise' clause


1. Case structure without 'otherwise' clause
CASE OF <identifier>
<value 1>: <statement>
<value 2>: <Statement>
ENDCASE

Example: Using pseudocode, write an algorithm (using case .. structure) that takes a
temperature, print "room temperature" if the temperature is from 1 to 37, prints "extreme
temperatures" if the temperature is from 38 to 100 or print "freezing temperatures" if
temperature is from -15 to o degrees Celsius.
Input temperature
Case of temperature
1 to 37: print "room temperature"
38 to 100: print "extreme temperatures"
-15 to 0: print "freezing temperatures"
End Case

Class Activity 9:
Write an algorithm that displays Grade E when student marks are 0 to 20, Grade D when
student marks are 21 to 35, Grade C when student marks are 36 to 45, Grade B when student
marks are 46 to 60, Grade A when student marks are 60+.
2. Case structure with 'otherwise'
CASE OF <identifier>
<value 1>: <statement>
<value 2>: <Statement>
OTHERWISE
<statement>
ENDCASE
Computer Science P-2 13 Unit-2: Algorithms

Example: -Using pseudocode, write an algorithm that displays Grade E when student marks
are 0 to 20, Grade D when student marks are 21 to 35, Grade C when student marks are 36 to
45, Grade B when student marks are 46 to 60, Grade A when student marks are 60+. 1f students
mark are not within the range, print Grade F (use case of ... otherwise structure)
Input grade
Case of grade
0 to 20: Display "Grade E"
21 to 35: Display "Grade D"
36 to 45: Display "Grade C"
46 to 60: Display "Grade "8"
60 +: Display "Grade A"
Otherwise:
Display "Grade F"
End Case

Class Activity 10:


Write the pseudocode for a program where someone types in the name of an animal and it
outputs the sound the animal makes. The animals it should handle are:

 Pig - Oink
 Cow- Moo
 Bear - Grr
 Sheep - Baa
 Tiger - Grr
 everything else – Meow
2.1.4 Iteration constructs
A loop is used when a block of program instructions is executed a finite number of times
according to some condition. Because the instructions inside the loop are repeated, these
loops are called iteration, or repetition, constructs.
There are 3 main types of iteration constructs/structures:
– For ... Next loop structure
– Repeat. .. Untilloop structure
– While ... End While structure
(i) For ... Next loop structure
This loop is used when you want to perform the sequence of instructions in a loop a number
of times. This construct take the following form:
FOR <identifier>  <start value> TO <end value>
<statements>
NEXT<identifier>
ENDFOR
Computer Science P-2 14 Unit-2: Algorithms

Note: The for loop is a count controlled loop since we know the number of iterations initially
(e.g. for count = 1 to 10). The identifier is the variable that will increase or decrease
each time and it is known as the loop counter.

Example: Using pseudocode, write an algorithm (use for ...loop structure) that takes 10 numbers
from a user and output their total.

Total  0
For N = 1 to 10
Read number
Total  Total + number
End For
Print Total

Class Activity 11:


Write the pseudocode to read an integer, n, and output the squares of the first n integers:

Class Activity 12:


Write the Pseudocode that that will allow a user to enter an employee's name, number of hours
worked rate of pay. It then calculates the employee's total pay: total pay = rate of pay * number
of hours worked. Then it output the name and total pay of the employee. Note: If the name
entered is END, the program ends. The Pseudocode must cater for 50 employees.
(ii) Repeat ... Untilloop structure
The sequence on instructions inside the loop is always performed at least once. If the condition
is false, the loop repeats, else it stops. This construct take the following form:
REPEAT
<Statement>
UNTIL <condition>
Note: The repeat ... until loop is a post-condition loop since the condition is found at the end,
after executing the statements.

Example: Write an algorithm using repeat ... until structure that adds up a series of numbers
until the total exceeds 100.
Total  0
Repeat
Read number
Total  Total + number
Until Total >100
Print Total
Computer Science P-2 15 Unit-2: Algorithms

Class Activity 13:


Write an algorithm using repeat ... until structure that will allow a user to continuously input
names of students and print them but stop when a name "End" is encountered.
(iii) While ... End While loop structure
This structure is used when you do not know how many times the steps inside a loop need to
be performed. This loop may not execute at all compared to for ... Ioop which will execute at
least once.
This construct take the following form:
WHILE <condition>
<statement>
ENDWHILE
Note: The while loop is a pre-conditioned loop since the condition is at the start itself, before
executing the loop.

Example: Using pseudocode, write an algorithm using while ...Ioop structure that will allow
a user to calculate area of a circle as long as the radius being entered is positive.
Pie  3.142
Input radius
While radius > 0
Area  Pie * radius * radius
Output area
Input radius
End While

Class Activity 14:


Write an algorithm that will read an item name and display it as long as the total number of
item is not equal to 100.
Note: Nested iteration Statements
Loops can also be nested. Consider a program that inputs a student's name followed by a set
of examination marks.

Hadi 66, 22, 55,-1


Mustafa 34, 22, 77,-1
Fawad 54, 32, 76, -1

The process repeats for a number of students and terminates when input of the student name
END. The list of marks for each student is terminated by a negative mark. The program outputs
the average mark for the student.
Computer Science P-2 16 Unit-2: Algorithms

The solution can be:


Input Name
While Name <> "END"
Sum  O
Count  0
Input Mark
While Mark >= 0
Sum  Sum + Mark
Count = Count + 1
Input Mark
End While
AverageMark ← Sum/Count
Output "Average mark for" Name, "is “ AverageMark
Input Name
End While
Note: Notice the use of nested while loops
2.1.5 Further exercises on pseudocode
(1) Write an algorithm using pseudocode that asks the user to enter two integers,
obtains them from the user and displays the larger number followed by the
words "is larger". If the numbers are equal, it must print the message "These
numbers are equal".
(2) Write an algorithm using pseudocode that asks the user to input three integers
from the user and displays the sum, average, product, smallest and largest of
the numbers.
(3) Write an algorithm using pseudocode that reads 10 numbers from the user then
prints out how many positive numbers and negative numbers user has entered
(consider 0 a positive number).
(4) Write an algorithm using pseudocode that will accept the name, math mark,
English mark and French mark of 50 students, calculates the sum, average of
the three marks and output the average of each student together with their
name.
(5) Write an algorithm using pseudocode that accept 10 marks and output its
average.
(6) Write an algorithm using pseudocode that counts the number of even and odd
numbers when 20 numbers are input.
(7) (a) Write an algorithm using pseudocode with For... loop structure to input 15
different values for radius and calculate the area of circle in each case.
Computer Science P-2 17 Unit-2: Algorithms

(b) Modify the algorithm so that whenever a value less than or equal to 0 is
entered for radius, the computer displays a message saying that "Error! Radius
must be greater than 0".
(8) Write an algorithm using pseudocode that accepts 10 temperatures reading in
Celsius, calculate and output the temperatures then in Fahrenheit. (Fahrenheit
= 32 + 9/5 * Celcius).
(9) Write an algorithm using pseudocode that outputs the smallest and largest
number when 10 numbers are input.
(10) Using Pseudocode, write an algorithm to print the even and odd numbers from
0 until 26.

2.2 Program Flowcharts

 A program flowchart is a diagram that can be very helpful to explain an algorithm.


 Flowchart is combination of two words i.e. flow and chart. Charts consist of different
symbols to display information about any program. Flow indicates the direction of
processing that takes place in the program. Flowchart is a graphical representation of
an algorithm. It is used to show all the steps of an algorithm in a sequence
Uses of logic flowcharts
Flowchart is used for the following reasons:

 Flowcharts are used to represent an algorithm in simple graphical manner.


 Flowcharts are used to show the steps of an algorithm in an easy way.
 Flowcharts are used to understand the flow of the program.
 Program can be reviewed and debugged easily.
2.2.1 Symbols used in program flowcharts

The Start and end box: START

Input/Output box: Print X


END

Decision/quary box:
No Yes
The process box: x=x+1 Is X >
5?

2.2.2 Trace table


It is a technique used to test Pseudocode or flowcharts to make sure that no logical errors
occur.
The trace table when built must consist of the
– Inputs: These are data taken from the user
Computer Science P-2 18 Unit-2: Algorithms

– Variables: They stores changing values


– Output: This is data that is to be printed
2.2.3 Hand tracing/Dry run
It is the process where you use a trace table to:
– see what the pseudocode or flowchart will do before you have to run it
– find where errors in your pseudocode or flowchart are
2.2.4 Test data
Test data are the values that will be used as sample in the trace table to test whether the
pseudocode or flowchart is doing what it should do.
Example: Design a flowchart that takes 10 numbers as input and outputs their total

Draw a trace table using the following test data: M = 2,4,6,8,1,3,5,7,9,10,11


Computer Science P-2 19 Unit-2: Algorithms

Solution:
Tot C M Output
0 0
2 1 2
6 2 4
12 3 6
20 4 8
21 5 1
24 6 3
29 7 5
36 8 7
45 9 9
55 10 10 55

Note: (1) Notice that the test data 11 is not taken into consideration since the flowchart cater
for 10 values only.
(2) This flowchart makes use of a counter-controlled loop as shown by the arrow
which goes upwards. Counter-controlled loops are used when a flowchart need to
take input and processed a fixed number of items.
Class Activity 15:
(i) Design a flowchart to calculate area of a circle while radius is positive
(ii) Draw a trace table with test data: r = 1, 2, –3, 5, 6
2.2.5 Condition-controlled loop
In the flowchart below, we do not know in advance the number of times we wish the loop to
repeat. The flow of data in this case is interrupted by using a rogue value/data terminator. For
example here, the loop will repeat until the special data item (a rogue value is that is less 0) is
met and thus terminates the loop.
Computer Science P-2 20 Unit-2: Algorithms

Class Activity 16:


(i) Design a flowchart to calculate the smallest mark when 5 marks are input (note: marks
are from 0 to 100)
(ii) Draw the trace table using test data for Marks: 80, 50, 60, 40, 10, and 70

Class Activity 17:


(i) Dry run the following flowchart using the following test data:
N=3
Number = 10, 20, 15
Computer Science P-2 21 Unit-2: Algorithms

(ii) State the purpose of the flowchart.


(iii) Write the pseudocode algorithm for the flowchart above.
2.2.6 Further exercises on flowcharts
1. (i) Design a flowchart to calculate the smallest mark when 5 marks are input (note:
marks are from 0 to 100)
(ii) Draw the trace table using test data for Marks: 80, 50, 60, 100, 10, 70
2. The pseudocode below that finds the roots of three inputs: a, band c. [Assuming there
is a function SQRT(x) which return the square root of x (x is an integer.]
Input a
Input b
Input c
db*b-4*a*c
If d < 0 Then
Output "No real roots"
Else
SquareRoot = SQRT(d)
Root1  ( - b + SquareRoot ) I ( 2 * a )
Rootz  ( - b - SquareRoot ) I ( 2 * a )
Output Root1 , Root2
End If
Draw the flowchart for the above pseudocode and dry run it using your own test data.
3.
Total  0
For N = 1 to 10
Read number
Total +- Total + number
Next N
End For
Print Total
Draw the flowchart for the above pseudocode and dry run it using your own test data.
Your feedback is important to us
please give your reviews about this book by filling this form and sending us by whatsapp
Book in which this card was found Article No.

Note: Please mark with aor X


Are you satisfied by Paper, Printing & Binding quality of this book.

Are you satisfied by contents of this book.

Will you recommend this book to others.

Have you found any Mistakes in this book (if any).

Page Nos / Questions Nos where you found Mistakes

Remarks:

Note: Please give your details if you want to be added in our Loyalty discount schemes
Name Facebook Id:

Address

City Country

E-mail: Whatsapp Phone No:

Please send your feedback at +92-321-1100570, E-mail:readandwriteoffi[email protected]

PLEASE FILL AND SEND WHATSAPP PHOTO OF THIS CARD TO RECEIVE


OUR LATEST CATALOG AND PROMOTIONAL ITEMS FREE OF CHARGE
Book in which this card was found Article No.

Check here to receive our catalog. To Send you wholesale information


Name Shop/School Name:

Address

Facebook Id: City Country

E-mail: Whatsapp Phone No:

Please check area(s) of interest to receive related announcements:


O-Level Checkpoint Primary Topical Past Papers Revision Notes Series
IGCSE Checkpoint Secondary Topical Workbooks Sciences Subjects
A-Level Kangaroo Contest Text book Series Business Subjects

Subjects: Article Nos: , , ,


Please send a catalog to my friend:
Name Company
Address Phone/Whatsapp
City Country
You can place your Order at +92-321-1100570, Website: www.readnwrite.org
E-mail:readandwriteoffi[email protected]
E-commerce: www.Yayvo.com/read & write publications

You might also like