Sunteți pe pagina 1din 29

Computer Science-X

Chapter Number.9
Problem Solving

Q: What is Problem Solving?


A: To solve a problem using suitable software is called Problem Solving.
Q: What is meant by defining the Problem?
A: It means knowing the objective of the Problem. It should include identification of the
input and the desired output of the program.
Q: What is Program?
A: Program is a set of instructions according to the syntax (rules) of a Programming
language.
Q: What is Programming language?
A: It is a set of letters, symbols, & numbers arranged according to the syntax of a
language used to write program.
Q: What is Pseudo-Code?
A: It is a tool for writing a program or solution of a problem in narrative form using
natural human language. Pseudo-Code can not be compiled nor executed. Also it
Has no any syntax like algorithm.
Q: What is meant by analyzing the problem?
A: It is the process of understanding the problem by asking series of Questions.
Example:
1. How to solve problem?
2. Can it be solved on computer?
3. What are input and output?
4. How many solutions are possible?
etc
Q: What is Problem identification Stage?
A: It is 1st stage of program development. In which we define and analyze the problem to
understand it properly because only then we can write a proper program.
Q: Define Algorithm?
A: It is a step by step procedure developed to solve a problem before writing an actual
program. It is a complete procedure or plan that describes the logic of program.
Q: What is Flowchart?
A: Flowchart is defined as, “The pictorial representation of the algorithm.”
Or
“The graphical form of the detailed steps (algorithm) to solve a problem.”
Note:
Learn all symbols of flowchart and their functions from page 5(gaba book).
Q: What is Coding?
A: The process of converting the algorithm into a computer program using computer
language.
Q: Name the types of Computer’s instruction used in a Program?
A: 1. Input/Output instructions.
2. Control instructions.
3. Arithmetic instructions.
4. Logical instructions.
5. Specification instructions.
Q: What is purpose of Input/Output instructions?
A: Theses instructions direct the computer to move information to and from the

Prepared by: Mrs. Naheeda Shafique 1


Computer Science-X
computer’s memory and an input or output unit.
Q: What is purpose of Control instructions?
A: These instructions control the order in which other instructions are executed by
transferring the control to the instruction executed next.
Q: What is purpose of Arithmetic instructions?
A: These instructions direct a computer for Arithmetical Computations and moving data
from one place to another in memory.
Q: What is purpose of Logical instructions?
A: These instructions enable the computer to compare items of data and proceed
according to the result of the comparison whether certain condition is true or false.
Q: What is purpose of Specification instructions?
A: These instructions are descriptive. A programmer can inform a computer about things
such as the types of data items used in a program, the allocation of storage so on and
so forth.
Q: What is Debugging and Testing? Why we test the program?
A: The process of finding and removing errors from a computer program is called
Debugging. We test the program to insure that it works correctly and will perform as
Intended.
Q: What types of Errors can be occurs during Testing?
A: Three types of Errors can be occurs during Testing:
1. Logical/Semantic Errors.
2. Syntax/Compiler Errors.
3. Run time/Execution Errors.
Q: Explain Logical Errors?
A: Logical Errors occurs may be due to improper use of formula or incorrect formula or
wrong use of the symbols or data.
Example:
Average=A+B*C/3 (incorrect)
Average=A+B+C/3 (correct)
Q: When Logical Errors occurs in a program? What does computer do?
A: Computer can not detect such Errors and give wrong results.
Q: Why Syntax Error occurs in a program?
A: Syntax Errors occurs due to wrong use of programming language, incorrect
Punctuation, incorrect word sequence, undefined terms or misuse of the terms.
Example:
C=A+/B (incorrect)
C=A/B or C=A+B (correct)
Q: When Syntax Errors occurs in a program? What does computer do?
A: These errors are automatically pointed out by the language processors. When these
errors appear in the program, computer do not process data and indicate Syntax Error
on execution.
Q: If program or module does not give correct result what steps will be taken next?
A: It must be examined for errors, Correct the errors, and test the program again.
Q: Why Execution Error occurs in a program?
A: Execution Errors arises due to the limitation of computer.
Example:
Division of a number by zero
Q: What happened when Execution Error occur in a program? Can computer detect these
Errors?
A: Execution of program is held up or sometimes it gives absurd result. These are difficult to
Prepared by: Mrs. Naheeda Shafique 2
Computer Science-X
locate.
Q: If a computer program do not meet the user’s needs. Then what the programmer should
do?
A: Then the programmer should trace through the program development procedure,
change the algorithm, flowchart, pseudo-code and the program coding.
Q: What is implementation?
A: It is a process of taking the program and placing it into operation.
Q: What are the four conversions through which a program can be implemented?
A: 1. Direct Conversion.
2. Parallel Conversion.
3. Phased Conversion.
4. Pilot Conversion.
Q: What is Direct Conversion?
A: The conversion from an old system into a new one all at once is called Direct
Conversion.

