Sie sind auf Seite 1von 13

COMPUTER SCIENCE 9608

Revision Notes P2

COMPILED BY: MUNEEB KHALID


O/A Level Computer Science & IT
Explain about Identifier and Variable. How identifier and variable is different? List down the
points.
Identifier:
The name we use to call a particular entity in a program, which is not a keyword, is called identifier.
1. Identifier is used to name a variable, function, class, structure, union, etc
2. It is created to give It is created to give unique name to an entity.
3. All identifiers are not variable.
Variable: The name given to a distinct memory location which contains a value which may be
modified while program gets executed is variable.
1. A variable is used to name a memory location, which holds a value.
2. Allots a unique name to a particular memory location.
3. All variables names are identifiers.

What is Algorithm and flowchart? What is pseudo-code? Why pseudo code is used?
Algorithm: An algorithm is a well-defined procedure that allows a computer to solve a program. It
is step-by-step solution to a program.

Flowchart: Flowchart is a graphical representation of the sequential steps in an algorithm.


Pseudo code: It is a method to represent algorithm. Pseudo code is not an actual programming
language. It uses short phrases to write code for programs before you actually create it in specified
languages. Pseudo code is for programmers own convenience and thus no standard syntax are
followed.

Difference between Procedure and Function. Explain about the types of passing parameters
type.
1. A function returns a value whereas a procedure may or may not return a value or may return more
than one
value using the output parameters.
2. Functions are normally used for computations whereas procedures are normally used for
executing
business logic.
3. Procedure is a bundle of code, it does not have return type whereas function have return type.
4. Procedure accepts input or output parameters but function only accepts input parameters.
Muneeb Khalid
Passing parameters type: Contact: 0324-4844888
By value ( byVal ): the actual value is passed into the procedure.
By reference ( byRef ): the address of the variable is passed into the procedure.

What is an array? List down its advantages and disadvantages. Also, explain about the types of
an array.
Array: An array is the combination of homogeneous elements with consecutive index number and
successive memory locations. The values of an array are called elements of that array.

Advantages of array:
1. Microprocessor takes time to search values stored on dispersed location but due to array values
become is
sequence, so searching process of microprocessor become fast.
2. It is used to represent multiple data items of same type by using single identifier name.
3. It can be used to implement other data structure like linked lists, stacks, queues, trees, etc

Disadvantage of an array:
The elements of an array are stored in consecutive memory locations. So, insertion and deletions are
very difficult and time consuming.

Types of an array:
One dimensional array (1D ): It represents and store data in linear form. One dimensional array is a
structured collection of component that can be accessed individually by specifying the position of a
component with a single index value. One subscript is needed to represent each element in 1D array.
Two dimensional array ( 2D ): It represents and store data in matrix form. Two dimensional array
is a structured collection of component that can be accessed individually by specifying the position
of a component with two index value. Two subscripts are needed to represent each element in 2D
array.

What is step-wise refinement, top-down design and structure chart? Explain with appropriate
figures about the diagrams used in structure chat.

Step-wise refinement: A way of developing a computer program by first describing general


functions, then breaking each function down into details which are refined in successive steps until
the whole program is fully defined is step-wise refinement.
Top-down design: An approach in which design begins by specifying complex pieces and then
dividing them into successively smaller pieces is top-down design. Structure chart: A structure chart
is a chart which shows the breakdown of a system to its lowest manageable parts. They are used in
structured programming to arrange program module into a tree. Each module is represented by a
box, which contains the module’s name. The tree structure visualizes the relationships between
modules, showing data transfer between modules with using arrows.
Muneeb Khalid
Contact: 0324-4844888
Diagram used in structure chart:
Data couple:
Data being passed from module to module that needs to be processed.

