0% found this document useful (0 votes)
205 views16 pages

SSC Gr10 ICT Q4 Module 2 WK 2 - v.01-CC-released-7June2021

Computer Programming for Grade 10 Science Class

Uploaded by

Vj Aleser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
205 views16 pages

SSC Gr10 ICT Q4 Module 2 WK 2 - v.01-CC-released-7June2021

Computer Programming for Grade 10 Science Class

Uploaded by

Vj Aleser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

10

ICT
(Special Science Class)
Computer Programming
Quarter 4 - Module 2:
Testing and Debugging

1
ICT (Computer Programming) – Grade 10
Alternative Delivery Mode
Quarter 4 – Module 2: Testing and Debugging
First Edition 2021

Republic Act 8293, section 176 states that: No copyright shall subsist in any work of
the Government of the Philippines. However, prior approval of the government agency
or office wherein the work is created shall be necessary for exploitation of such work
for profit. Such agency or office may, among other things, impose as a condition the
payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this module are owned by their respective copyright
holders. Every effort has been exerted to locate and seek permission to use these
materials from their respective copyright owners. The publisher and authors do not
represent nor claim ownership over them.

Published by the Department of Education


Secretary: Leonor Magtolis Briones
Undersecretary: Diosdado M. San Antonio

Development Team of the Module


Writer: MIGUELA M. CORTES
Reviewer: RENANTE R. ALESER
Grammarian: MARGIE B. ENANORIA
Layout Artist: CARLA L. KONG
Subject Area Supervisor: MERIAM T. ABADILLA
Management Team: RONALD G. GUTAY, ESTELA B. SUSVILLA,
MARY JANE J. POWAO, AQUILO A. RENTILLOSA,
CRISTINA T. REMOCALDO
Division ADM Coordinator: RYAN B. REDOBLADO

Printed in the Philippines by ________________________

Department of Education – Region VII Central Visayas


Office Address: Department of Education – Carcar City Division
(Learning Resources Management Section)
P. Nellas St., Poblacion III, Carcar City, Cebu ______
Telefax: (032) 487-8495
E-mail Address: [email protected]
10
ICT
(Special Science Class)
Computer Programming
Quarter 4 - Module 2:
Testing and Debugging
Introductory Message

This Self-Learning Module (SLM) is prepared so that you, our dear learners, can
continue your studies and learn while at home. Activities, questions, directions,
exercises, and discussions are carefully stated for you to understand each lesson.
Each SLM is composed of different parts. Each part shall guide you step-by-step as
you discover and understand the lesson prepared for you.

Pre-tests are provided to measure your prior knowledge on lessons in each SLM. This
will tell you if you need to proceed on completing this module or if you need to ask your
facilitator or your teacher’s assistance for better understanding of the lesson. At the
end of each module, you need to answer the post-test to self-check your learning.
Answer keys are provided for each activity and test. We trust that you will be honest in
using these.

In addition to the material in the main text, Notes to the Teacher are also provided to
our facilitators and parents for strategies and reminders on how they can best help you
on your home-based learning.

Please use this module with care. Do not put unnecessary marks on any part of this
SLM. Use a separate sheet of paper in answering the exercises and tests. And read
the instructions carefully before performing each task.

If you have any questions in using this SLM or any difficulty in answering the tasks in
this module, do not hesitate to consult your teacher or facilitator.

Thank you.
What I Need to Know

These topics should serve as a link for learners to identify the essential features: how
the program works and to evaluate a program by testing and debugging using Pascal
programming language.

This module is written in support of the K to 12 Basic Education Program to ensure


attainment of standards expected of you as a learner.

This module discusses the following:


• evaluate an output of a program by testing and debugging and
• explain how the program works.

The module contains one lesson:


Lesson 1 – Pascal Programming Language -Testing

After going through this module, you are expected to do the following:
3. Demonstrate skills in writing and documenting programs in Pascal
programming.
3.11. Evaluate an output of a program by testing and debugging.
3.12. Explain how the program works.

What I Know

Multiple Choices: Choose the letter of the correct answer.

1. The designs specifications of a program can be demonstrated by means of


A. Testing B. Documenting C. Phasing D. Analyzing
2. The technique used for writing structure programs is known to be
A. Structures programming C. Iterative programming
B. Logic programming D. Devised programming
3. A program will not produce desired results in case of
A. wrong logic C. undefined terms
B. incorrect punctuation D. wrong semantics
4. Programs designed in a way to be brought into use in other programs is known
as
A. procedures B. routines C. processes D. functions
5. Pascal encourages programmers to write
A. well-structured programs C. intermediate programs
B. modular programs D. both A and B
6. It is a group of statements that together perform a task
A. Procedure B. Function C. Testing D. Debugging
7. The type of error generated as a result of using illegal combination of
characters is said to be
A. Logical error C. Syntax error
B. Runtime error D. Compile time error
8. Errors in planning a program logic would generate a
A. Inception error C. Syntax error
B. Conception error D. Logical error
9. Testing is a properly defined process that must be
A. planned B. scheduled C. budgeted D. both A and B
10. It contains a collection of statements that define what the procedure does. It
should always be enclosed between the reserved words begin and end. It is
the part of a procedure where all computations are done.
A. arguments C. local declarations
B. procedure body D. reference

