Wednesday, November 11, 2020

Modular Programming - Computer Science - Grade X - New Syllabus

 

Modular Programming

Questions and Answers [25]

1.      Modular programming [SEE 2075 U] [SLC 2066] [SEE 2065 S] [MM 2076] [PMT 2075K]
Modular programming is a technique used to divide program into many small, manageable, logical and functional modules or blocks.

 

2.      Qbasic is called Modular Programming [MFT 2075] [SQE 2074K]

QBasic is called modular programming because it divides program into many small, manageable, logical and functional modules or blocks.

3.      Advantages of modular programming [SEE 2073 U] [MFT 2075] [SQE 2074K]

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.      Main module
The top level controlling section or the entry point in modular programming is called main module.

5.      Sub module
Module is a block of statement that solves a particular problem. Sub module is a program which is written under the main module. A program may have one or more sub modules under main module.

6.      Procedure [SLC 2072] [SLC 2071] [SLC 2064] [SLC 2067] [SLC 2068 S] [SQE 2075K] [PMT 2075K]

Procedure is a block of statements that solves a particular program.

Procedure is a section of code which performs one or more specific tasks and can be accessed from remote location. 

There are two types of procedure – SUB Procedure and FUNCTION procedure

7.      SUB procedure [SLC 2064] [SLC 2065] [SLC 2069 S] [MM 2076]
A SUB procedure is a small, logical and manageable functional part of program which prefers specific task and does not return any value. SUB-procedure is called by CALL statement. SUB-procedure’s name does not accept data type symbol because it does not need to return a value.

8.      FUNCTION procedure [SLC 2064] [SLC 2065] [SLC 2069 S] [MM 2076]
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. FUNCTION-procedure is called by statement and expression method. 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.

9.      String function [SEE 2074 U]

String function is used with string it returns string value.

 

10.   Numeric function [SEE 2074 U]

Numeric function is used with number it returns numeric value.

 

11.   Library functions [SQE 2074K]
Library functions are built-in or readymade functions provided by QBASIC. E.g. MID$( ), LEN( ), SQR( ) etc.

12.   User defined function [SLC 2066 S] [SQE 2074K]
Function which is defined by the user according to the need is called user defined function.

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

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

15.   CALL statement [SLC 2071] [PMT 2075K]
The function of CALL statement is to transfer the control to another procedure.

16.   DECLARE statement
The function of DECLARE statement is to declare procedure such as FUNCTION or SUB in modular programming.

17.   DIM SHARED statement
i) It makes variable accessible to all modules.
ii) It appears in main module/ program.

18.   SHARED [SLC 2071]

It is used in the sub program to share the values of certain variables between main module and sub program

19.   COMMON SHARED [SEE 2074 U]

It is used in the main program to share variable list between main module and all sub programs. This statement is used to declared variable global.

20.   Local Variable [SEE 2075 S2]

Variables which are declared inside the procedure are called local variables. Local variables are not visible to other modules or functions. Its value is protected from outside interference and has no effect on the variables outside the procedures. Local variable can access only in its own module.

21.   Global Variable [SEE 2075 S2]

Variables which are declared outside the procedure are called global variables.  Global variables are visible to other modules or functions. Its values can be accessed from any procedure or module. Global variable can be access throughout the program

22.   Passing arguments by value

When arguments are passed by value it makes a duplicate copy of arguments and their values (constants) are used directly in parameter. It doesn’t make any effect on values of variable which are passed to a procedure even they are changed in the procedure. To pass the argument by value, variable is enclosed in parenthesis.

 

23.   Passing arguments by reference

When arguments are passed by reference the address of the variables are passed to the procedure. The changes made in the procedure’s variable will affect the variables used at calling module. By default the value is passed by reference.

 

24.   Qbasic Operators [MFT 2075] [SQE 2074K]

Operators are special symbols that are meant for specific tasks or operators.

i) Arithmetic operators

ii) Relational operators

iii) Logical Operators

iv) String operator

 

25.   Static variable

The variable which is declared by using the “STATIC” keyword is called static variable.


 

Handling of data file

Questions and Answers [25]

1.      Data file

The file which contains data given by the user to the program and information provided by the user to the computer is called data file.

The different types of data file are:

a)      Sequential Access files - A data file that stores a sequential data file containing name, address of some people in the same order or in sequential order is called sequential access data file. It takes long time to access if the data file contains a large volume of data. In sequential access data file we cannot change the existing entry or insert a new entry.

b)     Random access files

2.      Program File

The file which contains a set of instructions that are needed for data processing is called program file.

3.      Mode of data file [SLC 2069]

Mode of data file means opening a sequential file for one of the three modes of operation like output mode, input mode and append mode.

4.      Modes of operation for opening a sequential file

a)      Output Mode: It is used to create a new data file and write data in it. If the file already exists its current contents will be destroyed.

b)     Input Mode: It is used to retrieve records or contents of existing data file.

c)      Append Mode: It is used to add more records in existing file. If the specified file does not exist APPEND mode creates it.

5.      File number

The number assigned to a file in order to identify it during processing is called file number.

Write down the functions of:

6.      OPEN statement: It opens a sequential file for one of the three possible operations (reading, writing, appending).

7.      WRITE statement [SEE 2075] [MM 2076]: It sends one or more data items to the specified file. It inserts commas between the data items. It encloses strings in double quotation marks.

8.      PRINT#: It adds spaces between data items while storing data. It does not enclose strings in double quotation marks.

9.      CLOSE statement [SEE 2074] [SEE 2073: It closes one or all open files.

10.   INPUT# statement [SEE 2075 U] [SEE 2075 S 2]: It reads data from the sequential data file.

11.   EOF( ) function [SEE 2075 S 2]: It is used to test the end of records with in a file.

12.   LINE INPUT statement: It reads the entire line or maximum 255 characters form the keyboard or the sequential file.

13.   INPUT$ function: It reads the specified number of characters form the data file.

14.   NAME statement [SEE 2073] [SLC 2071 S]: The NAME statement renames a file on a diskette. Only file name changes, data and program line remains intact.

15.   KILL statement [SEE 2074]: The KILL statement deletes the file or files from the specified drive and directory.

16.   MKDIR statement [SEE 2075 U]: It creates a subdirectory which is used to manage files.

17.   CHDIR statement: It allows QBASIC to change from one directory to another.

18.   RMDIR statement [SLC 2065] [SLC 2068 S]: It is used to remove or delete only the subdirectories from a disk. It can remove only empty subdirectories.

19.   FILES statement: The FILES statement displays the files of the current sub directory or specified sub directory.

20.   SHELL: The SHELL statement allows a program to run external programs or command line statements in Windows, MAC OS and Linux.

21.   INT [MM 2076] [MFT 2075]: It rounds and returns the largest integer less than or equal to a numeric expression.

22.   PRINT [PMT 2075K] : Display result on screen.

23.   MID$ ( ) [MFT 2075]: It is a string function that returns the specified number of characters from the specified location of string.

24.   LEN ( ) [SQE 2074K]: Returns the number of characters in a string or the number of bytes required to store a variable.

25.   SQR ( ) [SQE 2074K]: Returns the square root of a numeric expression.