0% found this document useful (0 votes)
352 views

Chapter #1 Concepts of Computer Programming

Computer languages allow communication with computer systems and development of programs and software. There are two main types - low-level languages which can directly control hardware, and high-level languages which are more like human languages and used for both system and application software. A computer program is a collection of instructions in a computer language to perform a specific task, while software is a collection of integrated programs with a defined purpose. The debugging process finds and removes errors in programs.

Uploaded by

sqamar68
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
352 views

Chapter #1 Concepts of Computer Programming

Computer languages allow communication with computer systems and development of programs and software. There are two main types - low-level languages which can directly control hardware, and high-level languages which are more like human languages and used for both system and application software. A computer program is a collection of instructions in a computer language to perform a specific task, while software is a collection of integrated programs with a defined purpose. The debugging process finds and removes errors in programs.

Uploaded by

sqamar68
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

XII Computer Science Page 1 of 35

CHAPTER #1
CONCEPTS OF COMPUTER PROGRAMMING

Q: What is a computer language? Explain with example.

A computer language is defined as the source of communication to the computer system


which provides all the materials to develop programs and consequently software.

A language provides all the material to develop software. Software is a collection of


programs and program are the collections of instructions which are written in a specific
computer language. Some programming languages are C language, C++, C#, JAVA.

Q: How many types of computer languages are there?

Computer language is categorized in following types:

LOW LEVEL LANGUAGE:

A low level language is the computer's machine language or codes near to machine
language. It can directly control the hardware. It is complex but have lots n lots of features. It
normally used to develop system software.

HIGH LEVEL LANGUAGE:

A computer language having programming codes near to human language is called a high
level language. A high level language is used to develop both system and application
software. But normally it is used for application software.

Examples are: C++, PASCAL, VB, etc

Q: Define a Computer Program?

A program is defined as a collection of instructions in a computer language to perform a


specific task. The programs are the components of a software which are integrated with
each other. A program contains a number of instructions which are definitely written in a
computer language.

Q: How do you Define a Software?

SOFTWARE:

Software is a collection of integrated programs having a defined purpose.

EXPLANATION:

The software is computer programs which are built using some computer language. IT is a
collection of programs which works integrated. The software that control and manage the
hardware is called system software and the software which facilitates user is called
application software.
XII Computer Science Page 2 of 35

Q: Explain Debugging Process?


The debugging process through which a program can be made error free and properly
functional is called debugging process. Several tools have been divided for finding and
removing three types of errors, as follows:
 Desk checking
 manual testing with sample data
 Structured walkthrough
 Attempt At Translation
 Testing Sample data on computer
 Run real world data.

Q: What is the development cycle?

The process of programming which is also called software engineering involves the following
steps:

 Defining a problem
 Planning the solution
 Coding the program
 Testing the program
 Documenting the program

DEFINING A PROBLEM:
The very first step for a programmer is to have a clear understanding of the problem that
what the problem is how it will be solved. The following steps are considered important:
 Determining program objectives
 Determining the desired output
 determining the input
 determining the process requirements
 planning the solution
XII Computer Science Page 3 of 35

CODING THA PROGRAM:

When the solution has been planned and designed it needs to be implemented using the
programming language. In process is called coding.

TESTING THE PROGRAM:

Once the program has been coded completely the next phase is the implementation. The
program is tested regarding all types of errors that are syntax errors, logical errors, and run
time errors. The testing phase makes sure that the program full fills all the objectives which
are required to the user.

DOCUMENTATION OF PROGRAM:

Documentation is an essential phase of the programming process. it is not a separate


phase. It is continued with all the steps in programming from problem to testing.

Q: What are language translators?

Language translators are programs those converts programming languages into 1s and 0s
or machine language. They either compile or interpret it. THESE method give the translators
their common names that are: compiler and interpreter.

COMPILER:

A compiler is a language translator which translates the whole program at once into machine
language before it is executed. After the source program has been converted this new file is
known as object file of object program.

INTERPRETER:

An interpreter is a program that a program in step by step manner. It translates one


instruction and control executes the resulting machine language, while the next instruction is
being translated. If the program is run several times a day it has to interpret many times.
XII Computer Science Page 4 of 35

CHAPTER # 2
ALGORITHMS AND FLOW CHARTS

Q: Define Algorithm and give its example.

ALGORITHMS:

Step by step process to solve any problem is called an algorithm.

The following are some characteristics of an algorithm:

 The number of steps in an algo. are finite.


 The steps mentioned in an algorithm should follow a sequence to get the desired
result.
 The algorithm must get the final result of the problem in the form of comprehensive
solution.

Methods to write an algorithm:

There are two main methods to write an algo.:

 General English
 Pseudo code

Q: Describe Pseudo Code.

The pseudo code is a particular way to write an algorithm. The pseudo code uses specified
words for different purposes. The pseudo code is near to the computer language. The
following are specific words which are used in a pseudo code:

Start: To start the algorithm

Exit: To end the algorithm

Read: To take input in a variable

Write: To print value of variable on monitor

If then: For condition checking

Repeat: For iteration

Q: For what purpose flow chart is used? Explain its symbols.

