Computer Programming Class 8 Computer Science Notes and Questions (2024)

Please refer toComputer ProgrammingClass8Computer Sciencenotes and questions with solutions below. These revision notes and important examination questions have been prepared based on the latestComputer Sciencebooks for Class8. You can go through the questions and solutions below which will help you to get better marks in your examinations.

Class8Computer ScienceComputer ProgrammingNotes and Questions

Question. Give brief answers to the following questions.

i) What is program? Give few examples of programs.
Ans: A set of instructions given to the computer to perform a specific task is called a program. A computer works according to the instruction written in program. Few examples of programs are:

  • A program to find area of a circle for a gives radius. A program to find sum and average of five values
  • A program to find the grades of students
  • A program to find greater of two values

ii) What is the purpose of programming language?
Ans: A programming language is designed to develop programs or instructions to communicate with computer to solve various problems. Programming languages are the means of communication between user and computer.

iii) Differentiate between a constant and variable.
Ans: A quantity whose value cannot be changed during execution of program is called constant. A quantity whose value can be changed during execution of program is called variable. Variables are the named memory locations that can store data and result of processing. Variables give meaningful names to constants.

iv) Differentiate between Syntax error and logical erro
Ans: Syntax error is a type of error that occurs when a program statement does not follow the syntax of programming language. A type of error that occurs due to wrong logic of the program is called logical error.

v) What are the rules for defining/declaring variables in GW -BASIC?
Ans: Following are the rules for defining/declaring variables in GW -BASIC:

  • Alphabets 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.
Ans: Constants are classified as string constants and numeric constants.

String constants: These are series of alphabetic or alphanumeric character written in double quotation marks. For example “Pakistan” , “Haider” and “H.No.107” et c.

Numeric constants: These are the numbers, for example 15 , 20.50 , -50 etc.

vii) Give the precedence of the arithmetic operators.
Ans: Precedence is the priority that is followed while applying operators in an expression. In other words the order in which operators in an expression are evaluated is known as precedence. It is also known as hierarchy of operators. The precedence of arithmetic operators is given below:

Priority level

Operator

Symbol

Precedence

First

Exponential Operator

^

Highest

Second

Multiplication, Divide

*OR /

Third

MOD Operator

MOD

Fourth

Addition or Subtraction

+ OR –

Lowest

viii) What is the purpose of modulus operator (MOD)?
Ans: Modulus operator is used to get the remainder after division. For example if a = 10 and b = 3 , the MOD operator ( a MOD b) will return 1 after performing division.

ix) What is the purpose of following GW-BASIC commands?
a. LIST b. RUN c. LOAD d. SAVE
Ans: a) LIST Command: List command is used to display all or specific statements of a program from memory on screen. The shortcut key for list command is F1.
Syntax: LIST [line number][- line number]
Example: LIST it displays al lines of the program.

b) RUN Command: RUN command is used to execute the program that is currently loaded in the memory. The shortcut key for RUN command is F
Syntax: RUN
Example: RUN it runs the program currently in memory.

c) LOAD Command: LOAD command is used to load a saved program file from disk to memory. The shortcut key for list command is F3.
Syntax: LOAD filename
Example: LOAD “Test.bas” it loads the file “Test.bas” in memory.

d) SAVE Command: SAVE command is used store a program from memory to disk permanently. The shortcut key for list command is F4.
Syntax: SAVE filename
Example: SAVE “Test.bas” it stores the file “Test.bas” from memory to disk.

Question. (i) What is arithmetic expression? Explain different types of operators with examples.
Ans: Arithmetic Expression: An expression that consists of different arithmetic operators, variables and constants is called arithmetic expression. It is evaluated by performing arithmetic operation on numeric values. There are three common types of operators.

  • Arithmetic Operators ( +, -, *, /, ^, MOD)
  • Assignment Operator (=)
  • Relational Operators (< , >, , =)

a) Arithmetic Operators: These are use to perform mathematical calculations like addition, subtraction, division, multiplication and exponentiation. Their explanation with examples is as follows:

Operator symbol

Operation

Description

Example

+

Addition

Gives the sum of values

A+B+C, X+50, 67+45

Subtraction

Gives the difference of values

X-56, A-C, 80-56

*

Multiplication

Gives the product of values

A*B, Y*50, 45*60

/

Division

Gives the quotient

X/Y, B/40, 125/25

^

Exponentiation

Raise the value to the power of an exponent

A ^ 10, 5^ 2, A^B

MOD

MODULUS

Gives the remainder after division

35 MOD 6, X MOD Y

b) Assignment Operator: An operator which is used to assign a value to a variable is called assignment operator. In programming languages “Equal to sign (=)” is used as an assignment operato For example A=5 , X = A + 2.54 etc.

c) Relational Operators:These are used to perform comparisons on two values. The result of comparison is either true (non zero) or false (zero). Following is their description with examples:

Operator symbol

Operation

Description

Example

=

Equal to

Returns true if the values are equal and false if not

A = B

Not equal to

Returns true if the values are not equal and false if they are equal.

5 7

>

Greater than

Returns true if the first number is greater than second and false if not

15 > 11

Less than

Returns true if the first number is less than second and false if not

7 < 9

>=

Greater than OR equal to

Returns true if the first number is greater than or equal to the second and false if not

(X+1) >= 7

Less than OR equal to

Returns true if the first number is less than or equal to the second and fal se if not

Y

(v) Explain the purpose of the following GW-BASIC statements with their syntax and examples.
a. PRINT b. INPUT c. READ and DATA d. IF-THEN-ELSE
Ans:a) PRINT Statement:PRINT statement is used to display message or output to the screen.
As shortcut”?” can be used for PRINT command.
Syntax:line numberPRINT[string/variables/constants]
String:It indicates the sequence of characters that is displayed on screen.
Variables:It indicates the variables whose values to be displayed on screen.Constants:It indicates the constants to be displayed on screen.
For example:10 PRINT “I LoveIndia” will print I LoveIndia
10 PRINT X, Y, Z will print values of variables x, Y and Z
10 PRINT 205 , -101 will print constant values 205 and -101

b) INPUT Statement:INPUT statement is used to take input from the user during the execution of the program.
Syntax:line numberPRINT[string;]list of variables
String is used to prompt the user to enter the required value using keyboard and it is optional. List of variables is used to store the entered values.
Example: 10 CLS
20 INPUT “Enter a number”, X
30 PRINT “Square of your number is=”, X^2

This program will get value for X from user at execution time and will print its square.

c) READ and DATA Statement:READ/DATA statement is a combination of two statements used together 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 these variables in READ statement. Values in READ and DATA statements should be separated by commas.
Syntax:line numberREADlist of variables separated by commas.
line number
DATAlist of constants separated by commas.
Example: 10 READ X, Y, Z, K
20 DATA 8, 9, 13, 15

The above program will specify four variables x, y, z and k and assign them values 8, 9, 13 and15 respectively. If values in DATA statement are more than variables in READ statement thenthe extra values are ignored but if the variables in READ statement are more than the values inDATA statement then syntax error encounters i.e. “Out of Data”.

d) IF-THEN-ELSE Statement:IF-THEN-ELSE is a decision making statement, depending upon the condition, it takes some action or changes the order of execution. It helps the computer to check whether a condition is true or false.
Syntax:IFexpression/conditionTHENstatement(s)1ELSEstatement(s)2
If the expression or condition is true then Statement(s)1 will be executed otherwise
Statement(s)2 will be executed.

T

Flowchart:

Condition

Statement (s)

Statement (s)

F

Output:

Enter your marks: 65

You have passed

Example: 10 CLS

20 INPUT “Enter your marks:”; marks

30 IF marks >= 40 THEN PRINT “ You have passed”

40 END Short Questions other than exercise

i) Explain the use of semicolon with PRINT.
Ans:Two or more variables can be separated in print statement by semicolon. If semicolon is used the second value appears right after the first value. There is no space be tween values.
Example: PRINT “Apple” ; “Mango” ; “Orange”
Output will be as: AppleMangoOrange

