Chapter #1 Concepts of Computer Programming
Chapter #1 Concepts of Computer Programming
CHAPTER #1
CONCEPTS OF COMPUTER PROGRAMMING
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.
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.
SOFTWARE:
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
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
When the solution has been planned and designed it needs to be implemented using the
programming language. In process is called coding.
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:
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:
CHAPTER # 2
ALGORITHMS AND FLOW CHARTS
ALGORITHMS:
General English
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:
FLOW CHART:
SYMBOLS:
IMPORTANCE:
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.
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
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.
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.
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.
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:
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.
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.
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.
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.
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
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<.....>
{ // start of function
Statement # 2;
..........
} //end of function
IDE:
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:
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.
The phase through which the computer program passes s called a development cycle. The
steps of a development cycle are as follows:
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.
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.
This step covers the inclusion of library files or other user defined header files which
functions are used in 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
In programming the evaluations are performed and decisions are taken because of the
utilization of different type of operators.
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:
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:
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;
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.
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.
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.
OPERATORS USED IN C:
ARITHMETIC OPERATIONS:
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.
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
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.
CHAPTER # 6
INPUT OUTPUT FUNCTIONS
Q: How many types of I/O functions are used in C language?
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:
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
CONTROL STRUCTURES:
The sequence structure defines that all the statement are executed in the same order in
which they are mentioned in the program.
The selection flow defines the flow of the program by choosing different alternatives on the
basis of some conditions.
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:
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
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
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
DI -
STATEMENT
STOP
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
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.
For loop
While loop
Do while loop
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:
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
WHILE LOOP:
SYNTAX:
While(condition)
Statements();
EXPLANATION:
FLOW CHART:
Testcndi
tion
Statement(s)
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
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:
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:
TYPES:
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.
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.
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
Q: What is the procedure for defining and using a 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.
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.
Syntax:
Example:
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:
statement(s);
Example:
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:
Example:
Ans= sum(21,22,23);
XII Computer Science Page 27 of 35
CHAPTER # 15
DATA BASE MANGMENT SYSTEM COMCEPTS:
DATA:
Data are the row fact and figure about different entities of any type of enterprise. Process
data is called information.
DATA BASE:
Example:
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:
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:
ENTITIES:
An entity is defined as any physical or logical thing which has some characteristics of some
value.
Example:
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
Example:
RECORD /ROW:
Example:
In the table of student: SID, Name, Address, Cell no,DOB are attributes and values under
these properties make a complete record.
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:
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.
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:
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.
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.
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
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.
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.
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.
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.
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:
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
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:
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.
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.
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:
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
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
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.
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.