QBASIC Programming Theory

Modular Programming - Theory (One mark Questions)
  1. What is QBASIC?
    Ans: A modular programming language, where program is divided in different modules or functions is called QBASIC.
  2. What is syntax?
    Ans: The rule and grammar followed while writing statements, functions and variables in any programming language is called syntax.
  3. Define variable and constant.
    Ans: A location in the memory, contents of which can be changed during program execution is called Variable.
    A symbol whose value does not change during program execution is called Constant .
  4. What is operator?
    Ans: Symbols, which are used for mathematical calculations, logical and string operations is called operator.
  5. What is relational operator?
    Ans: Relational operator is  symbol, which are used in relational or logical expressions.
  6. What is Logical operator?
    Ans: Logical operators are symbols, which are used to combine two or more logical or relational expressions and return a single true or false value.
  7. What is looping?
    Ans: A control structure that executes the same program statement or block of program statements repeatedly for specified number of times or till the given condition is satisfied is called Looping.
  8. What is nested loop?
    Ans: A loop within another loop is called nested loop.
  9. What is infinite loop
    Ans: Never terminating loop is called infinite loop.
  10. What is array?
    Ans: A collection of the data of similar type, all of which are referred by a single variable name with different subscripts is called array.
  11. Define user defined functions.
    Ans: The function which is written and stored by the programmer to do the specific task is called user defined functions. The programmer defines this type of function, if QBASIC does not provide a built-in function to solve any problem required by the programmer. FUNCTION - END FUNCTION statement can be used to define a user defined function.
    Example: DECLARE FUNCTION SUM (NUM1,NUM2) .
  12. Define built-in or Library Functions.
    Ans: The functions provided by the QBASIC system is called built in or library functions. They allow the programmer to use them according to the requirement. Built in functions require to be called by the programmer to use them in a program. Example: LEN, MID$ etc.
  13. Define modular Programming.
    Ans: An approach in which the program is divided into separate independent units, called modules to perform specific task is called modular programming.
  14. Mention any two advantages of modular programming.
    Ans: (i) Reducing redundancy of code (Code re-usability)
            (ii) Saving time during project development
  15. Why QBASIC is called modular programming language?
    Ans: QBASIC is called modular programming language because it allows the user to divide program into manageable and functional modules or blocks with the help of sub procedure and function procedure.
  16. Define Main module.
    Ans: The top level module is called main module, which is located at the top of all procedures such as sub procedures or function procedure. It is the entry point of modular programming. Procedure name and parameters are declared and called from the main module.
  17. Define Sub Procedure.
    Ans: A small manageable and functional part of a program that performs specific tasks and does not return any value to the calling module is called Sub procedure.
  18. What is the use of CALL statement.
    Ans: The CALL statement transfers the control to sub procedure and statement in the sub procedure execute. It is used to call or execute a sub procedure from the main module.
  19. Define arguments.
    Ans: The constant or variables enclosed in the parenthesis of procedure call statement and that are supplied to a procedure are called arguments. It is also known as actual parameter. The argument can be passed to a procedure either by reference or by the value method.
  20. Define parameters.
    Ans: Variables in sub module or a procedure declaration which accept data or variables passed to them from the calling module are called parameters. It is also known as formal parameter.
  21. Define Local Variable.
    Ans: A variable which is defined in a module and is not accessible to any other modules is called local variable. It is only accessible to the module where it is defined. Value of local variable is destroyed when execution of module is over.
  22. Define Global Variable.
    Ans: A variable in main module which can be accessed from any modules or procedure of a program is called global variable. Variable can be made global declaring them with DIM SHARED or COMMON SHARED or SHARED attribute.
  23. Write about Passing argument by reference.
    Ans: Arguments are normally passed to a sub program by reference, which gives the procedure access to the actual variable. In this method, the address of each variable is passed to the procedure. The changes made in the procedure's variable they will make change in the value of arguments. It is the default mode of passing arguments in QBASIC. Example: CALL TEST (A,B)
  24. Write about Passing argument by value.
    Ans: Argument passed by the value method does not make any effect to value of the variables which are passed to a procedure even they are changed in the procedure. When arguments are passed by value method, it makes a duplicate copy of arguments and their values are used directly in the parameters. The changes made in the procedure's variable they does not make any change in the value of arguments. To pass argument by value method each argument is enclosed in individual parentheses in the calling statement. Example: CALL TEST ( (A) , (B) )
  25. Define procedure.
    Ans: A collection of code which perform an action is called procedure.
  26. Mention the types of procedure.
    Ans: (i) Sub procedure           (ii) Function procedure
  27. List any two advantages of procedure.
    Ans: (i) It divides big program into small manageable module , makes easy to debug.
            (ii) It reduces the program codes because a single module can be used in different places.
  28. Differentiate between Function and Sub procedure.
    Ans:
Function Procedure Sub Procedures
(i) It returns value. (i) It does not return value.
(ii) It does not use call statement.  (ii) It uses call statement.

File Handling Theory (One mark Questions)
  1. What is file?
    Ans: An organized collection of related information saved under unique name is called file.
  2. What is program file?
    Ans: A collection of instructions written using any programming language which will perform some specific task is called program file.
  3. What is data file?
    Ans: A file containing data related to any subject matter , which supplies data to the respective program file is called data file.
  4. What is file handling?
    Ans: The process of doing operations with files such as reading/writing, deleting / moving / renaming etc is called file handling.
  5. What is mode of file?
    Ans: The purpose of opening data file is called file mode. In other words, mode of data file means the file to be opened in specific access mode such as reading or writing.
  6. List the mode of data file in QBASIC.
    Ans: (i) Output mode      (ii) Input mode     (iii) Append mode
  7. Differentiate between Output mode and Append mode.
    Ans: The OUTPUT mode creates a new file and prepares to write data to the file. If the file already exists, its current contents will be destroyed.
    The APPEND mode opens an existing file and prepares to add data to the file. If the specified file does not exist, APPEND creates it.
  8. Write down the function of following statements.
Statements Functions
1. NAME  Used to rename a file.
2. KILL Used to delete a file.
3. CLOSE Used to close the active file or files.
4. FILES Used to display the files of the current sub directory or specified sub directory.
5. WRITE# Sends one or more data items to the specified file.
6. CALL Used to call the sub program
7. OPEN Used to open file either to read or write.
8. PRINT# Used to write data on the file
9. MKDIR Creates a sub directory which is used to manage files
10. CHDIR allows QBASIC to change from one directory to another
11. RMDIR Used to remove or delete only sub directory from a disk.
12. INPUT# Used to read data items from a data file
13. LINE INPUT Reads the entire line or maximum 255 characters from the keyboard or from the sequential data file up to a carriage return
14. EOF Used to detect the end of file.
15. INPUT$ Reads the specified number of characters from the data file.
16. SHARED Used to share variables among parts of a module without making the variable global. It appears only in the sub module.
17. DIM SHARED makes the variable global to all the modules. Used only in main module
18. COMMON SHARED A non executable statement that describes variables as global, so that they can be shared between main module and sub modules.