Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Computre Science class X Notes Punjab

Computre Science class X Notes Punjab

Published by sanafatimaji298, 2023-01-01 12:59:44

Description: Computre Science class X Notes Punjab

Search

Read the Text Version

Computer Science Class x notes i) BASIC is a:  A. High Level Language  B. Low Level Language  C. Assembly Language  D. Machine Language ii) How many possible solutions are there for a problem?  A. One  B. Two  C. Three  D. Multiple iii) Program upgradation refers to:  A. Program enhancement  B. Program identification  C. Program development  D. Program implementation iv) Which of the following tasks are performed by most of the algorithms?  A. Input  B. Output  C. Processing  D. All of these v) Typographical errors in BASIC statements are:  A. Runtime errors  B. Logical errors  C. Syntax errors  D. Execution errors vi) The diamond symbol represents the:  A. Input/Output

 B. Decision making  C. Processing  D. Remarks vii) Division by zero is:  A. Syntax error  B. Logical error  C. Runtime error  D. Not an error viii) Which of the following documents describe various features of the software and the way it is used?  A. Software requirement specification  B. Problem description  C. User manual  D. Algorithm ix) Algorithm is a:  A. Requirement document  B. Design document  C. Test document  D. user guide x) The technique ‘Divide and Conquer’ is used to solve:  A. Simple problems  B. Complex problems  C. Large problems  D. Complex and large problems Short Questions Q.10 i) List steps that should be followed to solve a problem. Answer: Steps to Solve a Problem: The following steps should be followed to solve any kind of problem: 1. To identify problem

2. To understand Requirements 3. To analyze problem 4. Designing of an algorithm 5. Programming Code 6. Test and Debug the program 7. Implement the program 8. Maintain and Update the program 9. Document the program Q.10 ii) What is analysis? Describe its importance in solving a problem. Answer: Analysis: Analysis is the step in which a problem is divided into sub-problem or simple units. Importance of Analysis: Analysis leads to simple solution of complex and large problems. Example: Reverse the string \"zebra\". Solution: Following steps can approach simple solution for this problem: 1. Write zebra down. 2. Put \"a\" as the first letter. 3. Put \"r\" as the second letter. 4. Put \"b\" as the third letter. 5. Put \"e\" as the fourth letter. 6. Put \"z\" as the fifth letter. Q.10 iii) What method should be adopted to solve complex problems? Discuss briefly. Answer: Top-down Method should be adopted to solve complex problems. This design also called divide and conquer rule that leads to simple solution for complex problems because it breaks down the detailed description and find simple solution. Explanation: Following type of questions can approach the right solution for any problem:  Why it is a problem?  What caused the problem?  Who is responsible?  When did the problem start?

 What weaknesses have caused this problem?  Why didn't we do something else?  What will keep us from solving the problem? Q.10 iv) What do you mean by syntax of a programming language? Is it necessary to know the syntax for solving a problem on computer? Answer: Syntax: \"Syntax includes grammatical rules to write a problem\". Importance of Syntax: It is necessary to know the syntax of a problem on computer because if we don't know the syntax of a program, statements will not be executed so that result can not be display without syntax. Example: 10 READ A, B, C 30 PRINT A, B, C 30 END Q.10 v) Differentiate runtime errors and logical errors. Answer: Difference between Runtime and Logicl Errors: Q.10 vi) Why documentation is considered vital in problem solving process? Give reasons. Answer: Documentation: Documentation contains detailed description of a problem. It is quite valuable in problem solving process due to some reasons:  It is important for those users who depend upon this algorithm on daily basis.  It is easy to update and modify the problem solution.  Programmer can evaluate the solution on the basis of documentation.  It is the detailed description of solution.

Q.10 vii) Is it necessary for an algorithm to solve a problem in finite number of steps? If yes, why? Answer: Yes, it is necessary for an algorithm to solve a problem in finite number of steps because it leads to simple solution. At different stages programmer will be able to evaluate the solution.  First of all we investigate our problem.  After investigation, we develop an algorithm that reflects problem solving process in finite number of steps.  Then we refine this algorithm for further simple solution. Q.10 viii) Write the purpose of the following flowchart symbols: Answer: i. Decision making and branching ii. Input/output iii. Connector iv. Processing v. Off-page/ On-page connector vi. Predefined Process Q.10 ix) Compare flowchart and algorithm. Anwer: Comparison of Flow chart and Algorithm:

Q.10 x) Write an algorithm to calculate the distance covered by a car moving at an average speed of v ms-1 in time t. The program should input average speed v and time t. Answer: STEP 1: Take input of average speed v STEP 2: Take input of time t STEP 3: Calculate s=vt STEP 4: PRINT s Long Questions Q.4) What do you mean by problem solving? Briefly describe the problem solving process. Answer: Problem Solving: Problem-solving is basically a process in which the best possible solution is selected for a difficult problem. Some problems are very challenging and require research work but one problem has multiple solutions so we have to choose the best option for our problem, this is called problem-solving. The process of Problem Solving: There are a number of steps which are followed in order to find the best solution to the problem:  Identify the problem: This step includes basic information about the problem.  Understand requirements: This step demands clear statements from the user.  Analysis of the problem: In the analysis, larger problems are break down into smaller and simple units and this approach leads to a simple solution.  Diagrammatic representation: In this step, the documented design will be converted into a diagram by using different symbols.  Development: In the end, the problem will be translated into a programming language.  Test and Debug the program: Testing involves verification of program either is works properly or not.This step also detects errors from the program.  Implement the program: Implementation of the program includes installation and proper working environment.

 Maintenance: Maintenance is a process of upgrading existing program to introduce new changes and improvements.  Document the program: Documentation involves a detailed description of algorithm, coding, testing and usage of the program. This is a useful document in order to modify or update the work done by the programmer. Q.5) What is debugging? How many types of errors can occur in a program? Describe briefly. Answer: Debugging: Debugging is the process of identifying errors or bugs in a program. Types of Errors: There are three types of errors that may occur during execution: 1. Syntax Errors: Syntax errors are basic grammar errors that are done by programmer during coding. E.g. semi colon is missing. 2. Runtime Errors: This type of error may occur during execution of program and it will stop the working of compiler. E.g. divide some number by zero. 3. Logical Errors: This type of error can not be detected by compiler but it displays wrong results. E.g. using < this operator instead of >. Q.6) Define algorithm. Write a step-form algorithm for making a telephone call to your friend. Answer: Algorithm: Algorithm contains certain number of steps which are being followed in order to solve some specific problem. Step-form Algorithm For Making a Call: Step 1: Dial a number Step 2: Telephone start ringing on other side Step 3: Call received

Step 4: Conversation started Step 5: ended Call Q.7) What are the advantages of flowchart? Discuss limitation of flowchart. Answer: Flow chart: Flow chart is the visual representation of data. Advantages of Flow chart: 1. Flow chart helps in understanding the problem. 2. It is design based so it enhances efficiency. 3. It is useful in the process of finding errors. Limitations of Flow chart: 1. It is not suitable for large problems. 2. It become complex when there are too many executions. Q.8) Draw a flowchart to find the largest of three numbers. Answer: Flowchart to find the largest of three numbers:

Q.9) Write an algorithm to calculate the area of a circle when the radius is given, (area = 3.14 * radius * radius) Answer: Algorithm to Calculate Area of a Circle: STEP 1: Start STEP 2: Input value of radius STEP 3: Compute area of circle by formula STEP 4: Print area STEP 5: Stop execution i) GW-BASIC can operate in:  A. One mode  B. Two modes  C. Three modes

 D. Several modes ii) The maximum length of a variable name in GW-BASIC is:  A. 31  B. 32  C. 40  D. 45 iii) If two or more statements are written on a line, they must be separated by a:  A. Colon  B. Semi colon  C. Comma  D. Hyphen iv) Which of the following is a type declaration character for integer variables?  A. !  B. %  C. #  D. $ v) Which of the following operators has the highest precedence?  A. ^  B. *  C. +  D. = vi) A variable name must start with a(n):  A. Alphabet  B. Underscore  C. Digit  D. Alphabet or Underscore vii) Which of the following is a short key to run a program in GW-BASIC?  A. F4

 B. F3  C. F2  D. F1 viii) When a floating-point value is converted to an integer, the fractional part:  A. Truncated  B. Rounded off  C. May be truncated or rounded off  D. Conversion is impossible ix) Which of the following statement temporarily stops the execution of a program?  A. BREAK  B. END  C. PAUSE  D. STOP x) Which of the following command continues the program whose execution was terminated temporarily?  A. CONTINUE  B. CONT  C. RESTART  D. START i) Write the purpose of the function keys i.e., from FI to F9 in GW-BASIC. Answer: The Purpose of Function Keys in GW-BASIC: F1LIST To see the list of program ii) What does IDE stand for? Discuss features F2RUN To execute a program of GW-BASIC IDE. F3LOAD To load program Answer: F4SAVE To save program IDE stands for Integrated Development F5CONT To continue scrolling Environment. F6LPTI To connect computer on printer port The basic features of GW-BASIC IDE: The basic features of GW-BASIC IDE are: F7TRON To show line number I. Writing: F8TROFFTo turn off function A program consists of data and instructions, to F9KEY To show or hide keys write the statements of a program we need

writing features of GW-BASIC. II. Editing: Existing program statements can be changed or modified with this feature. III. Saving: This will save your program. IV. Loading: The term ‘Loading a Program’ includes carrying out program into the memory of the computer from the hard disk. V. Executing program: Executing means carrying out instruction one by one in order to run a program. iii) Explain the term ‘Loading a program’. Why should a program be loaded before execution? Answer: Loading a Program: The term ‘Loading a Program’ includes carrying out program into memory of computer from hard disk.The key to load a program is F3. The program should be loaded before execution because it can not be executed without loading in memory, in order to use the program it must exist in memory. iv) Differentiate BASIC commands and statements. Answer: Difference between BASIC Commands and Statement The differences between commands and statements are as follows: BASIC Commands BASIC Statements Definition GW-BASIC commands are basically GW-BASIC statements are written a instructions which are executable. program. Mode Commands execute in direct mode. Statements execute in indirect mode. Commands can work without a line Statements always preceded by line Line Number number. number. Example AUTO, CLEAR, CLS, DELETE END, REM, STOP v) What is the difference between CLEAR command and CLS command? Answer: Difference between CLEAR Command and CLS Command: CLEAR Command: Clear command is used to set all values equal to zero or null. CLS Command: CLS command clears the screen.