Old System New System

Q: What is meant by Documentation?


A: The description of what a program is and how to use it, is known as documentation.
Q: Name the types of Documentation?
A: 1. User Documentation.
2. Technical Documentation.
Q: Define User Documentation?
A: It is a Technical & Non-Technical discussion of a problem being solved. It include
description of the output from the program and discussion of the data that is required to run
a program it contains the list of potential problems that may be encountered by the user.
Q: Define Technical Documentation?
A: It helps the computer operators to execute the program. It also used by analyst and
programmers. It includes statement of problem, flowchart, structure chart, coding form,
definition, analysis, design stage, potential problems, description of solution and other
material.
Q: What important functions are performed by documentation?
A: 1. Helps in recovery of damage program.
2. Helps in reporting to the higher authority.
3. Helpful for all users.
4. Helps in understanding overall program structure and improve the program.
5. Helps in writing the same code for another computer.
Q: What is Maintenance?
A: It is an activity to keep the program in working, error free and up-to-date. It includes up dates,
repairs, replacements and many more activities.

Chapter Number.10

Prepared by: Mrs. Naheeda Shafique 3


Computer Science-X
Data Types, Assignment and Input/Output Statements

Q: Define BASIC? Who develop this language?


A: BASIC stands for “Beginners All Purpose Symbolic Instruction Code” The versions of
BASIC are BASIC, Q-BASIC, GW-BASIC and VISUAL BASIC. It is used for computation,
graphic designing and business applications. John Kemeny and Thomas Kurtz developed it in
1965.
Q: BASIC is All Purpose, what does it means? Write advantages of BASIC?
A: ● Simple and easy to learn.
● All purpose language.
● Instructions written in it are very similar to English language.
● Easy to program, test and debug.
Q: Write disadvantages of BASIC?
A: ● Slow in Processing but compiler version is faster.
● No standard version is available.
Q: What are the rules of BASIC Program Structure?
A: ● Each statement of program must start with positive line number.
● Physically Statements may be in any order but their execution must be in an ascending
order.
● Two statements can be written in one line one line separated by colon (:).
● To indicate the end of the program, End statement must be given.
Q: Write BASIC character set?
A: ● Numeric characters. (0-9)
● Alphabetic characters. (A to Z or a to z)
● Special characters. (=, +, -, *, / etc.)
Q: What is the purpose of giving line numbers in a program?
A: Line numbers tells the sequence of the program statements that are to be executed in that
order.
Q: What will happen if you do not give end statement in the program?
A: Program terminates automatically when the last statement will be executed.
Q: Is there any difference between $ and String declaration sign?
A: There is no difference between $ and String declaration sign.
Q: Define Reserved Words? (OR) What are the words in BASIC which are used for special
purpose or specific predefined actions?
A: These are some specific words that have special meanings, which directs the computer to take
a specific predefined action called reserved-words or keywords.
Q: What are the rules for Reserved Words?
A: GW-BASIC interprets keywords as a part of statement or command. These can not be used as
variable names. However, these may be embedded within variable names.
Q: What are Commands?
A: These are executable instructions and generally executed in the direct mode, or command
level of the interpreter. They usually perform some type of Program maintenance such as
editing, loading, or saving program.
Q: Write syntax and purpose of Auto Command?
A: To generate and increment line numbers automatically each time you press the enter key.
Syntax:
i) Auto [[line number], [increment]]
ii) Auto. [, [increment]]
Q: What happens if Auto command generates a line number that is already being used?
A: An asterisk appears after the number to warn that any input will replace the existing line.
Prepared by: Mrs. Naheeda Shafique 4
Computer Science-X
Q: Which command terminates Auto command?
A: CTRL + Break (or) CTRL + C
Q: What is the syntax and purpose of CLS command?
A: To clear the contents on the screen.
Syntax:
CLS (N) [N value is optional]
Q: What is the purpose of giving 0, 1 and 2 values in N in CLS Command?
A:
N Effect
0 Clears the screen having both text and graphics.
1 Clears only the graphics.
2 Clears only the text window.
Q: What is the purpose of pressing CTRL +HOME?
A: To clear the screen.
Q: What is the syntax and purpose of Clear command?
A: To set all numeric variables to zero, all string variables to null and to close all open files.
Syntax:
Clear
Q: Write syntax and purpose of Delete command?
A: To delete program lines or line range
Syntax:
i) Delete [line number 1] [-line number 2]
ii) Delete line number 1-
Q: What is the syntax and purpose of Edit command?
A: It displays the line given and position the cursor under the first digit of the line number to
make it available for editing.
Syntax:
i) EDIT line number
ii) EDIT
Q: What is the syntax and purpose of File command?
A: It is used to display the names of the files residing in the specified path.
Syntax:
Files [path-name]
Q: What will be the purpose of Files “B:*.*”?
A: List all files in the drive B with all types of extension.
Q: What will be the purpose of Files “TEST?.BAS”?
A: List all files start from TEST with the extension BAS.
Q: What will be the purpose of Files “E:Burki\*.DOC”?
A: List all files in the directory named Burki that are on the drive E and have the extension DOC.
Q: What is the syntax and purpose of Key command?
A: It assigns the string expression to the specified function key.
Syntax:
Key, Key number, String Expression.
Q: What is the purpose of Key List?
A: List all 10 function keys on the screen with the associated functions.
Q: Name types of constants?
A: 1. String Constant.
2. Numeric Constant.
Q: What is the syntax and purpose of Kill command?
A: To delete a file or files from the disk permanently.
Prepared by: Mrs. Naheeda Shafique 5
Computer Science-X
Syntax:
Kill filename
Q: What is the syntax and purpose of Load command?
A: To load a file from a diskette into memory.
Syntax:
Load “file name”[,r]
If the “r” option is used with load, the program runs after it is loaded.
Q: What is the syntax and purpose of MKDIR command?
A: To create a subdirectory with the specified path.
Syntax:
MKDIR pathname
Q: What is the syntax and purpose of Name command?
A: To change the name of a disk file.
Syntax:
NAME old filename AS new filename
Q: What is the syntax and purpose of New command?
A: To delete the program currently in memory and clear all variables.
Syntax:
New
This command is entered at command level to clear memory before entering a new program.
Q: What is the syntax and purpose of RENUM command?
A: To renumber the program lines.
Syntax:
RENUM [new number], [old number][,increment]
Q: What is the syntax and purpose of RDDIR command?
A: To delete a subdirectory with the specified path.
Syntax:
RDDIR pathname
Q: What is the syntax and purpose of RUN command?
A: To execute the program currently loaded in memory, or to load a file from the disk into
memory and run it.
Syntax:
i) RUN [line number] [,r]
ii) RUN filename
“RUN” runs the program while RUN line number runs the specified line number of a
program.
Q: What is the syntax and purpose of Save command?
A: To save a program file on disk.
Syntax:
i) Save filename [,a]
ii) Save filename [,P]
Q: What is the syntax and purpose of System command?
A: To quit from GW-BASIC and return back to MS-DOS or desktop.
Syntax:
System
Q: What is data-type?
A: The kind of values that a user use to store in the memory is called data-type.