Muneeb Khalid
Contact: 0324-4844888
Muneeb Khalid
Contact: 0324-4844888
What is meant by black-box testing, white-box testing and stub testing? Differentiate between
black-box and white-box testing. Muneeb Khalid
Contact: 0324-4844888
Black-box testing: In this method the internal structure design or implementation of the item being
tested is not known to the tester. Tester is mainly concerned with validation of output rather than
how the output is produced. In short, black-box testing is comparing expected value with actual
results when program runs.

White-box testing: In this method the internal structure design or implementation of the item being
tested is known to the tester. Tester validates the internal structure of the item under consideration
along with the output. In short, white-box testing is testing every path through the program code. In
IDE setting breakpoints, stepping and subroutine parameter checking are the features that provides to
carry out white box testing.

Stub testing: When you develop a user interface, you may wish to test it before you have
implemented all the facilities. You can write a ‘stub’ for each procedure. The procedure body only
contains an output statement to acknowledge that the call was made.
Define each of the types of an error in a program:
Muneeb Khalid
Syntax Error, Logic Error and Run-time Error. Contact: 0324-4844888

1. Syntax error: (An error in which a program statement does not follow the rules of the language.)
Syntax errors are errors in the grammar of the program language. That is, the rules of the language
have been broken. Common errors are typing errors, such as Selct for Select.
Other errors are more subtle, for example:

(i) an If statement without a matching End If statement


(ii) a For statement without a matching Next statement
(iii) an opening parenthesis without a closing parenthesis: (a + b.

Most syntax errors are spotted by the programmer before an attempt to run the code. Some program
editors help with this. For example, the Visual Basic.NET editor underlines any variable in the code
which has not been declared. Similarly, it highlights declared variables which have not been used in
the code. Syntax errors are finally picked up during the syntax analysis stage of the program’s
translation. In the case of an interpreter, the error is reported as soon as it is found. A compiler
reports all errors found in the complete program in its error report. You should be aware that some
editors can report syntax errors while the code is being entered. It is still the syntax analyzer that
spots the error. If an examination question asks when a syntax error is found, the answer is “during
the syntax analysis stage of the program’s translation”. Often the analyser reports program
statements that are not correctly formed. For example, the following statement reports an error:
For Index 1 To 20

The correct Visual Basic syntax is:

For Index = 1 To 20

A similar example is a call to a function that requires two parameters in the function header; an
error is reported if the programmer only provides one parameter. Similarly, the programmer may
provide the parameter but it is of the wrong data type.

Logic error: (An error in the logic of the solution that causes program not to behave as intended.) A
logic error occurs when the programmer makes a mistake in their logic for some part of the program.
Suppose a programmer wants the first 10 positive integers to be output and creates the following
algorithm:

FOR Count = 0 TO 10

OUTPUT Count
Muneeb Khalid
Contact: 0324-4844888
NEXT Count

This algorithm has no grammatical errors but it does not produce the correct result. It produces the
integers 0 to 10 not 1 to 10. This type of error can only be found by thorough testing. The
programmer care carefully check the code by reading it or can attempt to run the program. Another
common error is to use the wrong arithmetic symbol, e.g. a+b instead of a-b, or to put parentheses in
the wrong place, such as (a+b-c)*d instead of (a+b)-c*d. These errors should be identified during
testing and are all a mistake in the logic of the programmer.

Run-time error: (An error that cause program execution to crash or freeze. ) Run-time errors occur
during the execution (running) of the program. A typical error is to have an expression, such as
(a+b)/(c-d), used in the program but c is equal to d, resulting in an attempted division by zero. The
problem is that this error may be undetected for a considerable time because the equality of c and d
rarely happens. However, it could be disastrous when it does. It is a good idea to test the
denominator before division to ensure that this error doesn’t crash the program. Instead, the
programmer “traps” the error and displays an error message, as seen in the following code:
Muneeb Khalid
Contact: 0324-4844888
Muneeb Khalid
Contact: 0324-4844888
Muneeb Khalid
Contact: 0324-4844888
Muneeb Khalid
Contact: 0324-4844888
Muneeb Khalid
Contact: 0324-4844888

Das könnte Ihnen auch gefallen