Thursday, October 17

MID$ function

The MID$ function returns a string of m characters from x$ string, beginning with the n th character.
Syntax
LN MID$ (x$,n,m)
Where,
LN : Line Number
x$  : string from which the m characters are to be extracted starting from nth character.
n   : the position from which character are to be extracted.
m  : number of character.

n must be within the range 1 to 255.
m must be within the range of 0 to 255.
if m = 0, the MID$ function returns a null string.
Examples
10 LET P$= "GOLDEN RING"
20 LET Q$= MID$(P$,2,3)

Use of MID$ function in the program.
1. CS 8.5 Display on the screen for MID$ function

Ok
LIST 
10 REM use of MID$ function
20 P$ = "GOLDEN RING"
30 Q$= MID$ (P$,2,3)
40 PRINT "Original String :-"; P$
50 PRINT "Extracted String :-" Q$
60 END
Ok
RUN
Original String :- GOLDEN RING
Extracted String :- OLD
Ok

2. CS 8.6 Display on the screen for MID$ function

Ok
10  REM Learning the use of MID$ function
20  P$= "KATHMANDU"
30  FOR I= 2 TO 3
40  FOR J= 1 TO 6
50 PRINT MID$(P$,I,J)
55 NEXT J
60 NEXT I
80 END
RUN
A
AT
ATH
ATHM
ATHMA
ATHMAN
T
TH
THM
THMA
THMAN
THMAND



Saturday, October 12

Right$ function

The RIGHT$ function returns the rightmost n characters of string x$.
Syntax
LN RIGHT (x$, n)
Where ,
LN    :   Line Number
x$     :   string from which the n right most characters are to be extracted.
n       :   number of characters
  • The value of n must be within the range of 0 to 255
  • if n = 0, the null string (length zero) is returned.
Example

Use of RIGHT$ function in the program.

1.
CS 8.3 Display on the creen for RIGHT$ function

Ok
LIST
10 REM use of RIGHT$ function
20 P$ = "GOLDEN RING"
30 Q$ = "RIGHT$ (P$, 4)
40 PRINT " Original String - "; P$
50 PRINT " Extracted String - "; Q$
60 END
RUN
Original String - GOLDEN RING
Extracted String - RING
Ok


2..
CS 8.4 Display on the screen for RIGHT$ function

Ok
LIST 
10   REM Learning use of RIGHT$ function
20   LET A$ = "KATHMANDU"  
30   FOR I = 1 TO 9
40   Q$ = RIGHT$(A$, I)
50   PRINT Q$
60   NEXT I
70   END
Ok
RUN
U
DU
NDU
ANDU
MANDU
HMANDU
THMANDU
ATHMANDU
KATHMANDU
Ok
     




Monday, September 30