Q: What is the syntax and purpose of Restore Statement?


A: It is used to restore data statements from start.
Prepared by: Mrs. Naheeda Shafique 6
Computer Science-X
Syntax:
RESTORE [line number]
Q: What is the syntax and purpose of LET Statement?
A: It is called Assignment statement. LET is used to assign a numerical or string values to a
variable.
Syntax:
Line number [LET] variable=Constant/Variable/Expression
Q: What is the syntax and purpose of Read/Data Statement?
A: It is another type of input statement used to read values from data statement and assign them
to variable
Syntax:
i) Line number Read list of variables
ii) Line number Data list of constants/data items
Q: What is the syntax and purpose of Input Statement?
A: It is an input statement used to get input from the terminal during program execution.
Syntax:
i) Line number Input[;][Prompt String;]list of variables
ii) Line number Input[;][Prompt String,]list of variables
Each data item in the prompt string must be enclosed in double quotes, followed by
semicolon or a comma and name of variable to which it will be assigned. If more than one
variable is given will be separated by commas.
Q: What is the syntax and purpose of Print Statement?
A: It is an output statement used to display an output on screen.
Syntax:
i) Line number Print[Constants/Variables/Expressions list][;/,]
ii) Line number ?[Constants/Variables/Expressions list][;/,]
● ? may be used in place of “Print”.
● , and ; are separators.
● , generally causes the output to be printed across the screen in five zones.
● ; generally separates strings, The computer prints the strings without adding space.
Q: What is the syntax and purpose of Print using Statement?
A: To print strings or numbers using a specified format.
Syntax:
PRINT USING string expression; list of expressions[;]
Q: Which characters are used to format the string field in print using statement?
A: ! , \n spaces\
Q: What is the purpose of ‘!’ in string field in print using statement?
A: ! specifies that only first character in the string is to be printed.
Q: Which special characters are used to format the numeric field in print using statement?
A: ● Pound Sign (#).
● Sign Character (+).
● Sign Character (-).
● Double Asterisk (**).
● Double Dollar Sign ($$).
● Comma (,).
Note:
Learn the purpose of these characters and examples from page number 34, 35

Q: Name the types of numeric constant?


Prepared by: Mrs. Naheeda Shafique 7
Computer Science-X
A: 1) Integer Constant.
2) Fixed-Point Constant.
3) Floating-Point Constant.
Q: What is the format in string field in print using statement when we give “!” “\ \” “\ \”?
Explain with example.
A: 10 Let A$ = “IMCB”
20 Let B$ = “F-7/3”
30 Print Using “!”; A$; B$
40 Print Using “\ \”; A$; B$
50 Print Using “\ \”; A$; B$
60 End

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”

