Thursday, April 9, 2020

Chapter - 9 Review of Library Function


A function in QBASIC is a readymade small program or user made small program that can perform a specific task. The function manipulates the data passes to it and returns either a string  or a numeric value.  QBASIC supports two different kinds of functions.
i. User Defined Function
ii. Library Function
User Defined function is created by a user using function procedure to perform certain task which can’t perform by using library functions.
Library function is also known as Built-In function or Routine function. A library function in QBASIC may be string function or numeric function. A string library function can manipulate either string or numeric data and returns a string value. A function name having dollar sign ($) is string function. LEFT$(), Right$(), CHR$(), STR$( ), UCASE$( ), DATE$ ( ), MID$(), DATE$(), TIME$(), SPACE$(), LTRIM$(), RTRIM$(), INPUT$(), etc. are some example string functions.   A numeric function can manipulate either string or numeric data and returns a numeric value. A numeric library function name has no type declaration sign. CINT(), SQR(), ASC(), VAL(), LEN (), SGN( ),ABS( ), SIN( ), TAN( ), COS() etc. are some example of numeric library functions.

REM converts uppercase letters of a word in lowercase and vice versa.
CLS
INPUT “Enter a word”; W$
FOR k = 1 TO LEN (W$)
           E$= MID$(W$, k, 1)
           IF E$=UCASE$(E$) THEN
                      New$ =New$+ LCASE$(E$)
           ELSE
                      New$ =New$+ UCASE$(E$)
           END IF
NEXT k
PRINT “New word after converting case is :”; New$
END



REM removes vowels characters from the supplied word.
CLS INPUT “Enter a word:”; W$
FOR j= 1 TO LEN(W$)
           E$= UCASE$(MID$(W$, j, 1)
           IF E$<>”A” AND E$<>”E” AND E$<>”I” AND E$<>”O” AND E$<>”U” THEN
                      New$=New$+E$
           END IF
NEXT j
PRINT “New word is :”; New$
END

REM to check palindrome word.
CLS
INPUT “Enter a word”; W$
FOR j= LEN (W$) TO 1 STEP-1
           rev$= rev$+MID$(W$, j, 1)
NEXT P
IF W$=rev$ THEN
           PRINT “Palindrome word”
ELSE
           PRINT “Not palindrome word”
END IF
END



REM converts Decimal number into Binary Number.
CLS
INPUT “Enter a Decimal number”; N
M = N
DO WHILE N<> 0
           R= N MOD 2
           B$=STR$(R) + B$
           N= INT(N/2)
LOOP
Ans=VAL(B$)
PRINT “Binary equivalent of entered number is “; Ans
END



No comments:

Post a Comment