ii) Explain the use of comma with PRINT.
Ans:Two or more variables can be separated in print statement by comma. If com ma is used each value is displayed in 14 spaces. A maximum of five values can be printed in single line using commas.
Example: PRINT “Apple” , “Mango” , “Orange”
Output will be as: Apple Mango Orange

iii) What is expression? What are its types?
Ans:An expression is a combination of symbols (operands) and operators that represent a value.
There are two types of expressions:

  • Arithmetic expression uses arithmetic operators to perform arithmetic calculations.
  • Relational expression uses relational operators to compare two values.

iv) Define programming.
Ans:Programming is a technique to develop programs. Different programming languages are used to write programs. Simply computer programming is all about developing, implementing and maintaining the programs.

v) How arithmetic expression can be assigned to a variable?
Ans:An arithmetic expression can be assigned to a variable by using assignment operator (=). The variable is written on the left side of assignment operator and expression is written on right side of assignment operator. First expression is evaluated and result is stored in variable e.g. a = c – d * 10

vi) Differentiate between bug and debugging.
Ans:An error in a program is called a bug. The process of finding and removing errors in a program is called debugging. Errors can be found by testing the program.

vii) Differentiate between save and load command.
Ans:SAVE command is used to store a program from memory to the disk permanently whereas load command is used to load a stored program from disk to memory.

viii) How the commands are differ from statements?
Ans:Commands are key words which are used to issue instructions to the computer to perform specific task. They do not need any line number while statements are instructions for the computer program to perform an action. Each statement is started with a line number. Statements are executed according to line number in ascending order.

ix) Differentiate between string constant and numeric constant.
Ans:The string constant may consist of alphanumeric or numeric data and is written in double quotation marks while numeric constant consists of numeric data i.e. only numbersand is written without quotation marks.

x) Why variables are used with INPUT statement?
Ans:The variables are used with INPUT statement to store the input data. Two or more variables must be separated by comma.

xi) Write the use of $ in GW-BAS
Ans:A dollar sign $ is used after a string variable name such as A$ and Address$. The dollar sign indicates that the variable contains a string value.

xii) What is the use of arithmetic operators?
Ans:Arithmetic operators are used to perform arithmetic calculations like addition, subtraction, division, multiplication and exponentiation.

xiii) What is the use and syntax of CLS command?
Ans:CLS Command:CLS stands for Clear Screen. It is used to clear the contents of the screen.
Syntax: CLS

xiv) Define precedence.
Ans:Precedence is the priority that is followed while applying operators in an expression. In other words the order in which operators in an expression are evaluated is known as precedence. It is also known as hierarchy of operators.

xv) Define the syntax of programming language.
Ans:The syntax of programming language is the set of rules that defines the combination of symbols used by that language

xvi) What is “Out of Data” error?
Ans:If the variables in READ statement are more than the values in DATA statement then syntax error encounters i.e. “Out of Data”

Computer Programming Class 8 Computer Science Notes and Questions (1)

We hope the aboveComputer ProgrammingClass8Computer Scienceare useful for you. If you have any questions then post them in the comments section below. Our teachers will provide you an answer. Also refer toMCQ Questions for Class8Computer Science

Computer Programming Class 8 Computer Science Notes and Questions (2024)
Top Articles
Latest Posts
Article information

Author: Cheryll Lueilwitz

Last Updated:

Views: 6300

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Cheryll Lueilwitz

Birthday: 1997-12-23

Address: 4653 O'Kon Hill, Lake Juanstad, AR 65469

Phone: +494124489301

Job: Marketing Representative

Hobby: Reading, Ice skating, Foraging, BASE jumping, Hiking, Skateboarding, Kayaking

Introduction: My name is Cheryll Lueilwitz, I am a sparkling, clean, super, lucky, joyous, outstanding, lucky person who loves writing and wants to share my knowledge and understanding with you.