Q: Define Logical Operator?


A: It perform tests on multiple relations, bit manipulation, or Boolean operations. It returns a
Prepared by: Mrs. Naheeda Shafique 8
Computer Science-X
bit-wise results, which is either true(non-zero) or false(zero).
Example:
NOT(Unary), AND, OR etc.
Q: Define Arithmetic Operator?
A: Numeric expressions contain operators that perform arithmetic operations as addition,
subtraction, multiplication, division etc.
Example:
+, -, *, /, ^, \(integer division), mod(modulus)
● Two additional arithmetic operators are also available known as integer division and
modulus arithmetic.
● Integer division is denoted by (\). The operands are rounded to integers before the division
is performed and the quotient is truncated to a lower integer.
● The mod operator denotes modulus arithmetic. It returns remainder of an integer division.
.
Q: Define Functional Operator?
A: These are built in functions used to perform arithmetic and string operations.
Example:
ABS, INT, FIX etc.
Q: Write sample variable name of Integer, Single Precision and Double Precision variable?
Write required bytes of storage also?
A:
Variable Type: Sample name: Required bytes of storage:
Integer: NUM% 2
Single Precision: MIN! 4
Double Precision: PI# 8
Q: Differentiate between:

Prepared by: Mrs. Naheeda Shafique 9


