Friday, October 21, 2016

Modular Programming



1)     What is a modular programming?
Ans: Modular programming is a technique used to divide program into many small, manageable, logical and functional modules or blocks.

2)     What is module?
Ans: Module is a block of statement that solves a particular problem.

3)     What are the advantages of modular programming?
Ans: The advantages of modular programming are:
i) Different programmers can design different program modules independently, which is required in a large and complex program.
ii) It is easy to design code and test the program modules independently.
iii) It is possible to use a single module in different places which reduces program codes.

4)     What are two procedures QBASIC support to divide programs?
Ans: The two procedures used to divide programs in QBASIC are SUB-procedure and FUNCTION-procedure.

5)     What is SUB-procedure?
Ans: A SUB-procedure is a small, logical and manageable functional part of program which prefers specific task and does not return any value.

6)     What is a FUNCTION-procedure?
Ans: A FUNCTION-procedure is a small, logical and manageable functional part of a program which performs specific task and returns single value to the main program or calling module.

7)     Write down the function of CALL statement.
Ans: The function of CALL statement is to transfer the control to another procedure.

8)     Write down the function of DECLARE statement.
Ans: The function of DECLARE statement is to declare procedure such as FUNCTION or SUB in modular programming.

9)     What is main module?
Ans: The top level controlling section or the entry point in modular programming is called main module.

10) What is sub module?
Ans: Sub module is a program which is written under the main module. A program may have one or more sub modules under main module.

11) Define parameters and arguments.
Ans: Parameters are variables that will receive data (arguments value) sent to the procedures (SUB program and FUNCTION).

Arguments are the values that are sent to the procedures (SUB program and FUNCTION)
* Actual or real parameters are called arguments.
* Formal parameters are called parameter

12) What is actual parameter?
Ans: The parameter passed to the procedure from the calling procedure statements are called actual parameters.

13) What is formal parameter?
Ans: The parameter in the procedure which receives the value from the actual parameters are called formal parameters.

14) Write down the functions of DIM SHARED statement.
Ans: The functions of DIM SHARED statement are:
i) It makes variable accessible to all modules.
ii) It appears in main module/ program.

15) What are library functions?
Ans: Library functions are built-in or readymade functions provided by QBASIC.

16) What is user defined function?
Ans: Function which is defined by the user according to the need is called user defined function.

17) Write down the differences between SUB and FUNCTION procedure.
Ans:
SUB-procedure
FUNCTION-procedure
i) SUB-procedure does not return value.
i) FUNCTION-procedure must return a value.
ii) SUB-procedure is called by CALL statement.
ii) FUNCTION-procedure is called by statement and expression method.
iii) SUB-procedure’s name does not accept data type symbol because it does not need to return a value.
iii) FUNCTION-procedure’s name accepts data type symbols such as $, %, !, #, &, etc. and it depends on the type of value to be returned. E.g.: FUNCTION REV$ returns string.

18) Differentiate between SHARED and COMMON SHARED.
Ans:
SHARED
COMMON SHARED
It is used in the sub program to share the values of certain variables between main module and sub program
It is used in the main program to share variable list between main module and all sub programs.

19) Differentiate between local variable and global variable.
Ans:

Local Variable
Global Variable
i) Variables which are declared inside the procedure are called local variables.
i) Variables which are declared outside the procedure are called global variables.
ii) Local variables are not visible to other modules or functions.
ii) Global variables are visible to other modules or functions.
iii) Its value is protected from outside interference and has no effect on the variables outside the procedures.
iii) Its values can be accessed from any procedure or module.


20) Differentiate between passing argument by value and passing argument by reference
Ans:

Passing arguments by value
Passing arguments by reference
i) When arguments are passed by value it makes a duplicate copy of arguments and their values (constants) are used directly in parameter.
i) When arguments are passed by reference the address of the variables are passed to the procedure.
ii) It doesn’t make any effect on values of variable which are passed to a procedure even they are changed in the procedure.
ii) The changes made in the procedure’s variable will affect the variables used at calling module.
iii) To pass the argument by value, variable is enclosed in parenthesis.
iii) By default the value is passed by reference.


21) Why is large modules broken into small procedures?
Ans: Large modules are broken into small procedures to eliminate redundancy, for easier understanding, testing and debugging.

22) What are the major features of SUB procedure?
Ans: The major features of sub procedure are:
       i.          It does not return any value.
     ii.          It does not have a data type.
   iii.          The parameter can be passed by reference or by value.
   iv.          They can be recursive.

23) What are the three important parts of SUB procedure? List with examples.
Ans: The three important parts of SUB procedure are:
       i.          Declaration of SUB procedure
Example: DECLARE SUB AREA (L, B)
     ii.          Body of SUB procedure
Example: SUB AREA (L, B)
                                        .
                                        .
                                        .
                                        END SUB
   iii.          Invocation of SUB procedure
Example: CALL AREA (L, B)


24) What is static variable?
Ans: The variable which is declared by using the “STATIC” keyword is called static variable.

25) What is automatic variable?
Ans: An automatic variable is a local variable which is allocated and de-allocated automatically when program flow enters and leaves the variable's scope. 

26) What is an array?
Ans: An array is a collection of multiple data elements stored under a common variable name.

27) What is recursion?
Ans: Recursion is a programming technique that allows the programmer to express operations in terms of themselves.

26 comments:

  1. what is procedure?

    ReplyDelete
    Replies
    1. Procedure is a small, logical and manageable functional part of program which prefers specific task.

      Delete
  2. Why do we use SUB procedure instead of FUNCTION procedure ? Is there any specific benefit of using SUB procedure ?

    ReplyDelete
    Replies
    1. there are two ways to divide a program into different sub programs in qbasic.
      both sub and function have their own styles.....
      sub procedure doesnot return value whereas functions return value...
      so according to the need of the program we need to choose either by doing sub or function

      Delete
  3. What will happen if declare statement is removed?

    ReplyDelete
    Replies
    1. the program executes if declare statement is removed

      Delete
  4. What will happen if declare statement is removed?

    ReplyDelete
    Replies
    1. Nothing the program will execute as the qbasic automically adds the declare statement

      Delete
  5. How to separate argument and parameter in a function procedure

    ReplyDelete
    Replies
    1. DECLARE FUNCTION COUNT (S$)
      CLS
      INPUT "ENTER ANY STRING"; A$
      PRINT "TOTAL NO. OF VOWELS= "; COUNT(A$)
      END

      FUNCTION COUNT (S$)
      VC = 0
      FOR I = 1 TO LEN(S$)
      B$ = MID$(S$, I, 1)
      C$ = UCASE$(B$)
      IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
      VC = VC + 1
      END IF
      NEXT I
      COUNT = VC
      END FUNCTION

      --A$= argument (pass values)
      -- s$=parameter (receive values)

      Delete
  6. plz Example for actual and formal parameter

    ReplyDelete
    Replies
    1. 1. Parameters / Formal parameter / Real parameters [SEE 2074]

      Parameters are variables that will receive data (arguments value) sent to the procedures (SUB program and FUNCTION). Formal parameters are called parameter.

      2. Arguments / Actual Parameter
      Arguments are the values that are sent to the procedures (SUB program and FUNCTION). Actual or real parameters are called arguments.

      Delete
    2. rem program to find area of rectangle
      declare sub nepal(x,y)
      cls
      input "Enter the length of rectangle:";l
      input "enter the breadth of rectangle:";b
      call nepal(l,b)
      end
      sub nepal(x,y)
      area=x*y
      print "Area of rectangle=";area
      end sub


      Here (l,b) parameter is actual or real parameter and
      (x,y) parameter is formal or dummy parameter. Thank you. For more knowledge plz contact me on hacker5242515@gmail.com

      Delete
  7. Example of calling a sub procedure

    ReplyDelete
  8. WAP to read a sentence and print string formed by only vowel from the word.

    ReplyDelete
    Replies
    1. CLS
      INPUT "Enter a sentence"; a$

      FOR i = 1 TO LEN(a$)
      b$ = UCASE$(MID$(a$, i, 1))
      SELECT CASE b$
      CASE "A", "E", "O", "I", "U"
      C$ = C$ + b$

      END SELECT

      NEXT
      PRINT "String of vowels lettes in the sentence"; C$

      END

      Delete
  9. can any one explain this to me.
    A program that displays the first 5 odd numbers

    DECLARE FUNCTION series
    b = series
    END
    FUNCTION series
    a = 9
    FOR i = 1 TO 5
    PRINT a;
    a = a + 2
    NEXT

    END FUNCTION

    ReplyDelete
    Replies
    1. umm ... is that declare function needed?
      ummm... is the question incorrect ?
      i feel a little confused.

      Delete
  10. what do you mean by argument passing by reference method and by value method?

    ReplyDelete
  11. DECLARE SUB example(a$)
    CLS
    INPUT"Enter a string"; b$
    CALL example(b$)
    END
    SUB example(a$)
    FOR i = LEN(a$) to 1 step -1
    m$=MID$(a$,i,1)
    r$=r$+m$
    NEXT i
    PRINT r$
    END SUB
    ******************

    Questions :
    1. List argument and parameter in the above program
    2. List two library functions given in above program.

    ReplyDelete
  12. could you plz find the area and volume using DIM SHARED plz.

    ReplyDelete
  13. can u plz help me with program to find multiple of 6,7 and 8 in one program

    ReplyDelete
  14. Can you make me clear in 'return value'?

    ReplyDelete
  15. 46. WAP using FUNCTION procedure named extract (“Education”) to extract all the characters from the given string excluding the first and last characters only. The output of the given program is ducatio.
    (Your program should not contain any if condition and looping statement.)
    Solve it sir

    ReplyDelete
    Replies
    1. How to possible sir with out any condition and looping

      Delete