8th Computer Programming New Course UNIT-05
Q1. Tick the correct choice for the following questions.
i. A sequence of instructions given to the computer to perform a specific task is called____________________________.
a. Data
b. Program (Correct Answer)
c. Programming
d. Information
ii. What is a named space in the computer’s memory whose value can be changed during the execution of a program?
a. Variable (Correct Answer)
b. Constant
c. Program
d. Data
iii. In BASIC programming language, which character is used as a last character with string variable?
a. ?
b. &
c. %
d. $ (Correct Answer)
iv. Which shortcut key is used to apply RUN command in GWBASIC?
a. F1
b. F2 (Correct Answer)
c. F3
d. F4
v. Which of the following error cannot be detected by a computer?
a. Syntax error
b. Run time error
c. Logical Error (Correct Answer)
d. Execution Error
vi. Which of the following is a logical operator?
a. +
b. –
c. > (Correct Answer)
d. /
vii. Which of the following operator has the highest priority?
a. +
b. ^ (Correct Answer)
c. –
d. *
viii. If A=5, B=3 and C=2, what will be the answer of the following expression? Exp=A+B*C
a. 10
b. 11 (Correct Answer)
c. 13
d. 16
ix. Which of the following statements is used to accept data from the user during program execution?
a. PRINT
b. LOAD
c. READ-DATA
d. INPUT (Correct Answer)
x. The set of rules that define the combination of symbols used by programming languages is called ____________________________.
a. Syntax (Correct Answer)
b. Data
c. Program
d. Logic
Q2. Fill in the blanks.
i. ____________________________ language are the means of communication between user and computer.
Answer: Programming
ii. ____________________________ are the quantities whose values cannot be changed during program execution or running.
Answer: Constants
iii. In a program, the occurrence of incorrect or unexpected result is called ____________________________.
Answer: Error
iv. A ____________________________ error is an error resulting in wrong answer due to programmer’s own mistake.
Answer: Logical Error
v. ____________________________ are symbols that represent particular actions in an expression.
Answer: Operators
vi. An operator which is used to assign a value to a variable is called ____________________________.
Answer: Assignment Operator
vii. BASIC stands for _____________________________________________________.
Answer: Beginner’s All-purpose Symbolic Instruction Code
viii. In BASIC language, program line number is positive ____________________________.
Answer: Integer
ix. ____________________________ are keywords which are used to issue instructions to the computer to perform specific tasks.
Answer: Commands
x. In GWBASIC, ____________________________ command is used to clear the screen.
Answer: CLS
Q3. Match Column A with Column B.

Q4. Give brief answers to the following questions.
i. What is a program? Give a few examples of programs.
Answer: Program
A computer program is a sequence of instructions given to the computer to perform a specific task. Programs are written in languages called computer languages or programming languages. The computer can only do exactly what the program tells the computer to do. The computer follows the instructions written in the program to perform a particular task. A computer program is stored as a file on the computer’s storage medium, like hard disk.
Few examples of programs are:
- A program to find the average marks of a student in the final exam.
- A program to find the area of a circle for a given radius.
- A program to solve a quadratic equation.
- A program to control financial matters of a company.
- A program to manage items in a grocery shop.
ii. What is the purpose of a programming language?
Answer: Purpose of Programming Language
Natural languages. Like Urdu, English, Arabic and French, etc. are the means of communication among people to share their ideas and views. In the same way, programming languages are the means of communication between users and the computer. Users as well as computer understand these languages.
A programming language is a language designed to develop programs or instructions to communicate with the computer to solve various problems. There are different programming languages having their own set of rules and regulations that the computer programmers follow to write computer programs.
iii. Differentiate between a constant and a variable.
Answer: Difference between Constants and Variables
Constants are the quantities whose values cannot be changed during program execution or running.
While Variable is a named space in the computer’s memory whose value can be changed during the execution of a program. Variable gives meaningful names to constants. They are also used to store data and results during program execution.
iv. Differentiate between Syntax error and logical error.
Answer: Difference between Syntax error and logical error
A syntax error occurs when the instructions written in a program do not follow the rules of the programming language. Syntax errors are easy to find and correct because the computer finds them for the user.
While logical error is an error resulting in wrong answer due to the programmer’s own logical mistake. These errors occur due to wrong use of formulae or providing wrong value to a variable. If a programmer writes a statement that is logically incorrect, the computer will understand and execute it, but the result will be wrong.
v. What are the rules for defining / declaring variables in GWBASIC?
Answer: Rules for defining / declaring variables in GWBASIC
In programming language, like BASIC, certain rules are followed to declare / define a variable name. In GWBASIC following rules are used to define / declare variables
- Alphabet and numbers can be used for variables.
- The first character of the variable should be an alphabet.
- No special symbol is allowed except Underscore (_).
- Underscore cannot be used as a first or last character.
vi. Name different types of constants with examples.
Answer: Types of constants
Constants
Constants are the quantities whose values cannot be changed during program execution or running. These are the named spaces in the computer’s memory. Constants are classified as string constants and numeric constants.
String Constants:
These are sequence of alphabetic or alphanumeric characters enclosed in double quotation marks. For example “Male”, ”Married”, ”Haris”, ”Pakistan’ and “H.No.107”, et.
Numeric Constants:
These are the numbers, for example 117,20.5, -50 etc.
vii. Give the precedence of arithmetic operators?
Answer: Precedence of arithmetic operators
Precedence is the priority that is followed while applying these operators. This becomes important when more than one kind of arithmetic operator appears within one expression.
The precedence of arithmetic operator is given in the following table.