vi) Write the purpose and syntax of the following commands: a) DELETE b) KILL c) FILES d) LIST e) LOAD f) SYSTEM g) NAME h) RENUM i) RUN j) SAVE Answer: The purpose and syntax of commands: Commands Syntax Purpose DELETE DELETE line number 1- It is used to delete program KILL KILL filename It removes files FILES FILES[pathname] List all files name LIST LIST [line number-][,filename] It displays a program LOAD LOAD filename[,r] It loads a program SYSTEM SYSTEM It is used to close NAME NAME old-filename AS new-filename It rename files RENUM RENUM[new number], [old number] It re-number lines [,increment] RUN RUN [line number] [,r] It executes program SAVE SAVE filename, [,a] It saves program vii) Briefly describe the structure of a BASIC program. Answer: Structure of a BASIC program: The structure of GW-BASIC program is described below: I. Every statement should be followed by line number. II. There should be END statement. III. Repetition of line numbers with in same program is not allowed. IV. More than two sentences must be followed by a colon. V. Variable declaration is not necessary in GW-BASIC. VI. In GW-BASIC, line numbers do not matter because statements always execute in ascending order of specified line number. viii) Differentiate variable and constant. Answer: Difference between Variable and Constant: Variable Constant Variable is used to hold memory The constant value cannot be changed

Definition space that will store program data. once it is declared. Types 1. Numeric variable 1. Numeric constant 2. String variable 2. String constant Usage Use variable when you want Use constant when you declare something something to change during that will not change during execution. execution. Example DIM ABC (3) Const pi=3.14 ix) Write a program that asks for the name, roll number, class, section, and marks in different subjects of a student of class 10. The program should calculate and display total marks and percentage of the student. [Hint: use INPUT statement to get data from the user. Suppose total marks are 850] Answer: 10 CLS 20 INPUT “Enter your name:”;n 30 INPUT “Enter your roll no:”;r 40 INPUT “Enter your class:”; class 50 INPUT “Enter your section:”; section 60 INPUT “Enter obtained marks in english:”;e 70 INPUT “Enter obtained marks in physics:”;ph 80 INPUT “Enter obtained marks in math:”;m 90 INPUT “Enter obtained marks in pakistan studies:”;pk 100 INPUT “Enter obtained marks in computer:”; com 110 INPUT “Enter obtained marks in urdu:”; u 120 INPUT “Enter obtained marks in chemistry:”; chem 130 tm=e+ph+m+pk+com+u+chem 140 percentage=(tm/850)*100 150 PRINT “total marks of student is=”; tm 160 PRINT “percentage of a student is=”; percentage 170 END

x) Write a program to calculate the distance covered by a car moving at an average speed of v ms-1 in time t. The program should input average speed and time, [use INPUT statement to get the values for v and t. You have developed the algorithm for the program in the exercise of the previous chapter] Answer: 10 CLS 20 INPUT “Enter the value of v=”;v 30 INPUT “Enter the value of t=”;t 40 S=v*t 50 PRINT ”Total distance =”;S 60 END xi) Give an example to explain the use of comma (,) and semi colon (;) with PRINT statement. Answer: Use of Comma (,) and Semi colon (;) : Comma: Comma is used to separate different parts of statement. Semi colon: Semi colon is used at the end of statement.

Example: READ A, B, C, P$ PRINT P$; Q.4) In how many modes, GW-BASIC can operate? Discuss briefly. Answer: GW-BASIC operates in two modes which are discussed below: 1. Direct Mode: In direct mode, all commands will be running as they are typed. Description: When GW-BASIC is loaded,OK message will be displayed that indicates direct mode. All commands execute as they were typed. Direct mode can be used as a calculator. 2. Indirect Mode: The indirect mode includes typing a program. Description: Indirect mode can be started by AUTO command. It includes typing of program statements. Q.5) Describe rules of naming variable in GW-BASIC. Answer: Naming Variable: In GW-BASIC, the name of any variable is used for further refrences and its value can be accessed by its name.In order to name some variable you must be careful. Rules for Naming Variable: Following are some rules for naming variable in GW-BASIC: 1. GW-BASIC has 40 character limit which means variable name can not be more than 40 characters. 2. Alphabet must be in start. 3. Variable name may includes alphabets, numbers and the decimal point. 4. There is limit on usage of reserve words so they can not be used as variable names. 5. Blank spaces can not be used in variable names. 6. Last character of variable name may be a special type declaration Like $, #. Q.6) What are type declaration characters? Explain their uses with examples.

Answer: Type declaration characters: In GW-BASIC, type declaration characters are used to represent the type of variable. Following are type declaration characters in GW-BASIC: Character Type of variable Uses Examples $ String $ character used in names. 10 A$=\"punjab text\" % integer % character used with marks and 30 num%=23.68 percentage. ! Single precision This character used in average cases. 40 PRINT USING \"!\"; A$;B$ # Double precision # character is used to calculate area. 20 PRINT A# Q.7) Briefly describe the uses of arithmetic, logical, and relational operators. Answer: Uses of Arithmetic Operator: Arithmetic operators used in mathematical calculations. Operator Description Example + Addition AB+AC=TC - Subtraction X-Y * Multiplication (CL * 4 + MP * 3) / 10 Uses of Logical Operator: Logical operators used to combine two statements and they check conditions. Operator Description Example AND Both operands must be true in order to get true result. A&&B=01 OR If one operand is true and other is false its result will remain true. A|B=0011 NOT The NOT operator reverses the value of the expression. !(A &&B) Uses of Relational Operator: Relational operators used to compare two values. Operator Description Example > It checks if the value of left operand is greater than the value of right (X > Y) < operand, then condition becomes true. It checks if the value of left operand is less than the value of right A<B