What’s In

Directions: Search for the given words in the box. Copy and encircle the word you
have found.

Debugging Syntax Testing


Function Procedures

E P D A F G T F O R U
A R F C A B P T U F Y
D O D F F G O E G V H
S C T A G J J S P C A
G E H F U N C T I O N
B D E B U G G I N G G
B U J A T K W N M B C
T R G D G L S G H X V
E E T S H D A F A O B
S S Y N T A X X S B G
Lesson
Testing and Debugging
1

What’s New

Directions: Describe/define the following terms inside the box and come up with a
concept map to show the interrelationship between and among the different terms.

Logical

Sources of
Errors Syntactic

Semantic

What is It

Testing and Debugging, Procedures and


Functions as Sub-Programs
In every complex creative activity, errors are possible, and programming is no
exception. In programming, the errors are often called “bugs” and the process of finding
and removing them is called “debugging.” Unfortunately, even the smallest program
bug can cause a serious failure.

There are a number of different sources of errors, often classified as:


• Syntactic (compile-time errors)
• Semantic (execution or run-time errors)
• Logical (performance errors)
Syntactic Errors

Arise from improper forms in a language involving:


Execution Errors
- are not found by the compiler but do appear during a run. Some examples of
these “run-time” errors involve:

Logical Errors
- are those which may not prevent a program from running but do produce
wrong results and may go undetected. Some such errors include:

Other Errors
- may also be encountered, these include:
• Misunderstanding of functions;
• Misuse of operating system; and
• Misbehavior of the computer.

Testing means verifying correct behavior. Testing can be done at all stages of module
development: requirements analysis, interface design, algorithm design,
implementation, and integration with other modules. In the following, attention will be
directed at implementation testing. Implementation testing is not restricted to execution
testing. An implementation can also be tested using correctness proofs, code tracing,
and peer reviews, as described below.

Debugging is a cyclic activity involving execution testing and code correction. The
testing that is done during debugging has a different aim than final module testing.
Final module testing aims to demonstrate correctness, whereas testing during
debugging is primarily aimed at locating errors. This difference has a significant effect
on the choice of testing strategies.

Identifying and removing errors from a program or software is called debugging.


Debugging is ideally part of testing process but in reality it is done at every step of
programming. Coders should debug the smallest of their modules before moving on.
This decreases the number of errors thrown up during the testing phase and reduces
testing time and effort significantly. Let us look at the types of errors that can crop up
in a program.

Syntax Errors
Syntax errors are the grammatical errors in a program. Every language has its own
set of rules, like creating identifiers, writing expressions, etc. for writing programs.
When these rules are violated, the errors are called syntax errors. Many
modern integrated development environments can identify the syntax errors as you
type your program. Else, it will be shown when you compile the program. Let us take
an example −
In this program, the variable prod has not been declared, which is thrown up by the
compiler.

Semantic Errors
Semantic errors are also called logical errors. The statement has no syntax errors,
so it will compile and run correctly. However, it will not give the desired output as the
logic is not correct. Let us take an example.

Look at line 13. Here, programmer wants to check if the divisor is 0, to avoid division
by 0. However, instead of using the comparing operator ==, assignment operator =
has been used. Now every time the “if expression” will evaluate to true and program
will give output as “You cannot divide by 0”. Definitely not what was intended!!

Logical errors cannot be detected by any program; they have to be identified by the
programmer herself when the desired output is not achieved.

Runtime Errors
Runtime errors are errors that occur while executing the program. This implies that the
program has no syntax errors. Some of the most common run time errors your program
may encounter are −
• Infinite loop
• Division by '0'
• Wrong value entered by user (say, string instead of integer)

Code Optimization
Any method by which code is modified to improve its quality and efficiency is
called code optimization. Code quality determines life span of code. If the code can
be used and maintained for a long period of time, carried over from product to product,
its quality is deemed to be high and it has a longer life. On the contrary, if a piece of
code can be used and maintained only for short durations, say till a version is valid, it
is deemed to be of low quality and has a short life.

Reliability and speed of a code determines code efficiency. Code efficiency is an