In an expression the operations within parenthesis () are resolved first.
vii. What is the purpose of modulus operator (MOD)?
Answer: Purpose of Modulus operator
Modulus or MOD operator is used to find the remainder after division. For example, 35 MOD 6, X MOD Y
vii. What is the purpose of the following GWBASIC commands?
Answer: Purpose of GWBASIC commands
a. LIST
List command shows the list of all or part of a loaded program on the screen. F1 key is used as a shortcut key for LIST command.
b. RUN
RUN command is used to execute (get result) of the program. The F2 key is used as a shortcut key for RUN command.
c. LOAD
Load command is used to load (open) a file from any storage medium like Hard Disk into the main memory of the computer. F3 key is used as a shortcut key for LOAD command.
d. SAVE
SAVE command is used to save the program in the Hard Disk or any other storage media. F4 key is used as a shortcut key for SAVE command.
Q5. Give detailed answers to the following questions.
i. Explain different types of errors in programming with examples.
Answer: Different types of errors in programming
In a program, the occurrence of an incorrect or unexpected result is called an error. Errors occur due to some mistake in performing operations in a program. There are two common types of errors in programming.
Syntax Error
A syntax error occurs when the instructions written in a program do not follow the rules of the programming language. Syntax errors are easy to find and correct because the computer finds them for the user.
Example: PRNT instead of PRINT
5=X instead of X=5
Logical Error
A logical error is an error resulting in a wrong answer due to a programmer’s own logical mistake. These errors occur due to wrong use of formulae or providing wrong value to a variable. If a programmer writes a statement that is logically incorrect, the computer will understand and execute it, but the result will be wrong.
For example, if a programmer accidentally multiplies two variables when he or she meant to divide them, the program will give an incorrect result, but no error message. Such errors cannot be detected by a computer, therefore they are hard to find and correct.
Example: SUM =X-Y instead of SUM=X+Y
AREA =Pie*R^3 instead of AREA = Pie*R^2
ii. What is arithmetic expression? Explain different types of operators with examples.
Answer: Arithmetic Expression
An expression is a combination of symbols and operators that represents a value. Every expression consists of at least one operand and can have one or more operators. Operands are values, whereas operators are symbols that represent particular actions. For example, in the expression
X+3
X and 3 are operands, and + is an operator
An expression which represents a numeric value is called an Arithmetic Expression, An Arithmetic Expression is evaluated by performing a sequence of arithmetic operations to obtain a numeric value.
Some examples of Arithmetic Expressions are as follows:
Exp1=(A+3)*(C+2)
Exp2= (2*X+3*Y
Exp3=2*3.14*R
Following are the arithmetic operator in the below table.

iii. Convert the following algebraic expressions into computer expressions.
a. (AB)+ (BC)
Answer: (A*B) + (B*C)
b. 5X-7Y
Answer: 5*X – 7*Y
c. A/B*C3
Answer: A/B*C*3
d. B2-4AC
Answer: B*2 – 4*A*C
e. XY/(X-Y)
Answer: X*Y / (X-Y)
iv. Find the solution for the following expressions, if A=3, B=4 and C=5
a. C-A*B-5
Solution:
If A=3, B=4 and C=5 Then
C-A*B-5 = 5-3*5-5
=5-15-5 (First multiplication will be solved)
= -10-5 (Subtract the expression)
= -15 (Addition of negative numbers)
b. (A+B)-C^2
Solution:
If A=3, B=4 and C=5 Then
(A+B)-C^2 = (3+4)-5^2
= (3+4) – 25 (Solve exponent first)
=7-25 (Expression in parentheses second)
=-18 (Subtract the expression)
c. (B+C)/A*10
Solution:
If A=3, B=4 and C=5 Then
(B+C)/A*10 = (4+5)/3*10
= 9/3*10 (First expression in parentheses will be solved)
=3*10 (Division will be solved next)
=30 (Multiplication will be solved next)
d. A^2+B^2-2*A*B
Solution:
If A=3, B=4 and C=5 Then
A^2+B^2-2*A*B = 3^2+4^2-2*3*4
= 9+4^2-2*3*4 (Solve first exponent)
=9+16-2*3*4 (Solve second exponent)
=9+16-6*4 (Solve first multiplication)
=9+16-24 (Solve second multiplication)
=25-24 (Add expression)
=1 (Subtract expression)
e. C MOD A*B+C
Solution:
If A=3, B=4 and C=5 Then
C MOD A*B+C = 5 MOD 3*4+5
= 5 MOD 12+5
= 2+5
=7
v. Explain the purpose of the following BASIC statements with their syntax and examples.
a. PRINT
The PRINT statement is used to display a message or output to the screen.
As shortcut “?” can be used for PRINT command.
Syntax of PRINT statements are:
Syntax1: Line Number PRINT “Sequence of characters / String”
Example: 10 PRINT “I Love Pakistan”
Syntax: Line Number PRINT “Variables / Constants”
Example: 10 PRINT X, Y, Z
The above statement will output values of variable X, Y and Z on the screen.
20 PRINT 205,-101
The above statement will output constant values 205 and -101 on the screen.
Syntax 3: Line Number PRINT “String”, Variables / Constants
Example: 10 PRINT “Sum of numbers =”, SUM
The above statement will output a string “Sum of numbers =” with the value of variable SUM on the screen.
Use of Semicolon (;) with PRINT Statement
In PRINT statement, semicolon (;) between strings / variables / constants causes them to be printed right next to each other without any space between them.
Use of Comma (,) with PRINT Statement
In PRINT statement, a comma (,) between strings / variables / constants causes them to be printed with equal spaces between them. A maximum of five values can be printed on a single line using commas.
The following program shows the difference between semicolon and comma.

b. INPUT
INPUT statement is used to take input from the user during the execution of the program.
Syntax:
Line number INPUT [Sequence of characters / string;] List of variables sequence of characters / string is used to prompt the user to enter the required value using keyboard, and it is optional. A list of variables are used to store the entered values.
Program
10 CLS
20 INPUT X
30 PRINT “SQUARE of Your Number is = “ X^2
RUN
Enter Number = 5
SQUARE of Your Number is = 25
c. READ and DATA
READ and DATA statements are used when there is a need to process large number of variables with given data. READ statement defines the list of variables, while DATA statement contains constant values for the variables in READ statements. Values in READ and DATA statements should be separated by commas.
Syntax: Line number READ List of Variables separated by commas
Line number DATA List of Constants separated by commas
Example: 10 READ X, Y, Z, K
20 DATA 8,9,13,15
When the above program is executed, the line number 10 with the READ statement followed by the variables X, Y, Z, K will assign constant values from the DATA statement in line number 20 in the same order. A one-to-one correspondence exists in READ-DATA statements, i.e. X=8, Y=9, Z=13, K=15
If values in the DATA statements are more than the variables in the READ statement, then the extra values of DATA are ignored. But if the variables in the READ statement are more than the values in the DATA statement, then a syntax error encounters, i.e. “Out of Data”.
Example:
10 CLS
20 DATA 6,15,23,44
30 READ W, Y,X,Z
40 SUM1 = W+Y+X+Z
40 PRINT “Sum = “, SUM1
RUN
Sum = 88
d. IF-THEN-ELSE
IF-THEN-ELSE Statement
IF…THEN is a decision-making statement, depending upon the decision, it takes some action or changes the order of execution. It helps the computer to check whether a relation is TRUE or FALSE.
Syntax: IF relational expression THEN statement(s)1 ELSE statement(s)2
If the relational expression is true then statement(s)1 will be executed otherwise the statement(s)2 will be executed.

10th Class Computer Unit-05: Functions

10th Class Computer New Course Data & Repetition Unit-04
10th Computer New Course Conditional Logic Unit-03
10th Class Computer New Course User Interaction Unit-02
10th Class Computer New Course ITP Unit-01
9th Computer New Course Designing Website Unit-05
9th Computer New Course Data and Privacy Unit-04
9th Computer New Course Networks Unit-03
9th Computer New Course Binary System Unit-02
Buy Best Stationery Products in Pakistan
For more stationery items please visit : https://stationerystore.pk