Computer Science-X
Integer Constant: Single Precision Constant: Double Precision Constant:
These are stored as whole These are stored with 6 digits of These are stored with 16
numbers only. precision or fewer digits. digits of precision.
Exponential form using E. Exponential form using D.
A trailing exclamatory sign(!). A trailing number sign(#).
Direct Mode: Program Mode:
In Direct Mode, Program Statements are In this mode, program consist of line number
entered without a line number. After followed by an instruction or statement. It is
pressing Enter or Return Key, these used to write program. It is also called indirect
commands are executed. mode.
Delete Command: Kill Command:
To delete program lines or line range. To delete a file or files from the disk
permanently.
Syntax: Syntax:
Delete [line number 1][-line number 2] Kill filename
List Command: LList Command:
To list the part or the whole loaded program LList print a line or the whole program through
on the screen. the printer.
Syntax: Syntax:
List[line number -][,filename] LList[line number -][,filename]
Key ON: Key OFF:
Display the first six characters of the Disappear the key menu from the screen.
function keys on the 25th line of the screen.
Numeric Data: String Data:
Data having numbers used in calculations. Data consist of words or texts.
String consists of all the characters, words or
numbers enclosed by quotation marks.
Example: Example:
174, 16, 39.82 etc. “14th Aug. 1947” etc.
Constant: Variable:
Constants are static values that GW-BASIC These are the names that are taken to represent
interpreter uses during execution of a values used in GW-BASIC Program.
program.
Their values never change during execution Their values can be change during execution of
of a program. a program when needed.
The value of variable may be assigned
specifically through constants or may be the
result of calculation in your program.
String Constant: Numeric Constant:
It is a sequence of 0-255 alpha-numeric It consists of numbers those can be positive or
characters enclosed in double quotation negative. When entering a numeric constant,
marks. we should not give the commas.
It can be Integer, Single Precision and It can be Integer, Single Precision and Double
Double Precision. Precision.
Example: Example:
“Hello”, “Rs.25,000.00” etc. 10000 (correct constant)
10,000 (incorrect constant)
Integer
Prepared by: Mrs. Constant:
Naheeda Shafique Fixed-Point Constant:
10 Whole numbers between -32768 and Positive and negative real numbers.
+32767.
They do not contain decimal point. They contain decimal point.
Computer Science-X

Charter Number.11
Control Statement

Q: What is Transfer of Control?


A: Jumping from one statement breaking the normal program sequence, to a specified line.
Q: Name the types of Control Statement?
A: 1. Un-Conditional Transfer of Control.
2. Conditional Transfer of Control.
Q: Define Un-Conditional Transfer of Control?
A: It is the transfer of control, the control of execution is passed from one statement to other
without applying any condition.
Q: Which statement is used for Un-Conditional Transfer of Control?
A: The “GOTO” Statement.
Q: Write syntax of GOTO Statement?
A: Line Number GOTO Line Number.
Q: What is the purpose of GOTO Statement?
A: To jump unconditionally to a specified line number.
Q: What is the purpose of line number after GOTO Statement?
A: This line number is any valid line number within the program, where control has to be
transferred.
Q: What happened if line number contains an executable statement?
A: Then the statement and the statements following are executed.
Q: What happened if line number contains a non-executable statement?
A: Then execution proceeds until the first executable statement is encountered at the following
line numbers.
Q: What is end less program? How we can stop it?
A: Program with GOTO Statement is endless program and will only stop when “Ctrl + Break” is
encountered.
Q: What is Conditional Transfer of Control?

Prepared by: Mrs. Naheeda Shafique


11
Computer Science-X
A: In this transfer of control; the execution control is jumped from one statement to other
depending on the values of an expression.
Q: Which statement is used for Conditional Transfer of Control?
A: ON….GOTO, IF….THEN and IF….THEN….ELSE Statements are used for Conditional
Transfer of Control.
Q: Why ON….GOTO Statement is used? Is this statement is known as multiple branching
jump?
A: To branch to one of several specified line numbers, depending on the value returned when an
expression is evaluated, This is known as multiple branching jump.
Q: Write syntax of ON….GOTO Statement?
A: ON expression GOTO line number 1, line number 2,……….
Q: What is the purpose of the value of expression in ON….GOTO Statement?
A: The value of expression (0 TO 255) determines which line number in the list will be used for
branching.
Example:
If the value is 1, the first line number in the list will be destination of branch.
Q: Do you think that REM is an executable statement?
A: REM Statements are not executed but are displayed exactly as entered when program is
listed.

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:

Prepared by: Mrs. Naheeda Shafique


12
Computer Science-X
To jump unconditionally to a specified line To branch to one of the several specified
number. line numbers, depending on the value
returned, when an expression is evaluated.
Q: What happened if the outcome of an expression is non zero (logical true)?
in
IF….THEN….ELSE
and in
IF….GOTO….ELSE
A: THEN or GOTO line number is executed.
Q: What happened if the outcome of an expression is zero (false)?
in
IF….THEN….ELSE
and in
IF….GOTO….ELSE
A: THEN or GOTO line number is ignored and the ELSE line number (if present) is executed.
Otherwise, execution continues with the next executable statement.
Q: Differentiate between ON-GOTO Statement and ON-ERROR GOTO Statement?
A:
ON-GOTO Statement: ON-ERROR GOTO Statement:
To branch to one of several specified line To handle errors and transfer the control
numbers, depending on the value returned, to the line of the error-handling
when an expression is evaluated. sub-routine.
Q: Why CONT Statement is used?
A: To continue the program execution after a break with STOP Statement.
Q: Differentiate between ERR Variable and ERL Variable?
A:
ERR Variable: ERL Variable:
It is a library variable used to display the It display the line number where the error
nature or type of the error. (error number or occurs.
error code)

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.

Prepared by: Mrs. Naheeda Shafique


13
Computer Science-X
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.
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?
Prepared by: Mrs. Naheeda Shafique
14
Computer Science-X
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
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
Prepared by: Mrs. Naheeda Shafique
15
Computer Science-X
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
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
Prepared by: Mrs. Naheeda Shafique
16
Computer Science-X
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
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
Prepared by: Mrs. Naheeda Shafique
17
Computer Science-X
1
2
3
.
.
.
100

Q: Explain IF....THEN....ELSE Statement?


A: IF....THEN....ELSE Statement:
It is used for conditional branching. It is also called conditional transfer of control as it
transfer control to a specified portion of a program depending on the condition.
Syntax:
Line number IF (Condition) THEN (statement 1) ELSE (statement 2)

In this format THEN may be followed by a single BASIC Statement or sequence of


statements or it may be line number or branching one or more statements.
In general Format of IF....THEN....ELSE Statement, If the condition is true, then the
statement 1 is executed. If the condition is false, then statement 2 is executed.
The “ELSE” Statement is optional.
If “ELSE” Statement is not present and condition is false, then the control is automatically
transferred to the next executable statement.

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:
Prepared by: Mrs. Naheeda Shafique
18
Computer Science-X
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:
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.

Q: Explain the Multiple Branching Statement?


A: Multiple Branching/ON-GOTO Statement:
● This Statement is used to branch to one of several specified line numbers, depending on
the value returned when an expression is evaluated.
● This statement provides more than 2 options or transfer points, in which either one can be
selected at a time. It can be called as combination of GOTO and IF....THEN....ELSE
Statements.
Syntax:
ON Expression/Numeric Variable GOTO line number 1, line number 2,................
Prepared by: Mrs. Naheeda Shafique
19
Computer Science-X
● Value of Expression must be 0 – 255.A variable or expression is given after ON and
different line numbers are mentioned after GOTO.
● First of all, value of variable or expression is checked. If its value is 1, control transfer to
first line number after the word GOTO. If it is 2, the control goes to second line number
and so on. It is also called “Multiple Branching Statement”.
Example:
10 Input N
20 A$ = “-ve”
30 B$ = “0”
40 C$ = “+ve”
50 D$ = “The number you entered is”
60 S = SGN (N)+2
70 ON S GOTO 8, 90, 100
80 ? D$, A$
90 ? D$, B$
100 ? D$, C$
110 END
(OR)
10 Input N
20 ON N GOTO 50, 70, 90,110
30 Print “Wrong Value Try again”
40 GOTO 10
50 Print “Assalam-o-Alakum”
60 GOTO 10
70 Print “We are Muslims”
80 GOTO 10
90 Print “Always speak truth”
100 GOTO 10
110 Print “Allah Hafiz”
120 END
Q: Explain the FOR....NEXT Loop?
A: FOR....NEXT/Counter/Determined Loop:
● FOR....NEXT Statements are used together to form a loop. It allows a statement or a
group of statements to be performed in a loop for a given number of times.
● It is a determined loop as it specify how many times a loop will be executed.
● The FOR Statement is the first statement of the loop to name the counter and put initial
and final values.
● The NEXT Statement is the last statement of the loop that indicates the end of loop,
increments the counter and then test the counter.
● The statement between the FOR and the NEXT Statements are called the body of loop.

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
Prepared by: Mrs. Naheeda Shafique
20
Computer Science-X
. .
. .
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.

Example.1: To Print even numbers from 1 to 100.


10 FOR EVEN = 2 to 100 step 2
20 ? Even
30 NEXT Even
40 END
Example.2: To Print even numbers from 100 to 1.
10 FOR EVEN = 100 to 1 step-2
20 ? Even
30 NEXT Even
40 END
Q: Explain the WHILE/WEND Loop?
A: WHILE/WEND Loop:
● The WHILE/WEND Statement is used to execute a loop body in a loop as long as a
given condition is true. In this type of a loop it is not known in advance that how many
times the loop will be executed and when the condition becomes false, the control will be
transferred to the next statement following the WEND Statement.
● The WHILE/WEND Loop is used when the number of iteration is not known in advance.

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.

Example: To Print even numbers from 1 to 50.

10 LET C=2
20 WHILE C<=50
Prepared by: Mrs. Naheeda Shafique
21
Computer Science-X
30 ? C
40 LET C=C+2
50 WEND
60 END

● WHILE/WEND Loop Structure is illustrated with the following flowchart:

Is
Conditio False
n?

True

Body of the loop

(Next Statement following the WEND)

Prepared by: Mrs. Naheeda Shafique


22
Computer Science-X
Chapter Number.12
Arrays

Q: Define Array? Differentiate between One-dimensional and Two-dimensional array?


A: Array:
An Array is a collection subscripted variables with the same variable name. The subscript
must be either “0” or a “+ve” integer and must always be enclosed in parentheses.
Example:
A(2), B(5), B$(4), Num(0), Name$(7).
A, B, B$, Num and Name$ are variable and 2, 5, 4, 0 and 7 are subscripts.
1. One-Dimensional Array:
It is called linear, vector, I-D and One-Dimensional Array. In 1-dimentional array, single
subscript is used with the array-name and each subscript variable is used to store one number
or string.
Example:
A student has taken different marks in 8-subjects and wants to display them on computer.

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.

Prepared by: Mrs. Naheeda Shafique


23
Computer Science-X
First element of this array will represent the value of 1st row/1st column while last element
will be used for last row/last column. DIM statement is used in this array, when array has
more then 10 rows and 10 columns. Syntax will be
Line number DIM ABC(M,N)
Where; ABC: array-name, M: row, N: column.

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

It will print a table consisting of 3 rows and 4 columns.

Prepared by: Mrs. Naheeda Shafique


24
Computer Science-X

Chapter Number.13
Subprogram and file handling

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.

Like: LEFT $, TIME$ etc. Like: Sin(x), SQR(x) etc.

Q: What is file?
A: Data or information is collected together into what is called a file.
Q: Name types of file?
A: 1. Text Files.
2. Data Files.
Q: Differentiate between Text Files and Data Files?
A:
Text Files: Data Files:
It is just a file where we have text only. It is a collection of related types of data arranged
in some order.
Q: Draw a logical structure of data file starting with character?
A:
Character Character Character

Field Field Field Field Field

Record Record Record Record Record


Prepared by: Mrs. Naheeda Shafique
25

A File
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.

Student Name
Example:
Field 1

Roll no.
Field 2

These are two different fields.


Q: What is Record?
A: It is a collection of related fields to provide information about an entity (Say student).
Example:
Student’s Record
Name Father Name Roll Number Age Gender Address
------- --------------- ----------------- ------ --------- ----------------
Q: What are the two different techniques to organize files in BASIC?
A: 1. Sequential Files.
2. Random Access Files.
Q: Differentiate between Sequential Files and Random Access Files?
A:
Sequential File: Random Access Files:
In these files data is stored in the order it is In these files data is stored and retrieved in
given. any order.
In these files each and every record in the Records can be added or deleted in these
file has to be accessed until and unless the files at any position.
required record is retrieved.
It is also called a direct file.

Prepared by: Mrs. Naheeda Shafique


26
Chapter Number.14
Graphics in BASIC
Q: What are Graphics?
A: Graphics are shapes, pictures or drawing of different colors to represent information. These
may be colorful or black and white. Graphics are sophisticated mean of displaying
information on screen. For drawing graphics the system should have graphic adaptor.
Q: Name 3 modes of GW-BASIC to display data?
A: 1. Text Mode.
2. Medium-Resolution Graphic Mode.
3. High-Resolution Graphic Mode.
Q: Define Text Mode?
A: It is only used for textual data. Information may be displayed in either 40 x 25 or 80 x 25 text
mode (pixels1). Here 40 and 80 shows columns while 25 show rows. It has 16 colors out of
any two palettes. Columns are counted from 0 to 39 or 79 and rows from 0 to 24.
Q: Define Medium-Resolution Graphic Mode?
A: It is used in drawing graphics with a matrix of 320 x 200 graphic format having 4 colors
(numbered as 0, 1, 2 and 3). One of 16 colors can be chosen for background and one for
foreground.
Q: Define High-Resolution Graphic Mode?
A: These are used in drawing graphics with a matrix of 640 x 200 graphic format with only
black and white color.
Q: Differentiate between Pixel and Palette?
A:
Pixel: Palette:
It is a picture element that shows a single It is a little board of different colors used
dot on the screen. Greater numbers of pixel by painters for drawing pictures or making
shows good resolution. sceneries etc.
Q: Define Screen Statement with Syntax and Purpose?
A: It is used to set the specifications for display screen to select an appropriate screen.
Syntax:
screen [mode] [,[color switch]][,[apage]][,[vpage]].
Q: Which modes are provided in the following displays?
A: ●MDPA: Monochrome display has mod 0, Supports text only.
●CGA: Color Graphics Adaptor has mode 0, 1 and 2, Support text and medium-resolution
and high-resolution graphics.
●EGA: Enhanced Graphics Adaptor has mode 0, 1, 2, 7 and 8.
●EGA: With Enhanced Color Display has mode 9. Program written for this mode will not
work for any other hardware configuration.
●EGA: With Monochrome Display has mode 10. Program written for this mode will not
work for any other hardware configuration.
Q: Describe Screen 0?
A: ● Text mode only.
● Either 40 ● 25 or 80 ● 25 text format.
● Assignment of 16 colors to any of 2 attributes.
● Assignment of 16 colors to any of 16 attributes (with EGA).
Q: Describe Screen 1?
A: ● 320 ● 200 pixel medium-resolution graphics.
● 80 ● 25 text format.
● Assignment of 16 colors to any of 4 attributes.
Q: Describe Screen 2?
A: ● 640 ● 200 pixel high-resolution graphics.
● 40 ● 25 text format with character box size 8.8.
● Assignment of 16 colors to any of 2 attributes.
Q: Describe Screen 7?
A: ● 320 ● 200 pixel medium-resolution graphics.
● 40 ● 25 text format.
● Assignment of ay of 16 colors to 16 attributes.
Q: Describe Screen 8?
A: ● 640 ● 200 pixel high-resolution graphics.
● 80 ● 25 text format.
● Assignment of ay of 16 colors to 16 attributes.
Q: Describe Screen 9?
A: ● 640 ● 350 pixel enhanced-resolution graphics.
● 80 ● 25 text format.
● Assignment of either 64 colors to 16 attributes.
Q: Describe Screen 10?
A: ● 640 ● 350 enhanced-resolution graphics.
● 80 ● 25 text format with character box size 8 ● 14.
● Assignment of up to 9 pseudo-colors 1.
Q: Write Syntax and Purpose of color statement? Write its Syntax in text mode and in
graphics mode?
A: The purpose of color statement is to select the display colours.
Syntax:
(Screen 0) (Text Mode)
color [fore ground][,[back ground][, border]]
(Screen 1) (Graphic Mode)
color [back ground][,[Palette]]
(Screen7, 8, 9) (Graphic Mode)
color [fore ground][,[back ground]]
Note:
Learn modes and their effects with color statement from page 82(gaba book).
Q: Write Syntax and Purpose of PSET or PRESET statement?
A: To display a point at a specified location on the screen while working in graphics mode.
Syntax:
PRESET (x,y)[,color]
PSET (x,y)[,color]
(x, y) represents the co-ordinates of the point while color is the color of the point.
Q: Write Syntax and Purpose of Line statement?
A: To draw lines and boxes on the screen.
Syntax:
Line[(x1, y1)]-[(x2, y2)[,[attribute][,B][F]][,style]]
● x1, y1 and x2, y2 specify the starting and ending point of a line.
● Attributes color or intensity of the displayed pixel.
● The switch B draws a box with the points (x1, y1) and (x2, y2) at opposite corners while
switch BF draws a box just like B and fill-in the interior with points.
Q: Write Syntax and Purpose of Draw statement?
A: This statement is used to draw different shapes of figures. It is valid only in graphic mode.
Syntax:
Draw String Expression
Movement commands are used in it to move for a distance of scale factor * n, where the
default for n is 1; thus, they move one point if n is omitted.
Q: Make table of movement command?
A:
Commands: Moves
Un ↑
Dn ↓
Ln ←
Rn →
En
Fn
Gn
Hn
B Move without plotting any of point.
N Returns to original position when done.
Q: Write Syntax and Purpose of Circle statement?
A: This statement is used to draw circle, ellipse or a part of circle on the screen.
Syntax:
Circle(x center, y center), radius [, [color][, [start], [end][, aspects]]]
● x center and y center are x- and y- coordinates of the center of the ellipse.
● Radius is the radius (measured along the major axis) of the ellipse.
● Color specifies the color of the ellipse. Its value depends on the screen mode.
● Start and End parameters are radian arguments between -2π and 2π (begin and end of the
drawings of ellipse).
● Aspects describe the ratio of the x radius to y radius(x : y)(height : width)
Q: Write Syntax and Purpose of Palette statement?
A: It is used to change one or more colors in the palette.
Syntax:
Palette [attribute, color]
This statement work only for system equipped with IBM® EGA.

S-ar putea să vă placă și