0% found this document useful (0 votes)
7 views

CS

Computer Science notes for IGCSEs candidates

Uploaded by

Cosmos
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CS

Computer Science notes for IGCSEs candidates

Uploaded by

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

string

nesting
procedure
function
parameter
MOD, DIV,ROUND, RANDOM,Array

......................
8.1.6 Procedures and functions
When writing an algorithm, there are often similar tasks to perform that make use
of the same groups of statements.

Instead of repeating these statements and writing new code every time they are
required, many programming languages make use of subroutines, also known as named
procedures or functions.

These are defined once and can be called many times within a program.

Procedures, functions and parameters

A procedure is a set of programming statements grouped together under a single name


that can be called to perform a task at any point in a program.

A function is a set of programming statements grouped together under a single name


that can be called to perform a task at any point in a program.

In contrast to a procedure, a function will return a value back to the main


program.

Parameters are the variables that store the values of the arguments passed to a
procedure or function.

Some but not all procedures and functions will have parameters.

https://www.pakainfo.com/javascript-write-to-text-file/
https://www.w3resource.com/javascript-exercises/javascript-basic-exercises.php
https://www.programiz.com/javascript/examples/add-number
https://www.geeksforgeeks.org/linear-search/
https://www.youtube.com/watch?v=-Mg8L2b3y3Y
https://realpython.com/python-beginner-tips/
https://colab.research.google.com/drive/1_qdeQtpSyGkv0kbokIf6QbREzS53y6T8

https://www.guru99.com/python-tutorials.html
https://www.w3schools.com/python/
https://www.tutorialspoint.com/python/index.htm
https://www.python.org/

Chp 9

7.2 Decomposition of Computer System

Computer System... software, hardware, data, communication and people


Divided up into a set of sub-systems
Each sub-system can be further divided into sub-system
Each sub-system performs a single action
Top-down design
The Process of breaking down into smaller sub-systems is called stepwise refinement

Structure diagram
The design of a computer system in a hierarchical way

Flowcharts
Diagrammatically the stpes required for a task (sub-system)
the order that they are to be peformed
these steps together with the order are call ALGORITHM
Flowchart are an effecitve way to commuicae the algorithm that shows how a system
or sub-system works

Flowchart Terminator .... Begin/End


Process
Input/Output
Decision
Flow Line

Pseudocode
A simple moethod of showing an algorithm
using English-like words and mathematical operatiors that are set out to look like
a program

» a non-proportional font is used throughout


» all keywords (words used to describe a specific action e.g. INPUT) are written in
capital letters
» all names given to data items and subroutines start with a capital letter
» where conditional and loop statements are used, repeated or selected statements
are indented by two spaces

