Tuesday, July 9, 2019

C Programming

C Language



1)     Define C-language.Ans: C-language is a structured programming language that divides program into many functions.
2)     When and who developed C-language?Ans: Dennis Ritchie at Bell telephone laboratory developed C-language in 1972 AD.
3)     Why is C called middle level language?Ans: C is called middle level language because it combines elements of high level language with some features of assembler. A high level language tries to give programmer everything through built-in language. A low level language forces programmer to define function directly from user level.
4)     What are the uses of C-language?Ans: C is mostly used to write system program such as operating system, language, compiler, text editor, language interpreters, utilities, etc.
5)     List the basic data types used in C with their memory consumption.Ans: The basic data types used in C are:
Data Type
Description
Byte
Range
char
Character
1
0-255
int
Integer
2
-33767-32767
float
Single precision
4
6 digits of precision
double
Double precision
8
12 digits of precision
Data Modifiers: Data modifiers change the meaning of the basic data type to fit the various situations. The data modifiers are:

Data Type
Description
Byte
Range
short int
Short integer
2
-33767-32767
unsigned int
Unsigned Integer
2
0 to 65535
long int
Long integer
4
-4294967296 to 4294967295

6)     List the characteristics of C-language.Ans: The characteristics are :
i) It is a high level language with some features of low level language.
ii) It is mostly used to prepare system software.
iii) It is structured programming language with function procedure.
iv) It supports local and global variable.
v) It has only 32 characters.

7)     What are operators? What are the different types of C operator?
Ans: Operators are special symbols that are meant for specific tasks or operators.
The different types of C operators are:-
Arithmetic operators
Assignment operators
Unary operators
Relational operators
Logical operators
Conditional operators

8)     What are urinary operators? State the rules of logical operators.
Ans: The operator that operates on one operand variable or constant is called urinary operator.
The logical operator are:
1) // It connects two expression into one.
2) && operators connects two expression into one. Both expression must be true for the overall   expression must be true for the overall expression to be true
3) ! operator reverses the “true” of an expression

9)     Why is C language popular  than QBASIC?
Ans: Due to the following reasons C language is popular than QBASIC
1)     It is reliable, simple and easy to use
2)     Programs written in care efficient and fast
3)     It occupies less memory space
4)     Programs written in C can be reused

10) What do you mean by source code and object code?
Ans: The instructions written using C language is known as source code.
Thr machine – readable code which is obtained after translation is called object code.

11) What is structured programming ?
Ans: The programming that follows a top- down approach, on which developers separate the overall program structure into different sub selection is called structured programming.

12) Write any two advantages of structured programming ?
Ans: The two advantages of structured programming are:
a)     It is easy to design code and test the program modules independently
b)     It is possible to use a single module in different in different places which reduces program codes.  

13) Write down the features of C- language.
Ans: The features of structured language are:
a)     C is the structured programming language.
b)     C has powerful set of operators.
c)     C is a high level programming language.
d)     C contains very less number of keywords

14) Comparing C and QBASIC languages.
Ans:
QBASIC
C
It is a high level language without feature of low level language.
It is a high level language with some features of low level language.
It is mostly used to design application software.
It is mostly used to prepare system software.
It supports structure programming with sub and function procedure.
It is a structured programming language with function procedure.
It supports local and global variable.
It also supports local and global variable.
IBM PC version of BASIC has around 159 keywords.
It has only 32 keywords.

       
15) What is top-down designing model?
Ans: Dividing a complex task into many small modules into order to perform the task is called top-down design.

16) Mention the advantages of C language.
Ans: Advantages of C language:
a)     Readability
b)     Maintainability
c)     Portability
d)     Reusability

17) What are different types of C language?
Ans: Different types of C language are:
a)     Common C
b)     ANSI C

18) What do you mean by source code and object code?
Ans: The machine readable code written which is obtained after the translation is called object code.
The instructions written using C language C language is known as source code.

19) What are the advantages of C language?
Ans: the advantages of C language are:-
a)     It is machine independent programming language
b)     It is easy to learn and implemented C language
c)     It can be implemented from mobile device to mainframe computers.
d)     It is the mother of all modern programming language like python, pearl 5 and PHP

20) What are the disadvantages of C language?
Ans: The disadvantages of C languages are:-
a)     There is no runtime checking. It has poor errors detection system.
b)     On large programs , it is hard to find errors.
c)     There is no strict type checking int data type to float variables.
d)     It does not support modern programming methodologies oriented programming language.

21) Define counter and accumulator in terms looping.
Ans: A counter is a variable which controls the loop statement and provides the track to run the loop statement in certain number times.
Accumulator is a numeric variable which accumulates the values in a loop statement.

File Handling | Qbasic

Handling of Data File



1)     What is data file? What are the different types of data file?
Ans: 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
b.     Random access files

2)     What is a file? Name the two types of data file in data processing.
Ans: A bunch of bytes stored on some storage device like magnetic tape, magnetic disk and optical disk is called file.
The two different types of file in data processing are:
a.      Program file
b.     Data file

3)     What do you mean by program file and data file?
Ans) The file which contains a set of instructions that are needed for data processing is called program file.
The file which contains only data that are required during data processing is called data file.

4)     What is sequential access data file?
Ans) 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.

5)     What are the disadvantages of sequential access data file?
Ans) The disadvantages of sequential access data file are:
a)     It takes long time to access if the data file contains a large volume of data.
b)     In sequential access data file we cannot change the existing entry or insert a new entry.

6)     Mention the difference between program files and data files.
Ans:
Program files
Data files
A program file has set of instructions needed for data processing.
A data file has collection of related data stored in a secondary storage.

7)     What are the difference between PRINT# and WRITE# statements?
Ans:
PRINT#
WRITE#
It adds spaces between data items while storing data.
It inserts commas between the data items.
It does not enclose strings in double quotation marks.
It encloses strings in double quotation marks.

8)     What is a file number?
Ans: The number assigned to a file in order to identify it during processing is called file number.

9)     List the modes of operations for opening a sequential file.Ans: The modes of operation for opening a sequential file are:
i) Output Mode: It is used to create a new data file and write data in it.
ii) Input Mode: It is used to retrieve records or contents of existing data file.
iii) Append Mode: It is used to add more records in existing file.
10) Differentiate between output mode and append mode.Ans:
OUTPUT mode
APPEND mode
i)  It creates a new file and prepares to write data to the file.
i) It opens an existing file and prepares to add data to the file.
ii) If the file already exists its current contents will be destroyed.
ii) If the specified file does not exist APPEND mode creates it.

11) Write down the functions of:
a) OPEN statement:
It opens a sequential file for one of the three possible operations (reading, writing, appending).
b) WRITE statement:It sends one or more data items to the specified file.
c) CLOSE statement:It closes one or all open files.
d) INPUT# statement:It reads data from the sequential data file.
e) EOF() function:It detects the end of the file marker reading the data from an open sequential file.
f) LINE INPUT statement:It reads the entire line or maximum 255 characters form the keyboard or the sequential file.
g) INPUT$ function:It reads the specified number of characters form the data file.
h) NAME statement:The NAME statement renames a file on a diskette. Only file name changes, data and program line remains intact.
i) KILL statement:The KILL statement deletes the file or files from the specified drive and directory.
j) MKDIR statement:It creates a subdirectory which is used to manage files.
k) CHDIR statement:It allows QBASIC to change from one directory to another.
l) RMDIR statement:It is used to remove or delete only the subdirectories from a disk. It can remove only empty subdirectories.
m) FILES statement:
The FILES statement displays the files of the current sub directory or specified sub directory.

Modular Programming | Qbasic

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 referenceAns:
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.