important factor in ensuring high performance of a software.
There are two approaches to code optimization −
• Intuition based optimization (IBO) − Here the programmer tries to optimize the
program based on her own skill and experience. This might work for small
programs but fails miserably as complexity of the program grows.
• Evidence based optimization (EBO) − Here automated tools are used to find out
performance bottlenecks and then relevant portions optimize accordingly. Every
programming language has its own set of code optimization tools. For example,
PMD, Find Bug and Clover are used to optimize Java code.
Code is optimized for execution time and memory consumption because time is
scarce and memory expensive. There has to be a balance between the two.
If time optimization increases load on memory or memory optimization makes
the code slower, purpose of optimization will be lost.

Execution Time Optimization


Optimizing code for execution time is necessary to provide fast service to the users.
Here are some tips for execution time optimization −
• Use commands that have built-in execution time optimization
• Use switch instead of if condition
• Minimize function calls within loop structures
• Optimize the data structures used in the program
Memory Optimization
As you know, data and instructions consume memory. When we say data, it also
refers to interim data that is the result of expressions. We also need to keep a track
of how many instructions are making up the program or the module we are trying to
optimize. Here are some tips for memory optimization −
• Use commands that have built-in memory optimization
• Keep the use of variables that need to be stored in registers minimum
• Avoid declaring global variables inside loops that are executed many times
• Avoid using CPU intensive functions like sqrt()
What’s More

Directions: Below is a Pascal program containing errors. Analyze the written


program and debug. After debugging, write the correct code and output of the
program.

PROGRAM Test;
VAR
x : REAL;
i : INTEGER;
j : INTEGER
BEGIN
x := 12.449;
i := 10;
j := -300;
WRITE('This is some text');
WRITELN(“Unformatted integer “,i);
WRITELN('Unformatted integer computation ',i*i);
WRITELN('formatted integer',i:4);
WRITELN('formatted integer,’j:4);
WRITELINE('Unformatted real ',x);
WRITE('Formatted real');
WRITE(x:8:2)
WRITELN('all in one line');
END.
OUTPUT:
What I Have Learned

Directions: Briefly explain the given questions below.

➢ Give some reasons why debugging is important in programming languages.

➢ How do procedures help make better programs?

What I Can Do

Discuss your understanding on the following: (10pts.)

Differentiate between debugging and testing

Testing Debugging

1. 1.

2. 2.

3. 3.

4. 4.

5. 5.

.
.
Assessment

Directions: The program below displays the value of the variable Num on the
screen. Write your output inside the box. (10pts.)

PROGRAM SixteenthProgram;
USES Crt;
VAR Num: INTEGER;
BEGIN
{This is my sixteenth program}
CLRSCR;
FOR Num :=1 TO 24 DO WRITELN(Num);
END.

https://www.tutorialspoint.com/pascal/pascal_procedures.htm

Additional Activities

Visit the URL/site to practice online:

16
Answer Key

What I Know ASSESSMENT


1. A 1
2
2. A
3
3. A 4
4. D 5
5. D 6
6. B 7
7. C 8
9
8. D
10
9. D 11
10. B 12
13
14
15
16
17
18
19
20
21
22
23
What’s In 24

E P D A F G T F O R U
A R F C A B P T U F Y
D O D F F G O E G V H
S C T A G J J S P C A
G E H F U N C T I O N
B D E B U G G I N G G
B U J A T K W N M B C
T R G D G L S G H X V
E E T S H D A F A O B
S S Y N T A X X S B G
What’s More
PROGRAM Test;
VAR
x : REAL;
i : INTEGER;
j : INTEGER;
BEGIN
x := 12.449;
i := 10;
j := -300;
WRITE('This is some text');
WRITELN('Unformatted integer ',i);
WRITELN('Unformatted integer computation ',i*i);
WRITELN('formatted integer',i:4);
WRITELN('formatted integer',j:4);
WRITELN('Unformatted real ',x);
WRITE('Formatted real');
WRITE(x:8:2);
WRITELN('all in one line');
END.

Output:
This is some text
Unformatted integer 10
Unformatted integer computation 100
formatted integer 10
formatted integer-300
Unformatted real 1.24490000000E+01
Formatted real 12.45all in one line

References:
 St. Augustine Publications, Inc. 2006. Programming in Turbo Pascal the Easy
Way, pp. 149-158
 https://www.tutorialspoint.com/programming_methodologies/programming_m
ethodologies_debugging.htm
 https://www.slideshare.net/hidden__/pascal-tutorial?from_action=save
 https://www.wisdomjobs.com/e-university/pascal-programming-tutorial-
168/errors-in-programming-7036.html

For inquiries or feedback, please write or call:

Department of Education – Carcar City Division (Learning Resources


Management Section)
P. Nellas St., Poblacion III, Carcar City , Cebu, Philippines 6019
Tel. No. 4878495
Email Address : [email protected]

18

You might also like