History of Computer

Loading...

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