operand, then condition becomes true. == It checks if the value of two operands is equal or not, if yes then A==B condition becomes true. Q.8) What does it mean by type conversion? Describe rules of type conversion in BASIC. Answer: Type Conversion: Type conversion is also called type casting, basically it is the process of conversion of value from one data type to another data type. Rules for type conversion: There are some rules that must be followed in order to convert data types of values:  In floating point case, the fraction part will be rounded off. Example: 10 num%=45.6 20 PRINT num% it will display 47.  Numeric value can not be assigned to string. Example: 10 A$=10 If we pass integer to string it will produce wrong result as string takes character only.  All arithmetic expressions will be presented in double precision. Example: 10 x=12#13 20 PRINT x it will display .9230769 Q.9) Write a program to read ten values specified in DATA statement, and display the sum of these values on the screen. Answer: 10 CLS 20 READ A,B,C,D,E,F,G,X,Y,Z 30 Sum=A+B+C+D+E+F+G+X+Y+Z 40 PRINT “The sum of ten values is=”; Sum 50 DATA 10,20,33,40,50,78,70,80,26,100 60 END

Output: The output of the program is as follows: Q.10) Write a program to calculate the volume of a cylinder. The program should get the values for height of the cylinder and the radius of its base from the user through INPUT statement. [Hint: volume = 3.14 X radius X radius x height] Answer: 10 CLS 20 p=3.14 30 INPUT “Enter the value of height=”;h 40 INPUT “Enter the value of radius=”;r 50 V=p*r^2*h 60 PRINT “The volume of the cylinder is=”;V 70 END Output: The output of the program is as follows: Q.11) Write a program to compute the square of a given number. The program should get the number from the user through INPUT statement. Answer: 10 CLS 20 INPUT “ENTER THE NO. :=”;n 30 S=n*n 40 PRINT “SQUARE OF\"; n\" is”; S 50 END

Q.12) Write a program to calculate and print the sum and average of three numbers using LET statement. Answer: 10 CLS 20 LET A=2 30 LET B=3 40 LET C=4 50 LET SUM=A+B+C 60 LET AVERAGE=SUM/3 70 PRINT “SUM OF THREE NUMBERS=”; SUM 80 PRINT “AVERAGE OF THREE NUMBERS=”; AVERAGE 90 END

i) Which of the following is not a logical operator:  A. AND  B. OR  C. NEITHER  D. NOT ii) Which of the following can not be used to exit from an error handling routine:  A. RESUME  B. RESUME NEXT  C. END  D. STOP iii) Which one is a multiple branching statement?

 A. IF...ELSE  B. GOTO  C. ON....GOTO  D. ON ERROR GOTO line_number iv) If the integer value of the numeric expression following the keyword ON, in ON...GOTO statement, is greater than 255, which type of error occurs?  A. Syntax error  B. Logical error  C. Runtime error  D. Its not an error v) FOR.. .NEXT is used to implement:  A. Iteration  B. Selection  C. Sequence  D. All of the above Q.4) Define control structure. How many control structures are available in BASIC, discuss briefly. Answer: Control Structure: \"Control structures are used to control the flow of program execution\". Following types of Control Structures are available in GW-BASIC: a. Sequence: In sequential structure, statements are executed in the same order in which they are specified by line number. b. Selection: A selection structure selects a statement to execute on the basis of a condition. c. Loop: Loop is a control structure that repeats a statement or set of statements. Q.5) Define nested loop. Write the syntax of FOR...NEXT and WHILE...WEND loop and explain with examples. Answer: Nested Loop: In the body of FOR or WHILE loop there can be one or more FOR or WHILE loops, this type of control structure is known as nested loop. Syntax of FOR…NEXT Loop:

FOR variable=x TO y [STEP z] . . NEXT [variable] Explanation of Syntax: In the syntax of FOR loop, FOR is a loop variable, x and y are numeric constants where x gives starting value to the loop and y gives final value to the loop, z is followed by STEP statement that gives increment in x until it y is reached. Example: Program to calculate sum. 1,3,5….99 10 N=1 20 FOR I=1 TO 99 STEP 2 30 N=N+1 40 NEXT I 50 PRINT “SUM OF NUMBERS=” ; N 60 END Explanation of Example: 1. In the above example, N is a variable that is initialized by 1. 2. In the second statement, there is FOR loop in which I is initialized by 1 and its limit is 99 with the increment of 2 in each iteration. 3. Third statement will add up N and I. 4. NEXT statement gives increment in value of I. 5. This statement will print the sum of numbers. 6. Last statement will stop execution. Output: SUM OF NUMBERS=2500 Syntax of WHILE…WEND Loop: WHILE expression . . [Loop statement] . . WEND Explanation of Syntax: The loop repetition is controlled by expression of while loop.If condition is true, statements will execute and body of the loop will be exected untill condition remains true. In case of false condition, loop terminates and control transfers to the WEND statement. Example: Program to print number from 1 to 50.