String Functions(String handling commands

String functions or string handling commands allows us to examine and modify tring and convert tring to numeric values.

  • The string function with a dollar sign($) at the end returns a string whereas a string function without a dollar sign returns a numeric value.
  • String operation allow combination and comparison of strings.BASIC has the following string manipulation function.
LEFT$ function

The LEFT$ function returns a string that comprises the left most n characters of x$.
Syntax
LN LEFT$*(x$,n)
Where,
LN  : Line Number
x$   : string from which n left most characters are to be returned.
n     : number of characters

  • The value of n must be within range of 0 to 255.
  • if n = 0, the null tring (length zero) will be returned.
Example

10 LET P$ = "GOLDEN RING"
20 LET Q$ = LEFT$(P$,9)
The LEFT$ on line 20 will return nine characters of P$ string. o Q$ will have the string.
Q$= "GOLDEN RI"
Use the LEFT$ function in the program.

(1)CS 8.1 Dissplay on the screen for LEFT$ function 

Ok
LIST
10 REM use of LEFT$ function
20 P$ = "GOLDEN RING"
30 Q$ = LEFT$(P$,6)
40 print "Original String - "; P$
50 PRINT "Extracted String  - ";Q$
60 END
Ok
RUN
Original String - GOLDEN RING
Extracted String - GOLDEN
Ok

(2)CS Display on the screen for LEFT$ function

Ok
LIST
10   REM use of LEFT$ function
20   LET A$= " KATHMANDU"
30   FOR I = 1 TO 9
40   PRINT LEFT$ (A$,I)
50  NEXT I
60  END
Ok
RUN
K
KA
KATH
KATHM
KATHMA
KATHMAN
KATHMAND
KATHMANDU
Ok





Wednesday, August 28

Functions and Subroutines

A function is an operation which produces a single result on some data and can be used as part of an expression. BASIC provides  a large number of utility functions which are part of BASIC language and are known as Built-in function (or Library functions). The data upon which the function acts to produce the desired result is known as argument of the function. The argument can be a variable, a constant or an expression. The argument is to be enclosed in a pair of brackets.
Example :
1. 10 PRINT ABS (X) 
2. 10 PRINT LEN ("COMPUTER")
The functions in BASIC can be divided into the following categories :
1. String function
2. Arithmetic function
3. Trigonometric function   

Friday, August 9

WHILE-WEND statement

The WHILE-WEND statement executes a series of statements in a loop as long as given condition is true.
Syntax
LN WHILE expression
.
.
.
[loop statements]
.
.
.
WEND
Where ,
LN       : Line Number
expression     : valid BASIC expression
loop statement  : Series of statement which are to be repeated
Points to Remember

  • If expression is true, loop statements are executed until the WEND statement is encountered.
  • If expression not true execution starts with the statement following the WEND statement.

     Example
1. Write a BASIC program to find the sum of first N numbers using WHILE-WEND loop.

CS 7.9 Display on the screen for WHILE-WEND statement.

Ok
LIST
5     REM Learning use of the WHILE....WEND statement
10   INPUT "ENTER VALUE OF N:" ; N
20   LET SUM = 0 : LET CNT = 0
30  WHILE (CNT<N)
40  CNT = CNT+1
50  SUM = SUM+CNT
60 WEND
70 PRINT " The sum of number from 1 to 100 "; N; is  : "; SUM 
80 END
Ok
RUN
ENTER VALUE OF N: : ? 100
The sum of number 1 to 100 is : 5050 
Ok


Monday, August 5

IF...THEN..ELSE statement

The IF..THEN..ELSE statement allows us to make the decision regarding program flow based on the result returned by an expression.
Syntax
LN IF expression (,) THEN statement(,) ELSE statement

  • if the result of expression is true, the THEN statement is executed.
  • if the result of expression is false, the THEN line number is ignored and the ELSE line number is executed.
  • THEN and ELSE may be followed by either a line number for branching or one or more statements to be executed.
  • IF..THEN..ELSE is a single statement. They must be written in one line.

Example

1. 10 IF A>B THEN PRINT "A is greater " ELSE PRINT "B is Greater"
It will print the message "A is Greater" if A is greater than B and will print "B is Greater" if B is greater than A  

Use of IF..THEN...ELSE statement in the program.
1. Write a program to decide whether a student has passed or failed in the exam. ( use IF...THEN..ELSE) Pass marks=32

CS 7.7 Display on the screen for IF..THEN..ELSE statement

Ok
10 REM Program to check whether a student is passed
15 REM or failed in the S.L..C. Exam
30 INPUT "Enter the marks obtained :" ;M
40 IF M>=32 THEN 45 ELSE 65
45 PRINT  "MARKS OBTAINED :"; M
50 PRINT "CONGRATULATIONS :"; HE PASSED
60 GOTO 80
65 PRINT "MARKS OBTAINED :"; M
70 PRINT "SORRY ! HE FAILED"
80 END
Ok
RUN
Enter the marks obtained : ? 76
Marks OBTAINED : 76
CONGRATULATIONS ! HE PASSED
Ok
RUN
Enter the marks obtained : ? 23
MARKS OBTAINED : 23
SORRY ! HE FAILED 


2. CS 7.8 Display on the screen for IF...THEN...ELSE statement

Ok
LIST 
10   CLS
15 REM Learning the use of IF...THEN..ELSE statemet
20 INPUT "ENTER THE FIRST NUMBER" ; X
30 INPUT "ENTER THE SECOND NUMBER" ; Y
40 INPUT "THE THIRD NUMBER" ; Z
50 IF X.>Y THEN GOTO 90 ELSE GOTO 100
90 IF X>Z THEN GOTO 130
95 GOTO 150
100 IF Y>Z THEN GOTO 140
105 GOTO 90
130 PRINT "THE LARGEST NUMBER IS" ; X
135 GOTO 160
140 PRINT "THE LARGEST NUMBER IS "; Y
145 GOTO 160
150 PRINT "THE LARGEST NUMBER IS"; Z
160 END
OK 
RUN
  


   

Thursday, August 1

IF...THEN statement

The IF... THEN statement allows us to make a decision regarding program flow based on the result returned by an expression.
Syntax
LN IF expression [,] THEN statement[,]
Points to remember

  • If the result of expression is true (or non zero), THEN then statement is executed.
  • If the result of the expression is false (or zero), the THEN statement is ignored and execution continues with the next executable statement.
  • A comma is allowed before THEN

CS 7.5 Display on the screen for IF..THEN statement

Use of IF..THEN statement in the program.
1. To check the number for given data and print error message. 
Minimum and maximum value data are 10 and 100 respectively.
Ok
LIST
10    REM Learning the use of IF...THEN statement
30    INPUT A
40    IF A<10 THEN PRINT "DATA BELOW THE RANGE"
45    IF A>=10 AND A<=100 THEN PRINT "DATA WITHIN THE RANGE"
50    IF A>100 THEN PRINT "DATA ABOVE THE RANGE"
60    IF A<>0 THEN 30
70    END
Ok
RUN
?  5
DATA BELOW THE RANGE
? 10
DATA WITHIN THE RANGE
? 35
DATA WITHIN THE RANGE
? 150
DATA ABOVE THE RANGE
? 0
DATA BELOW THE RANGE
Ok  

2.CS 7.6 Display on the screen for IF...THEN statement
Ok
LIST 
20   REM To find the largest number among X.Y and Z
30  INPUT " ENTER THE FIRST NUMBER = "; X
40  INPUT " ENTER THE SECOND NUMBER = ";Y
50  INPUT " ENTER THE THIRD NUMBER = ";Z
60  IF X>Y THEN GOTO 100
70  IF Y>Z THEN GOTO 110
80  PRINT " THE LARGEST NUMBER IS "; Z
90 GOTO 140
100 IF X>Z THEN GOTO 130
105 GOTO 80
110 PRINT " THE LARGEST NUMBER IS " ; Y
120 GOTO 140
130 PRINT " THE LARGEST NUMBER IS " ; X
140 END
Ok
RUN
ENTER THE FIRST NUMBER = ? 68
ENTER THE SECOND NUMBER = ? 139
ENTER THE THIRD NUMBER = ? 23
THE LARGEST NUMBER IS 139  
   
          


Saturday, July 27

FOR and NEXT statements

The FOR and NEXT statement is used to execute a series of instructions a specified number of times in a loop.
Syntax
LN FOR variable = X To Y [STEP  Z]
.
.
.
NEXT [variable][,variable...]
Where,
LN      : Line Number
variable  : variable used as a counter
X, Y and Z  :numeric expressions
STEP  Z  :  specifies the counter increment for each loop.

Points to remember

  • The first numeric expression(x) is the initial value of the counter.
  • The second numeric expression is the final value of the counter.
  • Program lines following the FOR statement are executed until the NEXT statement is encountered. Then the counter is incremented by the amount specified by STEP.
  • When STEP is not mentioned, the increment is considered as 1.
  • It is checked if the value of the counters is greater than the final value(Y). If it is not greater, GW - BASIC branches back to the statement, immediately after the FOR statement, and the process is repeated. If it is greater, execution continues with the statement following the NEXT statement. Hence, FOR and NEXT statement forms a loop (i.e. FOR-NEXT loop)
  • If STEP value is negative, the final value of the counter will be less than the initial value.

Examples

1. 10 For A = 0 To 20   
.
.
.
80 NEXT A
2. For A = 0 To 20 STEP 2
.
.
.
80 NEXT A
3. 10 For A = 20 To 0 STEP-2
.
.
.
30 NEXT A

Use of FOR and NEXT statement in the program.
1. To sum the numbers from 1 to 5000 in step of 7

1. CS 7.3 Display on the screen for FOR and NEXT statement

Ok
LIST
5      REM Learning the use of FOR...NEXT statement
10    S = 0
20    FOR I = 1 TO 5000 STEP  7
30    S =S+I
40    NEXT I
50    PRINT "SUM =" ; S
60    END
Ok  
RUN
SUM = 1787500
Ok


2.To generate the natural number up to 10 (i.e. 1 to 10)

CS 7.4 Display on the screen for FOR and NEXT statement

Ok
LIST
10    REM To generate numbers from 1 to 10
20    FOR I = 1 TO 10
30    PRINT I
40    NEXT I
50    END
Ok
RUN
1
2
3
4
5
6
7
8
9
10
Ok      






Thursday, July 18

ON...GOTO Statement

The ON...GOTO Statement is used to branch to one of several specified line numbers depending on the value return, when an expression is evaluated.
Syntax
LN ON expression GOTO line numbers
Where,
LN      :  Line Number
Expression  :  Valid numeric expression
Line number  :  Line numbers to where jump has to take place.

  • In the ON...GOTO statement the value of expression determines which line number in the list will be used for branching.
For example  :
If the value of expression =3, the third will be the destination of the branch.

  • If value expression is zero the execution continues with next executable statement in the program.
  • If value of expression is negative or greater than 255, error 0 classes.
Examples
1.  100 ON  N  GOTO  200, 300, 400
2.  150 ON  M  GOTO  215, 50, 300
In Example 1, the branching takes place depending on the value of N
if N=1, the program branches to line 200
if N=2, the program  branches to line 300
if N= 3, the program branches to line 400 and so on.

START
A =1
PRINT A  (infinite loop)
N
A = A+1     

Note : The program displays the number 1,2,3... and so on infinitely (forming infinite loop)
1.  Press Pause key to stop the display of numbers temporarily.
2.  Press CTRL+Break to stop to the execution of the program (or to terminate the infinite loop)


CS 7.2 Display on the screen for GOTO statement

Ok
LIST
10   REM Learning the use of GOTO statment
20   CLS
30   LET A =1
40   PRINT A
50   LET A = A+1
60   GOTO 40
70   END
Ok    
            

Saturday, July 13

Branching and Looping

Introduction

In a computer program the statement are ordinarily executed line by line. In BASIC language the execution is done in the ascending order of line number, unless instructed otherwise by control statement. The control sequence of statement executed can be altered by means of control statement.
A transfer of control or jump from one part of the program to another is referred as unconditional branching. Another situation that arises frequently is transfer to one of two different portion of  program depending on the outcome of comparison between two quantities, such an operation is called a conditional  branching.
Looping involves repeating some portion of the program either a specified number of times or until some particular condition has been satisfied.    
BASIC has the following control statement :

GOTO Statement
The GOTO statement is used to branch unconditionally out of the normal program sequence to a specified line number:
Syntax
LN GOTO  line number
Where,
LN      Line Number
line number  : any valid line number within the program.
  •    if jumped line (line number) is an executable statement, that statement and those following are executed.
  • if the jumped line is not executable statement, execution proceeds at the first executable statement encountered after the jumped line.
Example
1. 40 GOTO 70, Jump to a higher line Number(70)
2. 60 GOTO 40, Jump to a lower line Number(40)
Use of GOTO statement in the program.
START
A = 1
PRINT A
IF
A >=100 (N) A=A+1
(Y)
STOP  
 
            

Sunday, July 7

SWAP Statement

The SWAP statement is used to exchange the values of two variables.
Syntax
LN SWAP variable1, varaible2
Where,
LN      :  Line Number 
variable1  :  the first variable
variable2  :  the second variable

  • Any type of variable may be swapped (numeric or string).
  • To use SWAP, the two variables must be of the same type.
Use of SWAP statement in the program.

  CS 5.12 Display on the screen for SWAP statement

Ok
 LIST 
5      REM Learning the use of SWAP statement
10    A$ = "STUDENTS"  :  B$ = "TEACHERS"  :   C$ = "HELP"
20    PRINT A$, C$, B$
30   SWAP A$, B$
40  PRINT A$, C$, B$
50  END
Ok
RUN
STUDENTS     HELP  TEACHERS
TEACHERS     HELP  STUDENTS                     
Ok

Saturday, July 6

RESTORE Statement

The restore statement allows DATA statements to be reread from a specified line.
Syntax
LN RESTORE [Line Number]
Where,
LN      :           Line Number
Line number    :       The particular line number from which data are to be read again.
  • if line number is specified the next READ statement reads the first data in the specifed DATA statement.
  • if line number is omitted, the next READ statement reads the first data in the first DATA Statement.
Example

10  RESTORE
Use the RESTORE Statement in program

CS 5.11 Display on the screen for RESTORE statement

2  REM  Learning use of RESTORE statement
5  READ A, B, C
10  RESTORE
15  READ D, E, F
20 DATA 1.8, 5.02, 8, 20, -47, 0.003
40 PRINT A, B, C, D, E, F
50 END

Explanation of the program
This program will assign the following values to the variables
A = 1.8
B = 5.02
C = 8
D = 1.8
E = 5.02
F = 8
The RESTORE statement results the pointer to the beginning of the line 20. 
In the absence of the RESTORE statement (i.e. line 10) , the following values would be assigned to the variables.
A = 1.8
B = 5.02
C = 8
D = 20
E = -47
F = 0.003      

Sunday, June 30

READ and DATA statement

The READ statement is used to read value from a DATA statement and assign them to variables.
The DATA statement is used to store the numeric, integer or string constants that are accessed by the READ statement.
Syntax
LN READ  list of variable
LN DATA constants
Where,
LN  :  Line Number
list of variables : numeric or string variables
Constants  : numeric or string data

  • A READ statement must always be used with a DATA statement.
  • READ statements assign variables to DATA statement values on a one- to - one basis.
  • READ statement variables may be numeric or string and DATA statement values {constants} must agree READ statement variables.
  • A single READ statement can access one or more DATA statement.
  • Several READ statements can access the same DATA statement.
  • String constant in DATA statements should be enclosed within double quotation marks.
  • DATA statements are not executable and may be placed any where in the program.
  • The variables in the READ statement are separated by a comma [,] similarly the constant in DATA statements are also separated by commas.
    Examples

1. 10  READ A, B
    50  DATA 10,20
The values assigned to the variables A and B of READ statement from the constants of DATA statements are as follows
A = 10
B = 20

2.  10 READ A, B, A1, A2, C% ,D%, A$, B$, X$
      80 DATA 1.7, -4.986, 2E-7, -1.2 E 6, 12,70 ,"BEAUTIFUL", "CITY" "POKHARA"
It assigns the following values to the variables :
A = 1.7
B = -4.986
A1 = 2E - 7
A2 = -1.2E6
C% = 12
D% = 70
A$ = "BEAUTIFUL"
B$ = "CITY"
X$ = "POKHARA"

       

       

             

Wednesday, June 19

INPUT Statement

The INPUT Statement is used to prepare the program for input from the keyboard during program execution.
Syntax
LN INPUT [Prompt string ;] List of Variables
Where,
LN      :       Line Number
Prompt String  :    Message displayed for data to be supplied during program execution.
List of Variable  : Contains the variable {s} that store data

  • The prompt string must be surrounded by double question marks, followed by a semicolon or comma and name of variables to which it will be assigned.
  •  If more than one variable is used, they must be separated by commas. Similarly, values entered for different variables should be separated by commas. 
  • The data entered is assigned to variable list. The number of data items supplied must be the same as the number of variables in the list.
  • The variable names in the list may be numeric, integer, string or sub scripted variable.
  • If it is necessary that the data supplied must be of the same type as the variable in the input statement.
  • Comma may be used , instead of semicolon, after prompt string to suppress the question mark.
  • When INPUT statement is encountered during program execution, the program halts (stops) and prints a question mark{?} {or the prompt string is displayed }, then you can enter data and if you press Enter, program execution continues.
  • Quotation marks are optioned in string type of data.
Examples 
The following are some of valid INPUT statements
1. 10  INPUT A
2. 20  INPUT A,B,C
3. 30 INPUT A$, A2$, B1, B2, C1%, C2%
4. 40 INPUT A, B$, D(5)

CS 5.7 Display on the screen for INPUT statement

Ok
LIST 
10    REM Learning the use of INPUT statement
20    REM Value of two numbers X and Y
30    INPUT X
40    INPUT Y
50    REM Addition of two numbers X and Y
60    LET A = X+Y
70    PRINT " VALUE OF X = "; X
80    PRINT " VALUE OF Y="  ; Y 
90    PRINT "ADDITION OF X AND Y = "; A
100  END
Ok
RUN
?   25
?   10
VALUE OF X = 25
VALUE OF Y = 10
ADDITION OF X AND Y = 35
Ok

CS 5.8 Display on the screen for INPUT statement
Ok
LIST 
10    REM Learning the use of INPUT statement
20    INPUT N$
30    INPUT C
40    INPUT A$
50    INPUT R
60    PRINT " MY NAME IS " ; N$
70    PRINT " I STUDY IN CLASS "; C
80    PRINT " MY SCHOOL'S NAME IS "; A$
90    PRINT " MY ROLL NO. IS "; R
100  END
Ok
RUN
?  SUMA SHAH
?  9
? EAST-POLE HIGH SCHOOL
? 26
MY NAME IS SUMA SHAH
I STUDY IN CLASS 9
MY SCHOOL'S NAME IS EAST POLE HIGH SCHOOL
MY ROLL NO IS 26 
         

     
        

Wednesday, June 5

LET statement

The LET statement assigns the value of an expression to a variable.
Syntax
LN [LET] Variable = expression
Where,
LN      :     Line Number
[LET]  :     LET is optional (i.e. the equal sign(=) is sufficient to assign an expression to a variable.
Variable  :  Stores the values of expression on the right hand side.
Expression  valid BASIC expression
Points to remember

  • In the LET statement the type of variable and type of expression must match each other.
  • The LET statement is optional in programs, only the equal sign(=) is sufficient to assign an expression to a variable.
Examples
1. 30 LET X = 20
2. 20 LET N $ = "SUMA SHAH"

CS 5.5 Dislplay on the screen for LET statement

Ok
LIST
10   REM Learning the use of LET statement
20   LET N$ = "SUM SHAH"
30   LET C = 9
40   LET A$ = EAST - POLE HIGH SCHOOL"
50  LET  R = 26
60  PRINT " MY NAME IS " ; N$
70  PRINT " I STUDY IN CLASS ";C
80  PRINT " MY SCHOOL'S NAME IS ";A$
90  PRINT "  MY ROLL NO. IS "; R
100  END
Ok
 RUN
MY NAME IS SUMA SHAH
I STUDY IN CLASS 9
MYS SCHOOL NAME IS EAST - POLE HIGH SCHOOL
MY ROLL NO IS 26
Ok

CS 5.6 Display on the screen for LET statement  

Ok
LIST 
10 REM Learning the use of LET statement
20 REM Values of two numbers X and Y
30 LET X=20
40 LET Y=10
50 REM Addition of two numbers X and Y
60 LET A =X+Y
70 PRINT "VALUE OF X =";X
80 PRINT "VALUE OF Y=";Y
90 PRINT "ADDITION OF X AND Y =";A
100 END
Ok
RUN
VALUE OF X= 20
VALUE OF Y=10
ADDITION OF X AND Y = 30
Ok
        
 



  
                


Sunday, June 2

TAB Function

The TAB function spaces to position on the screen.
Syntax
LN TAB (n)
Where,
LN     :  Line Number
n         :  number of spaces

  • Space 1 is the left most position.
  • n must be within the range of 1 to 255.
  • if the current print position is already beyond space n, TAB goes to that position on the next line.
  • TAB should be used with PRINT statement.

Example 2

1.  100  PRINT "NAME" TAB (15); "ADDRESS"; TAB(40); "PHONE NO"
2.  50    PRINT "ROLL NO." TAB(30); "MARKS OBTAINED"
Use of TAB function in the program

CS 5.3 Display on the screen the TAB function

Ok
LIST
5      REM Learning use of TAB function
10    PRINT "NAME" TAB(25) "FEE"
15    PRINT "----"      TAB(25) "---"
20    READ A$,B$
30    PRINT A$ TAB(25) B$
40    DATA "SUMA SHAH" , "RS.  500.00"
50    END
Ok
RUN
NAME                        FEE
----                              ---
SUMA SHAH            RS. 500.00
Ok

CS 5.4 Display on the screen for TAB statement
Ok
LIST
10  REM Result of First terminal Exam
20  REM of a student
30  PRINT "ENTER NAME, ROLL & MARKS"
40  INPUT "NAME :-"N$
50  INPUT "ROLL NO.:-" R
60  INPUT " MARKS IN ENGLISH" ; E
70  INPUT "MARKS IN NEPALI" ; N
80  INPUT "MARKS IN SCIENCE" ; S
90  INPUT "MARKS IN COMPUTER" ; C
100  PRINT "NAME" ; TAB(30) ; N$
103  PRINT "ROLL NO." ; TAB(30) ; R
106  PRINT 
110  PRINT "ENGLISH" ; TAB (30) ; E
120  PRINT "NEPALI" ; TAB(30) ; N
130  PRINT "SCIENCE" ; TAB(30) ; S
140  PRINT "COMPUTER" ;TAB(30) ; C
150  PRINT
160  PRINT "TOTAL" ; TAB(30) ; E+N+S+C
170  END
Ok
          
                  
       

Wednesday, May 29

Reading and Printing

Introduction

In a computer program it is often necessary to supply data to the program and print the result. This is done by input and output statements. In a BASIC program data can be supplied by INPUT, READ,DATA, RESTORE statements and printed with PRINT and LNPRINT statement.
PRINT Statement
The PRINT statement is used to output a display on the screen.
Syntax
LN PRINT [list of expression] [;] 
? [list of expression] [;] 
where,
LN  :  Line Number
list of expressions  :  value of expressions which is to be displayed
Points to Remember :

  • if list of expression is omitted , blank line is displayed.
  • if list of expression is included , values of expression are displayed.
  • Expression in the list may be numeric and / or string expressions, separated by comma or semicolons.
  • String constant in the list must be enclosed in double question marks.
  • ? (question mark) may be used in place of the word PRINT.
Example 1
Follwing are some valid PRINT statements :
1. 5 PRINT A
2. 10 PRINT 
3. 15 PRINT A+B, C
4. 20 PRINT "C, " , C, " A+B"; T
5. 25 PRINT A $+ B $, C $
6. 30 PRINT {28.34 - 11.28}^9*(1.5 E5)

Use of PRINT statement in the programs
CS 5.1 Display on the screen for PRINT statement

Ok
LIST
10   REM Learning the use of PRINT statement
20   REM  Values of two numbers X and Y
30   X=20
40   Y=10
50   REM Addition of two numbers X and Y
60   A=X+Y
70   PRINT X
80   PRINT Y
90   PRINT A
100 END
Ok
RUN
20
10 
30
Ok

CS 5.2 Dislpay on the screen for PRINT statement

Ok
LIST
10  REM Learning the use of PRINT statement
20  REM Values of the numbers X and Y
30  X=20
40  Y=10
50  REM Addition of two numbers X and Y
60  A=X+Y
70  PRINT "Value of X ="; X
80  PRINT " Value of Y="; Y
90  PRINT "Addition of X and Y ="; A
100 END
Ok
RUN
Value of X = 20
Value of Y = 10
Addition of X and Y = 30
Ok    
        
              
 
    

Sunday, May 19

End Statement

The END statement terminates program execution , closes all files and returns to the command level.
Syntax
END

  • Generally, the END statement indicates the end of a BASIC program.
  • END statement may be placed any where in the program to terminate execution.
  • END closes all files.
  • GW - BASIC always returns to the command level after END is executed.
Example 2

      .            .
      .            .
      .            .
100 End
It ends the program and returns to the command level.
Ok
LIST  
10   REM Learning use of END statement
20   REM Values of two numbers X and Y
30   X = 20
40   Y = 10
50   REM Addition of two numbers X and Y
60   A = X+Y
70  END
Ok
RUN
Ok


Diplay on the screen for END statement

Ok
LIST
10  REM Learning the use of END statement
20  REM Values of Base and Height of a triangle
30  B = 2
40  H = 4
50  REM Area of the triangle
60  A = 1/2*B*H 
70  END
Ok
RUN
Ok    
      

Tuesday, May 7

BASIC Statements

Program comments - the REM Statement 
The REM statement allows remarks to be inserted in program.
Syntax
LN REM  [comment]
'                 [comment]
Where, 
LN : Line Number
Comment : Remarks written by the programmer
'                : Apostrophe (') may be used in place of REM.
Points to Remember :

  •  REM statements are not executed, but they are listed with all other.
  • Statements in BASIC program.
  • Once REM or ' (apostrophe) is encountered, the program ignores everything until the next line number is encountered.
  • REM Statement may be branched into from GOTO or GOSUB statement.
  • Remarks can be added to the end of a line by an apostrophe (') instead of REM.
Example 1

1. 10 REM This program calculates percentage.
2. 20 REM Program to find area of a triangle
3. 30 REM " My Test Result"
4. 40 REM A = x + y 'Addition of x and y
Use of REM statement and apostrophe (') in the program. Suppose we have two numbers.
x = 20
y = 10
Now, we will write a program to add  these two numbers. The remarks are written using REM statement and apostrophe (')

CS 4.1 Display on the screen for REM statement

Ok
LIST 
10  REM Learning the use of REM statement
20  REM Values of two numbers x and y
30  X = 20
40  Y = 10
50  REM Addition of two numbers x and y
60  A = X+Y
Ok
RUN
Ok


CS 4.2 Display on the screen for REM statement

Ok 
LIST 
10 REM Learning the use of REM and apostrophe (') statement
20 REM Values of two numbers X and Y
30 X =20 'VALUE OF X
40 Y = 10 ' VALUE OF Y
50 REM Addition of two numbers X and Y
60 A=X+Y 'Addition of X and Y
Ok
RUN
Ok          

  

Sunday, May 5

RM DIR Command

The RMDIR Command is used to delete a sub directory.
Syntax
RMDIR pathname
Where,
Path name : Location of sub directory to be removed (deleted)
  • The path name must not exceed 63 characters.
  • The sub directory is to be removed from its present directory
  • The sub directory to be deleted must be empty (i.e. with no files)
Example 27

1. RMDIR CLASS IX (press enter key)
It is used to delete sub directory CLASS IX from its parent directory (current directory).
2. RMDIR "A : \ GWBASIC" (press enter key)
It is used to delete GWBASIC sub directory