FLOW CHART:

A flow chart is a diagrammatic or graphical representation of a program. It shows flow of all


the instruction being used in a program sequentially.
XII Computer Science Page 5 of 35

SYMBOLS:

 Terminal: it is used to start and end a flow chart.

 I/O symbol: used to show input and output statements.

 Process: represent Assignment equations

 Flow lines: Used to show the flow

 Decision: Represents Condition checking

 On page connector: To connect different parts on the same page

 Off page connector: To connect different parts on the different pages

IMPORTANCE:

 It is easier for a programmer to explain the logic of a program in pictorial form.


 A macro-flowchart presents the main lines of logic used in a program becomes a
model of a program.
 flow charts of all programmers can be placed together to visualize the overall system
design.
XII Computer Science Page 6 of 35

CHAPTER # 3 & 4
AN OVERVIEW OF 'C' LANGUAGE + C FUNDAMENTALS

Q: What is a variable?
A variable is a programming ingredient in the form of an identifier by the programmer. It is a
location in a memory on which the character or numeric data can be stored.
OR
A variable is declared using some data type which defines the type of the data. It is
necessary to follow the rules defining the variable name. A variable has got the following
characteristics:
 Its name
 The data type which defines its size
 The address on which it is located in memory
 The value which is stored in it.

Q: Describe rules used to define a variable.

The following rules must be followed while declaring a variable:

 The first letter must be non-numeric


 No space, commas, or special characters can be used in a variable name.
 The reserved words like int, void, for, if etc can't be used as a variable name.
 The variables must be declared in the beginning of the function.
 it is better to use a variable name up to eight character.

Q: What is a constant? Why it is used in programming?

CONSTANTS:

The constants are the fixed valid memory locations by an identifier given by the programmer.

The constant values cannot be changed throughout the program. The constant may be of
any data types.

 Integer constant
 Floating point constant
 Character constant

Examples: const float P=3.142; constint A=5; const char CH='f';

Q: What is a header file?

Header file are the library files of the C language, which holds the particular codes of the
library functions.

There are a number of library files in C language holding different functions for different
purposes like I/O functions and mathematical function.

Example; stdio.h, conio.h, math.h, string.hetc


XII Computer Science Page 7 of 35

Q:What is a C statement? Give example.

A C language statement may be a collection of variables, constants, identifiers or functions.


The C language uses single line statements or multi line statements. A single Line
statements is terminated by the semicolon and multi line statements is a block of code
enclosed by parenthesis ({}).
Example: total=a+b+c; printf("an example"); for(int i=0;i<3;i++){}

Q: Why do we use key words in C language?

The C language provides some reserved words having standard and pre-defined meanings
in C, which are called Key words.

The key words appear in white color in IDE of C they have their special purposes and cannot
be used as a variable or function name. There are number of key words present in Relevant
to different types of programming tasks.

Examples: void, int, if, break, while, do etc.

Q: Define pre-processor directives with examples.

The pre-processor directives are also a technique to identify any type of constants or any
type of other data.

In this technique #define term is used to define constants. The statements of a pre-
processor directive are written before starting of the main function.

Q: What are identifiers?

Identifiers are the names given to different program elements like variables and functions.
These names uniquely identify the variable or function. These rules must be followed while
creating identifiers:

 An identifier must be followed while creating identifiers.


 An identifier can contain letters, digits, or underscores.
 An identifier cannot contain blanks, commas, or any other special characters.
 An identifier cannot consist of more than 31 characters.
 An identifier must conform to case sensitivity.

Q: What is an input Statement ?


The input statement is defined as the instruction which is used to take for the data from user.
In C language the input taken from a function called input function. C provides some
functions for different types of input of data according to the requirement of the user.
Examples: scanf(); gets(); getch(); getche();

Q: What is an output statement?

The output statement is defined as the instructions which is used to print data or message
from the memory to the screen. In C language the output is given by the functions called
output functions. C provides some functions for different types of output of data and
messages according to the requirement of the user.

Examples: printf(); puts(); putchar();


XII Computer Science Page 8 of 35

Q: What is a format Specifier? Describe different format specifiers used in C.

The format specifier is a C language code which specifies the format of data for variable of a
particular data type.

The format specifier is used by the input and output statement. Without using a specific
format the data for a variable cannot be stored or retrived by a particular memory location.

DATA TYPE DESCRIPTION FORMAT SPECIFIER


Int Integer quantity %d
Char Single character %c
Float Floating point number %f
Double Double-precision floating point number %lf
String Array of characters %s

Q: Define address operator with example.

The address operator is defined as the C language code which is used to specify the
location of variable.

In C programming whole using pointers or while taking input, the programmer needs to
mention the address of the memory location or variable. This task is done by the address
operator. It is denoted by &.

Example: scanf("%d",&num);

The operator mention that address of the variable num to store the integer value on accurate
memory location.

Q: Define and explain escape sequences.

The escape sequences are the special purpose C language codes used for different
purposes. These codes are use with '\' backslash. These are used in input and output
statements in setting the cursor location and for some special purposes. Sometimes it is
used to print characters like backslash, inverted commas, sign of interrogation etc.

ESCAPE SEQUECES MEANING RESULT AT EXECUTION


\n New line Move the cursor at the beginning of next line
\r Tab Move cursor to next tab
\a Carriage return Move cursor to the beginning of the line
\b Alert Produce a beep
\\ Back space To print a black slash
\? Question mark To print a question mark
\' Single quote To print a single quote

Q: Define data type. How many data types are used in C language?

DATA TYPE:
A data type defines that what type of data is to be used in a program. The C language
supports several different types of data, each of which may be represent differently within
the computer's memory. The basic data types, their description and the memory
requirements for each data type are listed in the following table.
XII Computer Science Page 9 of 35

DATA TYPE DESCRIPTION TYPICAL MEMORY


REQUIRNMENT
Int Integer quality 2 bytes
Char Single character 1 byte
Float Floating point number 4 bytes
Double Double-precision floating 8 bytes
point number.

Q: What is structure of a C program?

C PROGRAM:

In C language a program has a specified format. From the editing of source code to the
execution of the program it passes through following steps.

STRUCTURE OF A C PROGRAM:

# include<.....>

void main(void) // function name

{ // start of function

Statement # 1; //function body

Statement # 2;

..........

} //end of function

Q: Describe the IDE of C language in detail.

IDE:

The IDE (Integrated Development Environment) is the programming environment for a


specific language which provides the facilities of editing, compilation, debugging and running
of a program.

Explanation:

An IDE contain the menus having commands which help the programmer for easy to use
programming from editing of the source code up to the screen output. The IDE contains the
menus or commands having short cut keys to facilitate the programmer. It displays the error,
warning and alerts to inform the programmer about a specific problem.

Example:

IDE of C language : Turbo C, visual studio

IDE OF C LANGUGE(turbo c):


XII Computer Science Page 10 of 35

The IDE of turbo c has got a blue color editor for the editing of source code. It displays
different programming text in different colors. The important menus of C language IDE are
as following:

 file
 edit
 search
 run
 compile
 debug
 project
 option
 window
 help

A number of commands are there which are required for the different programming options.

Q: Describe program development cycle.

THE DEVELOPMENT CYCLE:

The phase through which the computer program passes s called a development cycle. The
steps of a development cycle are as follows:

1. Editing source code.


2. Compiling the program
3. Linking the program
4. Running the program

EDITING SOURCE CODE:

In the very first step an algorithm is going to be coded completely and the file is saved with
an extension of .C or .CPP.

COMPILING THE PROGRAM:

Once a program has been edited, it needs to be compiled so that errors can be shown. If no
errors are there then object file having the same file name but extension .obj is created.

LINKING THE PROGRAM:

This step covers the inclusion of library files or other user defined header files which
functions are used in program.

RUNNING THE PROGRAM:

If no syntax and linking error are there, the program can be run successfully but any run time
error and linking error can also produce problem in the program output. When the program is
going to run, a file is created having same file name but it will have extension of .EXE
XII Computer Science Page 11 of 35

CHAPTER # 5
OPERATORS AND EXPRESSIOINS

Q: What is an operator? How many types of operators are there in C language?

An operator is considered to be a programming ingredient, which mathematically or logically


evaluates the value of variables, constants and other identifiers.

In programming the evaluations are performed and decisions are taken because of the
utilization of different type of operators.

CLASSIFICATION OF OPERATORS(on bases of operands):

Operators fall into three classes

 Unary Operators: The operators which requires one operand only is called unary
operator. example are ++(increment operator),--(decrement operator)
 Binary operators: The operator requires at least two operators for evaluation is called
binary operators. examples are +,-, /, * etc.
 Ternary Operators: The operator which requires three operands are called ternary
operators.

CLASSIFICATION OF OPERATORS:

OPERATOR OPERATION EXAMPLE


Arithmetic For mathematical operations +, -, /, *
like Addition, subtraction,
Division etc
Assignment To store some value in the +=, *=, /=
variables
Relational For comparison of data < ,<=, >=
values
Logical To take logical decision &&, ||

Q: Explain operands with example.

OPERANDS:

The operands are defined as the variables, constants or identifiers on which the operands
are applied.

Explanation:

Operators are always supposed to be performed on some value which may be in form of a
variable or constants. There may be multiple operands in a C statement to evaluate.

Example:

OPERATOR C STATEMENT OPERANDS


+ C=a+b A,b,c
- D=a-b A,b,d
XII Computer Science Page 12 of 35

Q: Define and explain expression.

EXPRESSIONS:
An expression is a collection of one or more operands and operators that can be evaluated
to a single value. An expression is constructed by the combination of operators, operands, or
any other C language identifier so an operand is a constant, a variable or may be another
expression.
EXAMPLES: c=a+b; x++; y=(2+5+x)/2;

Q: Explain Operator Precedence in C.

OPERATOR PRECEDENCE:

The operator precedence defines that in which order multiple arithmetic operators are going
to be applied in an expression. The normal order of arithmetic operations are as follows.

OPERATOR OPERATION ORDER


*, /, % Multiplication, Division, Higher
Remainder
+, - Addition, Subtraction Lower

ROLE OF PARENTHESE IN OPERATOR PRECEDENCE:

The parentheses can also play an important role while defining the order of precedence. The
natural order of precedence as mentioned can be changed using parentheses.

Q: What is a modulus operator? Why it is used?

MODULUS OPERATOR:

The modulus operator is a mathematical operator which returns the remainder after dividing
a numeric value by another. The modulus operator which is denoted by % is also called
remainder operator. The values on which the operator is being applied may be constant
values or in the form of variable.

C= 7%2

The variable C contain the remainder! which is left over after dividing 7 by 2.

Q: Explain all types of operators used in.

OPERATORS USED IN C:

There are following operators in C.

 Arithmetic operators  Assignment operators


 Relational operators  Logical / Boolean operators
 Increment / Decrement operators

ARITHMETIC OPERATIONS:

These operators are used to perform mathematical operation. An arithmetic expression is


made up of variable constants or both.
XII Computer Science Page 13 of 35

OPERATOR OPERATION EXAMPLE


+ Addition A+b
- Subtraction a-b
* multiplication A*b
/ Division a/b
% modulus A%b

ASSIGNMENT OPERATORS:
Assignment operators is denoted by (=) is it use to assign / to store the value of an
expression to an identifier.
EXPRESSION MEANINGS
A=5; 5 is assigned in 'a'
Total = 74.75; 74.75 has been stored in total
Area = length* breath; The product of length and breath will be
started in area.

The assignment operator is also use with combination of arithmetic operators.

OPERATOR OPERATION EXAMPLE EXPLANATION


+= Add assign A +=b Same as a=a+b
-= Subtract assign A -=b Same as a=a-b
*= Multiply assign A *=b Same as a=a*b
/= divide assign A /=b Same as a=a/b
%= Remainder assign A %=b Same as a=a%b

RELATIONAL OPERATOR:
The relational operators are used for the comparison of two numeric operands. The
operands may be variables or constant or expressions that ultimately results in a numeric
value. Character values can also be compared as these can be represented by their ASCII
codes.
OPERATOR OPERATION EXAMPLE
< Less than A<b
> Greater than a>b
<= Less than or equal A<=d
>= Greater than or equal a>=d
== Equals to A==b
!= Not equals to A !=y

LOGICAL BOOLEAN OPERATOR:

These operators are used to take decision on the basis of same conditions. An instruction
having logical operators may have unary or binary operators. The operands may be
constants, variables or expressions.

OPERATOR OPERATION EXAMPLE


&& Logical AND If a==b && c==d; else 0
|| Logical OR If a==b || c==d; else 0
! Logical NOT If !a ==c ; else0

INCREMENT AND DECREMENT OPERATOR:


These are two kinds of unary operator which are useful in programming. If a variable x has
to be incremented by 1 then the increment operator ++ can be used instead of expression
x=x+1; similarly the decrement operator – is used.
XII Computer Science Page 14 of 35

CHAPTER # 6
INPUT OUTPUT FUNCTIONS
Q: How many types of I/O functions are used in C language?

C language provides two types of I/O functions

 Formatted I/O functions


 Unformatted I/O functions

FORMATTED I/O FUNCTIONS:

Formatted I/O functions are the C language predefined functions which have particular
syntax for writing its code. It is necessary to follow the proper syntax while using them in a
program.

Example:

Printf(); is an example of formatted output function

Scanf(); is an example of formatted input function

UNFORMATTED I/O FUNCTIONS:

The unformatted I/O functions are the C language functions which do not have a specific
syntax in parenthesis.

Example:

Getch(); getche(); getchar(); puts(); putch(); etc are all examples of unformatted I/O
functions.
XII Computer Science Page 15 of 35

CHAPTER # 7
SELECTION CONTROL STRYCTURES

Q: What is control structures used in c?

CONTROL STRUCTURES:

In a program control structures control the flow of execution of program instructions or


functions. Structured programming uses a limited number of control structures to minimize
the complexity of the program.

CONTROL STRUCTURES USED IN C:

The three basic control structures used are:


 Sequence or Sequential flow
 Selection or Conditional flow
 Iteration or Repetitive flow

Q: Explain the control structure sequence flow?

The sequence structure defines that all the statement are executed in the same order in
which they are mentioned in the program.

Q: Explain the control structure selection flow.

The selection flow defines the flow of the program by choosing different alternatives on the
basis of some conditions.

Q: Explain the control structure iteration flow.

The repetitive or iteration defines flow of program in way when a statement or multiple
statements are supposed to be carried out for a number of times on the basis of some
conditions.

Q: Explain If statement with syntax and also draw the flow chart.

DEFINITION:

The If statement is a conditional control structure. It is used when an action is supposed to


be on the basis of some condition.

Examples:
Following are some general types of examples:
 If tomorrow it is holiday we will go for picnic
 If I pass intermediate exam I will apply in NED university.
 If tomorrow it is raining I will go for a walk.

SYNTAX:
If(condition)
{
//actions or statements;
}
XII Computer Science Page 16 of 35

FLOW CHART:

START

yes
CONDI- STATEMENT
TION

STATEMENT

STOP

Q: Define and explain switch statement with syntax.

DEFINITION:

The switch statement is selection control which is used to select an option from different
alternataives.

SYNTAX:

Switch(variable)

Case 1:

Statements;

Break;

Case 2:

Statements;

Break;

Default:

Statements;

}
XII Computer Science Page 17 of 35

FLOW CHART:

START

COND STATEMENT
I-

COND STATEMENT
I-

COND STATEMENT
I-

STATEMENT

STOP

PURPOSE OF BREAK AND DEFAULT:

 When the option is found in any case the statements under the case are performed
and the break statement specifies that no more case should be checked now.
 The statements under the default are performed if the user input is not form of given
cases.

Q: Define and explain if else statement with syntax and flow chart.

DEFINITION:

The If else statement is a conditional control structure. It is used when an action is supposed
to be on the basis of some condition.

Examples:
Following are some general types of examples:
 If tomorrow it is holiday we will go for picnic else we all have to go collage.
 If tomorrow it is raining I will stay at home else we will go for a walk.

SYNTAX:
If (condition)
{
statements;
}
Else
{
statements;
}
XII Computer Science Page 18 of 35

FLOW CHART:

START

STATEMENT CON STATEMENT

DI -

STATEMENT

STOP

Q: Why nested if statements are used?

DEFINITION:

Nesting refers to statement inside statement. Here nested statements refer to condition
under condition.

EXPLANATION

Sometimes we have to deal with the situation, when a condition is true but in the action block
of if statement we have to check for another condition and if the nested condition is also true
then we take some action.

SYNTAX:

If(condition)

If(condition)

Action1;

Action 2;…………

}
XII Computer Science Page 19 of 35

Q: Differentiate switch statement and if statement.

SWITCH STATEMENT IF STATEMENT

1. The switch statement uses identifiers 1. If uses key words like if, else etc.
and key words like switch, case,
default and break.
2. It checks the condition only for 2. In if statement the condition can
equality without using any operators. be checked using all relational
and logical operators.
3. Two or more conditions cannot be 3. It can make the combination of
merged together. two or more conditions by using
logical operators.
4. Switch is not usually coded as nested 4. Nested if is powerful feature of if
switch statements. statement.
5. Condition can be checked only for int 5. Condition can be checked for any
and char values. data type.
XII Computer Science Page 20 of 35

CHAPTER # 8
ITERATION CONTROL STRUCTURES
Q: Define the term iteration.

The term iteration refers to repetition. In programming when a statement or number of


statement are supposed to be repeated for a specified number of times. It is done by the
iterative control structure.

There are three iterative structures in C language

 For loop
 While loop
 Do while loop

Q: Differentiate between following.

WHILE LOOP DO WHILE LOOP


1. While loop uses pre testing. 1.do while loop uses post testing
2. No action is taken if condition is false 2.Action is taken one time even if the
on very first step. condition is false in very first time.
3. Block of loop is written after condition. 3.Block of code is written before
condition
4. Reserved word while is used. 4.reserved word do while is used.

FOR LOOP WHILE LOOP


1. For loop is a counter loop. 1.While loop is a conditional loop.
2. Number of repetitions is already known in 2.Most of the time number of repetitions is
this group. not known.
3. It has got three or four expressions in 3.It has only test expression in parenthesis.
parenthesis.
4. Reserved word for is used. 4.Reserved word while is used.

Q: Explain for loop with syntax.

FOR LOOP:

In C language the most commonly used iterative control structure is ‘for loop’ which is used
to repeat a statement or block of statements for a specific number of times.

SYNTAX:

For(initialization Exp; Test Exp; Increment/Decrement Exp)

Statements;

}
XII Computer Science Page 21 of 35

EXPLANATION:

For loop includes three expressions in parenthesis. The initialization expression tells the
compiler the starting value from where the loop is going to be started. The test expression
tells complier the last limit until the iteration has to be performed. The increment or
decrement expression brings the started value across the test condition. After parenthesis
the brackets {} includes a statement or a block of statement to be repeated.

FLOW CHART:
Initialization

Tes

t c

Statement

Increment/
Decrement

Q: Explain for while with syntax.

WHILE LOOP:

While loop is a iterative structure in C. It is a conditional loop which is used to repeat a


statement or a block of statements a number of times depending on a condition.

SYNTAX:

While(condition)

Statements();

EXPLANATION:

While loop is used in a particular programming situation when a statement or multiple


statement are to be repeated on the bases of some mentioned condition
XII Computer Science Page 22 of 35

FLOW CHART:

Testcndi
tion

Statement(s)

Q: Explain do while loop with syntax.

DO WHILE LOOP:

It is the third important iteration loop. It is a post testing conditional loop which performs a
statement or the block of statements at least one time even if the condition is initially false.

SYNTAX:

Do
{
Statements;
}
While(condition)
EXPLANATION:

This loop is used in programming situations where the action block is supposed to work at
least one time. Hence in do while the condition comes after the action block.

FLOW CHART:

Statement(s)

no
Testcn

yes
XII Computer Science Page 23 of 35

Q: Describe nested looping.

NESTED LOOPING:

Nested looping is defined as the loop inside the loop. It is a cyclic execution of a statement
or block of statement for specified number of times.

SYNTAX:
//with for
For(initialization exp; test exp; inc/decexp)
{
For(initialization exp; test exp; inc/decexp)
{
Statements;
}
}
Note that:
Nested looping can be done using multiple for loops, multiple while loops, multiple do while
loops, or the combination of any of the three loops. For example we can use a while loop
within for loop.

FLOW CHART:
Initialization(outer)

Testcndition

Initialization(outer)

no
Testcndition

yes

Statement(s)

Increment/Decrement
(inner)

Increment/Decrement
(outer)
XII Computer Science Page 24 of 35

CHAPTER # 9
FUNCTIONS
Q: Define functions and its types.

FUNCTIONS:

In C language a function is a statement or block of statement to perform a specific task.

EXPLANATION:

A function is one of the fundamental idea in structured programming. The idea defines the
development of independent modules which are separately solved as sub problems. Every C
program contains at least one function that is main ().

Example:

clrscr(); getch(); printf(); etc.

TYPES:

There are two types of functions

 pre-defined/ Built in/ Library functions


 Programmer defined/ User defined functions

Q: Describe predefined functions.

These are the functions which are created by the developers of the programming language
C. These functions are present in their concerned library files of C, that's why they are also
called library functions.

Q: Describe programmer defined functions used in C.

USER DEFINED FUNCTIONS:

According to the requirements in a software project, the programmer can also create his own
function to solve a specific problem. This type of function is called a programmer defined
function.

In programming sometimes the programmer needs to a task again and again so it can be
done by the user defined functions.

Q: Write advantages of user defined functions.

The following are some advantages of using functions

 The complexity of the entire program can be divided into simple subtask and
functions, sub-programs can be written for each subtask.
 Functions helps to avoid unnecessary repitiion of code using a single section of code
can be used many times in the program.
 Function can have inputs and outputs and can process information.
 The function or program are short carries to write, understand and debug.
XII Computer Science Page 25 of 35

 A function can be shared by other programs by compiling it separately and loading


them together.
 functions are mostly independent of each other just as one program is independent
of another program. Most of the activities in a function are hidden from the rest of the
program.

Q: What is the procedure for defining and using a user defined function.

NEED OF USER DEFINED FUNCTION:

Sometimes a user needs such types of functions which is not already available in any library
file. The user-defined function is an important feature of C language.

MAIN COMPONENTS AND STRUCTURE:

The structure of a user defined function looks like main () function. The following are three
main parts:

 function declaration
 function definition
 function call

FUNCTION DECLARATION:

While using a function, a compiler needs to be told that what type of function is going to be
defined in the program, it is done by the function declaration code. The function declaration
contains three parts.

 Returning type Data type


 function Name
 Argument

Syntax:

the syntax of function declaration is:

<returning data type> function name (type of argument1, type of argument2......);

Example:

A function for three numbers addition is:

int sum (int, int, int);

FUNCTION DEFINITION:

The function definition defines the task of the function which is to be done when the function
is called. The function definition has two parts.

 Function header
 body of the function
XII Computer Science Page 26 of 35

SYNTAX:

<returning data type> function name (type arg1,type arg2,.................)

statement(s);

Example:

int sum (int x, int y, int z)

T=x+y+z

return T;

FUNCTION CALL:

The definition of a function can be called from the main function or from any other function. If
any value is being returned from the function definition, so it necessary to hold the value in a
variable.

Syntax:

Variable name=Function name(arg1, arg2.......);

Example:

Ans= sum(21,22,23);
XII Computer Science Page 27 of 35

CHAPTER # 15
DATA BASE MANGMENT SYSTEM COMCEPTS:

Q: Define the following terms and give examples.

DATA:

Data are the row fact and figure about different entities of any type of enterprise. Process
data is called information.

DATA BASE:

The database is a collection of related files in an organization. The database is a particular


arrangement of data. In this arrangement data is stored in tabular form.

Example:

A database of students in a school.

A database of books in a library.

DATA BASE MANAGMENT SYSTEM:

The database management system is special purpose software. It provides all the facilities
for the management of a database. The database management system makes it possible to
develop a database for an organization and provides techniques to perform all types of
database operation like creation, insertion, deletion, updating.

Example:

Oracle, MS SQL Server, Dbase, MS-access

RELATIONAL DATABASE MANAGMENT SYSTEM:

A relational database model is based on the laws of relational algebra which allows the
programmer to work on one or more relations. The theory behind the relation database on
the laws of relational algebra which contain rules and regulations and mathematical methods
for relation database.

Example:

Oracle, SOL Server , etc.

ENTITIES:

An entity is defined as any physical or logical thing which has some characteristics of some
value.

Example:

Person:-Employee, student, patient, customer

Place:-State, Country, Region


XII Computer Science Page 28 of 35

ENTITY SET /TABLE:

An entity set / table is a collection of different instances of the same entity with there
attributes. Collection of rows and columns relating to the same type of entity is called the
table. In relational database management system a table is termed as the relational variable.

Example:

Student

GR-no NAME ADDRESS CELL NO


23342 Ahmed Ali R-234 Block 2 Tariq road 0345-3457575
23325 Zeeshan Khan H-344 Block 3 korangi 03457896215
23327 Fareed Khan C-19 Block 5 DHA 0458-54511458

FIELD /COLUMN/ ATTRIBUTES:

An attribute is a property or characteristic on an entity having some value. In a table a field is


represented by a column having values of the related attributes.

Example:

Student: SID, Name, Address, Cell no, DOB etc.

Account : ACC#, Title, Balance etc.

RECORD /ROW:

A record is a collection of related fields for a particular entity. In a table a record is


represented by a row.

Example:

In the table of student: SID, Name, Address, Cell no,DOB are attributes and values under
these properties make a complete record.

SID NAME ADDRESS CELL NO DOB


23324 Ahmed ali R-234 Block 2 Tariq road 0341-2531696 14-07-1990

KEY FIELD:

There may be a number of fields present in a table, but a field which uniquely identifies all
the records is called a key field.

The key field is unique in nature. There cannot be any duplication in a key field. Similarly it
cannot have a null value. The key field may be of the following types.

 Candidate key
 Primary Key
 Secondary Key
 Foreign
XII Computer Science Page 29 of 35

Example:

Employee: NIC, NTN, Password #, EID etc.

Q: What are the features of a database management system?

IMPORTANT FEATURES OF DBMS:

There are a number of DBMS available in the market. While choosing a database we should
be aware of some important characteristics exhibited by a particular database.

EFFICEINT USE OF RESOURCES:

The database must be able to use the current hardware without requiring any new hardware
and without wasting storage space.

SPEED:

In DBMS a query must be respond very fast within acceptable time frame. It means that a
database must have an extra ordinary speed.

COMPATIBILITY:

Compatibility refers to how much a DBMS can be conveniently installed on a computer


system.

ACCESSIBILITY:

A DBMS must provide easy to use methods for the users to access data. This task is done
via easy to learn query language or by form layouts.

DATA INTEGRITY:

A DBMS must have safeguard for data integrity. In case user committed mistakes, power
failures, the DBMS should have backup measures to insure that valuable data remains
intact.

PRIVACY AND SECURITY:

A major objective of any DBMS is to prevent the database from unauthorized users, medical
records are few examples of sensitivity and confidential material kept in database.

Q: Describe advantages of a DBMS.

The advantages of database and DBMS software are as follows:

REDUCTION OD DATA REDUNDANCY:

Instead of the same data fields being repeated in different files, in a database the information
appears just once. The single biggest advantage of a database is that the same information
is available to different users.
XII Computer Science Page 30 of 35

IMPROVEMENT OF DATA INTEGRITY:

Since data is centralized, the data update at only one place reflects throughout the system
automatically. There by avoiding the error that is often introduced when the same update
has to be made manually in several independent files.

MORE PROGRAM INDEPENDENCE:

With a database management system, the program and files formats are the same, so that
one programmer or even several programmers can spend less time to maintain files.

INCREASED USER PRODUCTIVITY:

Database management system is fairly easy to use, so that users can get their requests for
information answered without having to resort to technical manipulations.

INCREASED SECURITY:

Although various departments may share data in common access to specific information can
be limited to selected users. Thus, through the use of passwords, a student's financial
medical, and grade information in a university database is made available only to those who
have a legitimate need to know.

Q: What is a database model?

The database model is defined as the various waves in which the data can be structured in a
database. All database system are characterized by the way they structure, organized and
manipulate data items and by the relationship among the data items.

The following are the popular database models:

 Hierarchal Database model


 Network database model
 Relational database model

Q: Explain relational database model in detail.

RELATIONAL DATABASE MANAGEMENT SYSTEM:

A relational database model is based on the laws of relational algebra which allows the
programmer to work on one or more relations.

EXPLANATION:
The theory behind relational database model is called relational algebra, which contains
rules and mathematical methods for relational database.

EXAMPLE:
Oracle, SQL Server.

IMPORTANT FEATURES:

 Theory behind the relation database model is called relational algebra.


 The relation algebra was forwarded by Dr. Edgar F, cod, a famous mathematician.
XII Computer Science Page 31 of 35

 A relational database relates files through a key field.


 It is the most commonly used type of database model for all levels of mainframe
computers.
 A data query language is helpful tool that acts as an interface between user and
system.
 There are no parents or Childs in relational database model.

Q: Describe different components of a database system.

COMPONENTS OF A DATBASE MANGMENT SYSTEM:

The database management system may have a number of components including:

 Query language
 data dictionary
 utilities
 report generator
 security manager
 data recovery manager

1. QUERY LANGUAGE
An easy to use language to communicate with the DBMS in order to perform a
database operation (insertion, deletion, updating) is called a query language.
2. DATA DICTIONARY
Some DBMS contain the components of data a dictionary when stores the data
definition of the structure of the data being with the DBMS.
3. UTILITIES
The utilities are the subprograms which facilitates the user for the maintenance of the
database
 Data dictionary maintenance
 Monitoring Performance
 Data prevention
4. REPORT GENRATOR
The report generator is a DBMS component which can produce on-screen and print
the report according to requirements. The user is able to specify the format of the
report.
5. SECURITY MANAGER
The security manager is the important feature of DBMS which enables the DBA
(Database administrator) to specify different access privileges for different users of
DBMS. The purpose of the security feature is of course to protect data from
unauthorized users.
6. DATA RECOVERY MANAGER
This component enables the DBA to recover contents of hardware which were lost
due to software failure. The DBA takes backups for tha data time by time.
XII Computer Science Page 32 of 35

Q: Describe key fields and their types used in MS-Access.

KEY FIELD:

There may be a number of fields present in a table, but a field which uniquely identifies all
the records is called key field.

EXPLANATION:

The key field is unique in nature. There cannot be any duplication in a key field. Similarly it
cannot have a null value. The key field may be of the following types.

 Candidate Key
 Primary Key
 Secondary Key
 Foreign

EXAMPLE:
Employee: NIC, NTN, Password #, EID etc.

1. Candidate Key

All unique keys present in a table behaves as candidate keys. It means that these are
candidate to be selected as a primary key.

Example:

Employee: NIC, NTN, Passport #, EID etc

2. Primary Key

From the candidate keys a key which is selected as to uniquely identify all the record is
called a primary key. Normally in ERDs the primary key is underline in a table.

3. Secondary Key

Once a primary key has been selected the remaining candidate keys are called secondary
keys. Here NIC and NTN are secondary keys.

4. Foreign Key

In the database when a table is supposed to be linked with another table a key field is
required in both the tables which is called foreign key. Two tables cannot be linked without a
foreign key.

Q: Differentiate between following.

DBMS RDBMS
1. The database management system is 1. A relational database is a particular DBMS
special purpose software to manage based on relational algebra.
database.
2. It is based on the rules of DBMS 2. It is based on relational algebra.
3. The database management system 3. The theory behind the relation database
XII Computer Science Page 33 of 35

makes it possible to develop a database for model is called relational algebra, which
an organization and provides techniques to contain rules and regulations and
perform all types of database operation like mathematical methods for relation database.
creation, insertion, deletion, updating.
4. The DBMS foundations were developed 4. The relational algebra was forwarded by
by different computer science and Dr. Edgar, F, cod a famous mathematician.
mathematics scientists.
5. Example: Fox Pro 5.Example: Oracle, SQL Server, MS-Access
etc.

PRIMARY KEY FOREIGN KEY


1. The primary key is used to uniquely 1. The foreign key is used to link one table to
identify all the records in a table. another for data integrity.
2. It is necessary to have a primary key in a 2. Foreign key is required wherever there is
table. a need to link two tables.
XII Computer Science Page 34 of 35

CHAPTER # 16
MS-ACCESS
Q: What are the MS-Access objects explain any five.

MS-ACCESS OBJECTS

MS-Access is a relational database management system. Its main components which are
used for the development of a database are called MS-Access objects. each object has its
own functionality. Following are MS-Access Objects:

 Table / Relational Variable


 Form
 Query
 Report
 Pages
 Macros etc

1. TABLE / RELATIONAL VARIABLE

In a relational database a table is also called relational variable. A table is a collection of


rows and columns, where row represents a complete record and a column represents
related fields.

2. FORM

A form is defined as a GUI or windows like object which facilitates a user to perform
database operations in an easy to see way.

3. QUERY

A query is a view of selected columns taken from a single or multiple tables. A query is not
an actual table it shows the data of existing tables.

Sometimes user needs to have the data of different columns from different tables, in this
situation a query is defined as a view level table.

4. REPORT

A report is an important MS-Access object it facilitates the database designer to generate on


screen as well as printout reports for the user according to the requirement. The data is
taken from the concerned tables. Report can be formatted according to the requirements
having logos, company title, header, footer and other graphics.

5. PAGES

MS-Access object which enables a database designer to create a webpage linked with the
database. The data will be accessed from the concerned tables while using the website.
XII Computer Science Page 35 of 35

Q: What are the MS-Access data types? Explain any five.

While creating a column in table the database designer needs to define the type of the data
which is going to be stored in that column. The Microsoft Access provides a number of data
types which can be used according the requirement. The data types used in MS-access are
as follows:

 Text
 Number
 Date And Time
 Yes/No
 Ole Object
 Auto Number
 Memo
 Currency
 Hyperlink

1. TEXT

Character data can be stored using this data type. Maximum 255 characters can be stored
using this data type.

2. NUMBER

This data type is used for the fields which carry numeric data. The number data type
supports different sizes of numeric values.

3. DATE AND TIME

Besides using the text data type, Access provides a separate data type in order to store date
and time. This data type supports a number of formats to mention date and time.

4. YES/NO

This data type contains only two values for a particular column. These values are true or
false. Sometimes an entity can have a property which has a value in form of yes/ no.

5. OLE OBJECT

Besides the text or numeric data there may be any requirements to store data of any other
type. Pictures, audios, Videos, and animation files are special type of data which are stored
in MS-Access using this data type.

6. AUTO NUMBER

It is a numeric data type which is normally used for primary or foreign key. For every new
record MS-Access increases the next value itself without taking the input from the user.

You might also like