1O N=1 20 WHILE N<=10 30 PRINT N 40 N=N+1 50 WEND 60 END Explanation of Example: 1. In the above example, N is a variable that is initialized by 1. 2. In second statement, there is a WHILE loop in which there is a condition that states N must be less than and equal to 10. 3. If condition true, increment in value. 4. In case of false statement, control transfers to the WEND statement. 5. Last statement will end up the execution. Output: 1 2 3 4 5 6 7 8 9 10 Q.6) What does it mean by transfer of control? Briefly describe conditional and unconditional transfer of control in BASIC. Answer: Transfer of control: In GW-BASIC, transfer of control means control can be transfer form one part of program to another part during the execution of program. Types of Transfer of control: There are two types of transfer of control in GW-BASIC: Conditional Transfer of control: Program transfers control according to specific condition. Example: 10 INPUT X,Y 20 INPUT \"1-ADD, 2-SUB, 3-MUL, 4-DIV\";N 30 ON GOTO 30, 40, 50, 60 40 PRINT X+Y :END 50 PRINT X-Y :END 60 PRINT X*Y :END 70 PRINT X/Y :END Explanation of Example: In above example, during execution of program, line number 10 displays 1-ADD, 2-SUB, 3- MUL, DIV. If user enters 1 then N takes value of 1 and control transfers to line number 30 and it will display sum and line number 40, 50, 60 will be execute respectively by entering 2, 3 and 4 values for N. Unconditional Transfer of Control:

In this case, there is no specific condition to transfer control. Example: 10 READ A, B, X, Y 20 GOTO 60 30 LET X=X*X+A 40 LET Y=Y*Y+B 50 PRINT X,Y 60 REM X and Y will not be calculated in above lines due to unconditional transfer of control 70 LET X=A*X 80 LET Y=B*Y 90 PRINT X,Y 100 DATA 6, 3, 4, 5 110 END Explanation of Example: In the above example, In line number 10 after reading the values of A, B, X, Y, control directly transfers to line number 60 where statements are non-executable.Then control moves to the line number 70 where X and Y are calculated, after this control moves to line number 90 that will print the X and Y and program ends.Line number 30, 40 and 50 are skipped without any specific condition. Q.7) Differentiate WHILE...WEND and FOR...NEXT loop. Which one is better in a situation where you don’t know the number of iteration prior to the execution of the loop? Answer: Difference between FOR…NEXT and WHILE...WEND Loop: Factor FOR NEXT LOOP WHILE WEND LOOP FOR..NEXT loop is used when a WHILE…WEND loop executes until Definition program need to be executed up to condition remains true. specific number of times. Suitable FOR NEXT loop is useful when WHILE WEND loop is useful when you Situation you want to execute a program up don't know the number of iterations in to certain number of times. advance. Working of loop Loop variable is initialized and In while wend loop, the loop variable is variable initialized outside and is incremented or incremented or decremented decremented inside the body of the loop. within the FOR statement. Syntax FOR variable=x TO y [STEP z]

WHILE expression NEXT [variable] [loop statement] WEND 10 WHILE N<=10 Example 10 FOR 1=2 TO 100 STEP 2 20 N=N+1 30 WEND Suitable Loop in a situation where iterations are unknown: WHILE… WEND loop is used in a situation where you don’t know the number of iterations in advance. Q.8) Write a program to calculate the area of a triangle. The program should get the values for base and altitude of the triangle from the user, and display the result. [Hint: area = ½ X base X altitude] Answer: 10 REM AREA OF TRIANGLE 20 INPUT \"ENTER BASE=\"; B 30 INPUT \"ENTER HEIGHT=\"; H 40 area=(1/2)*B*H 50 PRINT \"AREA OF TRIANGLE=\";area 60 END Output: The output of the program is as follows:

Q.9) Write a program to calculate area and circumference of a circle. The program should get the radius of the circle from the user and display result. [Hint: area = 3.14 X radius X radius, and circumference = 2 x 3.14 X radius] Answer: 10 INPUT \"Enter Radius of Circle\"; R 20 LET PIE=22/7 30 AREA = PIE * R * R 40 C = 2 * PIE * R 50 PRINT “Area of the Circle is=”; Area 60 PRINT “Circumference of the Circle is=”; C 70 END Output: The output of the program is as follows:

Q.10) Write a program to print first ten odd numbers using WHILE.. .WEND loop. Answer: 10 REM first Ten ODD Numbers 20 PRINT \"First Ten ODD Number are ...\" 30 C=1 40 X=1 50 WHILE C<=10 60 IF X MOD 2<>0 THEN 70 ELSE 90 70 PRINT X; 80 C=C+1 90 X=X+1 100 WEND 110 END Output: The output of the program is as follows:

Q.11) Write a program to print the sum of squares of first five even numbers using FOR...NEXT loop. Answer: 10 REM sum of squares of first Five Even Numbers 20 SUM=0 30 C=2*5

40 FOR X=2 TO C STEP 2 50 SUM=SUM+(X*X) 60 NEXT X 70 PRINT \"SUM OF SQUARES OF FIVE EVEN NUMBERS :\";SUM 80 END Output: The output of the program is as follows: Q.12) Write a program to find the larger of two numbers. The program should get the numbers from the user. Answer: Program to find the larger of two numbers: 10 CLS 20 INPUT “Enter the first number=”;x 30 INPUT “Enter the second number=”;y 40 IF x>y THEN PRINT x ELSE PRINT y 50 END Output: The output of the program is as follows:

Q.13) Write a program to print the table of a given number. The program should get the number from the user. Answer: 10 REM this program is used to find the table of any number 20 CLS 30 INPUT \"ENTER THE TABLE NUMBER\"; t 40 INPUT \"ENTER LENGTH OF TABLE\"; l 50 n = 1 60 WHILE (n <= l) 70 PRINT t; \"*\"; n; \"=\"; t * n 80 n = n + 1 90 WEND 100 END Output: The output of the program is as follows:

Q.14) Write a program that should accept obtained marks of a student in an examination. It should then calculate the percentage and assign a grade to the student. The grade should be assigned according to the following criteria. Percentage_________________ Grade >=80 A1 > = 70, but <80 A > = 60, but <70 B

>= 50, but <60 C > = 40, but <50 D <40 F Answer: 10 CLS 20 INPUT “ENTER NAME” ; N$ 30 INPUT “ENTER ROLL NO” ; RN 40 INPUT “ENTER CLASS AND SECTION” ; cs 50 INPUT “ENTER COMPUTER MARKS\" ; comp 60 INPUT “ENTER PHYSICS MARKS” ; phy 70 INPUT “ENTER MATHS MARKS” ;chem 80 INPUT “ENTER MATHS MARKS” ; math 90 INPUT “ENTER ENGLISH MARKS” ; eng 100 INPUT “ENTER URDU MARKS” ; urdu 110 INPUT “ENTER ISLAMIYAT MARKS” ; isl 120 INPUT “ENTER P.STUDIES MARKS” ; pstd 130 tom=comp+phy+chem+math+eng+urdu+isl+pstd 140 percentage=(total obtain marks*100/850) 150 PRINT “total obtain marks=” tom 160 PRINT “PERCENTAGE=” percentage 170 IF percentage>=80 PRINT “grade A+” 180 IF percentage>=70 AND percentage< 80 PRINT “GRADE A” 190 IF percentage>=60 AND percentage<70 PRINT “GRADE B” 200 IF percentage>=50 AND percentage< 60 PRINT “GRADE C” 210 IF percentage >=40 AND percentage< 50 PRINT “GRADE D” 220 IF percentage <40 PRINT “GRADE F” 230 END Output: The output of the program is as follows:

i) There are________ types of array.  A. 1  B. 2  C. 3  D. 4 ii) The statement x(30) will reserve___________ memory locations:  A. 29  B. 30  C. 31  D. None of the above iii) In two dimension array, when dimension is not mentioned, the array should not have more than________ elements:  A. 10  B. 100

 C. 110  D. 121 iv) Which of the following statement is used to find the largest value from an array?  A. INPUT  B. READ....DATA  C. ON-ERROR - GOTO  D. None of them v) Which of the following is not a valid subscript?  A. NUM(10)  B. A(2)  C. B(4)  D. A(-2) vi) An element of an array is mentioned by its:  A. Subscript  B. array  C. object  D. name of element vii) Dimension statement uses the keyword _________ .  A. DMS  B. DS  C. DIM  D. DM viii) Maximum number of elements per dimension is:  A. 10  B. 255  C. 32767  D. None of them ix) The doubly subscripted variable p(3,2) specifies the data element present in

 A. Column 3 and Row 2  B. Column 3 and Column 2  C. Column 2 and Row 3  D. Row 3 and Row 2 x) The statement DIM C(30,50) would reserves.  A. 80 Locations  B. 1500 Locations  C. 1800 Locations  D. 50 Locations Q.4) What is meant by DIM statement? Answer: DIM Statement: DIM is the short form of Dimension and DIM Statement is used to indicate the largest index. Maximum index number for an array is 255. Example: 10 DIM NUM(50) 20 INPUT \"How many number you want to enter; Max:50:\",LIMIT 30 FOR I=1 TO LIMIT 40 INPUT \"Enter number\", NUM (I) 50 NEXT I 60 LARGE=NUM(I) 70 FOR I=1 TO LIMIT 80 IF LARGE 90 NEXT I 100 PRINT \"Largest number of list is\";LARGE 110 END Explanation: In the above program, DIM statement is used to define the maximum index that is 50 in this program, it takes different values from user and each time it will check that value enter by user does not increase the limit. At the end program displays the largest number from the list given by user. Q.5) Describe the use of subscript variable in array. Answer: Uses of subscript variable: Subscript variable represents array elements. It is used to access specific memory location. Example:

10 FOR K=1 TO 4 20 READ N$(K) 30 PRINT N$(K) 40 NEXT K 50 DATA ali, mona. umair, sami 60 END Output: ali mona umair sami Explanation: In this example, when program runs, the subscript variable N$(k) automatically represents each of four elements of an array. After execution of loop, ali is assigned to N$(1) , mona is assigned to N$(2), umair is assigned to N$(3) and sami is assigned to N$(4). Q.6) How would you Fill and Print the array? Answer: Filling of an Array: To enter data into an array is called filling of an array. How to Fill: LET, READ and INPUT statements are used to fill an array. Syntax: Line No. READ array name/ variable Example: READ N$(K) Printing of an Array: To display the data from an array is called printing of an array. How to Print: Array is printed through assignment of data to subscripted variables during execution. Syntax: PRINT array name/ variable Example: 50 PRINT N$(K) Q.7) What is meant by Manipulation of array? Answer: Manipulation of Array: There are different operations that can be performed on array, this is called manipulation of an array. Array operation:

 Sorting: Sorting is used to return indices that sort an array in an ascending order.  Searching: Searching is used to search particular element in the array.  Comparison: It is used to compare two arrays.  Max: Max returns the largest value of an array.  Min: Min returns the smallest value of an array.  Inverse: It reverses the order of one dimension of an array. Program to display Maximum Number: 10 CLS 20 DIM ARRAY (4) 30 FOR N=0 TO 4 40 INPUT \"Enter a number:\"; ARRAY (N) 50 NEXT N 60 MAX=ARRAY (0) 70 FOR N=0 TO 4 80 IF MAX < ARRAY (N) THEN MAX=ARRAY (N) 90 NEXT N 100 PRINT \"Maximum number is \" ; MAX 110 END Output: Enter a number: 52 Enter a number: 15 Enter a number: 84 Enter a number: 5 Enter a number: 29 Maximum number is 84 Explanation: The above program gets input of five values from user and then displays the maximum number from these numbers. Q.8) Differentiate between 1-D-Array and 2-D-Array. Answer: Difference between one dimensional and two dimensional array: Factors One Dimensional Array Two dimensional Array Two dimensional array has two or more Definition One dimensional array has single rows and columns. They also called TABLE or MATRIX. column and single row. Two dimensional array requires two Alternative They also called vector array. Loop Requirement One dimensional array requires