I)Mathematical Operators
+/-/*/
II)Conditional Statement
(Condition True/False) IF ... THEN.....ELSE.....ENDIF
(A choice between several diff value) CASE OF...OTHERWISE...ENDCASE
II)Comparison Operators

IV)Iteration
When some actions performed as part of an algorithm need repeting this is call
iteration
Loop structures are used to perform the iteration
3 Type of loop structures

1)A set number of repetitions FOR … TO … NEXT


FOR Counter ← 1 TO 10
OUTPUT "*"
NEXT Counter

2)A repetition, where the number of repeats is not known, that is completed at
least once: REPEAT … UNTIL
ထပ်ခါတလဲလဲ အကြိမ်အရေအတွက်ကို မသိပါ၊ အနည်းဆုံး တစ်ကြိမ် ပြီးမြောက်သည်
Counter ← 0
REPEAT
OUTPUT "*"
Counter ← Counter + 1
UNTIL Counter > 9
3)A repetition, where the number of repeats is not known, that may never be
completed: WHILE … DO … ENDWHILE
ထပ်ခါတလဲလဲ အကြိမ်အရေအတွက်ကို မသိရဘဲ၊ ဘယ်တော့မှ ပြီးမြောက်နိုင်မှာ မဟုတ်ပါဘူး
Counter ← 0
WHILE Counter < 10 DO
OUTPUT "*"
Counter ← Counter + 1
ENDWHILE

Loops

FOR … TO … NEXT loops

FOR Counter ← 1 TO 10
OUTPUT "Enter Name of Student "
INPUT StudentName[Counter]
NEXT

studentname[counter 1] = "ye mon"


studentname[counter 2] = "kaung khant"
studentname[counter 3] = "Nay Yan"
...

studentname[counter 10] = "Lei Lei"

Counter starts at 1 and finishes at 10


items StudentName[1] to StudentName[10] have data input
...........................................

REPEAT … UNTIL loops

Total ← 0
Mark ← 0

REPEAT
Total ← Total + Mark
OUTPUT "Enter value for mark, -1 to finish "
INPUT Mark
UNTIL Mark = -1

Variables Total and Mark are both initialised to zero


At least one mark is entered.

............................
WHILE … DO … ENDWHILE loops

Total ← 0
OUTPUT "Enter value for mark, -1 to finish "
INPUT Mark
WHILE Mark <> -1 DO
Total ← Total + Mark
OUTPUT "Enter value for mark, -1 to finish"
INPUT Mark
ENDWHILE

Only the variable Totalis initialised to zero


Condition tested at start of loop
.....................................

The pseudocode for input and output statements

INPUT and OUTPUT are used for the entry of data and display of information.

Sometimes READ can be used instead of INPUT but this is usually used for reading
from files

– see Chapter 8. Also, PRINT can be used instead of OUTPUTif a hard copy is
required

INPUT is used for data entry; it is usually followed by a variable where the data
input is stored,
INPUT Name
INPUT StudentMark

OUTPUT is used to display information either on a screen or printed on paper;


it is usually followed by a single value that is a string or a variable, or a list
of values separated by commas,
OUTPUT Name
OUTPUT "Your name is ", Name
OUTPUT Name1, "Ali", Name3

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

7.3 The purpose of an algorithm

An algorithm sets out the steps to complete a give task.


ပေးသည့်အလုပ်တစ်ခုပြီးမြောက်ရန် algorithm သည် အဆင့်များကို သတ်မှတ်ပေးသည်။
Shown as a flowchart or pseudocode
The purpose of the task and the processes needed to complete it are clear to those
who study it

Example 1 Output an alarm sound


Activity 7.6 What would be output if the numbers 7 and 18 were input?
.........................................................
Exercise

Re-write the algorithm and pseudo to check for a mark between 0 and 20 and a pass
mark of 10

Use a CASE statement to display the day of the week if the variable DAY has a whole
number value between 1 and 7 inclusive and an error message otherwise

Consider the following algorithm written in pseudocode to check if a child is old


enough or tall enough to go on a theme park ride.

OUTPUT "Plese enter age of child"


INPUT Age
OUTPUT "Plese enter age of child"
INPUT Height
IF Age >=5 or Height>=10 Then OUTPUT "OK"
ELSE OUTPUT "Not OK"

......................................
7.4 Standard methods of solution

The ability to repeat existing methods is very important in the design of


algorithms;
when an algorithm is turned into a program the same methods may
be repeated many thousands of times.

» Totalling
» Counting
» Finding maximum, minimum, and average (mean) values
» Searching using a linear search
» Sorting using a bubble sort

7.4.1 Totalling

Totalling means keeping a total that values are added to.


For example, keeping a running total of the marks awarded to each student in a
class.
Total ← 0
FOR Counter ← 1 TO ClassSize
Total ← Total + StudentMark[Counter]
NEXT Counter

7.4.2 Counting
Keeping a count of the number of times an action is performed is another standard
method.
For example, counting the number of students that were awarded a pass mark:

PassCount ← 0
FOR Counter ← 1 TO ClassSize
INPUT StudentMark
IF StudentMark > 50
THEN
PassCount ← PassCount + 1
NEXT Counter
Count ← Count + 1:

Counting is also used to count down until a certain value is reached, for example,
checking the number of items in stock in a supermarket
NumberInStock ← NumberInStock - 1
IF NumberInStock < 20
THEN
CALL Reorder():

...........................................
7.4.3 Maximum, minimum and average
Finding the largest and smallest values in a list are two standard methods that are
frequently found in algorithms, for example, finding the highest and lowest mark
awarded to a class of students

7.4.4 Linear search


Linear search is a sequential searching algorithm where we start from one end and
check every element of the list until the desired element is found. It is the
simplest searching algorithm.

............................................
7.6 Test Data
Algorithms written in pseudocode or as flowcharts can be tested by a person working
through them using any data that is required and seeing what the result
is. Computer programs can be tested by running them on a computer using any data
that is required and seeing what result is output. However, in order to
test a solution thoroughly it may need to be worked through several times with
different sets of test data.

A set of test data is all the items of data required to work through a solution.
The type of test data used to do this is called normal data.

Normal data should be used to work through the solution to find the actual
result(s) and see if they are the same as the expected result(s).

Normal test data: 50, 50, 50, 50, 50, 50 50, 50, 50, 50
Expected result: 50

Solutions also need to be tested to prove that they do not do what they are
supposed not to do.
In order to do this, test data should be chosen that would be rejected by the
solution as not suitable, if the solution is working properly

This type of test data is called abnormal test data. (It is also sometimes called
erroneous test data.
၎င်းတို့သည် ၎င်းတို့လုပ်သည့်အတိုင်း မလုပ်ကြောင်း သက်သေပြရန် အဖြေရှာရန်လည်း လိုအပ်
ပါသည်။မလုပ်သင့်ဘူး။
ထိုသို့လုပ်ဆောင်ရန်အတွက် စမ်းသပ်မှုဒေတာကို ရွေးချယ်သင့်သည်။
ဖြေရှင်းချက် မှန်ကန်စွာ လုပ်ဆောင်ပါက သင့်လျော်မှုမရှိသော ဖြေရှင်းချက်ဖြင့် ပယ်ချပါ။

For example, erroneous/abnormal data for our algorithm to find the average
percentage marks from ten end of term examinations could be:
Erroneous/abnormal data: -12, eleven
Expected results: both of these values should be rejected

There is another type of test data called boundary data. This is used to establish
where the largest and smallest values occur. At each boundary two values are
required: one value is accepted and the other value is rejected.
For example, for percentage marks in the range 0 to 100, the algorithm should be
tested with the following boundary data:
Boundary data for 0 is: -1, 0
Expected results: -1 is rejected, 0 is accepted

7.7 Trace tabels to documents dry runs of algothrims


Exercise Activity 7.12
Use a trace table and the test data 400, 800, 190, 170, 300, 110, 600, 150, 130,
900 to record another dry run of the highest and lowest number flowchart from

Exercise Activity 7.13


Use the trace table below and the test data 4, 8, 19, 17, 3, 11, 6, 1, 13, 9 to
record a dry run of the pseudocode.

....................................
<html>
<h2>Create Text file in JavaScript</h2>
<script>
function createFile()
{ var object = new ActiveXObject("Scripting.FileSystemObject");
var file = object.CreateTextFile("C:\\Welcome.txt", false);
file.WriteLine('Welcome To Pakainfo');
file.WriteLine('Free Download Source code for Pakainfo,com');
file.Close();
}
</script>
<input type="Button" value="Make File" onClick='createFile()'>
</html>

You might also like