CS
CS
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.
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
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
Pseudocode
A simple moethod of showing an algorithm
using English-like words and mathematical operatiors that are set out to look like
a program
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
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 Counter ← 1 TO 10
OUTPUT "Enter Name of Student "
INPUT StudentName[Counter]
NEXT
Total ← 0
Mark ← 0
REPEAT
Total ← Total + Mark
OUTPUT "Enter value for mark, -1 to finish "
INPUT Mark
UNTIL Mark = -1
............................
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
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
.......................................................
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
......................................
7.4 Standard methods of solution
» Totalling
» Counting
» Finding maximum, minimum, and average (mean) values
» Searching using a linear search
» Sorting using a bubble sort
7.4.1 Totalling
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.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
....................................
<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>