Q.1:-Deﬁne Subprogram. Explains types.
Ans.:- Sub Programs
The primary plan of routine is to interrupt up the big programs into smaller, manageable components known as modules or subprograms. A routine may be a section of the program that perform speciﬁc task- If a routine is simply too sophisticated to perform a speciﬁc task, then it ought to be additional counteracted into smaller subprograms or modules. This method of subdividing task continues till no a lot of modules or sub programs square measure required. Subprograms or modules offer United States of America how of breaking the program into separate, short and well deﬁned tasks, which can simply be designed, debugged, modiﬁed and documented.
Types of Subprograms
There square measure 2 main sorts of subprograms, that square measure as following: .
1-Function Subprograms 2-Subroutine Subprograms
A operate routine is meant to perform a speciﬁc task and come a worth. the fundamental language contains operate subprograms that perform arithmetic and string operations that build programming abundant less complicated in several things and cut back efforts concerned in programming.
Types of operate Subprograms
There square measure 2 sorts of operate subprograms
1 System Deﬁned/Built-in Functions
2-User’s Deﬁned Functions
A software itself may be a little program consisting of set of statements that square measure sometimes written at intervals a main program. A software is wont to calculate and come several values. A software routine may be a series of BASIC statements that square measure written once into a program however these could also be used variety of times anyplace in an exceedingly BASIC program as and once desired.
Q.2:- Describe built-in functions.
Ans.:- Built-in functions
These functions perform operations on their operands and return values. Basically these are subprograms that have been written by‘ developers of language and have been incorporated in it. These functions are also called standard functions, library functions or built in functions. These functions can be used any where in a program by calling them.
Types of built-in functions
There are two types of system deﬁned functions, which are as following.
1. Numeric built-ins functions 2. String built-in functions
1-Numeric built-in functions
Numeric built-in functions deal in numbers. These functions are applicable on numeric values only, and produce the numeric results. There are too many numeric functions available, but some are INT, ABS, COS, SIN, TAN, SQR etc.
2- String built-in Functions
String built-in functions are used with strings. Any thing which is enclosed in double quotes is called a string. These functions are used to process character strings and produce the numeric values or string values. These functions include LEFTS, MID$, RIGHT$, STR$,-TIME$, DATE$, CHR$,
INKEY $ etc.
Q.3:- Write down the purpose of the following functions: (i). ABS ( ) (ii). INT() (iii). SQR ( ) (iv). SIN ( ) (v). TAB ()
Ans:- ABS ( ) Function
ABS function is used to return the absolute
value of the expression X i.e., the value without any sign
Where x must be a numeric expression or value ,
10 INPUT. 1
30 PRINT ABS(X)
(ii). INT () Function:
INT Function is used to returns the lowest integer less then or equal to x. In case of whole number it returns the same number
Where x is the number.
30 PRINT INT(_N)
40 PRINT INT(M)
SQR function is used‘ to returns the square root value of a given positive number ‘N’ V i I s
Where N is a positive number value which must be greater than 0.
2 O PRINT
SIN Function is used to calculate the trigonometric ratio called sine of an angel expressed in radians.
Note: -SIN (x) is calculated in single precision unless the /d switch is used when GW-BASIC is executed. To obtain Asin(a) when a is in degrees, use the
20 PRINT SIN(X)
30 INPUT “Number;
40 PRINT SIN(Y)
(v). TAB ( ) Function:
TAB function is used for screen designing. It is used to skip a speciﬁed number of spaces in a print or LPRINT statements on the screen. If the current print position is already beyond space x, TAB goes to given position on the next line. Space 0′ is the leftmost position.
Where x is a number value which is rounded to an integer and must be within the range of l to
Note: – SPC function
can only be used with
PRINT, LPRINT and
PRINT # statements.
10 FOR X= 1 TO 60
20 PRINT TAB(X);X
30 PRINT TAB(X)“ALIF”
Q.4:- Write down the purpose of the following functions: (i) FIX () (ii). RND () (iii). SPC (iv) TAN () (v). VAL ( )
Ans.:-FIX ( ) Function: –
FIX function is used to return the Whole number of any real integer. Fix function does not round off numbers; it _simply eliminates the decimal point and all characters to the right of the-decimal point.
Where x_ is any real integer.
10 N=3 .6
30 PRINT FIX(N)
40 PRINT FIX (M )
_ v . I l I
(ii)-RND ( ) Function: –
RND I Function is used to generate
random numbers between 0 and 1 .
RND (x) 1
Where x is the number. If n is greater than 0, or if x is omitted then the next random number is generated in the sequence. The same sequence of random number is generated each time the problem is run unless the random number generator is reseeded.
10 FORN=1TO 5
20 PRINT INT (RND* 100);
3 0 NEXT N
(iii). SPC () Function: –
SPC is used for screen designing. It is used to skip a speciﬁed number of spaces in a print or an LPRINT statements. The argument n must be in the range of 0 to 25 5.
Where x is an number value which is rounded to an integer and must be within the range of O to 255.
Note: – SPC function can only be used with PRINT, LPRINT and PRINT‘# statements.
l0FORX= ITO 40 STEP2
20 PRINT SPC(X);X,
30 PRINT SPC(X);“ALIF”
40 NEXT X
(iv)-TAN () Function: –
TAN Function is used to calculate the trigonometric tangent of a given number X in radians.
If TAN overﬂows, the ‘Overﬂow” error message is displayed. To obtain the
T AN(X), when N is in degrees, use the following formula.
20 PRINT TAN(N)
(v)- VAL ( ) Function: –
VAL Function is used to return the numerical value of a given string A$.
The VAL function also strips leading tabs, blank spaces from the given string
Note: -If the ﬁrst character of a given ASE is not numeric, the VAL(A$) function will return O.
1 0 N$=”22”
40 PRINT C
Q.5:- Write down the purpose of the following functions: (i) LOG () (ii) ASC (_) (iii) CHR$ ( ) (iv). DATE$ ( )
Ans.:-(i)-LOG ( ) Function:
LOG function is used to return the natural logarithm of n.
LOG (N) Y
Note: – N must be a number
greater than 0.
3 0 PRINT LOG(N)
40 PRINT LOG(M)
(ii)- ASC () Functi0n:-
ASC Function is used to return a numeric value that is equal to ﬁrs tASCII code for the ﬁrst character of the given string A$.
20 PRINT ASC(A$)
The program will returns the ASCII
code value of the A, Which is 65.
CHR$ Function is used to convert an ASCII code to its equivalent character value.
CHR$(n) e ”
Where n is the numeric value having the value from 0 to 255.
20 PRINT CHR$(A)
30 PRINT CHR$(66) S
The above program will returns the character equivalent value of variable
A and character equivalent value of ASCII 66 numeric value.
DATE$ function is used to set or see the current system date.
Date can be any of the following formats.
20 PRINT V$
30 PRINT DATE$
Q.6:- Write down the purpose of the following functions: (I) LEFT$ (D) (ii) RIGHT$ (Iii) SPACE$ ( ) (iv) MID$( ) (V) TIME$ ( )
LEFT$ function is used to return the n leftmost speciﬁed characters from the given string.
Syntax : – LEFTT$(A$, N) I E
Where N is the number of speciﬁed characters which you want from the given string.
10 A$=”Alif Publication”
20 PRINT LEFT$(A$,4)
RIGHT$ function is used to return the n rightmost speciﬁed characters of the given string A$.
Where N is the number of speciﬁed characters which you Want from the given string.
10 A$=”Alif Publication”
20 PRINT RIGHT$(A$,l1)
3 0 END
(iii)- SPACE$ Function:-
SPACE$ function is used for screen designing. It is used to return a given
string of ‘x’ spaces.
Where x is an number value which is rounded to an integer and must be within the range of 0 to 255.
10 FOR X= 1 TO 6-0 STEP 2
20 PRINT SPACE$(X);X,
30 PRINT SPACE$(X);“ALIF”
(iv)-MID$ () Function
MID$ Function is used to return the number of speciﬁed characters from the middle of the given string.
Where n1 is the required starting character of the given string within the range of 0 to 255. n2 is the required ending character of the given string which must be within the range of 0 to 255.
Note: – If either n1 or n2 is out of range, an “Illegal function call error” is returned”.
10 A$=” Alif Publication
20 PRINT mid$(A$,5,12)
(v)-TIME$ Function ():-
TIME$ Function is used to set or see the current system time.
Time can be the following fonnat.
Where HH is the Hour, MM is the Minute and SS is the second.
20 PRINT T$
3 0 PRINT
50 PRINT TIME$
Q.7:- What is meant by user deﬁned functions? Explain them with examples.
Ans.:-User Deﬁned Functions
User deﬁned functions are the functions which are completely developed by the users themselves to solve their problems. Functions which We write are called user deﬁned functions. User deﬁned functions may be numeric or strings. If a type is speciﬁed in the function name, the value of the expression is forced to that type before it is returned to the calling statement. If a type is speciﬁed in the function name and the argument type does not match, an error message is given.
User deﬁned functions returns a single value and are generally used to Perform an operation that will be needed numerous of times in a program. In BASIC, user deﬁned functions are referred to as procedures; similar to SUB procedures except function procedures return one value. .
DEF FN Statement
This statement is used to deﬁne & name a function subprogram written by the user. These functions are deﬁned only for the life of a given program and
are not part of the BASIC language. A single line function can be deﬁned by DEF F N statement that is executing same codes more than once in the different place of program.
DEF FN name [ARGUMENT] =expression
Where name must be a legal variable name. This name preceded by FN becomes the name of the function. The argument consists ‘of those variable names in the function deﬁnition which is to be replaced when the function is called. The items in the list are separated by commas. The expression is a demonstration that performs the operation of the function. It is limited to one statement. The variable in the argument represent, on a one-to-one basis, the argument variables or values that are to be given in the function call. One of the advantage of a user deﬁned function is that once the function is deﬁned, it may be used anywhere in the program in the same way in which built in functions are used. Another advantage is that a user deﬁned function can easily be changed to another function. A ﬁlnction name can be used in the expressions of a program like a variable.
ADEF F N statement must be executed before the function it deﬁnes may be called. If a function is called before it has been deﬁned, an “Undeﬁned User Function” error occurs. DEF FNI statement is not allowed in the direct mode. Recursive functions are not supported in the DEF FN statement.
10 DEF FNX(Y)=(Y“3+y/\2)/Y
20 INPUT “Number-1:”, A
30 INPUT “Number-’21”, B
40 C=DEF FNX(A) +DEF FNX(B)
50 PRINT c
Q.8:- Describe the use of GOSUB…. RETURN statements.
Ans.:- GOSUB and RETURN Statements
A GOSUB statement is used to invoke a subroutine. There are two statements in BASIC that allow us to use the subroutines; the GOSUB statement and the RETURN statement. The GOSUB statement will cause the transfer of control to the subroutines. When a GOSUB statement is executed, control is transferred to a new line number.
A subroutine may be called any number of times in a program, and a subroutine may be called from within another subroutine. Such nesting of subroutines is limited only by available memory.
A RETURN statement shows a formal end of the subroutine and transfers control back to the line following the GO SUB statement. A subroutine can contain more than one RETURN statement, should logic dictate a RETURN at different points in the subroutine. Subroutines can appear anywhere in the program, but must be readily distinguishable from the main program. To prevent inadvertent entry, precede the subroutine by a STOP, END, or GOTO statement to direct program control around the subroutine.
Line N0. I GOSUB line number
Line N0 RETURN Line Number
Line Number is the starting line number of the subroutine and optional in
10 GOSUB 50
20 PRINT “DPS”
30 PRINT “LAHORE”
50 PRINT “SENIOR BOYS WING”
60 PRINT “MODEL TOWN” ‘
Q.9:- What are ﬁles? Explain the components of ﬁles.
A ﬁle is a systematic and organized collection of records. In computer terminology, the Word ﬁle means exactly the same as statedabove i.e. a device which can store the information. Files hold records and information on a variety of storage media, such as magnetic tapes, hard disks and ﬂoppy disks etc. Files are also stored in the internal or main memory of the computers. The information present in these ﬁles can be retrieved and altered as and when required by the computer system or by the computer programs. A computer can process large amount of data. It is always useful to store input and output in a data ﬁle. .
Components of ﬁles
Main components of ﬁles are as follows:
1. Characters 2. Data ﬁelds 3.Record
Character consists of alphabets, digits and special characters. These are represented inside the computer as a sequence-of l s and Os.
A Data ﬁelds are group of related characters to have a unit of information.
For example a student name, his roll no are different data ﬁelds ,
A group of related ﬁelds is called a record. For example the combination of name, father name, roll no, age, address is a record of a student.
Q.10:- Differentiate between data ﬁle and program ﬁle.
Ans.: -Difference between data ﬁle and program ﬁle
1- Program Files
Program ﬁles contain the program or instructions for the computer. These ﬁles contain a number of lines written in appropriate high level language such as C++, COBOL, PASCAL etc. The programs from ea program ﬁle can be accessed by a computer, loaded into memory and executed. Similarly, programs run by a computer may be stored in a storage device to create a program ﬁle. Obviously these program ﬁles provide tremendous powers to computers to perform data processing I
2- Data Files
Data ﬁles contain data and information needed for programs to perform execution successfully. Data ﬁles are linked to or included with a program ﬁle during run time or compilation time. Data ﬁle is a collection of record and each record is a collection of related data items known as ﬁelds. So, collection of ﬁelds make a record and collection of records make a ﬁle. If you take student information as an example then each student’s information is a record and different data items, roll no, name, address etc. are ﬁelds, collection of all the students’ record is called a ﬁle
Types of Data Files
There are two types of data ﬁles, which are as following:
1. Sequential Data Files 2. Random Access Data Files
Q.11:- Differentiate between Sequential File and Random File
Ans.: -Difference between Sequential File and Random File
- Sequential access and Random access ﬁles can be compared to the Cassette and the Record operation.
- Like a cassette, in a sequential access data is stored one after the other sequentially, Reading and writing both these-F process take place sequentially.
- Like a record, in a random access, the order of data storage is not important, in a record when 4“ or 5’“ song is required record player’s head can be directly moved to the required song without going through all the songs before it.
- Somewhat same way, in random access operation whenever some data is required by the computer, it can directly move to the position wherever the data is stored and read it. To read 5“ data it does not has to go through ls’ to 4“ data.
- Sequential ﬁle is useful when every time you want to process the entire data in the ﬁle, for example using the student ﬁle to generate marks-sheet, where you have to read and make the mark sheet for each and every student
- Whereas random ﬁle is more useful when most of the time you want to process only a single data or a small group of data from the ﬁle.
Q.12:- Describe Sequential data Files
Ans.: -Sequential data Files
In the Sequential data ﬁles as the name suggest complete data is stored as a continuous sequence of characters with some information in between the data items to differentiate one data from another. These individual data items may be different records or single entities and may comprise of numeric or strings or both. In sequential data ﬁles data is stored one after the other in the order of their entry and are read back in the same order. If you store ten different data and if you want to read 7” data then you will have to pass through” ls‘ to 6“ to reach 7“, there is no way to directly go to 7m data. _ ‘
This method of accessed the records is called Sequential access method. This limits the speed of reading a sequential ﬁle. When the user needs data from different location of a ﬁle, sequential ﬁle access is very slow. When the user does not require data from different locations but require the data in the sequential order of the entry, then storing data as sequential ﬁle saves a lot of storage space compared to a random ﬁle.
The storage space is saved in sequential access because the GW-BASIC language saves sequential data ﬁle as a continues data in the storage device whereas in a random ﬁle,\data is saved as ﬁxed length records.
Q.13: – How would you create a Sequential ﬁle?
Ans.: -Creating a Sequential File
Creating a ﬁle is equivalent to writing some information into a register. The steps you follow or the process and their order are almost the same for Writing into a register and for. creating a sequential ﬁle, as it is Shown below.
- Open the register
- Think about what you want to write or get the information that is to be written.Write the information into the register
- If writing is over then close the register
- These same four steps are followed when creating a ﬁle or writing some information into a computer, data ﬁle: The only difference is in place of a register you will use a data ﬁle.The steps for creating a data ﬁle are as follows. .
1.Opening a ﬁle 2. Get data from the user
3.Write into the ﬁle 4. If writing is over then close the ﬁle
Q.14: – Describe the way of opening, closing, reading and writing to a sequential ﬁle.
Ans.: -Opening a Sequential File
When creating or accessing a sequential ﬁle, the ﬁrst thing the programmer must do is open the ﬁle using the OPEN statement. The statement tells the user that he is now free to make contact with the ﬁle. It is just like writing some information into register. By default BASIC allows 35 ﬁles to be open at a time. Opening a ﬁle allocates a buffer in computers memory for input/output to that ﬁle and determines the mode of access i.e. sequential or random to be used. It also decides the process required, read, write, append etc.
The program which is to write or read data from the ﬁle can use this ﬁle only if the ﬁle has been opened.
Format of OPEN Statement
OPEN “File Name” FOR mode” AS # [buffer]
OPEN : a keyword or reserved word
File Name : Name of File to be Opened
Mode : The way of using ‘ﬁle i.e. Append,
INPUT or OUTPUT
#[buffer] : Buffer Number of ﬁle
The same rules apply for naming data ﬁles as they do for naming program ﬁles. The extension of the data ﬁle is .DAT. You can use a data ﬁle as either OUTPUT, INPUT or APPEND mode. OUTPUT means that the program will eventually write data to the ﬁle. INPUT means that the data contained in the ﬁle will eventually be read into the calling program. APPEND means that data will be added to the end of an existingﬁle on disk.
A buffer is a reserved section of primary storage used for storingtemporary data being written to or read from a ﬁle. The programmer speciﬁes the buffer number of a ﬁle, and it is used bythe program to recognize and identify the ﬁle that is attempting to be manipulated.
10 OPEN “Student.DAT” FOR OUTPUT AS #1
The above statement opens the gates for the information to be put into Student.DAT. The marks must now be transported to the ﬁle. This transporting will be done through a choice of statements i.e. the LET, INPUT etc. statements
ii -Closing the Sequential Files
When the data entry operation is over, before stopping the program the ﬁle must be closed. If a ﬁle is not closed before switching off the machine, some of the data in the buffer may not get written into the ﬁle and the complete data ﬁle may become useless. In GW-BASIC language CLOSE # statement is used for closing the ﬁle.
CLOSE # buffer
Where buffer number is the number under which the ﬁle was opened.
- The CLOSE statement writes the complete buffer data into the ﬁle.
- Once a ﬁle is closed it can be reopened using the same ﬁle number or a different ﬁle number.
- A CLOSE statement with no speciﬁc ﬁle number closes all open ﬁles
- The END, NEW, RESET, SYSTEM, RUN statements always closes all the ﬁles automatically but the STOP statement does not close any ﬁle.Example
CLOSE # 1
iii- Reading data from a File
To read data from a ﬁle follow the following steps.
- Open the File
- Read data from the File
- Instead of noting down, display the data on the screen
- If reading is over then close File
In GW-BASIC Input statement can be used to get the data from the user into computer. If data is to be put into a sequential ﬁle, you must remember to work in the ‘O‘ mode. You can also read the data from a ﬁle using INPUT # or
LINE INPUT # statements. The syntax of input statement is as follows
INPUT # File number, list of variables.
Where ﬁle number is the number used when the ﬁle was opened for input, and Variable list contains the variable names of the data items we want to read from the ﬁle.
In order to read the data stored in STUD.DAT ﬁle, your INPUT # statement should be
20 INPUT# 1,ROLL,NAMES$,MARKS
In the above statement you take input of three variables roll, names$ and marks with the single input statement.
Note: -With INPUT # no question mark is displayed on the screen, as in the case of a INPUT statement I Line INPUT ‘# Statement
This statement is used to read an entire line of a data record from a ﬁle as astringe.
Line number LINE INPUT #1, A$
The ﬁrst line of the ﬁle will be read as a single string and stored in the
iv- Writing data into File
Writing to a ﬁle that has been previously opened in OUTPUT mode is accomplished using the WRITE# statement. This statement can be used to write the data into the data ﬁles. WRITE #’statement can be used to write the data into the data ﬁle. While using WRITE # statement, you must ﬁrst indicate the buffer number of the ﬁle being written to.
WRITE # number, variable list separated by comma
20 WRITE # 1, ROLL, NAM$
30 WRITE # 1,~CLASS$
10 OPEN “O”, 1,”G:\STUD.DAT”
20 INPUT ”Please Enter Your Roll Number..:”;Roll’
30 INPUT ”Please Enter Your Name ………….. .:”;Nam$
40 INPUT ”Please Enter Total Marks ….. .;..:.”;Marks
50 WRITE #1, ROLL,NAM$,Marks
60 INPUT “Do you want to continue. . …(Y/N)”,ch$
70 IF(CH$=”Y” OR CH$=”y”) THEN GOTO 20
80 CLOSE #1
Q.15: -Write down a program for creating a sequential access data ﬁle and printing the data from it.
Ans.: -Program for creating a sequential access data ﬁle and printing the data from it
20 OPEN “A”,#l,”G:\TEST.DAT”
30 INPUT’ “Enter the total number of members. . . :”,TM
40 FOR A= 1 TO TM
50 INPUT “Enter the Member ID..:”,MID
60 INPUT “Enter the Member Name..:”,MNAME$
70 INPUT “Enter the Member Address.. :”,MAD$ ,
80 INPUT “Enter the Member Telephone Number..:”,MTEL.
90 INPUT “Enter the Member E_Mail Address..:”,MEAD$ .
100 WRITE #1,MID,MNAME$,MAD$,MTEL,MEAD$
120 CLOSE #1
130 OPEN “I”,#l,”G:\TEST.DAT”
150 PRINT STRING$ (6O,”-“)
160 PRINT “List of Members”
170 PRINT STRING$ (60,”-“)
190 IF EOF(1) THEN GOTO 230
200 INPUT #1 ,.MID,MNAME$,MAD$,MTEL,MEAD$
“Member:”;MNAME$,”ID:”;MID,”Address:”;MAD$,”Phone:”;MTE L,”E_Mail:”;MEAD$ ‘ .
220 GOTO 190
240 PRINT STRING$ (60,”-“)
250 CLOSE #1
Q.16: – What are Random ﬁles
Ans.: -Random files
A random ﬁle is the one which allows direct and independent access of each of its data item. For example, to read 20“ data item one does not need to go through all the data from 1 to l9. Data number 20 can be directly accessed without going through other data items.
- Creating and reading a random access data ﬁle requires more program steps than a sequential access program. But, a random access data ﬁles system allows more ﬂexible data access and you can read or write any record directly without going through all the previous records.
- Information in random access ﬁles is stored and accessed in separate numbered unit called “Records”. While storing the information or reading the information a record number is used to identify different records.
- Since a record number is used to read or write a particular record, the data can be read from any location and the reading of the entire data ﬁle is not required as it is with the sequential ﬁle
Q.17:- How would you write and read records in random ﬁles?
Ans.:- Writing or Storing Records in Random files
When dealing with random ﬁles, you can’t send data from each ﬁeld in a record one-by-one into the ﬁle, random ﬁles let you send the contents of the entire record to the ﬁle in one statement. This is accomplished by using the PUT statement, and the PUT statement also speciﬁes the location in the ﬁle where the record is being sent. The PUT statement has the following fonn:
PUT #[buffer] , record Number, record Variable
In the above statement, the buffer ﬁle number must be ﬁrst speciﬁed, the number of the record or the location of the record to be placed in the ﬁle is next, and ﬁnally the actual record variable is speciﬁed so the program knows which record to send to the ﬁle.
Reading Records from Random ﬁles
The complete opposite operation of the PUT statement would be to retrieve or get data contained in a data ﬁle. BASIC has a built in function to handle this situation also. It is called GET and has a font identical to the PUT statement. The form of the GET statement is as follows:
GET # [Buffer], Record Number, Record Variable
When using the GET statement, any record can be directly accessed by specifying the record’s number or location ﬁle number. This is what makes random ﬁles more powerful than sequential ﬁles.
Q.1:- Deﬁne subprogram
It is a program within a program. A sub program is a section of the program that performs a speciﬁc task. If a sub program is too complicated to perform a speciﬁc task, then it should be further broken down into smaller subprograms. This process of subdividing task continues until no more subpro grams are needed.
Q.2:- What are functions?
Functions are small manageable parts, which are designed to perform a speciﬁc task and return a value.
Q.3:- Write down the types of functions?
Ans.:- Types of functions
There are two types of functions, which are as following:
0 User deﬁned functions T 0 Built-in functions
Q.4:- What are built-in functions?
Ans.:- Built-in Functions
These functions perform operations on their operands and return values. These functions are written by language developers or -third party and incorporated in the language. These functions are also called system deﬁned functions, standard functions, library functions or intrinsic functions.
Q.5:- Write down the types of built-in functions?
Ans.:- Types of built-in functions
There are two types of built-in functions, which are as following:
Numeric functions 0 String functions
Q.6:- What are numeric functions?
Ans.:- Numeric Functions A –
These functions are applicable on numeric values only, and produce the numeric results. E. g. INT ( ), SIN ( ), ABS ( ) and etc
Q.7: -Write down the name of at least 5 numeric built-in functions.
Ans.: Numeric Built-in Functions .
1- ABS (x) 2-FIX (x) 3-SIN (X)
4- COS (x) 5-TAN (x)
Q.8:- What is the purpose of ABS () Function?
Ans.:- ABS () Function
ABS ( ) function is used to retum the absolute value of the expression x i.e. positive value or the value without any sign. E. g. PRINT ABS (-10)
Q.9:- What is the purpose of INT ( ) Function?
Ans.:- INT ( ) Function
INT ( ) function is used to returns the lowest integer less then or equal to x. in case of whole number it returns the same number. E. g. PRINT INT (5.678)
Q.10:- What is the purpose of SQR ( ) Function?
Ans.:- SQR ( ) Function
SQR ( ) function is used to returns the square root of a positive number x.
Fix must be greater than or equal to 0. e. g. PRINT SQR ( 36)
Q.11:- What is the purpose of SIN () Function?
Ans.:- SIN () Function
SIN ( ) function is used to returns the trigonometric ratio called sine of an angle x expressed in radians. E. g. PRINT SIN (45)
Q.12:- What is the purpose of COS ( ) Function?
Ans.:- COS ( ) Function
COS ( ) function is used to returns the trigonometric ratio called cosine of an angle x expressed in radians. E. g. PRINT COS (23)
Q.13:- What is the purpose of FIX ( ) Function?
Ans.:- FIX ( ) Function
FIX ( ) function is used to returns an integer value by simply dropping of the decimal part. FIX ( ) function does not round the number. E. g. PRINT FIX(6.89)
Q.14:- What is the purpose of TAB ( ) Function?
Ans.:- TAB ( ) Function
TAB ( ) function is used to print at certain column position x on the screen. If the current print position is already beyond space x, TAB goes to given position on the next line. Space 0 is the left most position. The rightmost position is the screen width. X must be Within the range of 1 to 255. e. g. TAB(3)
Q.15:-What is the purpose of RND () function?
Ans.: RND Function
RND function is used to return a random number between 0 and 1 .
Q.16:-What is the purpose of LOG () function?
Ans.: LOG ( ) Function
LOG ( ) functions used to return a natural logarithm value. E. g. PRINT LOG (23)
Q.17:-What is the purpose of SPC ( ) function?
Ans.: SPC () Function
SPC function skips x spaces in a PRINT statement.
Q.18:-What are string functions?
Ans.: String Functions
String functions are used to process character strings and produce the numeric values or string values.
Q.19:-What is the purpose of DATES function
Ans.: DATE$ Function
This function is used to set or retrieve the current date.
Q.20:-What is the purpose of LEN ( ) function?
Ans.: LEN () Function
LEN ( ) function is used to return the number of characters in string x$.
The x$ is any string expression. Nonprinting characters and blanks are counted in the number of characters. E. g. PRINT LEN (“ALIF”)
Q.21:-What is the purpose of MID$ () function?
Ans.: MID$ ( ) Function
MID$ ( ) function is used to return the requested part of a given string. E.g. PRINT MID$(“ALIF PUBLICATIOS”,5,3)
Q.22:-What is the purpose of CHR$ ( ) function?
Ans.: CHR$ () Function
CHR$ ( ) function is used to converts an ASCII code value to its equivalent character. The function CHR$ saves the opposite to ASC and is useful in getting out put ASCII control characters.
Q.23:-What is the purpose of LEFT$ () function?
-Ans.: LEFT$ ()Functi0n,
LEFT$ ( ) function is used to return the left most speciﬁed characters from the given string. E.g. PRINT LEFT$(“ALIF PUBLICATIOS”,4) .
Q.24:-What is the purpose of RIGHTS ( ) function?
Ans.: RIGHTS () Function .
RIGHTS ( ) function is used to return the right most speciﬁed characters from the given string. E. g. PRINT RIGHT$(“ALIF PUBLICATIOS”, l 1)
Q.25:-What are user-defined functions?
Ans.:-User Deﬁne Functions
A user deﬁned function is completely deﬁned and customized by the programmer to solve some problem. Functions that we write are called userdeﬁned functions. User deﬁned functions return a single value and is generally used to perform an operation that will be needed numerous of times in at program.
Q.26: -What is the purpose of DEF statement?
Ans.: Purpose of DEF statement
This statement is used to deﬁne & name a function subprogram written by the user.
Q.27: -What is the syntax of DEF FN statement?
Ans.: Syntax of DEF FN statement
DEF FN name D [ARGUMENT] expression
Q.28: -How is DEF statement different from GOTO statement?
Ans.: Difference between DEF and GOTO Statement
DEF statement is used to deﬁne a function, subprogram written by the user, where as GOTO instructs the control toGOTO speciﬁc line no. The line no. is the one that appears after the word GOTO.
Q.29:- What is the purpose of GOSUB/RETURN statements?
Ans. Purpose of GOSUB/RETURN statements A
The purpose of the GOSUB statement is to cause the transfer of control to the subroutines. When ea GOSUB statement is encountered, control is transferred to a new line #. The subroutine begins at a line number referred by the GOSUB instruction an end with the RETURN instruction. When the subroutine is executed, it returns control to the statement immediately after the GO SUB statement.
Q.30:- Differentiate between GOTO and GOSUB/RETURN statement?
Ans. Difference between GOTO and GOSUB/RETURN statement
A GOTO statement transfer the control to the speciﬁed line number
Whereas GOSUB/RETURN statement is used to invoke a subroutine by its line number.
Q.31:- What are ﬁle? How ﬁles are handled in computer?
File is a set of related computer data or program instructions that has been given a name.
To handle a ﬁle, it must be created and it is necessary to Write a program to enter data or some instruction program and the system program.
Q.32:-What is character?
Characters consist of alphabets, digits and special characters. These are represented inside the character as a sequence of 1 s and Os-
Q.33:-What are data fields?
Data ﬁelds are group of related characters to have a unit of information. For example a student name, his rolls no are two data ﬁelds.
Q.34:-What are records?
Record is a group of related ﬁelds is called record. For example the combination of name, father name, rolls no, age, address is a record of a student.
Q.35:-What are the types of ﬁles?
Ans.:-Types of Files
There are two types of ﬁles, which are as follows:
Data ﬁles 0 Program ﬁles
Q.36:-What are program ﬁles?
Program ﬁles contain the program or instructions for the computer.
Q.37:-What are data ﬁles?
Data ﬁles contain data and information needed for programs to perform execution successfully. Data ﬁles are “linked” to or “included” with a program ﬁle during run-time or compilation time.
Q.38:- What is the use of buffer?
A buffer is a reserved section of primary storage used for storing temporary data being written to or read from a ﬁle. The programmer speciﬁes
Q.47:- What is the use of CLOSE Statement?
Ans.:- CLOSE Statement
After use of a ﬁle, it must be closed. When writing data to a ﬁle on disk, the CLOSE statement is responsible for transferring the data currently in primary memory to secondary memory. E. g. CLOSE #1
Q.48:- What is-the use of PUT Statement?
Ans.:- PUT Statement
PUT statement is used to send the contents of entire record to the ﬁle in one statement. It also speciﬁes the location in the ﬁle Where the record is being sent.
Q.49:- What is the use of ‘GET Statement?
Ans. :- GET Statement
GET statement is used to retrieve the contents of entire record from the ﬁle in one statement. When using the GET statement, any record can be directly accessed by specifying the record’s number or location ﬁle number.