Professional Documents
Culture Documents
Programming Computer Notes For 10th Class
Programming Computer Notes For 10th Class
Chapter Number.9
Problem Solving
Chapter Number.10
RUN
IF
IMF-
IMCB F-7/3
Q: Define floating-point constant?
A: ● Positive or negative numbers are represented in exponential form.
● Consist of an optional-signed integer or fixed point number (the mantissa), followed by the
letter E and optional-signed integer (the exponent.)
Example:
235.988E-7
2359E6
Q: What is allowable range for floating-point constant?
A: 3.0●10-39 to 1.7●1038.
Q: Name types of variables?
A: 1) Numeric Variable.
2) String Variable.
Q: Define Numeric Variable?
A: Numeric Variable always has numeric values. A numeric variable name may consist of all
alphabets and numeric constants but must begin with an alphabet. Special Characters and
blank spaces are not allowed . it can be Integer, Single- Precision and Double-Precision. Valid
variable name are: A, B2, X55, NUM, TPAY etc.
Q: Define String Variable?
A: It represent a character string that is a character or a sequence of characters i.e. letters,
numbers and special characters. Blank spaces may include in a string but not the quotation
marks. It must be followed by $ sign such as A$, B33$, GRAD$ etc.
Q: Define Operator? Name its types?
A: An Operator performs mathematical or logical operations on values. These are divided into 4
types:
● Arithmetic Operator.
● Logical Operator.
● Relational Operator.
● Functional Operator.
Q: Define Relational Operator?
A: It is used to relate or compare two quantities. The result of comparison may be either “Yes”
or “No” or may be “True” or “False”
Charter Number.11
Control Statement
Q: What happened, if
1. The value of expression is non-integer?
2. If the value of expression is less than 0 or more than 255?
A: 1. If the value of expression is non-integer then fractional portion is rounded.
2. If the value of expression is less than 0 or more than 255, a message “illegal function call”
is generated.
Q: Why REM Statement is used?
A: To insert some exclamatory comment in a program.
Syntax:
REM [Comments]
Q: What happened if once a REM or its substitute an apostrophe (’) is encountered?
A: The program ignores every thing else until the next line number or program is
encountered.
Q: How Remarks can be added to the end of the statement?
A: Remarks may be added to the end of the statement by preceding the remark with an
apostrophe (’) instead of REM.
Example:
10 LET A=5 “a constant value 5 is assigned to a variable A”
Q: Define Control Structures?
A: It consists of decision block and repetition block. It control the flow of statement and
execution with in the program.
Q: What is the decision block and repetition block in control structure?
A: ● The Decision block controls the statements to be executed.
● The Repetition block controls the repeated execution of one or more statements.
Q: Differentiate between the purpose of GOTO Statement and ON-GOTO Statement?
A:
GOTO Statement: ON-GOTO Statement:
To jump unconditionally to a specified line To branch to one of the several specified
number. line numbers, depending on the value
Q: What is looping?
A: The process of repetition of a statement or group of statements.
Q: What happened if the starting value of the loop exceeds the ending value?
A: The body of the loop is skipped.
Q: What is the disadvantage of using ON-ERROR GOTO Statement?
A: Any Error including disk problem or a Syntax Error, will cause the program to GOTO the line
specified. This can make the debugging very difficult.
Q: How debugging can be very difficult, when we are using ON-ERROR GOTO Statement
in a program?
A: Because, any error including disk problem or a syntax error, will cause the program to GOTO
the line specified. This can make the debugging very difficult.
Q: Name the 3-conditional values, with whom the loop deals?
A: 1. Initial/Starting value.
2. Testing Condition. (for finishing the loop)
3. Incremental value.
Q: Differentiate between WHILE….WEND Loop and FOR….NEXT Loop?
A:
WHILE….WEND Loop: FOR….NEXT Loop:
It is used when the numbers of iterations It is used for fixed number of iterations
(number of execution of statement) are known in advanced.
Prepared by: Mrs. Naheeda Shafique 13
Computer Science-X
not known in advanced.
Q: Differentiate between STOP Statement and END Statement?
A:
END Statement:: STOP Statement
It terminates program execution, close all It terminates program execution and return to
files, return to command level. Physically command level like END Statement. It may
it can be given any where in the program be given any where in the program but
but logically it must be last statement of breaks program execution temporarily when
program. it is encountered. It does not close file like
END Statement.
Q: Define Nested Loop?
A: The loop that occur within other loops are called Nested Loop.
Q: What conditions must be met while nesting a FOR….NEXT Loop?
A: ● Each loop must have a different variable name as its counter.
● The NEXT of inner loop must appear before the outer loop.
● If nested loops have the same end point, a single NEXT Statement may be used for all of
them.
Q: Which statements are used to produce sound in WHILE/WEND Loop and FOR/NEXT
Loop? Write their Syntax?
A: Sound Statement and Beep Statement are used to produce sound in WHILE/WEND Loop and
FOR/NEXT Loop.
Syntax:
● Beep
● Sound F,T
F is frequency in Hz (range 37 to 32767)
T is time interval described in tick (range 0 to 65535)
Q: Why CONT Statement is used?
A: It is used to continue the program execution after a break with STOP Statement.
Syntax:
CONT
Q: What is loop? Explain its types in detail?
A: Loop:
It is an instruction or a group of instructions that the computer executes repeatedly to a
specified number of times or until some terminating condition is satisfied.
Types:
1) Counter\Determined Loop.
2) Controlled\Undetermined Loop.
1) Counter\Determined Loop:
● It is used in that case when the specific number of repetition is known in advance.
● It executes statement or a group of statements in a specified line number of times such
as 10 times or 100 times.
● It is also called Counter or Determined Loop because in this type of loop the number of
iteration is known in advance.
● FOR….NEXT Statements are used to implement this type of loop.
● Example:
10 FOR C=1 TO 5 Step 1
20 Print C
Prepared by: Mrs. Naheeda Shafique 14
Computer Science-X
30 NEXT C
40 END
2) Controlled\Undetermined Loop:
● A loop whose execution depends on a condition being true or false.
● It is also known as undetermined loop because in this loop structure, the number of
execution of the loop is not determined before the execution of the loop.
● WHILE….WEND Statements are used to implement this loop structure.
● Example:
10 C=1
20 WHILE C<=100
30 Print C
40 C=C+1
50 WEND
60 END
Q: What is transfer of control? Explain its types?
A: Transfer of Control:
Normally, The BASIC program runs in the sequence of the line numbers, Sometimes the
sequence is broken according to the requirement; and the statement to be executed next is
other than that is in the sequence.
Types:
1) Unconditional Transfer of Control.
2) Conditional Transfer of Control.
1) Unconditional Transfer of Control:
When the control of execution is passed from one statement to other without applying
any condition then such transfer of control is called Unconditional Transfer of Control. The
GOTO Statement is used for this purpose.
Syntax:
line number GOTO line number
●Control can be transferred to any part of program but the second line number given after the
GOTO must be different from the first line number.
●No condition is given in the programs of GOTO , therefore it is repeated indefinitely. To
stop it, Ctrl+C should be pressed
Example:
10 Print “Pakistan Zindabad”
20 GOTO 10
30 END
Output:
Pakistan Zindabad
…
…
…
…
…
…
…
2) Conditional Transfer of Control:
When the control of execution is jumped from one statement to other depending on the
value of an expression. ON….GOTO and IF….THEN….ELSE are Conditional Transfer of
Prepared by: Mrs. Naheeda Shafique 15
Computer Science-X
Control Statements.
a. ON….GOTO Statement:
Purpose:
To branch to one of several specified line numbers, depending on the value
returned when an expression is evaluated.
Syntax:
ON exp/var GOTO line number 1, line number 2,………………
Example:
10 CLS
20 Input N
30 A$= “-VE”
40 B$= “0”
50 C$= “+VE”
60 D$= “The number you entered is”
70 S=SGN(N)+2
80 ON S GOTO 90, 100, 110
90 ? D$, A$
100 ? D$, B$
110 ? D$. C$
120 END
Output:
? 57
The number you entered is +ve.
b. IF….THEN….ELSE Statements:
Purpose:
To transfer the control somewhere else depending upon a condition.
Syntax:
IF (Condition) THEN (Statement 1) ELSE (Statement 2)
Example:
10 CLS
20 Input N
30 Let R=N MOD 2
40 If R=0 THEN ? “even” ELSE ? “odd”
50 END
Q: Explain IF-THEN Statement?
A: IF-THEN Statement:
The IF Statement is used for conditional branching. It is also called conditional transfer of
control as it transfer control to specify portion of a program depending on the condition.
Syntax:
Line number IF (Condition) THEN [line number (OR) Statement]
The general format of IF Statement consist of:
1) Line number
2) IF (Condition):
IF is reversed word and condition can be relational, logical or
combination of these two.
3) THEN [line number (OR) Statement]:
‘THEN’ is reversed word and statement is which we want to execute
when become true.
The IF Statement determines, whether the condition is true or false. If it is true, the control
will be transferred to ‘THEN’ part, and ‘THEN’ part will be executed. Otherwise the control
Prepared by: Mrs. Naheeda Shafique 16
Computer Science-X
will be transferred to the next executable statement of the IF Statement.
The IF….THEN can be represented by a flow chart with a decision (diamond) symbol as
follow:
Is True
Conditio
n
False
Example:
10 REM “Program of numbers 1to 100”
20 LET C=0
30 LET C=C+1
40 ? C
50 IF C=100 THEN 70
60 GOTO 30
70 END
Output:
Program of numbers 1 to 100
1
2
3
.
.
.
100
False Is True
Conditio
n?
Statement 2 Statement 1
Example:
10 REM “Grade finding
Next from given
Statement in thepercentage
program marks”
20 Print “Enter your percentage marks”; M
30 IF M>=90 THEN G$=A : GOTO 70 ELSE
40 IF M>=80 THEN G$=B : GOTO 70
50 IF M>=70 THEN G$=C : GOTO 70 ELSE
60 IF M>=60 THEN G$=D : ELSE G$=E
70 Print “your grade is :”; G$
80 END
Output:
Enter your percentage marks: ? 82
your grade is : B
Q: Explain the use of ON ERROR GOTO Statement? Write disadvantages?
A: ON ERROR GOTO Statement:
● This Statement suppresses error message, as soon as an error occurs, it transfer control to
the line number specified.
● The ON ERROR OFF no longer suppress error message i.e. the computer handles error
in the normal way the print command prints out the error message for the last error.
Example:
10 X=0
20 ? 27/X Program without error message.
30 ?:? “Impossible”
40 END
Output:
Division by zero
1.701412E+38
Impossible
When this program will be written using ON ERROR GOTO Statement then:
● The error number is stored in the variable ERR.
● The line number at which the error occurred is stored in the variable ERL.
Program using ON ERROR GOTO:
Prepared by: Mrs. Naheeda Shafique 18
Computer Science-X
10 REM “ERROR detecting program”
20 ON ERROR GOTO 200
30 X=0
40 ? 27/X
50 ?:? “Impossible”
60 E
200 ? “ERROR Code”; ERR
210 ? “Error at line”; ERL
220 GOTO 50
Output:
ERROR Code 11
Error at line 40
Division by zero in 40
Impossible
OK
Disadvantages:
Any error including a disk problem or a syntax error, will cause the program to GOTO
the line specified. This can make the debugging very difficult.
Syntax:
Constant-1 Constant-2 Constant-3
Line number FOR Index variable Variable-1 To Variable-2 STEP Variable-3
Expression-1 Expression-2 Expression-3
. .
. .
. Body of Loop
. .
. .
Line number NEXT Index variable.
where,
Variable: is known as index variable or control variable used as a counter.
Expression-1: is the initial value of the counter.
Expression-2: is the ending value of the counter.
Expression-3: is used as an increment.
STEP: is optional.
Syntax:
Line number WHILE <Condition>
.
.
.
.
Line number WEND
● WHILE is the 1st statement of the loop and WEND is the last statement of the loop.
● When the WHILE Statement, executed, it checks the condition, If the condition is true
then the control will transfer to the loop body.
● After executing the loop body, the WEND Statement will transfer control back to the
WHILE Statement to check the condition again.
● If the condition become false, execution resumes with the statement following WEND
Statement.
10 LET C=2
20 WHILE C<=50
30 ?C
40 LET C=C+2
50 WEND
60 END
Is
Conditio
False
n?
True
Sub Array
Sub(1) 45
Sub(2) 55 A list is referred as One-Dimensional Array.
Sub(3) 85 Sub is array-name and 1,2,3,4,5,6,7 and 8 are subscripts which are
Sub(4) 37 enclosed in parentheses.
Sub(5) 41 45, 55, 85, 37, 41, 60, 71 and 46 are elements of array.
Sub(6) 60 If there are more than 10 elements then it uses DIM statement.
Sub(7) 71 Like: DIM A(20)
Sub(8) 46
Program
10 FOR K=1TO8
20 Read SUB(K)
30 PRINT “SUB” ; K ; “=”; SUB(K)
40 NEXT K
50 DATA 45, 55, 85, 37
60 DATA 41, 60, 71, 46
70 End
2. Two-Dimensional Array:
It is also called 2-D Array, table or matrix. In this type of array, two arguments are used
in parentheses separated by a comma. Like: ABC(I,J) is a two-dimensional array which
contains 2 values I and J. This type of array is mostly used to read and process data table. In
this array, the first argument represents Row of the table while the second argument is used
for column.
Example:
5 7 9
10 2 17
11 3 21
It has 3 rows and 3 columns.
Program
10 FOR K=1TO3
20 FOR L=1TO4
30 READ NUM(K,L)
40 NEXT L
50 NEXT K
60 FOR M=1TO3
70 FOR N= 1TO4
80 PRINT NUM(M,N)
90 NEXT N
100 NEXT M
110 DATA 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120
120 End
Q: What is Subprogram?
A: A Subprogram or a module is defined as “group of statements that performs a single task or
function.” Physically it is a short segment of a program.
Q: What are the rules of Subprograms?
A: ●Subprograms are written once in the main program or independently but can be called
(used) more than one time in the main program.
●These are written internally with in the main program or externally outside the main
program as an independent program.
Q: Name types of Subprograms?
A: 1. Function Subprogram.
2. Subroutine Subprogram.
Q: What are the Function Subprograms?
A: Function is a Subprogram that takes a single or more values and returns a single value output.
There are two types of functions; String Functions and Numeric Functions.
Q: Differentiate between String Functions and Numeric Functions?
A:
String Function: Numeric Function:
These functions manipulate only These functions perform numeric operations. These can
strings. be trinomial and arithmetical operations.
A File
Prepared by: Mrs. Naheeda Shafique 25
Computer Science-X
Q: What is Character?
A: It is a smallest piece of information in a data file. It may be (A-Z), (0-9) or special symbols
such as &, *, %, #, @ etc.
Q: What is data field?
A: These are group of related characters to have a unit of information. In general, It is a specified
location where one type of data is kept.
Example:
Field 1 Student Name