Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
title]
Junaid Qaiser
[COMPANY NAME]
[Document subtitle]
grammer or syntax of the programming language. For example, in BASIC, if you type PRINTE instead of
PRINT or type ENPUT instead of INPUT or type a statement like INPUT D, P1 without a statement
number, clearly you are making errors. Such errors are called syntax errors.
(B) Logical Error: - Whenever there are no syntax errors in the program at the execution time, but still the
program generates a non-valid result then it means that there is some logical error. It is important to note
that logical errors, as the computer cannot detect them, are considered difficult to remove. For example,
when we want to obtained the AVERAGE of THREE numbers, then we divided the SUM in THREE
numbers. If we divided SUM in FOUR numbers instead of THREE that is a Logical Errors.
(C) Execution Error: - When the computer displays error massage at run time or execution time, even
though the program neither contains syntax nor logical error, then such type of errors is called execution
errors.
Example: - Get three numbers, add Its and 2nd values and divided their sum by the 3rd value. The result
is then display on the serene.
10 Input A, B, C
20 D= (A+B)/C
30 PRINT D
40 END
When this program is run, it asks for values and then displays the output as:
? 10, 20, 30
1OK.
This works quite fine. However, if we enter 0 values for C means want to divide the sum of A and B by 0
then the computer displays the following errors message:
? 10,20,0
Division by zero
OK.
CHAPTER-2 "Data Type Assinment & input/output Statement"
Q NO: - What do you know about basic language? Write down its history and advantages.
Introduction to BASIC: - The word BASIC stands for Beginners All purpose Symbolic Instruction. BASIC
language is one of the simplest high- level languages in use today. It is a general- purpose programming
language. It is effective for many applications such as, business, science, games and education. Actually
BASIC was designed for use in teaching the elementary principles of computer programming in a
straightforward manner. That is why, it is particularly well suited for person learning to program for the first
time. Because of its simplicity, it is now used almost universally. In Pakistan, many high and junior schools
now offer courses in this programming language.
HISTORY OF BASIC: - BASIC was developed by Dr.John G.Kemeny and Dr.Thomas E.Kurtz at
Dartmouth Collage in the mid 1960s in an effort to provide a simple teaching language for beginners of
computer programming. As BASIC was a simple and user-friendly language, so very quickly it became
one of the most widely used languages in schools, and universities. It was also adopted as a principal
language by several commercial timesharing services. All this made it a very popular language among
thousands of computer users.
ADVANTAGE OF BASIC LANGUAGE: There are the following advantages of the basic language.
1. It has very simple and easy grammatical rules and therefore, easy for beginners to learn, and as such,
can be learned in a very short period of time.
2. BASIC is an All-purpose programming language. It is equally suitable for solving scientific and
engineering problems as well as for business applications
3. BASIC has conversational nature, which makes communication with a computer simple, easy and
almost natural.
4. BASIC is a user-friendly language. It is not a purely teaching language likes others and therefore, user
fined it friendly.
5. Computer games can be developed in BASIC language requiring the use of graphics as well as sound
generations.
6. One of the advantages of BASIC is its much built- in functions.
7. BASIC has the staying power to keep you hooked and busy until you have become an expert.
Q NO: - What do you meant by a program? Write down the structure of a BASIC program.
PROGRAM: - BASIC, lick other languages, has its own syntax or structure. Each instruction in a BASIC
program is written as a separate statement that is called program.
Structure of a BASIC program: - A complete BASIC program consists of a sequence of statements, which
are executed in ascending order. General rules for writing a BASIC program are as follows.
? Each statement must begin with an unsigned positive integer quantity known as a statement number
(Line number).
? Two statements cannot have the same statement or line number.
? Successive statements must have increasing statement numbers.
? Each statement number must be followed by a BASIC key word (like PRINT, READ, INPUT etc)
indicating the type of instruction that is to be carried out.
? Each statement begins with a statement number and ends with a Carriage Return
(ENTER/RETURN/CR/).
? Each statement with an END statement, physically, it can by written any where in the program, but
logically it must be the very last statement to be executed.
Q NO: - What for we use operator? What are its types? Explain each with suitable examples. Also
explain priority of operators.
Operators are special characters used to perform specific operation on their operands (data type). In
BASIC language we use three types of operators, which are listed below.
ARITHMETIC OPERATORS: 1. Following are the arithmetic operations.
+ Use for addition
- Use for subtraction
* Use for multiplication
/ Use for division
\ Use for integer division
MOD MOD used for remainder in division e.g 5 MOD 2 = 1
^ Used for power or exponentiation
() Used to change the default priorities of operators.
REALTIONAL OPERATORS:2. Following are the relational operators.
< Used for less than
> Used for greater than
= Used for equal to
<> Used for not equal to
<= Used for less than or equal to
>= Used for greater than or equal to
3. LOGICAL OPERATORS:In BASIC we have three logical operators, which are AND, OR and NOT. AND and OR operators are used
to form compound conditional expressions, in which more than one logical conditions are tested in the
same statement.
The NOT operator is used to negate an operand (i.e. change true to false and false to true)
CONSTANTS: - A constant in BASIC is something that does not change its value during execution of the
program. There are two types of constants; Numeric constant and string constant.
Numeric Constants: - Numeric constants are positive or negative number. A plus sign is optional for a
positive number. A numeric constant in BASIC cannot contain commas. For example: 23, -4.756, + 38.15
String Constants:- A string constant is any set of characters enclosed in quotation marks. Blank spaces
may be included in a string but not quotation marks. A string constant is a sepuence of 255 alphanumeric
characters enclosed in double quotation marks. For example:AREA OF TRIANGLE
** I LOVE PAKISTAN**
23 RD MARCH
Variables: - Variables are the names or labels used to represent values that are used characters, the first
character must be a letter like A, B, A1, A2 etc. However longer names may also be used. The number of
character that can be used varies in different versions of BASIC. There are two types of variables.
Numeric Variable: - A numeric variable always has a value that is a number. This value is assigned to the
of the entire nest. However, control cannot be transferred to a statement with in a nest from a point out
side the nest.
Q NO 3:-What is the difference between?
Loop: - a loop is a set of statement which is executed repeatedly.
Nested loop: - By nested loops we mean one loop within another loop.
Conditional transfer of control statements: - Those statements which transfer control to other part of the
program based on same condition are known as conditional transfer of control statements e.g.
IF/THEN/ELS.
Unconditional transfer of control statements: - Those statements which do not need any condition to
jumps form one part of the program to another e.g., GOTO, ON, GOTO.
IF/THEN/ELSE and ON/GOTO statements: - It is similar to the IF-THEN statement, with an added power
to transfer control to another part of the program whether the condition is true or false.
e.g., 10 IF marks>33 THEN PRINT PASSELSE PRINTFAIL
THE ON/GO TO statement: - It is multiple branching unconditional transfer of control statement which is
used to transfer control to any one of the indicated line numbers.
e.g., 40 on choice GO TO 15,35,60,100,60.
FOR/NEXT LOOP statement: - This is a loop which is used to perform repetitive tasks and is used when
we know in advance the number of times the loop will be executed.
WHILE/WEND LOOP statement: - It is used when the numbers of repetitions are not known in advance. It
has the capability to be terminated any time depending on the condition.
Chapter No-4 "ARRAYS"
Q:-WHAT IS AN ARRAY? WRITE DOWN A DETAILED NOTE ON ONE DIMENSIONAL AND TWO
DIMENSIONAL ARRAYS?
ANS:-ARRAYS:-An array can be defined as a subscripted variable that has upper and lower bounds as
its ending and starting positions and that subscripted value may range between these two bounds, is
called an array.
Types of arrays:An array can be categorized into two types on the basis of these rows and columns. These types are
given one by one below:
One dimensional array:
A subscripted variable in which a single variable is used to represent the subscripts of the array and
ranges between the lower and upper bounds of the array is called one-dimensional array. An example of
such arrays in the real life may be a matrix consisting of rows or columns only.
Two dimensional arrays:A Two dimensional array consist of two subscripts in which ,the first represents the number of rows
between the lower and upper bounds of row values and the second represents the number of columns
between the lower and upper bounds of columns values. An example of such array is the two dimensional
matrix which has two or more than two rows and two or more than two columns. Such an arrays can be
diagrammatically shown as
Q:-Why do we use (DIM) statement? If omitted? What will happen? Write down the detailed note
on its use?
Ans:-if we want to declare an array then it is called DIM statement. With DIM statement we can also
declare two dimensional arrays. Two dimensional arrays, which has two subscripts to identify each
element of the array.eg A(3,2)
SYNTAX:For single dimensional arraty
[Line no]DIM [variable (subscripts)], {variable (subscripts)}
For double dimensional array
[Line no]DIM [variable (subscripts, subscript)]
EXAMPLE:10DIM AR (90)
These statements will create a single dimension array in memory with 90 subscripts.
20 DIM NAME$ (26), RNO (26), CLASS (26)
These statements will create three single dimension arrays in memory each with 26 subscripts.
30 DIM TBL (10, 10)
These statements will crate a double dimension array in memory each with 100 subscripts. These array
elements are denoted like.
TBL (2, 5), TAB (5, 3).
PROGRAM: - Now we make a program to learn the use of arrays.
This program will count down the values from 25 to 5 with interval of 5 and then count up from 5 to 25
with same interval.
10 DIM A (5)
20 FOR 1= 1 TO 5
30 READ A (1)
40 NEXT 1
50 DATA 5,10,15,20,25
60 FOR 1= 5 TO 1 STEP -1
70 PRINT A (1)
80 NEXT
90 FOR F= 1 TO 5
100 PRINT A (F)
110 NEXT 1
PROGRAM: - This program is used to find the smallest number.
10 DIM K (100)
20 INPUTHOW MANY NUMBER YOU WANT TO ENTER;N
30 FOR 1= 1 TO N
40 INPUT K (1)
50 NEXT 1
60 KK= K (1)
70 FOR J= 2 TO N
80 IF KK>K (J) THEN KK= K (J)
90 NEXT J
100 PRINT KK
110 END
Chapter- 5 "Subprograms"
Subprograms:- A subprogram is a set of statements which are written once in the program and used or
called many times in different places of program.
Basic language offers two types of sub programs.
1:-subroutnes subprograms
2:-functions Subprograms
Functions Subprograms: - Functions are those sub programs which are used to replace simple process
such as calculating the square of a number, finding out the natural logarithm of a number and so on.
Subroutines subprograms: - Subprogram which are used to do complex programming operations like
calculating the roots of a quadratic equation, solving a matrix and soon.
What is the purpose of intrinsic functions? Why do we use them? Explain with suitable examples
the different types of intrinsic functions.
Purpose of intrinsic: - They perform the most basic operations like calculating the square root, sine,
cosine, tanguage of angles and so on.
Why do we use them: - When we want to solve the most basic operations like calculating the square root,
sine, cosine, tanguage of angles and so on then we use intrinsic functions.
Types of intrinsic functions: - Then are categorized follows:1. Numeric function: - The number of built-in functions which can be used for mathematical calculations.
These functions return a number as their results.
They are: Trigonometric functions:Functions purpose
Sin(X) Calculates the sine of X.
Cos(X) Calculates the cosine of X.
Tan(X) Calculates the tangent of X.
Atn(X) Calculates the tangent inverse (arctangent) of X.
Arithmetic functions:-
Functions purpose
SQR(X) Calculates the square root of a given number.
LOG(X) Calculates the natural logarithm of X.
EXP(X) Calculates the exponential value of X.
2. String Functions:- The number of built-in functions which can be used for manipulations of string data.
These functions return string and numeric values as their result. They are:Functions purpose
LEFT$(Sring,n) Selects the left most n characters of the given string.
If n is greater then the number of characters
Contained in the string, the entire string will be printed.
RIGHT$(String,n) Selects the right most n character of the given string.
3. String$ functions:- This string functions is used to repeatedly print out a character specified by the
given ASCII number to the function STRING$. This functions has the following general form:
STRING$(N,M).
Exp:- 60 PRINT STRING$(3,67)
4. Time$ functions:- The TIME$ is a built-in functions in BASIC which is related with system time. It is
used to show the current time or used to set the new time of the system.
Exp:- 10 PRINTTIME$ and
20 TIME$ =16:00:00
5. Date$ functions:- Like time$ functions Date$ functions is used to display the current date, or set the
new date of the system. The general syntax as:Line DATE$.
Exp:- 10 DATE$ =03-07-2001
6. ASC functions:- It is the inverse of CHR$ function, which returns corresponding character for a given
ASCII value, because it returns the ASCII code for a given character. Its general form is : ASC(X$)
10 PRINT ASC (ABC).
7. LEN Function:- This function is used to print the total number of characters contained in the string. It
has the general from like.
LEN(X$)LEN () Will print 0 where
LEN (Nafid ullah khan).
8. VAL function:-This function is used to return to return the numeric value of the given string argument in
a string of numbers enclosed in the double quotation. It must be noted that the string must be the
combination of number. Its general form.
VAL(X$)
Exp:- A$= 852772
9. OCT$ function:- This functions is used to calculate the equivalent of a decimal number in the octal
number system. The general form:
OCT$(Decimal Number).
10. HEX$ function:- That is used to calculate the Hexadecimal equivalent of a number which is in the
decimal number system. The general form:
HEX$(Decimal Number).
CHAPTER 6 Graphics
What is meant by computer graphics? What do you know about different modes of graphics in
BASIC? Explain.
Computer graphics: - Graphics is that area of computer programming which is highly in use these days. It
is that type of programming in which we draw text or pictures i.e., shape and images on the screen of the
computer.
Types of Graphics: - There are three modes of drawing Graphics.
1. Text Mode: - It is the first mode of drawing graphics and it refers to drawing number, letter and special
characters (like $, % and so on) in the graphics form like high lighting, make them blinking or to convert
them into invisible form.
In text mode these characters are displayed in terms of 25 rows x 40 columns or 25 rows x 80 columns on
the screen of the computer monitor.
2. Medium-Resolution Graphics Mode:- In this mode of Graphics, the display is divide into a matrix
consisting of 320 columns and 200 rows of pixels. This graphical mode works with 4 columns. The
columns are numbered from 0 to 319 and the rows from 0 to 199.
3. High-resolution graphics Mode: - High-Resolution graphics Mode contains more pixels than the
medium resolution mode. In this mode the screen is divided into 640 columns and 200 rows which make
a matrix of 640 x 200 pixels. This high resolution is used to facilitate more precise and clear drawing of
graphics.
Why do we use CIRCLE statement? Explain with suitable example.
Some time we need to make a circle. In order to draw a circle, we use the CRICLE statements. This
statement has the following general form:
Line# CRICLE(X, Y), radius [colour].
Where (x,y) is the position of the point that is located at the center of the circle and radius is the radius of
the circle. The colour value is optional and is used to colour the circle with specific colour selected
according to the graphic mode and the available colour palette. An example may be:
20 CIRCLES (110,150), 70
Which is used to draw a circle of radius equal to 10 and having the pixel located at?
(110,150) as its center.
Example: - This program is used to draw a circle one with in another by using CRICLE statements, as
following:
10 CLS
20 SCREEN 1
30 FOR = 60 TO 10 STEP 10
40 CRICLE (100,50);I
50 NEXT I
60 END
Write the purpose and complete syntax of DRAW statements. What types of shapes you can draw
with this statement? Give two examples.
This statement is used to draw lines and other shapes on the screen of the monitor. This statement is
used in both the resolution graphics modes, which are the medium resolution and high resolution graphics
mode.
The general form of DRAW statements is:
Line # DRAW string
Where string may be enclosed in quotes and its contain commands to create a shape on the screen. This
string may be using one of the following commands:
Un is used to move up n points or pixels.
Dn for moving down by n points or pixels.
Fn for moving left n points or pixels.
R for moving right n points or pixels.
En for moving diagonally down and right by n points i.e., pixels.
Gn for moving diagonally down and left by n points i.e., pixels.
Hn for moving diagonally up and left by n points or pixels.
When one of these commands is executed, a line is drawing n from the starting position which has been
specified. Thus this drawing utility of BASIC language is used to specify the number of points or pixels
and the specific direction in which the line is to be drawn.
By DRAW statements we draw the following shapes:This program is used to draw a square.
10 CLS
20 SCREEN 1
30 DRAWU40L50D40R50
Program 2:- This program is written to draw a rectangle.
10 CLS
20 SCREEN 1
30 DRAW U40R70D40L70
What is the role of SCREEN statements? Write down its different modes and their effect on the graphic
quality.
SCREEN statement:- SCREEN statement insert effect on the graphic quality.
It must be notified that the statement SCRREN 1 is used to select an appropriate screen mode i.e.,
Medium Resolution graphics mode. The general form of the SCREEN statement is:
(3) Style: - In the help of this option we change the font in different style.
(4) Filed: - In the help of this option we select any filed for us.
BASIC STATEMENT
LET STATEMENT: - It is one of the most fundamental and most important statements of BASIC language.
This statement is also called as assignment statement, because it is used to assign a numeric or string
value to a variable. LET statement has the following general form:
Line# LET Variable = [constant]
[Variable]
[Expression]
Exp:Let A$=NAFID Let X = 8
Let B$=YULIA Let Y = X+2
Let B$ = A$ Let X = X+Y
Let A$ = B$ PrintResult = ;Z
PRINT A$,B$ End
END
PRINT STATEMENT:- Print statement is used to display the data on the screen. It can be used to display
message, value of variables and to print the answers of arithmetic expression. The PRINT statement has
the following form:
Line # PRINT [OR?] [Constant]
[Variable]
[Expression]
Exp:To Print Blank lines:10 PrintNAFID ULAH
20 Print
30 PrintYULIA
40 Run
To Print Constants: Printsoma
10 Print 9 PrintHell! How are you?
20 Print -100 PrintWellcome to show
30 Print 3.14159 Print **************
40 Print 1.23E+2 Run
50 Run
LPRINT STATEMENT: - It is used for printer output. It is used to print output data on the printer rather
than on the screen. It has the following general form:
Line# LPRINT {Constant, Variable, and/ Expression}
Exp:
20 LPRINT X; Y; Z
PRINT USING STATEMENT:- It is used for formatted that is allows printed output to be formatted. Both
numeric and string data can be rounded as well as +,-,$ Signs can easily be inserted in the output result.
Syntax:
Line# PRINT USING Format string; List-of-expressions
10 Print using####; 44
REM STATEMENT: - REM Statement is used to include comments/remarks in BASIC program. This
statement consists of statement number followed by the keyword REM, followed by any remarks. It has
the following general form:
1. Line # REM [OR,] Any Comments.
Exp:
10 This is a comment line.
END STATEMENT:- END statement is used to terminate the execution of the program. It can be given
anywhere in the BASIC program physically but logically it must be the very last statement of the program.
Though the END statement is optional to use, but it is a good programming practice to include the END
statement in all BASIC programs. The END statement has the following format:
LINE# END
LOOP: A loop is an instruction or group of instruction that the computer executes repeatedly to a specified
number of time or until some terminating satisfied
Or
Repetition of statement
1:
10 For I=2 to 20
20 Print I
30 next
2:
10 For I = 2 to 20 step 2
20 print I
30 next
BASIC COMMANDS OF BASIC LANGUAGE
Auto Commands (Alt+A):Auto Commands are used to generate the line number automatically.
Syntax: - Auto (Enter).
Syntax: - Auto 2 (Enter).
Syntax: - Auto 100 (Enter).
Syntax: - Auto 10, 50 (Enter).
Syntax: - Auto 100,100 (Enter).
To End Page Break: - Clt+Break.
List Commands (List). (F1)
Its produce the entire list of the program on the screen.
Syntax: - List (Enter).
Syntax: - List 40 (Enter).
Syntax: - List 100-200 (Enter).
Syntax: - List -80 (Enter).
Syntax: - List 80 (Enter).
Run Commands (F2).
To execute the Basic program.
Syntax: - Run (Enter).
Load Commands (F3).
To load a program to disk into memory.
Syntax: - Load Basic. Bas (Enter).
Save Commands (F4).
To save the Basic program on disk.
Syntax:-Save File name (Enter).
Delete Commands (Alt+D)
The delete commands are used to delete a program statements or a group of statements.
Syntax: - Delete (Enter).
Syntax: - Delete 70 (Enter).
Syntax: - Delete 80-150
Syntax: - Delete -100
Syntax: - Delete 100Renum Commands:The Renum commands are used to renumber the program statements numbers.
Syntax: - Renum (Enter).
Files Commands:To display all Basic Files.
Syntax: - Files (Enter).
Kill Commands:It is used to delete Basic files permanents.
Syntax: - Kill File name.bac (Enter)
Key Commands:-