Sub-Program and File Handling. Types of Subprograms

Q.1:-Define 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 specific task- If a routine is simply too sophisticated to perform a specific 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 defined tasks, which can simply be designed, debugged, modified and documented.

Types of Subprograms

There square measure 2 main sorts of subprograms, that square measure as following: .

1-Function Subprograms 2-Subroutine Subprograms

1-Function Subprograms

A operate routine is meant to perform a specific 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 Defined/Built-in Functions

2-User’s Defined Functions

2-Subroutine Subprograms

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 defined 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

Syntax:

ABS(x)

Where x must be a numeric expression or value ,

Example:

10 INPUT. 1

20 Y=-55

30 PRINT ABS(X)

40 PRINTABS(Y)

50 END

(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

Syntax:

INT (x)

Where x is the number.

Example

10 N=2.5

20 M=6.4

30 PRINT INT(_N)

40 PRINT INT(M)

50 END

(iii). SQR()Functi0n:

SQR function is used‘ to returns the square root value of a given positive number ‘N’ V i I s

Syntax:

SQR(N)

Where N is a positive number value which must be greater than 0.

Example

1OFORN=lTO100STEP3

2 O PRINT

N,SQR(N)

30 NEXTN

40 END

 

(iv). SIN()Functi0n:

SIN Function is used to calculate the  trigonometric ratio called sine of an angel expressed in radians.

Syntax:

SIN(x)

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

following formula

SIN(A*3.l4/180)

Example

l0X=3O

20 PRINT SIN(X)

30 INPUT “Number;

40 PRINT SIN(Y)

50 END

(v). TAB ( ) Function:

TAB function is used for screen designing. It is used to skip a specified 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.

Syntax:

TAB(x) V

Where x is a number value which is rounded to an integer and must be within the range of l to

255.

Note: – SPC function

can only be used with

PRINT, LPRINT and

PRINT # statements.

Example

10 FOR X= 1 TO 60

STEP 3

20 PRINT TAB(X);X

30 PRINT TAB(X)“ALIF”

40 NEXTX

5o END

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.

Syntax: .

FIX (X)

Where x_ is any real integer.

Example

10 N=3 .6

20 M=-56.2

30 PRINT FIX(N)

40 PRINT FIX (M )

50 END

_ v . I l I

(ii)-RND ( ) Function: –

RND I Function is used to generate

random numbers between 0 and 1 .

Syntax:

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.

Example

10 FORN=1TO 5

20 PRINT INT (RND* 100);

3 0 NEXT N

40 END

(iii). SPC () Function: –

SPC is used for screen designing. It is used to skip a specified number of spaces in a print or an LPRINT statements. The argument n must be in the range of 0 to 25 5.

Syntax:

SPC(x)

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.

Example

l0FORX= ITO 40 STEP2

20 PRINT SPC(X);X,

30 PRINT SPC(X);“ALIF”

40 NEXT X

50 END

 (iv)-TAN () Function: –

TAN Function is used to calculate the trigonometric tangent of a given number X in radians.

Syntax:

TAN (X)

If TAN overflows, the ‘Overflow” error message is displayed. To obtain the

T AN(X), when N is in degrees, use the following formula.

TAN(N*3.14/180)

Example

10 N=10

20 PRINT TAN(N)

30 END

(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

Syntax

VAL(A$)

Note: -If the first character of a given ASE is not numeric, the VAL(A$) function will return O.

Example

1 0 N$=”22”

20 M$=”05”

30 C=VAL(N$)+VAL(M$)

40 PRINT C

50 END

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.
Syntax:
LOG (N) Y
Note: – N must be a number
greater than 0.
Example
10 N=2
ZOINPUT M
3 0 PRINT LOG(N)
40 PRINT LOG(M)
50 END
(ii)- ASC () Functi0n:-
ASC Function is used to return a numeric value that is equal to firs tASCII code for the first character of the given string A$.
Syntax:
ASC(A$)
Example
10 A$=”ALIF”
20 PRINT ASC(A$)
30 END
The program will returns the ASCII
code value of the A, Which is 65.
(iii)-CHR$()Functi0n:-
CHR$ Function is used to convert an ASCII code to its equivalent character value.
Syntax: –
CHR$(n) e ”
Where n is the numeric value having the value from 0 to 255.
Example
10 INPUTA
20 PRINT CHR$(A)
30 PRINT CHR$(66) S
40 END
The above program will returns the character equivalent value of variable
A and character equivalent value of ASCII 66 numeric value.
(iv)-DATES Functi0n:-
DATE$ function is used to set or see the current system date.
Syntax: .
DATE$
Date Formats
Date can be any of the following formats.
mm-dd—yyyy
mm-dd-yy e
mm/dd/yyyy
Mm/dd/yy
Example
10 V$=DATE$
20 PRINT V$
30 PRINT DATE$
40 END

Q.6:- Write down the purpose of the following functions: (I) LEFT$ (D) (ii) RIGHT$ (Iii) SPACE$ ( ) (iv) MID$( ) (V) TIME$ ( )

Ans.:-(i)-LEFT$ Function

LEFT$ function is used to return the n leftmost specified characters from the given string.

Syntax : – LEFTT$(A$, N) I E

Where N is the number of specified characters which you want from the given string.

Example

10 A$=”Alif Publication”

20 PRINT LEFT$(A$,4)

30 END

(ii)-RIGHT$ Function

RIGHT$ function is used to return the n rightmost specified  characters of the given string A$.

Syntax:

RIGHT$(A$, N)

Where N is the number of specified  characters which you Want from the given string.

Example:

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.

Syntax :

SPACE$(x)

Where x is an number value which is rounded to an integer and must be within the range of 0 to 255.

Example:

10 FOR X= 1 TO 6-0 STEP 2

20 PRINT SPACE$(X);X,

30 PRINT SPACE$(X);“ALIF”

40 NEXT

50 END

(iv)-MID$ () Function

MID$ Function is used to return the number of specified characters from the middle of the given string.

Syntax:

MID$(A$,nl ,n2)

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”.

Example:

10 A$=” Alif Publication

Lahore Pakistan”

20 PRINT mid$(A$,5,12)

30 END

(v)-TIME$ Function ():-

TIME$ Function is used to set or see the current system time.

Syntax:

TIME$

Time Formats

Time can be the following fonnat.

HH-MM-SS .

Where HH is the Hour, MM is the Minute and SS is the second.

Example:

10 T$=TIME$

20 PRINT T$

3 0 PRINT

40 PRINT

50 PRINT TIME$

60 END

Q.7:- What is meant by user defined functions? Explain them with examples.

Ans.:-User Defined Functions

User defined functions are the functions which are completely developed by the users themselves to solve their problems. Functions which We write are called user defined functions. User defined functions may be numeric or strings. If a type is specified 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 specified in the function name and the argument type does not match, an error message is given.

User defined 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 defined functions are referred to as procedures; similar to SUB procedures except function procedures return one value. .

DEF FN Statement

This statement is used to define & name a function subprogram written by the user. These functions are defined only for the life of a given program and

are not part of the BASIC language. A single line function can be defined by DEF F N statement that is executing same codes more than once in the different place of program.

Syntax: –

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 definition 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 defined function is that once the function is defined, 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 defined function can easily be changed to another function. A filnction name can be used in the expressions of a program like a variable.

ADEF F N statement must be executed before the function it defines may be called. If a function is called before it has been defined, an “Undefined User Function” error occurs. DEF FNI statement is not allowed in the direct mode. Recursive functions are not supported in the DEF FN statement.

Example:

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

60    END

 

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.

Syntax: .

Line N0. I GOSUB line number

Line N0 RETURN Line Number

Line Number is the starting line number of the subroutine and optional in

RETURN statement.

Example

10 GOSUB 50

20 PRINT “DPS”

30 PRINT “LAHORE”

40 END

50 PRINT “SENIOR BOYS WING”

60 PRINT “MODEL TOWN” ‘

70 RETURN

 

Q.9:- What are files? Explain the components of files.

Ans.: -Files

A file is a systematic and organized collection of records. In computer terminology, the Word file 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 floppy disks etc. Files are also stored in the internal or main memory of the computers. The information present in these files 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 file. .

Components of files

Main components of files are as follows:

1. Characters     2. Data fields   3.Record

1-Character:-

Character consists of alphabets, digits and special characters. These are represented inside the computer as a sequence-of l s and Os.

2-Data Fields:-

A Data fields are group of related characters to have a unit of information.

For example a student name, his roll no are different data fields ,

3-Record:-

A group of related fields 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 file and program file.

Ans.: -Difference between data file and program file

1- Program Files

Program files contain the program or instructions for the computer. These files contain a number of lines written in appropriate high level language such as C++, COBOL, PASCAL etc. The programs from ea program file 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 file. Obviously these program files provide tremendous powers to computers to perform data processing I

2- Data Files

Data files contain data and information needed for programs to perform execution successfully. Data files are linked to or included with a program file during run time or compilation time. Data file is a collection of record and each record is a collection of related data items known as fields. So, collection of fields make a record and collection of records make a file. 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 fields, collection of all the students’ record is called a file

Types of Data Files

There are two types of data files, 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 files 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 file is useful when every time you want to process the entire data in the file, for example using the student file to generate marks-sheet, where you have to read and make the mark sheet for each and every student
  •  Whereas random file is more useful when most of the time you want to process only a single data or a small group of data from the file.

Q.12:- Describe Sequential data Files

Ans.: -Sequential data Files

In the Sequential data files 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 files 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 file. When the user needs data from different location of a file, sequential file 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 file saves a lot of storage space compared to a random file.

The storage space is saved in sequential access because the GW-BASIC language saves sequential data file as a continues data in the storage device whereas in a random file,\data is saved as fixed length records.

Q.13: – How would you create a Sequential file?

Ans.: -Creating a Sequential File

Creating a file 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 file, 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 file or writing some information into a computer, data file: The only difference is in place of a register you will use a data file.The steps for creating a data file are as follows. .

    1.Opening a file    2. Get data from the user

    3.Write into the file   4. If writing is over then close the file

Q.14: – Describe the way of opening, closing, reading and writing to a sequential file.

Ans.: -Opening a Sequential File

When creating or accessing a sequential file, the first thing the programmer must do is open the file using the OPEN statement. The statement tells the user that he is now free to make contact with the file. It is just like writing some information into register. By default BASIC allows 35 files to be open at a time. Opening a file allocates a buffer in computers memory for input/output to that file 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 file can use this file only if the file has been opened.

Format of OPEN Statement

OPEN “File Name” FOR mode” AS # [buffer]

Here

OPEN               : a keyword or reserved word

File Name       : Name of File to be Opened

Mode              : The way of using ‘file i.e. Append,

INPUT or OUTPUT

#[buffer]         : Buffer Number of file

The same rules apply for naming data files as they do for naming program files. The extension of the data file is .DAT. You can use a data file as either OUTPUT, INPUT or APPEND mode. OUTPUT means that the program will eventually write data to the file. INPUT means that the data contained in the file will eventually be read into the calling program. APPEND means that data will be added to the end of an existingfile on disk.

A buffer is a reserved section of primary storage used for storingtemporary data being written to or read from a file. The programmer specifies the buffer number of a file, and it is used bythe program to recognize and identify the file that is attempting to be manipulated.

Example

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 file. 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 file must be closed. If a file is not closed before switching off the machine, some of the data in the buffer may not get written into the file and the complete data file may become useless. In GW-BASIC language CLOSE # statement is used for closing the file.

Syntax:

CLOSE # buffer

Where buffer number is the number under which the file was opened.

  • The CLOSE statement writes the complete buffer data into the file.
  • Once a file is closed it can be reopened using the same file number or a different file number.
  • A CLOSE statement with no specific file number closes all open files
  • The END, NEW, RESET, SYSTEM, RUN statements always closes all the files automatically but the STOP statement does not close any file.Example

    CLOSE # 1

    iii- Reading data from a File

    To read data from a file 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

INPUT Statement

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 file, you must remember to work in the ‘O‘ mode. You can also read the data from a file using INPUT # or

LINE INPUT # statements. The syntax of input statement is as follows

Syntax:

INPUT # File number, list of variables.

Where file number is the number used when the file was opened for input, and Variable list contains the variable names of the data items we want to read from the file.

In order to read the data stored in STUD.DAT file, 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 file as astringe.

Syntax

Line number LINE INPUT #1, A$

The first line of the file will be read as a single string and stored in the

variable A$

iv- Writing data into File

Writing to a file 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 files. WRITE #’statement can be used to write the data into the data file. While using WRITE # statement, you must first indicate the buffer number of the file being written to.

Syntax:

WRITE # number, variable list separated by comma

Example

10   CLS

20    WRITE # 1, ROLL, NAM$

30    WRITE # 1,~CLASS$

PROGRAM

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 file and printing the data from it.

Ans.: -Program for creating a sequential access data file and printing the data from it

10    CLS

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$

110   NEXT

120   CLOSE #1

130   OPEN “I”,#l,”G:\TEST.DAT”

140    PRINT

150    PRINT STRING$ (6O,”-“)

160    PRINT “List of Members”

170    PRINT STRING$ (60,”-“)

180     PRINT

190     IF EOF(1) THEN GOTO 230

200     INPUT #1 ,.MID,MNAME$,MAD$,MTEL,MEAD$

210      PRINT

“Member:”;MNAME$,”ID:”;MID,”Address:”;MAD$,”Phone:”;MTE L,”E_Mail:”;MEAD$ ‘ .

220      GOTO 190

230      PRINT

240      PRINT STRING$ (60,”-“)

250      CLOSE #1

260       END

 

Q.16: – What are Random files

Ans.: -Random files

A random file 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 file requires more program steps than a sequential access program. But, a random access data files system allows more flexible data access and you can read or write any record directly without going through all the previous records.
  • Information in random access files 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 file is not required as it is with the sequential file

Q.17:- How would you write and read records in random files?

Ans.:- Writing or Storing Records in Random files 

When dealing with random files, you can’t send data from each field in a record one-by-one into the file, random files let you send the contents of the entire record to the file in one statement. This is accomplished by using the PUT statement, and the PUT statement also specifies the location in the file 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 file number must be first specified, the number of the record or the location of the record to be placed in the file is next, and finally the actual record variable is specified so the program knows which record to send to the file.

Reading Records from Random files

The complete opposite operation of the PUT statement would be to retrieve or get data contained in a data file. 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 file number. This is what makes random files more powerful than sequential files.

Short Questions

Q.1:- Define subprogram

Ans.: -Subprogram

It is a program within a program. A sub program is a section of the program that performs a specific task. If a sub program is too complicated to perform a specific 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?

Ans.:- Function

Functions are small manageable parts, which are designed to perform a specific 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 defined 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 defined 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 specified 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 specified characters from the given string. E. g. PRINT RIGHT$(“ALIF PUBLICATIOS”, l 1)

Q.25:-What are user-defined functions?

Ans.:-User Define Functions

A user defined function is completely defined and customized by the programmer to solve some problem. Functions that we write are called userdefined functions. User defined 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 define & 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 define a function, subprogram written by the user, where as GOTO instructs the control toGOTO specific 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 specified line number

Whereas GOSUB/RETURN statement is used to invoke a subroutine by its line number.

Q.31:- What are file? How files are handled in computer?

Ans. File

File is a set of related computer data or program instructions that has been given a name.

File Handling

To handle a file, 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?

Ans.:-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?

Ans.:-Data Fields

Data fields are group of related characters to have a unit of information. For example a student name, his rolls no are two data fields.

Q.34:-What are records?

Ans.:-Records

Record is a group of related fields 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 files?

Ans.:-Types of Files

There are two types of files, which are as follows:

Data files 0 Program files

Q.36:-What are program files?

Ans.:-Program Files

Program files contain the program or instructions for the computer.

Q.37:-What are data files?

Ans.:-Data Files

Data files contain data and information needed for programs to perform execution successfully. Data files are “linked” to or “included” with a program file during run-time or compilation time.

Q.38:- What is the use of buffer?

Ans.:- Buffer

A buffer is a reserved section of primary storage used for storing temporary data being written to or read from a file. The programmer specifies

encountered.

Q.47:- What is the use of CLOSE Statement?

Ans.:- CLOSE Statement

After use of a file, it must be closed. When writing data to a file 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 file in one statement. It also specifies the location in the file 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 file in one statement. When using the GET statement, any record can be directly accessed by specifying the record’s number or location file number.

Please follow and like us:
error