only one loop to process values. loops to process values of rows and column. Syntax Name-of-Array(Value for number MyArray(Value for number of of locations) Rows,Value for number of Columns) Example 10 DIM MyArray(3) 10 DIM MyArray(3, 3) Explanation of Above example is declaring one Above example is declaring two Example dimensional array having name dimensional array having name \"MyArray\" and size 3. \"MyArray\", rows 3 and columns 3. Q.9) Describe about printing two dimensional array with the help of an example. Answer: Printing Two dimensional Array: A two-dimensional array can be printed through nested loops. One is outer and other is the inner loop. The outer loop changes subscript values of row and inner loop changes column value. Example: 10 DIM A(2,2), B(2,2), Z(2,2) 20 FOR R=1 TO 2 30 FOR C=1 TO 2 40 READ A(R,C), B(R,C) 50 Z(R,C)=A(R,C) + B(R,C) 60 PRINT Z(R,C) 70 NEXT 80 PRINT 90 NEXT R 100 DATA 8,4,3,5 110 DATA 6,4,5,5 120 END Output: The output of the program is as follows:

Q.10) Write a program in BASIC to enter integer type data into an array and then to print the values in reverse order. Answer: Program to print values in Reverse order: 10 REM NUMBERS TO PRINT IN REVERSE ORDER 20 DIM REVERSE(50) 30 INPUT \"Enter the Length of REVERSE (5):\";limit 40 FOR x=1 TO limit 50 PRINT \"Enter Value at INDEX \";x\" :\"; 60 INPUT REVERSE (x) 70 NEXT x 80 PRINT \"ARRAY in given order.......\" 90 FOR i=1 TO limit 100 PRINT REVERSE (i); 120 NEXT i 130 PRINT 140 PRINT \"ARRAY IN REVERSE ORDER....\" 150 FOR c=limit TO 1 STEP -1

160 PRINT REVERSE (c); 170 NEXT c 180 END Output: The output of the program is as follows: Q.11) Differentiate between simple and subscript variable

Answer: Difference between Simple and Subscript Variable: Factors Simple Variable Subscript Variable Definition Variables are basically memory Subscript variable is used to access a locations that store data. particular element of an array. Location Simple variables are created in Subscript variables are adjacent in different memory locations. memory. Name The name of each simple variable The name of subscript variable is same but is different. indices are different. Access Value The name of simple variable is The name with index value is used to used to access its value. access the value of subcript variable. Example X=5 X(5) Explanation of X=5 can store only single value. X(5) can store 5 values in consecutive Example memory locations. Q.12) Draw a flowchart for the Q.NO. 16 program. Answer:

Q.13) Write an algorithm to sum array A elements and array B elements. Answer: Algorithm to Sum Array A elements and Array B elements: STEP 1: START STEP 2: DECLARE two array A(4), B(4) STEP 3: INPUT element of array A(4), B(4) STEP 4: ADD element of array A(4) , B(4) STEP 5: PRINT element of array A(4) , B4) STEP 6: PRINT addition of array A(4), B(4) STEP 7: END Q.14) Write a program to print a list of odd numbers from the given numbers. 6, 42, 4, 77, 32, 9, 21, 22, 8, 45, 15, 46 Answer: 10 CLS

20 A(12) 30 FOR B=1 to 12 40 READ A(B) 50 IF A(B) mod 2 <>0 then PRINT A(B) 60 NEXT B 70 DATA 6,42,4,77,32,9,21,22,8,45,15,46 80 END Output: The output of the program is as follows: Q.15) Write a program that read an array N with 20 numbers and find the product of the elements of array. Answer: Program to find the product of the elements of array: 10 CLS 20 DIM N(20) 30 PRODUCT=1 40 FOR I=1 TO 20 50 READ N(I) 60 PRODUCT= PRODUCT*N(I) 70 NEXT I 80 PRINT \"PRODUCT OF THE NUMBERS= \";PRODUCT 90 DATA 1, 3, 2, 4, 1, 2, 6, 3, 2, 1 100 DATA 4, 1, 2, 1, 3, 1, 1, 1, 2 ,1 110 END Output: The output of the program is as follows:

Q.16) Write a program that read an array Z having 12 numbers given by user then print the sum and average of all array elements. Answer: Program to print sum and average of array elements: 10 CLS 20 DIM Z (12) 30 FOR K=1 TO 12 40 READ Z (K) 50 S=S+Z(K) 60 NEXT K 70 PRINT “sum of array=” S 80 PRINT “average of array=” S/12 90 DATA 9, 6, 2, 1, 8, 7, 9, 2, 0, 6, 4, 8 100 END Output: The output of the program is as follows: Q.17) Find out the errors in the following program segments if any. a) 10 DIM N$(10) b) 10 FOR J = K TO 15 20 FOR K= 4 TO 15 20 K(J) = J 30 INPUT N$ 30 PRINT K(J) 40 NEXT I 40 NEXT J Answer: a) There is error in line number 40 because there must be NEXT K instead of NEXT I. b) There is error in line number 20 because subscript is out of range. Q.18) Write a program to sort the list of 20 names in descending order. Answer: Program to sort names in descending order:

10 REM sort the list of 20 names in DESCENDING ORDER 20 REM SELECTION SORT algorithm is used 30 DIM arr$(20) 40 FOR x=1 TO 20 50 READ arr$(x) 60 NEXT x 70 PRINT \"Name List in GIVEN ORDER...... \" 80 FOR x=1 TO 20 90 PRINT arr$(x), 100 NEXT x 110 PRINT 120 REM SELECTION SORT algorithm 130 FOR x=1 TO 20 140 FOR y=(x+1) TO 20 150 IF arr$(x)<arr$(y) THEN 160 ELSE 190 160 temp$=arr$(x) 170 arr$(x)=arr$(y) 180 arr$(y)=temp$ 190 NEXT y 200 NEXT x 210 PRINT \"Name List in DESCENDING ORDER.....\" 220 FOR x=1 TO 20 230 PRINT arr$(x), 240 NEXT x 250 REM use UPPER case only OR LOWER case only 260 DATA ASLAM,ASGHER,DAUD,RAMZAN,SHEHBAZ,ASGHER 270 DATA WAQAR,SHEHBAZ,IJAZ,KAMRAN,USMAN,ZAHID,ZAID 280 DATA AKHTER,TALHA,HAMZA,SHABEER,ALI,HAMZA,RIZWAN 290 END Output: The output of the program is as follows:

i) LEFT$ (‘Pakistan”,3) =_________  A. ‘Pak’  B. ‘PAK’  C. ‘ Pa’  D. ‘kis’ ii) The outer of a function INT(-5.7):  A. -5  B. -4  C. -6  D. 5 iii) RIGHTS (x$,n) will  A. Leave ‘n’ spaces at the right of string x$  B. Leave ‘n’ spaces at the left of string x$

 C. select ‘n’ characters from the right of side  D. select ‘n’ spaces from the right of side. iv) The__________ function is used to convert ASCII codes to its character equivalent.  A. CHAR$()  B. CHR()  C. CHAR,  D. CHR$() v) Instructions that are written once in the main program or independently and can be called more than one time in the main program is called  A. Control Statement  B. Loop  C. Subprogram  D. None of them vi) TAN(x) =  A. SIN (x)/COT (x)  B. COT (x)  C. COS(x) / SIN(x)  D. SIN(x)/COS(x) vii) The output of SGN(-4) is:  A. ‘ _ ’sign  B. ‘ + ’sign  C. 0  D. None of them viii) A file is activated with one of the following statements before its use:  A. WRITE  B. READ  C. PRINT  D. None of them

ix) A file can be organized in the following ways:  A. One way  B. Two ways  C. Three ways  D. Four ways x) To read information from a file, it must be opened for:  A. Input  B. Output  C. Both a and b  D. None of them Q.4) What is the difference between user-defined function and built-in functions? Answer: Built-in Function: Built-in functions are the part of programming language and they are included by developer of the language. Example: 10 X=INT (3.9999) 20 PRINT X Output: 3 Explanation: In the above example, INT function is used that returns the lowest integer less than or equal to x.In this case, program returns 3 instead of 3.9999. User define Function: User define function includes those functions which are defined by user according to problem requirement. Example: 10 DEF FNX (Y)=(Y^3+Y^2)/Y 20 INPUT \"Enter two numbers\" ,A,B 30 C=DEF FNX(A)+DEF FNX(B) 40 PRINT C Output: Enter two numbers 5 6 Explanation: DEF FN function is used to define numeric and string function.It returns string if name is string variable and numeric value in case of numeric variable name. Q.5) Differentiate between Sub-routine and Function.

Answer: Difference between Sub-routine and Function: Sub-routine Function Definition Sub-routine is a set of statements that can Funtion is a block of code that be used in a program according to need. performs specific task given to it. Declaration In sub-routine, there is no need to declare Function declaration is must in sub-routine name in main program. main program. Return value Sub-routine does not return any value. Function returns some value. Activation Sub-routine is activated by using CALL Function is always called by its segment. name and parameters. Q.6) Describe the use of GOSUB.. .RETURN statement. Answer: Uses of GOSUB…RETURN statement: GOSUB…RETURN statement used in subroutines as follows:  To call a subroutine, GOSUB statement must be specified.  GOSUB...RETURN statement causes program execution to jump on specific line. Example: 10 GOSUB 40 20 PRINT \"BACK FROM SUBROUTINE\" 30 END 40 PRINT \"SUBROUTINE\"; 50 PRINT \"IN\"; 60 PRINT \"PROGRESS\" 70 RETURN Explanation: In the above example, GOSUB statement will cause the program to jump on line number 40 and it will print \"SUBROUTINE\".In line number 30 END statement prevents the repetition of execution of subroutine. Output: The output of the program is as follows:


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook