You are on page 1of 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

Helps in reporting to the higher authority. description of solution and other material. Helpful for all users. repairs. Q: What is Maintenance? A: It is an activity to keep the program in working. is known as documentation. 2. 2. replacements and many more activities. 4.10 Prepared by: Mrs. definition.Computer Science-X locate. Helps in writing the same code for another computer. 3. Direct Conversion. flowchart. It includes up dates. potential problems. User Documentation. 2. Old System New System Q: What is meant by Documentation? A: The description of what a program is and how to use it. Q: What important functions are performed by documentation? A: 1. 3. Q: If a computer program do not meet the user’s needs. Parallel Conversion. Naheeda Shafique 3 . Q: Name the types of Documentation? A: 1. 5. Helps in recovery of damage program. Q: What are the four conversions through which a program can be implemented? A: 1. It also used by analyst and programmers. Technical Documentation. structure chart. 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. 4. Q: What is Direct Conversion? A: The conversion from an old system into a new one all at once is called Direct Conversion. Pilot Conversion. pseudo-code and the program coding. Helps in understanding overall program structure and improve the program. Then what the programmer should do? A: Then the programmer should trace through the program development procedure. Q: What is implementation? A: It is a process of taking the program and placing it into operation. Phased Conversion. Q: Define User Documentation? A: It is a Technical & Non-Technical discussion of a problem being solved. coding form. error free and up-to-date. design stage. Q: Define Technical Documentation? A: It helps the computer operators to execute the program. change the algorithm. analysis. Chapter Number. flowchart. It includes statement of problem.

● Easy to program. John Kemeny and Thomas Kurtz developed it in 1965. It is used for computation. ● All purpose language. / etc. -. ● No standard version is available. Q: Write syntax and purpose of Auto Command? A: To generate and increment line numbers automatically each time you press the enter key. Q: What are Commands? A: These are executable instructions and generally executed in the direct mode. ● Physically Statements may be in any order but their execution must be in an ascending order. +.) 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. [increment]] ii) Auto. 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. GW-BASIC and VISUAL BASIC. Q: BASIC is All Purpose. loading. ● Two statements can be written in one line one line separated by colon (:). Naheeda Shafique 4 . [increment]] Q: What happens if Auto command generates a line number that is already being used? Prepared by: Mrs. (=. test and debug. End statement must be given. However. Q: Write disadvantages of BASIC? A: ● Slow in Processing but compiler version is faster. which directs the computer to take a specific predefined action called reserved-words or keywords. graphic designing and business applications.Computer Science-X Data Types. ● Instructions written in it are very similar to English language. what does it means? Write advantages of BASIC? A: ● Simple and easy to learn. They usually perform some type of Program maintenance such as editing. ● To indicate the end of the program. These can not be used as variable names. or saving program. (A to Z or a to z) ● Special characters. Q: What are the rules for Reserved Words? A: GW-BASIC interprets keywords as a part of statement or command. these may be embedded within variable names. (0-9) ● Alphabetic characters. [. Q: Write BASIC character set? A: ● Numeric characters. or command level of the interpreter. 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: What are the rules of BASIC Program Structure? A: ● Each statement of program must start with positive line number. 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. Syntax: i) Auto [[line number]. Q-BASIC.

Q: What is the purpose of pressing CTRL +HOME? A: To clear the screen. Syntax: Key.Computer Science-X A: An asterisk appears after the number to warn that any input will replace the existing line. Q: What is the syntax and purpose of Kill command? Prepared by: Mrs. Q: Name types of constants? A: 1. 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. Q: What will be the purpose of Files “E:Burki\*. Numeric Constant. Naheeda Shafique 5 . Syntax: Files [path-name] Q: What will be the purpose of Files “B:*. Key number. Q: What will be the purpose of Files “TEST?. 2 Clears only the text window. 1 Clears only the graphics. Q: What is the syntax and purpose of Clear command? A: To set all numeric variables to zero.BAS”? A: List all files start from TEST with the extension BAS. Syntax: CLS (N) [N value is optional] Q: What is the purpose of giving 0. Q: What is the purpose of Key List? A: List all 10 function keys on the screen with the associated functions. all string variables to null and to close all open files. Q: What is the syntax and purpose of Key command? A: It assigns the string expression to the specified function key. 1 and 2 values in N in CLS Command? A: N Effect 0 Clears the screen having both text and graphics.*”? A: List all files in the drive B with all types of extension.DOC”? A: List all files in the directory named Burki that are on the drive E and have the extension DOC. String Constant. 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. 2. String Expression. 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: Load “file name”[. the program runs after it is loaded. 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: Kill filename Q: What is the syntax and purpose of Load command? A: To load a file from a diskette into memory. Syntax: i) Save filename [. Q: What is the syntax and purpose of Restore Statement? Prepared by: Mrs.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: RENUM [new number].Computer Science-X A: To delete a file or files from the disk permanently.increment] Q: What is the syntax and purpose of RDDIR command? A: To delete a subdirectory with the specified path. Q: What is the syntax and purpose of MKDIR command? A: To create a subdirectory with the specified path. Q: What is the syntax and purpose of Save command? A: To save a program file on disk.r] If the “r” option is used with load. Syntax: RDDIR pathname Q: What is the syntax and purpose of RUN command? A: To execute the program currently loaded in memory. Naheeda Shafique 6 . Syntax: i) RUN [line number] [.a] ii) Save filename [.r] ii) RUN filename “RUN” runs the program while RUN line number runs the specified line number of a program. [old number][. 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. or to load a file from the disk into memory and run it. Syntax: New This command is entered at command level to clear memory before entering a new program. Syntax: MKDIR pathname Q: What is the syntax and purpose of Name command? A: To change the name of a disk file. Q: What is the syntax and purpose of RENUM command? A: To renumber the program lines.

][Prompt String.] ● ? may be used in place of “Print”. Q: Which special characters are used to format the numeric field in print using statement? A: ● Pound Sign (#). Syntax: RESTORE [line number] Q: What is the syntax and purpose of LET Statement? A: It is called Assignment statement. ● . ● . ● Double Dollar Sign ($$).]list of variables Each data item in the prompt string must be enclosed in double quotes. 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.] Q: Which characters are used to format the string field in print using statement? A: ! . generally separates strings. Note: Learn the purpose of these characters and examples from page number 34. \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.). Syntax: PRINT USING string expression. ● . Naheeda Shafique 7 . Q: What is the syntax and purpose of Print Statement? A: It is an output statement used to display an output on screen. If more than one variable is given will be separated by commas. list of expressions[. ● Double Asterisk (**).] ii) Line number ?[Constants/Variables/Expressions list][.Computer Science-X A: It is used to restore data statements from start./. ● Sign Character (+). ● Sign Character (-)./. ● Comma (.][Prompt String. followed by semicolon or a comma and name of variable to which it will be assigned. Q: What is the syntax and purpose of Print using Statement? A: To print strings or numbers using a specified format. The computer prints the strings without adding space. and . 35 Prepared by: Mrs. Syntax: i) Line number Print[Constants/Variables/Expressions list][. Syntax: i) Line number Input[. are separators. generally causes the output to be printed across the screen in five zones.]list of variables ii) Line number Input[.

TPAY etc. numbers and special characters. A$. Naheeda Shafique 8 . Q: Define Operator? Name its types? A: An Operator performs mathematical or logical operations on values. 2) Fixed-Point Constant. B2.988E-7 2359E6 Q: What is allowable range for floating-point constant? A: 3.7●1038.Precision and Double-Precision. A$. B$ 50 Print Using “\ \”. Single. The result of comparison may be either “Yes” or “No” or may be “True” or “False” Q: Define Logical Operator? Prepared by: Mrs. B33$. A$. 2) String Variable. Valid variable name are: A. NUM. Q: Define String Variable? A: It represent a character string that is a character or a sequence of characters i. Q: What is the format in string field in print using statement when we give “!” “\ \” “\ \”? Explain with example. These are divided into 4 types: ● Arithmetic Operator. X55. ● Relational Operator. ● Consist of an optional-signed integer or fixed point number (the mantissa). Q: Define Relational Operator? A: It is used to relate or compare two quantities. it can be Integer.0●10-39 to 1. Q: Define Numeric Variable? A: Numeric Variable always has numeric values. 3) Floating-Point Constant. letters.e. ● Logical Operator. B$ 40 Print Using “\ \”. A numeric variable name may consist of all alphabets and numeric constants but must begin with an alphabet.) Example: 235. Q: Name types of variables? A: 1) Numeric Variable. ● Functional Operator. GRAD$ etc.Computer Science-X Q: Name the types of numeric constant? A: 1) Integer Constant. Blank spaces may include in a string but not the quotation marks. A: 10 Let A$ = “IMCB” 20 Let B$ = “F-7/3” 30 Print Using “!”. 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. Special Characters and blank spaces are not allowed . followed by the letter E and optional-signed integer (the exponent. It must be followed by $ sign such as A$.

^. Naheeda Shafique 9 . Example: +. AND. /. multiplication. ● Integer division is denoted by (\). Q: Define Functional Operator? A: These are built in functions used to perform arithmetic and string operations. Q: Write sample variable name of Integer. FIX etc. -. 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. It returns remainder of an integer division. or Boolean operations. INT. Example: ABS. which is either true(non-zero) or false(zero). ● The mod operator denotes modulus arithmetic. *. division etc. subtraction.Computer Science-X A: It perform tests on multiple relations. \(integer division). bit manipulation. OR etc. . Example: NOT(Unary). mod(modulus) ● Two additional arithmetic operators are also available known as integer division and modulus arithmetic. The operands are rounded to integers before the division is performed and the quotient is truncated to a lower integer. Q: Define Arithmetic Operator? A: Numeric expressions contain operators that perform arithmetic operations as addition. It returns a bit-wise results.

Syntax: Syntax: List[line number -][. 39. “14th Aug. Exponential form using D. String consists of all the characters. Example: Example: 174. Delete Command: Kill Command: To delete program lines or line range. we should not give the commas. 10 +32767. Single Precision and It can be Integer. Numeric Data: String Data: Data having numbers used in calculations.000. 10000 (correct constant) 10. marks.filename] LList[line number -][. . Direct Mode: Program Mode: In Direct Mode. Precision. The value of variable may be assigned specifically through constants or may be the result of calculation in your program. It is also called indirect commands are executed. Naheeda -32768 and Positive and negative real numbers. 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. mode.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.00” etc.filename] Key ON: Key OFF: Display the first six characters of the Disappear the key menu from the screen. Exponential form using E. A trailing exclamatory sign(!). a program when needed. Program Statements are In this mode.25. After followed by an instruction or statement. 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. Their values never change during execution Their values can be change during execution of of a program. A trailing number sign(#).82 etc. function keys on the 25th line of the screen. Example: Example: “Hello”. the printer. It can be Integer. digits of precision. It is pressing Enter or Return Key. words or numbers enclosed by quotation marks. 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. Single Precision and Double Double Precision. To delete a file or files from the disk permanently. They contain decimal point. precision or fewer digits. program consist of line number entered without a line number. 16. Data consist of words or texts. They do not contain decimal point. “Rs. 1947” etc. these used to write program.000 (incorrect constant) Integer Constant: Fixed-Point Constant: Whole numbers between Shafique Prepared by: Mrs. When entering a numeric constant. program.

Q: What is the purpose of GOTO Statement? A: To jump unconditionally to a specified line number. where control has to be transferred. Naheeda Shafique 11 . Q: Name the types of Control Statement? A: 1. to a specified line. Conditional Transfer of Control. the execution control is jumped from one statement to other Prepared by: Mrs. Q: What is Conditional Transfer of Control? A: In this transfer of control. 2. 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 the purpose of line number after GOTO Statement? A: This line number is any valid line number within the program. 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: Write syntax of GOTO Statement? A: Line Number GOTO Line Number. the control of execution is passed from one statement to other without applying any condition. Un-Conditional Transfer of Control.11 Control Statement Q: What is Transfer of Control? A: Jumping from one statement breaking the normal program sequence. Q: Which statement is used for Un-Conditional Transfer of Control? A: The “GOTO” Statement. Q: What happened if line number contains an executable statement? A: Then the statement and the statements following are executed.Computer Science-X Charter Number. Q: Define Un-Conditional Transfer of Control? A: It is the transfer of control.

If the value of expression is less than 0 or more than 255? A: 1. depending on the value Prepared by: Mrs. a message “illegal function call” is generated.THEN and IF…. Q: What is the decision block and repetition block in control structure? A: ● The Decision block controls the statements to be executed. Q: Which statement is used for Conditional Transfer of Control? A: ON….………. It control the flow of statement and execution with in the program. Q: What happened. 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.THEN…. 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. 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.GOTO. This is known as multiple branching jump.GOTO Statement is used? Is this statement is known as multiple branching jump? A: To branch to one of several specified line numbers. line number 2. Q: Why REM Statement is used? A: To insert some exclamatory comment in a program. depending on the value returned when an expression is evaluated. Naheeda Shafique 12 . line numbers. IF…. 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.GOTO Statement? A: The value of expression (0 TO 255) determines which line number in the list will be used for branching. the first line number in the list will be destination of branch. if 1. Q: Write syntax of ON…. 2.GOTO Statement? A: ON expression GOTO line number 1. 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. If the value of expression is non-integer then fractional portion is rounded. The value of expression is non-integer? 2. ● The Repetition block controls the repeated execution of one or more statements. Q: What is the purpose of the value of expression in ON…. Example: If the value is 1.Computer Science-X depending on the values of an expression. Q: Why ON…. If the value of expression is less than 0 or more than 255.ELSE Statements are used for Conditional Transfer of Control.

THEN…. will cause the program to GOTO the line specified.ELSE and in IF…. Prepared by: Mrs. 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.ELSE and in IF….GOTO…. (for finishing the loop) 3.WEND Loop and FOR…. Q: What is the disadvantage of using ON-ERROR GOTO Statement? A: Any Error including disk problem or a Syntax Error. to the line of the error-handling when an expression is evaluated. Q: What happened if the starting value of the loop exceeds the ending value? A: The body of the loop is skipped. Testing Condition. Initial/Starting value. with whom the loop deals? A: 1. 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. Q: What happened if the outcome of an expression is non zero (logical true)? in IF….GOTO…. Q: Differentiate between WHILE…. any error including disk problem or a syntax error. Incremental value.ELSE A: THEN or GOTO line number is executed. depending on the value returned. This can make the debugging very difficult. Q: Name the 3-conditional values. when an expression is evaluated. Q: How debugging can be very difficult.ELSE A: THEN or GOTO line number is ignored and the ELSE line number (if present) is executed.NEXT Loop? A: WHILE….WEND Loop: FOR…. execution continues with the next executable statement. This can make the debugging very difficult.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. Naheeda Shafique 13 . Otherwise. (error number or occurs. Q: What happened if the outcome of an expression is zero (false)? in IF…. will cause the program to GOTO the line specified. when we are using ON-ERROR GOTO Statement in a program? A: Because.Computer Science-X returned. error code) Q: What is looping? A: The process of repetition of a statement or group of statements.THEN…. 2. sub-routine.

● FOR…. Q: Define Nested Loop? A: The loop that occur within other loops are called Nested Loop. 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.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. Q: What conditions must be met while nesting a FOR…. close all It terminates program execution and return to files. ● It is also called Counter or Determined Loop because in this type of loop the number of iteration is known in advance. 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. Naheeda Shafique 14 . Q: Differentiate between STOP Statement and END Statement? A: END Statement:: STOP Statement It terminates program execution. 2) Controlled\Undetermined Loop. 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. ● The NEXT of inner loop must appear before the outer loop.NEXT Statements are used to implement this type of loop. Types: 1) Counter\Determined Loop.Computer Science-X not known in advanced. 1) Counter\Determined Loop: ● It is used in that case when the specific number of repetition is known in advance. return to command level. Physically command level like END Statement. It does not close file like END Statement. Syntax: ● Beep ● Sound F. ● If nested loops have the same end point. it is encountered. ● It executes statement or a group of statements in a specified line number of times such as 10 times or 100 times.NEXT Loop? A: ● Each loop must have a different variable name as its counter. a single NEXT Statement may be used for all of them. ● Example: 10 FOR C=1 TO 5 Step 1 20 Print C Prepared by: Mrs.

therefore it is repeated indefinitely. ON…. The GOTO Statement is used for this purpose. the number of execution of the loop is not determined before the execution of the loop. To stop it.GOTO and IF…. 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. ● It is also known as undetermined loop because in this loop structure. Types: 1) Unconditional Transfer of Control. The BASIC program runs in the sequence of the line numbers. and the statement to be executed next is other than that is in the sequence. 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.Computer Science-X 30 NEXT C 40 END 2) Controlled\Undetermined Loop: ● A loop whose execution depends on a condition being true or false. 2) Conditional Transfer of Control. ●No condition is given in the programs of GOTO . ● WHILE…. 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. ● 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. Naheeda Shafique 15 .ELSE are Conditional Transfer of Prepared by: Mrs.THEN….WEND Statements are used to implement this loop structure. Sometimes the sequence is broken according to the requirement.

ON…. If it is true. Otherwise the control Prepared by: Mrs. 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. C$ 120 END Output: ? 57 The number you entered is +ve. B$ 110 ? D$.Computer Science-X Control Statements. IF…. depending on the value returned when an expression is evaluated. 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. line number 2. a.ELSE Statements: Purpose: To transfer the control somewhere else depending upon a condition.THEN…. b. The IF Statement determines. It is also called conditional transfer of control as it transfer control to specify portion of a program depending on the condition.……………… 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.GOTO Statement: Purpose: To branch to one of several specified line numbers. whether the condition is true or false. and ‘THEN’ part will be executed. logical or combination of these two. A$ 100 ? D$. 3) THEN [line number (OR) Statement]: ‘THEN’ is reversed word and statement is which we want to execute when become true. 100. 110 90 ? D$. Naheeda Shafique 16 . Syntax: ON exp/var GOTO line number 1. the control will be transferred to ‘THEN’ part.

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 Q: Explain IF.ELSE Statement.THEN. It is also called conditional transfer of control as it transfer control to a specified portion of a program depending on the condition.ELSE Statement? A: IF... .ELSE Statement: It is used for conditional branching.. In general Format of IF. Naheeda Shafique 17 ..THEN... ....THEN. 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.. If the condition is true..Computer Science-X will be transferred to the next executable statement of the IF Statement. then the Prepared by: Mrs... The IF…..

● The line number at which the error occurred is stored in the variable ERL. 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 :”. 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”. it transfer control to the line number specified. If “ELSE” Statement is not present and condition is false. If the condition is false. then statement 2 is executed. the computer handles error in the normal way the print command prints out the error message for the last error. 30 ?:? “Impossible” 40 END Output: Division by zero 1. Example: 10 X=0 20 ? 27/X Program without error message. ● The ON ERROR OFF no longer suppress error message i.701412E+38 Impossible When this program will be written using ON ERROR GOTO Statement then: ● The error number is stored in the variable ERR. as soon as an error occurs. The “ELSE” Statement is optional. Program using ON ERROR GOTO: Prepared by: Mrs.e. Naheeda Shafique 18 . 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.Computer Science-X statement 1 is executed.

the control goes to second line number and so on... B$ 100 ? D$.. ● First of all. It is also called “Multiple Branching Statement”. If its value is 1.ELSE Statements.. Naheeda Shafique 19 . ● This statement provides more than 2 options or transfer points.. It can be called as combination of GOTO and IF. ERR 210 ? “Error at line”.. 70. ● Value of Expression must be 0 – 255. 90.. 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. A$ 90 ? D$.. Syntax: ON Expression/Numeric Variable GOTO line number 1.... If it is 2. value of variable or expression is checked. depending on the value returned when an expression is evaluated. in which either one can be selected at a time...... line number 2..110 30 Print “Wrong Value Try again” 40 GOTO 10 Prepared by: Mrs.A variable or expression is given after ON and different line numbers are mentioned after GOTO. 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. 90. control transfer to first line number after the word GOTO... 100 80 ? D$...THEN.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”.. 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. C$ 110 END (OR) 10 Input N 20 ON N GOTO 50.

. 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 Prepared by: Mrs. Naheeda Shafique 20 . Variable: is known as index variable or control variable used as a counter. increments the counter and then test the counter. .. . ● The FOR Statement is the first statement of the loop to name the counter and put initial and final values. . ● The statement between the FOR and the NEXT Statements are called the body of loop.. Body of Loop .Computer Science-X 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. Example. .2: To Print even numbers from 100 to 1.NEXT/Counter/Determined Loop: ● FOR.. ● The NEXT Statement is the last statement of the loop that indicates the end of loop. Expression-1: is the initial value of the counter.1: To Print even numbers from 1 to 100. ● It is a determined loop as it specify how many times a loop will be executed. Expression-2: is the ending value of the counter. Line number NEXT Index variable.NEXT Statements are used together to form a loop. where.. .. It allows a statement or a group of statements to be performed in a loop for a given number of times. Expression-3: is used as an increment.. 10 FOR EVEN = 2 to 100 step 2 20 ? Even 30 NEXT Even 40 END Example.. . 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 .. . STEP: is optional.NEXT Loop? A: FOR.

10 LET C=2 20 WHILE C<=50 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 Prepared by: Mrs. Syntax: Line number WHILE <Condition> . Example: To Print even numbers from 1 to 50. the control will be transferred to the next statement following the WEND Statement. executed. .Computer Science-X 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. Line number WEND ● WHILE is the 1st statement of the loop and WEND is the last statement of the loop. . execution resumes with the statement following WEND Statement. it checks the condition. ● The WHILE/WEND Loop is used when the number of iteration is not known in advance. the WEND Statement will transfer control back to the WHILE Statement to check the condition again. ● When the WHILE Statement. If the condition is true then the control will transfer to the loop body. Naheeda Shafique 21 . ● If the condition become false. ● After executing the loop body.

Computer Science-X (Next Statement following the WEND) Prepared by: Mrs. Naheeda Shafique 22 .

The subscript must be either “0” or a “+ve” integer and must always be enclosed in parentheses. Num and Name$ are variable and 2. 41. Example: 5 7 9 10 2 17 11 3 21 It has 3 rows and 3 columns.J) is a two-dimensional array which contains 2 values I and J. One-Dimensional Array: It is called linear. 37 60 DATA 41. B$(4). 37. Name$(7). K . Naheeda Shafique 23 . table or matrix. 4. 85. 85.Computer Science-X Chapter Number. Sub(6) 60 If there are more than 10 elements then it uses DIM statement. In 1-dimentional array. the first argument represents Row of the table while the second argument is used for column. In this array.2.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. Sub(5) 41 45. 1. Like: ABC(I. A.7 and 8 are subscripts which are Sub(4) 37 enclosed in parentheses. “=”. B$.5. 60. 46 70 End 2. Two-Dimensional Array: It is also called 2-D Array. This type of array is mostly used to read and process data table. Prepared by: Mrs. 60. 55. 71. 5. 55. Sub(7) 71 Like: DIM A(20) Sub(8) 46 Program 10 FOR K=1TO8 20 Read SUB(K) 30 PRINT “SUB” . B. SUB(K) 40 NEXT K 50 DATA 45.3. 71 and 46 are elements of array. 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. In this type of array. 0 and 7 are subscripts. Example: A student has taken different marks in 8-subjects and wants to display them on computer. Example: A(2). vector.6. I-D and One-Dimensional Array. Num(0). single subscript is used with the array-name and each subscript variable is used to store one number or string. B(5).4. two arguments are used in parentheses separated by a comma.

M: row. 60. 100. Syntax will be Line number DIM ABC(M.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. Naheeda Shafique 24 . N: column. 20. 80. 40.N) Where. 90. 120 120 End It will print a table consisting of 3 rows and 4 columns. 50.N) 90 NEXT N 100 NEXT M 110 DATA 10. ABC: array-name. 110. 70. 30. DIM statement is used in this array.L) 40 NEXT L 50 NEXT K 60 FOR M=1TO3 70 FOR N= 1TO4 80 PRINT NUM(M. Prepared by: Mrs. Program 10 FOR K=1TO3 20 FOR L=1TO4 30 READ NUM(K. when array has more then 10 rows and 10 columns.

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. There are two types of functions. Data Files. These can strings. 2. Text Files. Q: Differentiate between Text Files and Data Files? A: Text Files: Data Files: It is just a file where we have text only. Q: What are the Function Subprograms? A: Function is a Subprogram that takes a single or more values and returns a single value output. TIME$ etc. ●These are written internally with in the main program or externally outside the main program as an independent program. SQR(x) etc. Like: LEFT $. Function Subprogram. Q: Name types of file? A: 1. Subroutine Subprogram. 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 A File Prepared by: Mrs. Like: Sin(x). Q: Differentiate between String Functions and Numeric Functions? A: String Function: Numeric Function: These functions manipulate only These functions perform numeric operations. be trinomial and arithmetical operations. 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. Q: Name types of Subprograms? A: 1. Q: What is file? A: Data or information is collected together into what is called a file. String Functions and Numeric Functions. Naheeda Shafique 25 . It is a collection of related types of data arranged in some order.” Physically it is a short segment of a program. 2.Computer Science-X Chapter Number.

It is a specified location where one type of data is kept. Naheeda Shafique 26 .Computer Science-X Q: What is Character? A: It is a smallest piece of information in a data file. Sequential Files. (0-9) or special symbols such as &. *. @ etc. required record is retrieved. Example: Field 1 Student Name Field 2 Roll no. Q: What is data field? A: These are group of related characters to have a unit of information. %. It may be (A-Z). Random Access Files. 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.----------------. Prepared by: Mrs.---------------- Q: What are the two different techniques to organize files in BASIC? A: 1. In general. 2. any order. Example: Student’s Record Name Father Name Roll Number Age Gender Address ------. These are two different fields.--------. 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. Q: What is Record? A: It is a collection of related fields to provide information about an entity (Say student).-----.--------------. #. It is also called a direct file.

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. pictures or drawing of different colors to represent information. ● Either 40 ● 25 or 80 ● 25 text format. High-Resolution Graphic Mode. Text Mode. It has 16 colors out of any two palettes. Program written for this mode will not work for any other hardware configuration. Q: Name 3 modes of GW-BASIC to display data? A: 1. ● 80 ● 25 text format. 2. Q: Define Screen Statement with Syntax and Purpose? A: It is used to set the specifications for display screen to select an appropriate screen. Program written for this mode will not work for any other hardware configuration. These may be colorful or black and white. Syntax: screen [mode] [. Supports text only. Q: Describe Screen 0? A: ● Text mode only. Greater numbers of pixel painters for drawing pictures or making shows good resolution.14 Graphics in BASIC Q: What are Graphics? A: Graphics are shapes. 7 and 8. ●EGA: With Monochrome Display has mode 10. Q: Define Text Mode? A: It is only used for textual data. 2 and 3). 2. ●CGA: Color Graphics Adaptor has mode 0. ●EGA: Enhanced Graphics Adaptor has mode 0. For drawing graphics the system should have graphic adaptor. ● Assignment of 16 colors to any of 16 attributes (with EGA). Support text and medium-resolution and high-resolution graphics. Q: Describe Screen 1? A: ● 320 ● 200 pixel medium-resolution graphics. 3. Graphics are sophisticated mean of displaying information on screen. . Columns are counted from 0 to 39 or 79 and rows from 0 to 24.[apage]][. 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: Which modes are provided in the following displays? A: ●MDPA: Monochrome display has mod 0. sceneries etc. ● Assignment of 16 colors to any of 4 attributes. ● Assignment of 16 colors to any of 2 attributes.[color switch]][. Here 40 and 80 shows columns while 25 show rows.[vpage]]. 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 by dot on the screen. 1. 1. One of 16 colors can be chosen for background and one for foreground. Chapter Number. ●EGA: With Enhanced Color Display has mode 9. 1 and 2. Information may be displayed in either 40 x 25 or 80 x 25 text mode (pixels1). Medium-Resolution Graphic Mode.

y2) at opposite corners while switch BF draws a box just like B and fill-in the interior with points. Syntax: (Screen 0) (Text Mode) color [fore ground][. y) represents the co-ordinates of the point while color is the color of the point. ● Assignment of ay of 16 colors to 16 attributes.[attribute][. y2 specify the starting and ending point of a line.[back ground]] Note: Learn modes and their effects with color statement from page 82(gaba book). y1)]-[(x2.y)[. 8.style]] ● x1. border]] (Screen 1) (Graphic Mode) color [back ground][. Syntax: PRESET (x. .B][F]][.color] PSET (x.Q: Describe Screen 2? A: ● 640 ● 200 pixel high-resolution graphics. Q: Describe Screen 10? A: ● 640 ● 350 enhanced-resolution graphics. ● 80 ● 25 text format with character box size 8 ● 14. 9) (Graphic Mode) color [fore ground][. y1) and (x2. Syntax: Line[(x1. ● Assignment of up to 9 pseudo-colors 1. y1 and x2. Q: Describe Screen 9? A: ● 640 ● 350 pixel enhanced-resolution graphics. Q: Write Syntax and Purpose of Line statement? A: To draw lines and boxes on the screen. 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. ● Attributes color or intensity of the displayed pixel.[Palette]] (Screen7. ● 40 ● 25 text format. 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. Q: Describe Screen 8? A: ● 640 ● 200 pixel high-resolution graphics. Q: Describe Screen 7? A: ● 320 ● 200 pixel medium-resolution graphics. ● Assignment of either 64 colors to 16 attributes.color] (x. ● 40 ● 25 text format with character box size 8.y)[.[back ground][. ● The switch B draws a box with the points (x1. ● Assignment of ay of 16 colors to 16 attributes.8. ● Assignment of 16 colors to any of 2 attributes. ● 80 ● 25 text format. y2)[. ● 80 ● 25 text format.

Syntax: Draw String Expression Movement commands are used in it to move for a distance of scale factor * n.coordinates of the center of the 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. [start]. they move one point if n is omitted. ellipse or a part of circle on the screen. where the default for n is 1.and y. It is valid only in graphic mode. N Returns to original position when done. Q: Write Syntax and Purpose of Circle statement? A: This statement is used to draw circle. y center).Q: Write Syntax and Purpose of Draw statement? A: This statement is used to draw different shapes of figures. ● Color specifies the color of the ellipse. aspects]]] ● x center and y center are x. color] This statement work only for system equipped with IBM® EGA. . thus. Syntax: Palette [attribute. radius [. [color][. [end][. Q: Make table of movement command? A: Commands: Moves Un ↑ Dn ↓ Ln ← Rn → En Fn Gn Hn B Move without plotting any of point. Syntax: Circle(x center. ● Radius is the radius (measured along the major axis) of the ellipse. ● Start and End parameters are radian arguments between -2π and 2π (begin and end of the drawings of ellipse). Its value depends on the screen mode.