Grade8 Programming Concepts
Elementary Programming Concept
Qbasic
Programming:
What is a programming language?
Programming language: A combination of restricted vocabulary (words and symbols) and a syntax (rules) is called a programming language.
A programming language is a medium used by the
users to communicate and write instruction for a computer.
What is programming?
Programming – the
process of writing instructions for computer by using computer programming
language is called as programming or coding.
What is a program?
Program – A set
or collection of sequential instruction grouped together to perform a specific
task is called a program.
What is qbasic
QBASIC – QBASIC stands for
Quick Beginners All Purpose Symbolic Instruction Code. It is the most popular
high level programming language used by the beginners to write and develop
elementary programs.
The original BASIC programming language was
developed by Thomas Kurtz and John Kemeny in the year 1963 -1964.
Define a loop
Loop – In programming
repeated execution of a sequence of statements is called a loop or looping.
What is nested loop?
Nested loop – A loop
within a loop is called a nested loop.
What is a bug?
Bug – An error or
fault present in a program is called a bug.
Define debugging.
De-bug (debugging) – The
process of finding and correcting the bug (error) in a program is called
debugging.
What is branching?
Branching (jumping)
– If the execution of any program depart conditionally or unconditionally from
its sequential flow depending on the result of a test, it is called branching..
What is an algorithm?
Algorithm – A set
sequential steps that specify the solution to a given problem is called an
algorithm.
Define a flowchart.
Flowchart –
Symbolic visual representation of an algorithm is called a flowchart.
Characters used in Qbasic:
a) Alphabetic
characters (A to Z)
b) Numeric
characters (0 to 9)
c) Special
characters (“”, etc.)
d) Function
keys (F1 to F12)
What are the Elementary data types used in Qbasic?
Qbasic supports two data types represented by
variable which are:
a) Numeric
b) String
Define a variable
Variable – a
symbol whose value changes during the program execution is called a variable.
For example in x = y + z (the value of x varies
depending upon the values of y and z.)
What is a numeric variable?
Numeric variable – A
symbol that is used to store a number is known as numeric variable.
For example a= 9 and b =1.5
Define a string variable.
String variable – A
symbol or variable used to store string or strings is called a string variable.
The name of a string variable should start with a
character and should end with a dollar ($) sign.
For example K$= “KATHMANDU
N$
=”NEPAL”
What is a string.
String – A group of letters
or numbers or both which are enclosed within a pair of quotation marks (““) is
called a string.
For example “EURO “
“123
EURO “
Define a constant and mention its types.
Constant- A symbol
whose value does not change during the execution of the program is called a
constant.
Types of constant:
i)
numeric
constant
ii) String constant
What are operators.
Operators- Operators
are symbols representing valid operations on values.
Example of operator
OPERATOR
X = 7 + 9
Mention the types of operators.
Types of operators:
a) Arithmetic
operators
b) Relation
operators
c) Logical
operators
d) String
operators
Arithmetic operators –
Arithmetic operators are used to solve the value of an expression. In Qbasic,
the following arithmetic operators can be used.
Operators |
Action |
+ |
Addition |
- |
subtraction |
* |
multiplication |
/ |
Division |
^ |
To the power |
Relational operators –
Relational operators are used to compare two or more values. Using this, we can
compare values of variables with a constant. In Qbasic the following relational
operators can be used.
Operators |
Relation |
= |
Equal to |
<> |
Not equal to |
< |
Less than |
<= |
Less than equal to |
> |
Greater than |
>= |
Greater than equal to |
Logical operators –
Logical operators are used to examine two or more relations. The outcome of
this examination is given in TRUE or FALSE. Logical operators most often used are
AND, OR, and NOT.
What is a statement? Mention its types
Statement – a
collection of commands used in the lines of a program is called a statement. In
Qbasic, the statements can be divided into four groups :
a) Assignment
statement
b) Input
/ output statement
c) Declaration
statement
d) Control
statement
b) Input
/ output statement – Input / output statements allow the user to input
data to the computer and print the result after processing. They are used to
perform input/output operations of a computer. Some common input/output
statements are INPUT, LINE INPUT, PRINT, LPRINT etc.
CLS
Function – Clears the screen.
INPUT
Function – Reads input from the keyboard.
PRINT
Function – Writes data to the screen or to a file.
Declaration statement – A
statement used to define or declare a constant, variable or array etc, is
called declaration statement.
CONST, DIM, REM
CONST
Function – declares one or more symbolic constants.
DIM
Function – Declares an array or specifies data type
for a non array variable.
REM
Function – Allows explanatory remarks to be
inserted in a program.
Example of CONST and REM
REM TO CALCULATE AREA OF A CIRCLE
CLS
CONST PI =3.141593
INPUT “RADIUS OF CIRCLE”; R
PRINT “AREA = “ PI * R ^ 2
END
EXAMPLE OF DIM
DIM NAME$ (4)
FOR I = 1 TO 5
READ NAME$ (I)
PRINT NAME$ (I)
NEXT I
DATA NEPAL,INDIA,CHINA,BHUTAN
END
Control flow statements – A
statement which controls the program flow while executing the program
instructions one after another is called control statement.
GOTO, IF …. END IF, FOR ….. NEXT etc. are few examples of control statements.
GOTO LINE
Function – Branches to a specified line.
Decision making statements:
1. IF
….. THEN …. END IF
Function – This statement is used for making
decisions and it also checks a single condition.
Syntax – IF <CONDITION> THEN
<STATEMENTS>
END
IF
EXAMPLE: CLS
LET
C = 1
TOP
:
PRINT
C
LET
C = C + 1
IF
C < = 10 THEN
GOTO
TOP
END
IF
END
2. IF
…… THEN ….. ELSE ….. END IF
Function – This statement is used for making
decisions and it checks double condition.
Syntax – IF <CONDITION> THEN
<STATEMENT>
ELSE
<STATEMENT>
END
IF
Example
:
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH “; B
LET A = L * B
IF A > = 50 THEN
PRINT “BIG”
ELSE
PRINT “SMALL”
END IF
END
3. IF
…. THEN …. ELSE IF
Function – This statement is used for checking
multiple conditions
Syntax – IF <CONDITION> THEN
<STATEMENTS>
ELSE
IF
<STATEMENTS>
ELSE
<STATEMENTS>
END
IF
EXAMPLE ;
CLS
INPUT “ENTER PERCENTAGE “; P
IF P > = 60 THEN
PRINT “ 1ST. DIVISION”
ELSE IF P >= 50 AND P < =
59 THEN
PRINT “2ND DIVISION”
ELSE IF P > = 40 AND P < =
49 THEN
PRINT “3RD DIVISION”
ELSE
PRINT “FAIL “
END IF
END
5. FOR
…..
NEXT
Function – Repeats a block of statements
a specified number of times.
Syntax
-
FOR <VARIABLE > = < 1 TO N ><STEP
>
STATEMENTS
NEXT
EXAMPLE – FOR I
= 1 TO 10
PRINT
I
NEXT
END
7. DO
…. LOOP
Function – This command repeats a block of
statements while the condition is true or until the condition becomes true.
Syntax
-
DO <WHILE /UNTIL > CONDITION
STATEMENTS
LOOP
EXAMPLE –
X
= 1
DO
WHILE X < = 10
PRINT
X
X
= X + 1
LOOP
END