Computers
Computers
Computers
Computers
COMPUTERS
A computer system consists of two major elements: hardware and software.
Computer hardware is the collection of all the parts you can physically touch.
Computer software, on the other hand, is not something you can touch. Software is a set of
instructions for a computer to perform specific operations. You need both hardware and software
for a computer system to work.
IN
The computer performs basically five major operations of functions irrespective of their size and
make. These are 1) it accepts data or instruction by way of input, 2) it stores data, 3) it can
process data as required by the user, 4) it gives results in the form of output, and 5) it controls all
operations inside a computer.
Components of a Computer
GA
The five classic components of a computer are briefly described below. The operation of the
processor is best understood in terms of these components.
Processor(CPU)
Storage unit
Input devices
Output devices
Hardware
Software
&
BE
A
It is consists of ALU & CU. Performing operation like arithmetic and logical operations is called
processing. Processing devices are the components responsible for the processing of information
within the computer system. The processor is an electronic device about a one inch square,
covered in plastic. Inside the square is an even smaller square of silicon containing millions of
tiny electrical parts. A processor may contain 100 million transistors. It does the fundamental
computing within the system, and directly or indirectly controls all the other components.
Controls the operation of the computer and performs its data processing functions the computer
and performs its data processing functions. Often simply referred to as processor. A main
memory, which stores both data and instructions. An arithmetic-logical unit (ALU) capable of
operating on binary data. A control unit, which interprets the instructions in memory and cseaus
them to be executed.
Central Processing Unit: The brains of the computer, which performs the primary
computations I Some computations may be offloaded to other parts of the computer, but the CPU
remains the central area of computation I Each modern CPU consists of hundreds of millions of
Computers
individual switches, each switch physically constructed as a transistor, with only two states: on
or off I Recent CPUs in mainstream PCs are multiple-core, which means two or more CPU
units on the same chip I Multiple core computers are most efficient when the software is able to
support parallel computing, dividing tasks up to run separately on each core.
Memory - The RAM in your system is mounted on the motherboard. This is memory that must
be powered on to retain its contents. Main memory is sometimes called volatile because it looses
its information when power is removed. Secondary memory is usually nonvolatile because it
retains its information when power is removed. (However, it needs power when information is
stored into memory or retrieved from it.)
Primary storage is used for four purposes.
IN
To store the input data until the CPU is ready for processing.
As a working storage space like a sheet of paper used for calculations.
As an output storage area that holds the finished results.
As a program storage area that stores the processing instructions. These separate areas are
not fixed. The size of each area varies from application to application.
GA
&
Secondary memory: connected to main memory through the bus and a controller.
stored data are easily changed, but changes are slow compared to main memory.
used for long-term storage of programs and data.
before data and programs can be used, they must be copied from secondary memory into
main memory.
does not need electric power to keep its information.
BE
A
Secondary storage Secondary storage Computers primary storage or main memory is volatile
and expensive. So, one need some storage device to store data and other information. It should
be cheap and should not loose the content when power is switched off. This storage is called as
the secondary storage. All secondary storage devices act both as input and output devices.
Magnetic storage media fulfills these requirements and most common storage devices are disks
and tapes.
Input Unit: An input device is any device that provides input to a computer. There are many
input devices, but the two most common ones are a keyboard and mouse. Every key you press on
the keyboard and every movement or click you make with the mouse sends a specific input
signal to the computer.
Input is data coming into the processor from external input devices such as keyboards, mice,
disks, and networks.
In modern processors, this data is placed in memory before entering the processor. Input
handling is largely under the control of operating system software.
Keyboard: The keyboard is very much like a standard typewriter keyboard with a few
additional keys. The basic QWERTY layout of characters is maintained to make it easy
Computers
to use the system. The additional keys are included to perform certain special functions.
These are known as function keys that vary in number from keyboard to keyboard.
Mouse: A device that controls the movement of the cursor or pointer on a display screen.
A mouse is a small object you can roll along a hard and flat surface. Its name is derived
from its shape, which looks a bit like a mouse. As you move the mouse, the pointer on
the display screen moves in the same direction.
Trackball: A trackball is an input device used to enter motion data into computers or
other electronic devices. It serves the same purpose as a mouse, but is designed with a
moveable ball on the top, which can be rolled in any direction.
IN
GA
Touch Screen: It allows the user to operate/make selections by simply touching the
display screen. A display screen that is sensitive to the touch of a finger or stylus. Widely
used on ATM machines, retail point-of-sale terminals, car navigation systems, medical
monitors and industrial control panels.
BE
A
&
Light Pen: Light pen is an input device that utilizes a light-sensitive detector to select
objects on a display screen.
Magnetic ink character recognition (MICR): MICR can identify character printed with
a special ink that contains particles of magnetic material. This device particularly finds
applications in banking industry.
Optical mark recognition (OMR): Optical mark recognition, also called mark sense
reader is a technology where an OMR device senses the presence or absence of a mark,
such as pencil mark. OMR is widely used in tests such as aptitude test.
Bar code reader: Bar-code readers are photoelectric scanners that read the bar codes or
vertical zebra strips marks, printed on product containers. These devices are generally
used in super markets, bookshops etc.
Optical Scanner: These devices are used for automatic data collection. The devices of
this category completely eliminate manual input of data. For example, the bar-code
reader is actually just a special type of image scanner. An image scanner translates
printed images into an electronic format that can be stored in a computers memory, and
with the right kind of software, one can alter a stored image. Another example of scanner
is optical character recognition (OCR) device, used by banks to convert the scanned
image of a typed or printed page into text that can be edited on the computer.
Track Ball: Trackball, a pointing device, is a mouse lying on its back. To move the
pointer, you rotate the ball with your thumb, your fingers, or the palm of your hand.
There are usually one to three buttons next to the ball, which you use just like mouse
buttons. The advantage of trackballs over mouse is that the trackball is stationary so it
does not require much space to use it. In addition, you can place a trackball on any type
of surface, including your lap. For both these reasons, trackballs are popular pointing
devices for portable computers.
Computers
OUTPUT DEVICES
IN
Output devices return processed data that is information, back to the user. Some of the
commonly used output devices are:
1. Monitor (Visual Display Unit)
2. Printers
3. Plotter
4. Speakers
Monitor: Out of all the output devices, monitor is perhaps the most important output
device because people interact with this device most intensively than others. Computer
information is displayed, visually with a video adapter card and monitor. Information
processed within the CPU, that needs to be visually displayed, is sent to video adapter.
The video adapter converts information from the format used, in the same manner as a
television displays information sent to it by a cable service. Two basic types of monitors
are used with microcomputers, which are as follows: 1. CRT 2. LCD
GA
Printer: After a document is created on the computer, it can be sent to a printer for a hard
copy (printout). Some printers offer special features such as colored and large page
formats. Some of the most commonly used printers are: 1. Laser Printer 2. Ink Jet Printer
3. Dot Matrix Printer 4. Line Printer.
BE
A
&
Plotter: A plotter is a special kind of output device that, like a printer, produces images
on paper, but does so in a different way. Plotters are designed to produce large drawings
or images, such as construction plans for buildings or blueprints for mechanical objects.
A plotter can be connected to the port normally used by a printer. An array of different
colored pens in a clip rack and a robotic arm is part of plotter. The instructions that a
plotter receives from a computer consist of a color, and beginning and ending coordinates
for a line. With that information, the plotter picks up the appropriate pen through its arm,
positions it at the beginning coordinates drops the pen down to the surface of the paper
and draws to the ending coordinates.
Plotters draw curves by creating a sequence of very short straight lines. Plotters usually
come in two designs:
Flat Bed: Plotters of small size to be kept on table with restriction of paper size.
Drum: These plotters are of big size using rolls of paper of unlimited length.
Speaker: Speakers are another type of output device, which allow you to listen to voice
like music, and conversation with people.
Computers
Software
Software refers to a program or a set of instructions and applications used to manage and control
various functions of a device such as a computer.
Software is a program that enables a computer to perform a specific task, as opposed to the
physical components of the system (hardware).
Computer software has to be "loaded" into the computer's storage (such as a hard drive, memory,
or RAM). Once the software is loaded, the computer is able to execute the software. Computers
operate by executing the computer program.
IN
There are two main categories of computer software: system software and application software.
System software is a basic requirement for any computer, as it controls all main functions and
integrates all parts into a unitary system. An example of a system software is an operating
system.
GA
Application software serves more specific purposes, such as creating databases and spreadsheets
or processing images. Application software is available as single programs, software packages or
software suites.
&
Hardware
The term computer hardware refers to the physical components of a computer, namely
Keyboard, Monitor, Mouse, and Printer, including the digital circuitry. Computer hardware is
an integral part embedded in all modern day automobiles, microwave ovens, electrocardiograph
machines, compact disc players, and other devices.
BE
A
The hardware that makes up the computer is the body of the computer, and any other additional
device needed by the computer to communicate with the outside world, pretty much in the way
we have our eyes to see, our hands to write, our voice to speak, and so on.
Hardware refers to the physical equipment used for the input, processing, output, and storage
activities of a computer system. It consists of the following:
Central processing unit (CPU)
Computers
CLASSIFICATION OF COMPUTER
Computer can be classified based on their size and design. Since the first
computer, there are different types of computers. Some are to do specific task and some for
general purpose do everything a program can make it to do. Some computers work with
continuous signals of the physical quantities such as pressure, temperature, speed, current etc.
and some with discrete data or the digital signals. Some computers are really huge in size while
others are as tiny that fit in our pockets and palm. There are computers from different companies
that work totally different and some work similar to others.
If we look at the computers from this perspective, we can group them into four major classes
Mainframe, Mini and Microcomputers, supercomputers.
IN
Mainframes
GA
A Mainframe is a large, expensive, powerful computer that can handle hundreds or thousands of
connected users simultaneously. Most major corporations use mainframes for business activities.
Mainframes remain the computer of choice in situations where realibility, data security, and
centralized control are necessary. The price of a mainframe computer typically starts at $100,000
and can easily exceed to $1 million.
Supercomputers
&
The fastest most powerful computer and the most expensive.Applications in medicine,
aerospace, automotive design, online banking, weather forecasting, nuclear energy research and
petroleum
exploration
use
a
supercomputer.
BE
A
At one time, supercomputer designers focused on building specialized, very fast, and very large
CPUs. Today, most supercomputer CPUs are constructed from thousands of microprocessors. Of
the 500 fastest supercomputers in the world, the majority use microprocessor technology.
Mini Computers
These computers are smaller and less experience than Mainframe and medium sized computers.
These computers can support multiple users simultaneously and is less powerful than mainframe
computers. They are relatively faster it can support about 10-20 user terminals. These computers
are generally easy to use. They can handle database, statistical problems Accounting etc.
Micro Computer
These are the mostly used category of computes called as personal computers (PC's). The word
Micro suggests only the size, but not the capacity. They are capable to do all input - output
operations. They can also be connected to peripheral devices.
Desktop Computer: a personal or micro-mini computer sufficient to fit on a desk.
Laptop Computer: a portable computer complete with an integrated screen and keyboard. It is
generally smaller in size than a desktop computer and larger than a notebook computer.
Computers
Some command:
&
GA
IN
DOS is a single-user, single-tasking operating system with basic kernel functions that are nonreentrant: only one program at a time can use them and DOS itself has no functionality to allow
more than one program to execute at a time. The DOS kernel provides various functions for
programs (an application program interface), like character I/O, file management, memory
management, program loading and termination. These early operating systems did not multitask,
as they were only able to run one program at a time. The command line interface, in which a user
has to type in commands, required the user to remember commands to run programs or do other
operating system tasks, making it difficult for novices to use. For example, typing the command
"cd \directory_name" changed the current working directory to the named directory and typing
the command "dir" listed the files in the current directory.
DATE: Displays the system date and prompts the user to enter a new date. Complements
the TIME command.
BE
A
DEL & ERASE: DEL (or the alternative form ERASE) is used to delete one or more files.
Cd: The cd command is the shorthand version of the ch dir command.
DIR: The DIR command displays the contents of a directory.
EDIT: EDIT is a full-screen text editor, included with MS-DOS 5 and 6, OS/2 and Windows NT
to 4.0.
EXIT: Exits the current command processor.
FIND: The FIND command is a filter to find lines in the input data stream that contain or don't
contain a specified string and send these to the output data stream. It may also be used as a pipe.
PRINT: The PRINT command adds or removes files in the print queue.
PATH: Displays or sets a search path for executable files.
Computers
FILE
A file system is the methods and data structures that an operating system uses to keep track
of files on a disk or partition; that is, the way the files are organized on the disk. The word is also
used to refer to a partition or disk that is used to store the files or the type of the file system.
IN
File system is a method of organizing and retrieving files from a storage medium, such as a hard
drive. File systems usually consist of files separated into groups called directories. Directories
can contain files or additional directories. Today, the most commonly used file system with
Windows is NTFS. Without a file management, all files would have no organization and it would
be impossible for a file with the same name to exist. Typically, files are managed in a hierarchy,
which allows you to view files in the current and then navigate into any subdirectories.
File Structure
GA
File structure is a structure, which is according to a required format that operating system can
understand.
A file has a certain defined structure according to its type.
An object file is a sequence of bytes organized into blocks that are understandable by the
machine.
When operating system defines different file structures, it also contains the code to
BE
A
&
support these file structure. Unix, MS-DOS support minimum number of file structure.
Folder
A folder is a virtual location where programs, files, and other folders can be located. A
container for programs and files in graphical user interfaces, symbolized on the screen by a
graphical image of a file folder.
Computers
Number System
IN
BE
A
&
GA
Decimal To Binary
Computers
BE
A
&
GA
IN
Decimal - To - Octal
10
Computers
&
GA
IN
Decimal-to-Hexadecimal
BE
A
Binary-to-Decimal
11
Computers
BE
A
&
Hexadecimal-To-Decimal
GA
IN
Octal-To-Decimal Conversion
12
Computers
BE
A
&
GA
IN
Fractional Conversion
13
Computers
BE
A
&
GA
IN
14
Computers
BE
A
&
GA
IN
15
Computers
BE
A
&
GA
IN
16
Computers
IN
BE
A
&
GA
17
Computers
BE
A
&
GA
IN
18
Computers
BE
A
&
GA
IN
19
Computers
BE
A
&
GA
IN
20
Computers
Programming In C
Overview of c
C has a formal grammar specified by the C standard. Unlike languages such as FORTRAN 77, C
source code is free-form which allows arbitrary use of whitespace to format code, rather than
column-based or text-line-based restrictions; however, line boundaries do have significance
during the preprocessing phase. Comments may appear either between the delimiters /* and */ ,
or (since C99) following // until the end of the line. Comments delimited by /* and */ do not
IN
nest, and these sequences of characters are not interpreted as comment delimiters if they appear
inside string or character literals.
Character set
GA
Decimal digits: 0 9
Whitespace characters: space, horizontal tab, vertical tab, form feed, newline
&
Keywords
Newline indicates the end of a text line; it need not correspond to an actual single character,
although for convenience C treats it as one.
BE
A
Structures
1. As we know that Array is collection of the elements of same type , but many time we
have to store the elements of the different data types. A structure is a convenient way
of grouping several pieces of related information together.
21
Computers
Structure is composition of the different variables of different data types , grouped under
same name.. Suppose Student record is to be stored , then for storing the record we have
to group together all the information such as course, age, year which may be of different
data types.
Example: typedef struct {
char name[64];
IN
char course[128];
int age;
int year;
GA
} student;
&
Unions
BE
A
union stud
In C Programming we have came across Structures. Unions are similar to structure syntactically.
Syntax of both is almost similar. Let us discuss some important points one by one
struct stud
{
int roll;
int roll;
char name[4];
char name[4];
int marks;
int marks;
}s1;
}s1;
Union is similar to that of Structure. Syntax of both are same but major difference between structure
and union is memory storage.
22
Computers
GA
IN
&
For the union maximum memory allocated will be equal to the data member with maximum size.
union stud
BE
A
In the example character array name have maximum size thus maximum memory of the union
will be 4 Bytes. Example:
int roll;
char name[4];
int marks;
}s1;<
Operators Precedence in C
Operator precedence determines the grouping of terms in an expression. This affects how an
expression is evaluated. Certain operators have higher precedence than others; for example, the
multiplication operator has higher precedence than the addition operator.
For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
23
Computers
Here, operators with the highest precedence appear at the top of the table, those with the lowest
BE
A
&
GA
IN
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
24
Computers
BE
A
&
GA
IN
Loops
Loop control statements in C are used to perform looping operations until the given condition is true. Control comes
out of the loop statements once condition becomes false. There are 3 types of loops:
I.
II.
III.
Control statements
for
while
3.
do-while
25
GA
IN
switch
break
continue
goto
&
1.
2.
3.
4.
nested if statements
There are 4 types of case control statements in C language. They are,
3.
There are 3 types of decision making control statements in C language. They are,
if statements
if else statements
BE
A
1.
2.
Computers
26
Computers
BE
A
&
GA
IN
27
Computers
BE
A
&
GA
IN
28
Computers
BE
A
&
GA
IN
29
Computers
BE
A
&
GA
IN
30
Computers
BE
A
&
GA
IN
31
Computers
BE
A
&
GA
IN
32
Computers
GA
IN
BE
A
&
Result is:
33
Computers
BE
A
&
GA
IN
Example
34
Computers
BE
A
&
GA
IN
35
Computers
GA
IN
BE
A
&
Example
36
Computers
BE
A
&
GA
IN
37
Computers
BE
A
&
GA
IN
38
Computers
BE
A
&
GA
IN
39
Computers
BE
A
&
GA
IN
Example
40
Computers
GA
IN
BE
A
&
Example
41
Computers
BE
A
&
GA
IN
42
Computers
BE
A
&
GA
IN
Example
43
Computers
BE
A
&
GA
IN
44
Computers
BE
A
&
GA
IN
45
Computers
GA
IN
BE
A
&
Example
46
Computers
IN
GA
Function
A function is a block of code that performs a specific task. Dividing complex problem
into small components makes program easy to understand and use.
&
b) Improves the reusability of the code, same function can be used in any program rather than
writing the same code from scratch.
c) Debugging of the code would be easier if you use functions as errors are easy to be traced.
BE
A
d) Reduces the size of the code, duplicate set of statements are replaced by function calls.
Depending on whether a function is defined by the user or already included in C
compilers, there are two types of functions in C programming:
47
Computers
These functions are defined in the header file. When you include the header file, these
functions are available for use. For example:
The printf() is a standard library function to send formatted output to the screen
(display output on the screen). This function is defined in "stdio.h" header file.
There are other numerous library functions defined under "stdio.h" , such
as scanf() , fprintf() , getchar() etc. Once you include "stdio.h" in your program, all these
functions are available for use.
IN
User-defined functions
GA
#include <stdio.h>
void functionName()
&
Depending upon the complexity and requirement of the program, you can create as
many user-defined functions as you want.
BE
A
{
... .. ...
int main()
{
... .. ...
functionName();
... .. ...
48
Computers
IN
void functionName()
And, the compiler starts executing the codes inside the user-defined function.
GA
The control of the program jumps to statement next to functionName(); once all the
codes inside the function definition are executed.
&
return_type: Return type can be of any data type such as int, double, char, void, short etc. Dont
BE
A
worry you will understand these terms better once you go through the below examples.
function_name: It can be anything, however it is advised to have a meaningful name for the
functions so that it would be easy to understand the purpose of function just by seeing its name.
argument list: Argument list contains variables names along with their data types. These
arguments are kind of inputs for the function. For example A function which is used to add two
integer variables, will be having two integer argument.
Block of code: Set of C statements, which will be executed whenever a call will be made to the
function.
49
Computers
Example :-
GA
IN
int square(int x)
{
int square_of_x;
square_of_x = x * x;
return square_of_x;
}
To understand how to write such a function like this, it may help to look at what this function does as a whole.
&
It takes in an int, x, and squares it, storing it in the variable square_of_x. Now this value is returned.
The first int at the beginning of the function declaration is the type of data that the function returns. In this case
type.
when we square an integer we get an integer, and we are returning this integer, and so we write int as the return
Next is the name of the function. It is good practice to use meaningful and descriptive names for functions you
BE
A
may write. It may help to name the function after what it is written to do. In this case we name the function
"square", because that's what it does - it squares a number.
Next is the function's first and only argument, an int, which will be referred to in the function as x. This is the
function's input.
In between the braces is the actual guts of the function. It declares an integer variable called square_of_x that
will be used to hold the value of the square of x. Note that the variable square_of_x can only be used within
this function, and not outside. We'll learn more about this sort of thing later, and we will see that this property
is very useful.
We then assign x multiplied by x, or x squared, to the variable square_of_x, which is what this function is all
about. Following this is a return statement. We want to return the value of the square of x, so we must say that
this function returns the contents of the variable square_of_x.
Our brace to close, and we have finished the declaration.
50
Computers
Written in a more concise manner, this code performs exactly the same function as the above:
int square(int x)
{
return x * x;
}
Pointer
GA
Reference operator(&)
IN
Pointers are used in C program to access the memory and manipulate the address.
When, argument is passed using pointer, address of the memory location is passed
instead of value.
&
#include <stdio.h>
BE
A
printf("Value: %d\n",var);
Output
Value: 5
Address: 2686778
Note: You may obtain different value of address while using this code.
51
Computers
In above source code, value 5 is stored in the memory location 2686778. var is just
the name given to that location.
You, have already used reference operator in C program while using scanf() function.
scanf("%d",&var);
Declaration of Pointer
int* p;
GA
data_type* pointer_variable_name;
IN
&
BE
A
int c, *pc;
Normal variable stores the value whereas pointer variable stores the address of the variable.
52
Computers
IN
GA
Formal arguments: while declaring a function, the arguments list of parameters we specify are
known as formal parameters.
Actual arguments: The parameters value (or arguments) we provide while calling a function is
&
BE
A
For example:
int main(
{
int var1 =10;
int var2 = 20;
int var3 = sum(var1, var2);
printf("%d", var3);
return 0;
}
In the above example variable a and b are the formal parameters (or formal arguments). Variable
var1 and var2 are the actual arguments (or actual parameters).
53
Computers
Call by Value
In the call by value method the actual arguments are copied to the formal arguments, hence any
operation performed by function on arguments doesnt affect actual parameters. It may sound
confusing but let me explain this with the help of an example
IN
GA
int main()
{
int num1=20;
int num2 = increment(num1);
printf("num1 value is: %d", num1);
printf("num2 value is: %d", num2);
return 0;
}
&
Output:
num1 value is: 20
num2 value is: 21
Why did it happen? num1 is still have 20 even after increment operation, why?
The reason is simple, function is called by value in above program, which means num1s value
BE
A
gets copied into var and the variable var got incremented (not variable num1), which later stored
in num2, via call.
Unlike function call by value, in this method the addresses of actual arguments (or parameters)
are passed to the formal parameters, which means any operation performed on formal parameters
affects the value of actual parameters. It may sound confusing first time but the below example
would clear your doubt
Im taking the same example, which I took while explaining call by value method, however here
Im using call by reference method
int increment(int *var)
54
Computers
{
*var = *var+1;
return *var;
}
int main()
{
int num1=20;
int num2 = increment(&num1);
printf("num1 value is: %d", num1);
printf("num2 value is: %d", num2);
return 0;
}
Output:
IN
GA
Unlike call by value, in this method the value of num1 got changed because the address of
num1 is passed as an argument so the increment operation is performed on the value stored at the
address.
&
Swap example
int main( )
{
int num1 = 35, num2 = 45 ;
printf("Before swapping: num1 value is %d and num2 value is %d", num1, num2);
BE
A
printf("After swapping: num1 value is %d and num2 value is %d", num1, num2);
}
Output:
Before swapping: num1 value is 35 and num2 value is 45
After swapping: num1 value is 45 and num2 value is 35
55
Computers
When we tried to write the above code using call by value method, the value of both the integer
variables didnt get change, however with this method of call by reference we have dealt with
the address of actual arguments and got desired output.
WHy Use C++ ?
Using C inline in C++ code is usually for certain modules that need to be highly optimized, do very lowlevel work closer to the hardware, or are critical for integrity of the data or even human safety and need to
be auditable and proven correct. Rather than doing it all in C, the bulk of the project can take advantage of
C++ features for flexible designs, while getting the benefits of C's tightness in those places where it is
needed.
IN
GA
In C++, the major change was the addition of classes and a mechanism for inheriting class objects into
other classes.
Most C Programs can be compiled in C++ compiler.
BE
A
&
56
Computers
BE
A
&
GA
IN
57
Computers
GA
IN
C++
BE
A
&
C++ supports for the Structured programming and also it fully supports OOP
1. Encapsulation
2. Abstraction
58
Computers
3. Inheritance
C++ is a
1. Statically typed
&
GA
IN
4. Polymorphism.
2. Free-form
BE
A
3. Multi-paradigm
4. Compiled
59
Computers
GA
IN
2.
Classes
3.
Abstraction
4.
Encapsulation
5.
6.
7.
Objects
BE
A
1.
&
C++(technically).
Inheritance
Overloading
Exception Handling
60
Computers
IN
Class methods - belong to the class as a whole and have access only to class variables
and inputs from the procedure call
GA
Instance methods - belong to individual objects, and have access to instance variables for
the specific object they are called on, inputs, and class variables.
&
According to the sample given below we can say that the Student object, named
objectstudent, has been created out of the Student class
Student objectStudent = new Student();
Data Abstraction: Data abstraction refers to, providing only essential information to
the outside world and hiding their background details, i.e., to represent the needed
BE
A
Abstraction:
Abstraction is "To represent the essential feature without representing the back
ground details." Abstraction lets you focus on what the object does instead of
how it does it. Abstraction provides you a generalized view of your classes or
object by providing relevant information.
Abstraction is the process of hiding the working style of an object, and showing the
information of an object in understandable manner. Abstraction is the process of taking
away or removing characteristics from something in order to reduce it to a set of essential
characteristics. In object-oriented programming, abstraction is one of three central principles
(along with encapsulation and inheritance).
61
Computers
Through the process of abstraction, a programmer hides all but the relevant data about
an object in order to reduce complexity and increase efficiency. In the same way that abstraction
sometimes works in art, the object that remains is a representation of the original, with unwanted
detail omitted. The resulting object itself can be referred to as an abstraction, meaning a named
entity made up of selected attributes and behavior specific to a particular usage of the originating
entity. Abstraction is related to both encapsulation and data hiding.
IN
Real world Example of Abstraction: Suppose you have an object Mobile Phone.
Suppose you have 3 mobile phones as following:-
GA
&
BE
A
62
Computers
&
GA
IN
Abstraction means putting all the variables and methods in a class which are
necessary.
For example: - Abstract class and abstract method.
Abstraction is the common thing.
example:
If somebody in your collage tell you to fill application form, you will fill your
details like name, address, data of birth, which semester, percentage you have got
etc.
If some doctor gives you an application to fill the details, you will fill the details
like name, address, date of birth, blood group, height and weight.
See in the above example what is the common thing?
Age, name, address so you can create the class which consist of common thing that
is called abstract class.
That class is not complete and it can inherit by other class.
BE
A
Wrapping up data member and method together into a single unit (i.e. Class)
is called Encapsulation.
Encapsulation is like enclosing in a capsule. That is enclosing the related
operations and data related to an object into that object.
Encapsulation is like your bag in which you can keep your pen, book etc. It
means this is the property of encapsulating members and functions.
class Bag
{
book;
pen;
ReadBook();
}
63
Computers
C++ supports the properties of encapsulation and data hiding through the creation of
user-defined types, called classes. We already have studied that a class can
contain private, protected and public members. By default, all items defined in a class
are private. For example:
class Box
{
public:
double getVolume(void)
IN
{
return length * breadth * height;
}
double length;
// Length of a box
double breadth;
// Breadth of a box
double height;
// Height of a box
&
};
GA
private:
The variables length, breadth, and height are private. This means that they can be accessed only
by other members of the Box class, and not by any other part of your program. This is one way
encapsulation is achieved.
BE
A
To make parts of a class public (i.e., accessible to other parts of your program), you must
declare them after the public keyword. All variables or functions defined after the public
specifier are accessible by all other functions in your program.
Making one class a friend of another exposes the implementation details and reduces
encapsulation. The ideal is to keep as many of the details of each class hidden from all other
classes as possible.
64
Computers
&
GA
IN
BE
A
65
Computers
Virtual Function
To declare a function virtual, we use the Keyword virtual.
class Shape
{
public:
virtual void sayHi (){ cout <<Just hi! \n; }
IN
};
Constructors and Destructors
GA
A destructor can be virtual. Virtual destructors are very useful when some derived
classes have cleanup code.
&
Example:
class B
public:
BE
A
66
Computers
When creating a class, instead of writing completely new data members and member
functions, the programmer can designate that the new class should inherit the members of an
existing class. This existing class is called the baseclass, and the new class is referred to as
the derived class.
The idea of inheritance implements the is a relationship. For example, mammal IS-A animal,
dog IS-A mammal hence dog IS-A animal as well and so on.
GA
IN
&
BE
A
67
Computers
Output:
Parent Constructor.
Child Constructor.
I'm a Parent Class.
IN
form:
GA
Where access-specifier is one of public, protected, or private, and base-class is the name of a
previously defined class. If the access-specifier is not used, then it is private by default.
// Base class
BE
A
class Shape
#include <iostream>
&
Consider a base class Shape and its derived class Rectangle as follows:
public:
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
68
Computers
int height;
};
// Derived class
class Rectangle: public Shape
{
public:
int getArea()
{
IN
GA
};
int main(void)
{
&
Rectangle Rect;
Rect.setHeight(7);
Rect.setWidth(5);
BE
A
return 0;
}
When the above code is compiled and executed, it produces the following result:
Total area: 35
69
Computers
We can summarize the different access types according to who can access them in the following
IN
way:
A derived class inherits all base class methods with the following exceptions:
Constructors, destructors and copy constructors of the base class.
Type of Inheritance:
&
GA
When deriving a class from a base class, the base class may be inherited through public,
explained above.
BE
A
We hardly use protected or private inheritance, but public inheritance is commonly used.
While using different type of inheritance, following rules are applied:
Public Inheritance: When deriving a class from a public base class, public members of
the base class become public members of the derived class and protected members of
the base class become protected members of the derived class. A base class's private
members are never accessible directly from a derived class, but can be accessed through
calls to the public and protected members of the base class.
70
Computers
Multiple Inheritances:
A C++ class can inherit members from more than one class and here is the extended syntax:
class derived-class: access baseA, access baseB....
IN
Where access is one of public, protected, or private and would be given for every base class
and they will be separated by comma as shown above. Let us try the following example:
GA
#include <iostream>
public:
void setWidth(int w)
{
BE
A
width = w;
&
class Shape
void setHeight(int h)
{
height = h;
protected:
int width;
int height;
};
71
Computers
{
public:
int getCost(int area)
{
return area * 70;
}
};
// Derived class
IN
GA
public:
int getArea()
{
return (width * height);
&
int main(void)
{
BE
A
Rectangle Rect;
};
int area;
Rect.setWidth(5);
Rect.setHeight(7);
area = Rect.getArea();
72
Computers
return 0;
}
When the above code is compiled and executed, it produces the following result:
Total area: 35
Total paint cost: $2450
Forms of Inheritance
GA
IN
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hybrid Inheritance
Hierarchical Inheritance
BE
A
&
1.
2.
3.
4.
5.
73
Computers
Data Structure
Data Structures are the programmatic way of storing data so that data can be used efficiently.
Almost every enterprise application uses various types of data structures in one or other way.
This tutorial will give you great understanding on Data Structures concepts needed to understand
the complexity of enterprise level applications and need of algorithms, data structures.
Time Complexity Running time or execution time of operations of data structure must
be as small as possible.
IN
GA
As applications are getting complex and data rich, there are three common problems
applications face now-a-days.
Data Search Consider an inventory of 1 million(106) items of a store. If application is
to search an item. It has to search item in 1 million(106) items every time slowing down
the search. As data grows, search will become slower.
Processor speed Processor speed although being very high, falls limited if data grows
to billion records.
BE
A
&
To solve above problems, data structures come to rescue. Data can be organized in a data
structure in such a way that all items may not be required to be search and required data can be
searched almost instantly.
There are three cases which are usual used to compare various data structure's execution time in
relative manner.
Worst Case This is the scenario where a particular data structure operation takes
maximum time it can take. If a operation's worst case time is (n) then this operation
will not take time more than (n) time where (n) represents function of n.
Average Case This is the scenario depicting the average execution time of an
operation of a data structure. If a operation takes (n) time in execution then m
operations will take m(n) time.
74
Computers
Best Case This is the scenario depicting the least possible execution time of an
operation of a data structure. If a operation takes (n) time in execution then actual
operation may take time as random number which would be maximum as (n).
Basic Terminology
Data Data are values or set of values.
Group Items Data item that are divided into sub items are called as Group Items.
Elementary Items Data item that cannot be divided are called as Elementary Items.
Attribute and Entity An entity is that which contains certain attributes or properties
which may be assigned values.
&
GA
IN
Stack
BE
A
A stack is an abstract data type (ADT), commonly used in most programming languages. It is
named stack as it behaves like a real-world stack, for example deck of cards or pile of plates
etc.
A real-world stack allows operations at one end only. For example, we can place or remove a
card or plate from top of the stack only. Likewise, Stack ADT allows all data operations at one
end only. At any given time, We can only access the top element of a stack.
This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element
which is placed (inserted or added) last, is accessed first. In stack terminology, insertion
operation is called PUSH operation and removal operation is called POP operation.
Stack Represtation
A stack can be implemented by means of Array, Structure, Pointer and Linked-List. Stack can
either be a fixed size one or it may have a sense of dynamic resizing. Here, we are going to
implement stack using arrays which makes it a fixed size stack implementation.
75
Computers
&
GA
IN
Basic Operations
BE
A
Stack operations may involve initializing the stack, using it and then de-initializing it. Apart
from these basic stuffs, a stack is used for the following two primary operations
isfull()
Algorithm of isfull() function
begin procedure isfull
if top equals to MAXSIZE
return true
else
76
Computers
return false
endif
end procedure
Implementation of isfull() function in C programming language
bool isfull() {
if(top == MAXSIZE)
IN
return true;
else
}
BE
A
else
&
isempty()
Algorithm of isempty() function
GA
return false;
return false
endif
end procedure
77
Computers
return false;
}
PUSH Operation
The process of putting a new data element onto stack is known as PUSHOperation. Push
operation involves series of steps
Step 1 Check if stack is full.
Step 3 If stack is not full, increment top to point next empty space.
Step 4 Add data element to the stack location, where top is pointing.
&
GA
IN
BE
A
if linked-list is used to implement stack, then in step 3, we need to allocate space dynamically.
Algorithm for PUSH operation
A simple algorithm for Push operation can be derived as follows
begin procedure push: stack, data
if stack is full
return null
endif
top top + 1
78
Computers
stack[top] data
end procedure
Implementation of this algorithm in C, is very easy. See the below code
void push(int data) {
if(!isFull()) {
top = top + 1;
}else {
printf("Could not insert data, Stack is full.\n");
GA
IN
stack[top] = data;
&
Pop Operation
Accessing the content while removing it from stack, is known as pop operation. In array
implementation of pop() operation, data element is not actually removed, instead top is
decremented to a lower position in stack to point to next value. But in linked-list
implementation, pop() actually removes data element and deallocates memory space.
BE
A
Step 3 If stack is not empty, access the data element at which topis pointing.
79
Computers
IN
GA
return null
endif
BE
A
data stack[top]
if stack is empty
&
top top - 1
return data
end procedure
Implementation of this algorithm in C, is shown below
int pop(int data) {
if(!isempty()) {
80
Computers
data = stack[top];
top = top - 1;
return data;
}else {
printf("Could not retrieve data, Stack is empty.\n");
}
}
Infix Notation
Prefix (Polish) Notation
Postfix (Reverse-Polish) Notation
GA
IN
The way to write arithmetic expression is known as notation. An arithmetic expression can be
written in three different but equivalent notations, i.e., without changing the essence or output
of expression. These notations are
&
Infix Notation
We write expression in infix notation, e.g. a-b+c, where operators are used in-between
operands. It is easy for us humans to read, write and speak in infix notation but the same does
not go well with computing devices. An algorithm to process infix notation could be difficult
and costly in terms of time and space consumption.
BE
A
Prefix Notation
In this notation, operator is prefixed to operands, i.e. operator is written ahead of operands. For
example +ab. This is equivalent to its infix notation a+b. Prefix notation is also known
as Polish Notation.
Postfix Notation
This notation style is known as Reversed Polish Notation. In this notation style, operator
is postfixed to the operands i.e., operator is written after the operands. For example ab+. This is
equivalent to its infix notation a+b.
81
Computers
IN
GA
Parsing Expressions
As we have discussed, it is not very efficient way to design an algorithm or program to parse
infix notations. Instead, these infix notations are first converted into either postfix or prefix
notations and then computated.
&
To parse any arithmetic expression, we need to take care of operator precedence and
associativity also.
BE
A
Precedence
When an operand is in between two different operator, which operator will take the operand
first, is decided by the precedence of an operator over others. For example
82
Computers
remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored
first will be accessed first.
IN
Queue is a specialized data storage structure (Abstract data type). Unlike, arrays access
of elements in a Queue is restricted. It has two main operations enqueue and dequeue.
Insertion in a queue is done using enqueue function and removal from a queue is done using
dequeue function. An item can be inserted at the end (rear) of the queue and removed from the
front (front) of the queue. It is therefore, also called First-In-First-Out (FIFO) list. Queue has
five properties - capacity stands for the maximum number of elements Queue can hold, size
stands for the current size of the Queue, elements is the array of elements, front is the index of
first element (the index at which we remove the element) and rear is the index of last element
(the index at which we insert the element).
GA
First in First Out data structure (FIFO). Like people waiting to buy tickets in a queue - the first
one to stand in the queue, gets the ticket first and gets to leave the queue first. Documentation of
the various operations and the stages a queue passes through as elements are inserted or deleted.
C Program source code to help you get an idea of how a queue is implemented in code.
Algorithm:
Functions
&
Queue structure is defined with fields capacity, size, *elements (pointer to the array of
elements), front and rear.
BE
A
2. enqueue function - This function takes the pointer to the top of the queue Q and the item
(element) to be inserted as arguments. Check for the emptiness of queue
3. dequeue function - This function takes the pointer to the top of the stack S as an
argument and will then dequeue an element.
4. front function This function takes the pointer to the top of the queue Q as an argument and
returns the front element of the queue Q.
83
Computers
As we are using single dimension array to implement queue, we just check for the rear
pointer to reach at MAXSIZE to determine that queue is full. In case we maintain queue
in a circular linked-list, the algorithm will differ. Algorithm of isfull() function
begin procedure isfull
IN
Properties:
1. Each function runs in O(1) time.
GA
&
BE
A
84
Computers
BE
A
&
GA
IN
85
Computers
Linked Lists
IN
A linked list is a linear data structure where each element is a separate object. Each element
(we will call it a node) of a list is comprising of two items - the data and a reference to the next
node. The last node has a reference to null. The entry point into alinked list is called the head of
the list.
Linked List is a sequence of links which contains items. Each link contains a connection to
GA
another link. Linked list the second most used data structure after array. Following are
important terms to understand the concepts of Linked List.
Link Each Link of a linked list can store a data called an element.
Next Each Link of a linked list contain a link to next link called Next.
LinkedList A LinkedList contains the connection link to the first Link called First.
&
BE
A
Linked list can be visualized as a chain of nodes, where every node points to the next node.
As per above shown illustration, following are the important points to be considered.
Each Link carries a data field(s) and a Link Field called next.
Each Link is linked with its next link using its next link.
86
Computers
Last Link carries a Link as null to mark the end of the list.
Doubly Linked List Items can be navigated forward and backward way.
Circular Linked List Last item contains link of the first element as next and and first
&
GA
IN
BE
A
87
Computers
Basic Operations
Following are the basic operations supported by a list.
Insertion add an element at the beginning of the list.
GA
Insertion Operation
IN
&
BE
A
//create a link
link->data = data;
88
Computers
BE
A
&
GA
IN
Deletion Operation
89
Computers
IN
GA
&
BE
A
They are a dynamic in nature which allocates the memory when required.
Insertion and deletion operations can be easily implemented.
Stacks and queues can be easily executed.
Linked List reduces the access time.
Graphs
A graph is a set of vertices and edges which connect them. We write:
90
Computers
G = (V,E)
where V is the set of vertices and the set of edges,
E = { (vi,vj) }
GA
IN
Paths
&
V = {a, b, c, d, e}
BE
A
There are two important sets of objects, which specify graph and its structure. First set
is V, which is calledvertex-set. In the example with road network cities are vertices. Each
vertex can be drawn as a circle with vertex's number inside.
91
Computers
GA
IN
&
Sequence of vertices, such that there is an edge from each vertex to the next in sequence,
is called path. First vertex in the path is called the start vertex; the last vertex in the path
is called the end vertex. If start and end vertices are the same, path is called cycle. Path is
called simple, if it includes every vertex only once. Cycle is called simple, if it includes
every vertex, except start (end) one, only once. Let's see examples of path and cycle.
BE
A
The last definition we give here is a weighted graph. Graph is called weighted, if
every edge is associated with a real number, called edge weight. For instance, in
the road network example, weight of each road may be its length or minimal
time needed to drive along.
92
Computers
IN
&
GA
The first key to solving a graph related problem is recognizing that it is a graph problem.
This can be more difficult than it sounds, because the problem writers dont usually spell it
out for you. Nearly all graph problems will somehow use a grid or network in the problem,
but sometimes these will be well disguised. Secondly, if you are required to find a path of
any sort, it is usually a graph problem as well. Some common keywords associated with
graph problems are: vertices, nodes, edges, connections, connectivity, paths, cycles and
direction.
Vertex Each node of the graph is represented as a vertex. In example given below,
labeled circle represents vertices. So A to G are vertices. We can represent them using
an array as shown in image below. Here A can be identified by index 0. B can be
identified using index 1 and so on.
BE
A
Edge Edge represents a path between two vertices or a line between two vertices. In
example given below, lines from A to B, B to C and so on represents edges. We can use
a two dimensional array to represent array as shown in image below. Here AB can be
represented as 1 at row 0, column 1, BC as 1 at row 1, column 2 and so on, keeping
other combinations as 0.
Adjacency Two node or vertices are adjacent if they are connected to each other
through an edge. In example given below, B is adjacent to A, C is adjacent to B and so
on.
Path Path represents a sequence of edges between two vertices. In example given
below, ABCD represents a path from A to D.
93
Computers
&
Basic Operations
GA
Tree
IN
BE
A
94
Computers
Memory Organisation
Just as processes share the CPU, they also share physical memory. This section is about
mechanisms for doing that sharing.
EXAMPLE OF MEMORY USAGE:
Calculation of an effective address
Fetch from instruction
Use index offset
IN
Example:
BE
A
&
GA
The concept of a logical address space that is bound to a separate physical address space is
central to proper memory management.
Logical and physical addresses are the same in compile-time and loadtime address-binding
schemes; logical (virtual) and physical addresses differ in execution-time address-binding
scheme.
Memory Management
Relocatable Means that the program image can reside anywhere in physical memory.
Binding Programs need real memory in which to reside. When is the location of that real
memory determined?
95
Computers
IN
Memory hierarchy
BE
A
&
GA
Main Memory : memory unit that communicates directly with the CPU (RAM) z Auxiliary
Memory : device that provide backup storage (Disk Drives) z Cache Memory : special veryhigh-speed memory to increase the processing speed.
96
Computers
Registers
&
GA
IN
Register Memory and Disk Memory. Let us locate these 3 types of memory in a simplified
model of a computer:
Registers are memories located within the Central Processing Unit (CPU). They are few in
number (there are rarely more than 64 registers) and also small in size, typically a register is less
than 64 bits; 32-bit and more recently 64-bit are common in desktops.
BE
A
The contents of a register can be read or written very quickly however, often an order of
magnitude faster than main memory and several orders of magnitude faster than disk memory.
Different kinds of register are found within the CPU. General Purpose Registers are available for
general use by the programmer. Unless the context implies otherwise well use the term
"register" to refer to a General Purpose Register within the CPU. Most modern CPUs have
between 16 and 64 general purpose registers. Special Purpose Registers have specific uses and
are either nonprogrammable and internal to the CPU or accessed with special instructions by the
programmer. Examples of such registers that we will encounter later in the course include: the
Program Counter register (PC), the Instruction Register (IR), the ALU Input & Output registers,
the Condition Code (Status/Flags) register, the Stack Pointer register (SP). The size (the number
of bits in the register) of these registers varies according to register type. The Word Size of an
architecture is often (but not always!) defined by the size of the general purpose registers. In
contrast to main memory and disk memory, registers are referenced directly by specific
instructions or by encoding a register number within a computer instruction. At the programming
(assembly) language level of the CPU, registers are normally specified with special identifiers
(e.g. R0, R1, R7, SP, PC). As a final point, the contents of a register are lost if power to the CPU
is turned off, so registers are unsuitable for holding long-term information or information that is
97
Computers
needed for retention after a power-shutdown or failure. Registers are however, the fastest
memories, and if exploited can result in programs that execute very quickly.
IN
If we were to sum all the bits of all registers within CPU, the total amount of memory probably
would not exceed 5,000 bits. Most computational tasks undertaken by a computer require a lot
more memory. Main memory is the next fastest memory within a computer and is much larger in
size. Typical main memory capacities for different kinds of computers are: PC 512MB ,
fileserver 4GB, database server 8GB. Computer architectures also impose an architectural
constraint on the maximum allowable RAM. This constraint is normally equal to 2 WordSize
memory locations.
GA
RAM (Random Access Memory) is the most common form of Main Memory. RAM is normally
located on the motherboard and so is typically less than 12 inches from the CPU. ROM (Read
Only Memory) is like RAM except that its contents cannot be overwritten and its contents are
not lost if power is turned off (ROM is non-volatile).
&
Although slower than register memory, the contents of any location in RAM can still be read
or written very quickly. The time to read or write is referred to as the access time and is
constant for all RAM locations.
In contrast to register memory, RAM is used to hold both program code (instructions) and data
(numbers, strings etc). Programs are loaded into RAM from a disk prior to execution by the
CPU.
BE
A
Locations in RAM are identified by an addressing scheme e.g. numbering the bytes in RAM
from 0 onwards. Like registers, the contents of RAM are lost if the power is turned off.
Disk memory
Disk memory is used to hold programs and data over the longer term. The contents of a disk are
NOT lost if the power is turned off. Typical hard disk capacities range from 100GB to over 1TB
(1x1030). Disks are much slower than register and main memory, the access-time (known as the
seek-time) to data on disk is typically between 2 and 4 milli-seconds, although disk drives can
transfer thousands of bytes in one go achieving transfer rates from 25MB/s to 500MB/s.
Disks can be housed internally within a computer box or externally in an enclosure connected
by a fast USB or firewire cable. Disk locations are identified by special disk addressing schemes
(e.g. track and sector numbers).
98
Computers
GA
IN
&
Primary Memory / Volatile Memory: Primary Memory is internal memory of the computer.
RAM AND ROM both form part of primary memory. The primary memory provides main
working space to the computer.The following terms comes under primary memory of a computer
are discussed below:
BE
A
Random Access Memory (RAM): The primary storage is referred to as random access memory
(RAM) because it is possible to randomly select and use any location of the memory directly
store and retrieve data. It takes same time to any address of the memory as the first address. It is
also called read/write memory. The storage of data and instructions inside the primary storage is
temporary. It disappears from RAM as soon as the power to the computer is switched off. The
memories, which lose their content on failure of power supply, are known as volatile memories
.So now we can say that RAM is volatile memory.
Read Only Memory (ROM): There is another memory in computer, which is called Read Only
Memory (ROM). Again it is the ICs inside the PC that form the ROM. The storage of program
and data in the ROM is permanent. The ROM stores some standard processing programs
supplied by the manufacturers to operate the personal computer. The ROM can only be read by
the CPU but it cannot be changed. The basic input/output program is stored in the ROM that
examines and initializes various equipment attached to the PC when the power switch is ON. The
memories, which do not lose their content on failure of power supply, are known as non-volatile
memories. ROM is non-volatile memory.
PROM: There is another type of primary memory in computer, which is called Programmable
Read Only Memory (PROM). You know that it is not possible to modify or erase programs
stored in ROM, but it is possible for you to store your program in PROM chip. Once the
99
Computers
programmers are written it cannot be changed and remain intact even if power is switched off.
Therefore programs or instructions written in PROM or ROM cannot be erased or changed.
EPROM: This stands for Erasable Programmable Read Only Memory, which overcome the
problem of PROM & ROM. EPROM chip can be programmed time and again by erasing the
information stored earlier in it. Information stored in EPROM exposing the chip for some time
ultraviolet light and it erases chip is reprogrammed using a special programming facility. When
the EPROM is in use information can only be read.
GA
IN
Cache Memory: The speed of CPU is extremely high compared to the access time of main
memory. Therefore the performance of CPU decreases due to the slow speed of main memory.
To decrease the mismatch in operating speed, a small memory chip is attached between CPU and
Main memory whose access time is very close to the processing speed of CPU. It is called
CACHE memory. CACHE memories are accessed much faster than conventional RAM. It is
used to store programs or data currently being executed or temporary data frequently used by the
CPU. So each memory makes main memory to be faster and larger than it really is. It is also very
expensive to have bigger size of cache memory and its size is normally kept small.
&
Registers: The CPU processes data and instructions with high speed; there is also movement of
data between various units of computer. It is necessary to transfer the processed data with high
speed. So the computer uses a number of special memory units called registers. They are not part
of the main memory but they store data or information temporarily and pass it on as directed by
the control unit.
BE
A
100
Computers
without affecting the stored data. So the reading operation is non-destructive. But if you want to
write a new data, then the existing data is erased from the disk and new data is recorded. For
Example-Floppy Disk.
Optical Disk: With every new application and software there is greater demand for memory
capacity. It is the necessity to store large volume of data that has led to the development of
optical disk storage medium. Optical disks can be divided into the following categories:
1.
Compact Disk/ Read Only Memory (CD-ROM
2.
Write Once, Read Many (WORM)
3.
Erasable Optical Disk
IN
GA
&
When computers were first introduced, the user interacted with them using a command
line interface, which required commands. Today, almost every computer is using a Graphical
User Interface (GUI) operating system that is much easier to use and operate.
Microsoft Windows 7 - PC and IBM compatible operating system. Microsoft Windows is the
most common and used operating system.
BE
A
Apple MacOS - Apple Mac operating system. The only Apple computer operating system
is MacOS.
Ubuntu Linux - A popular variant of Linux used with PC and IBM compatible computers.
Google Android - operating system used with Android compatible phones.
iOS - Operating system used with the Apple iPhone.
101
Computers
Data Communication
GA
IN
Data communications refers to the transmission of this digital data between two or more
computers and a computer network or data network is a telecommunications network that allows
computers to exchange data.
BE
A
&
A data communication system may collect data from remote locations through data transmission
circuits, and then outputs processed results to remote locations. Figure provides a broader view
of data communication networks. The different data communication techniques which are
presently in widespread use evolved gradually either to improve the data communication
techniques already existing or to replace the same with better options and features. Then, there
are data communication jargons to contend with such as baud rate, modems, routers, LAN,
WAN, TCP/IP, ISDN, during the selection of communication systems. Hence, it becomes
necessary to review and understand these terms and gradual development of data communication
methods.
Components of data communication system
102
Computers
3. Receiver: It is the device or computer that receives the message. The location of receiver
computer is generally different from the sender computer. The distance between sender and
receiver depends upon the types of network used in between.
4. Medium: It is the channel or physical path through which the message is carried from sender
to the receiver. The medium can be wired like twisted pair wire, coaxial cable, fiber-optic cable
or wireless like laser, radio waves, and microwaves.
5. Protocol: It is a set of rules that govern the communication between the devices. Both sender
and receiver follow same protocols to communicate with each other.
IN
1. Data sequencing. It refers to breaking a long message into smaller packets of fixed size. Data
GA
sequencing rules define the method of numbering packets to detect loss or duplication of packets,
and to correctly identify packets, which belong to same message.
2. Data routing. Data routing defines the most efficient path between the source and destination.
&
3. Data formatting. Data formatting rules define which group of bits or characters within packet
constitute data, control, addressing, or other information.
4. Flow control. A communication protocol also prevents a fast sender from overwhelming a
slow receiver. It ensures resource sharing and protection against traffic congestion by regulating
the flow of data on communication lines.
BE
A
5. Error control. These rules are designed to detect errors in messages and to ensure
transmission of correct messages. The most common method is to retransmit erroneous message
block. In such a case, a block having error is discarded by the receiver and is retransmitted by the
sender.
6. Precedence and order of transmission. These rules ensure that all the nodes get a chance to
use the communication lines and other resources of the network based on the priorities assigned
to them.
7. Connection establishment and termination. These rules define how connections are
established, maintained and terminated when two nodes of a network want to communicate with
each other.
103
Computers
IN
GA
8. Data security. Providing data security and privacy is also built into most communication
software packages. It prevents access of data by unauthorized users.
9. Log information. Several communication software are designed to develop log information,
which consists of all jobs and data communications tasks that have taken place. Such information
&
may be used for charging the users of the network based on their usage of the network resources.
BE
A
1.
2.
3.
1- Simplex Mode
In simplex mode, data can flow in only one direction. In this mode, a sender can only send
data and cannot receive it. Similarly, a receiver can only receive data but cannot send it. Data
sent from computer to printer is an example of simplex mode.
104
Computers
In simplex mode, it is not possible to confirm successful transmission of data. It is also not
possible to request the sender to re-transmit information. This mode is not widely used.
However, this mode is used in business field at certain point-of-sale terminals. The other
examples of simplex communication modes are Radio and T.V transmissions.
IN
2- Half-Duplex Mode
In half-duplex mode, data can flow in both directions but only in one direction at a time. In
this mode, data is sent and received alternatively. It is like a one-lane bridge where two-way
traffic must give way in order to cross the other.
GA
The Internet browsing is an example of half duplex mode. The user sends a request to a Web
server for a web page. It means that information flows from user's computer to the web server.
Web server receives the request and sends data of the requested page. The data flows the Web
server to the user's computer. At a time a user can a request or receive the data of web page.
BE
A
&
3- Full-Duplex Mode
In full duplex-mode, data can flow in both directions at the same time. It is the fastest
directional mode of data communication. The telephone communication system is an example of
full-duplex communication mode. Two persons can talk at the same time. Another example of
fully-duplex mode in daily life is automobile traffic on a two-lane road. The traffic can move in
both directions at the same time.
Data Transmission
Data is transmitted over networks using signals, which are transformed, or encoded, by
computers into the voice, video, graphics, and/or the print we see on our computer screens. The
signals used by computers to transmit data are either digital or analog.
105
Computers
GA
IN
Analog signals are continuous signals that vary in strength. Sound is an example of an analog
signal. Sound is actually a wave and is quite similar, or analogous, to electromagnetic waves,
hence the name analog. Telephones have transmitters that encode sound waves into
electromagnetic waves, which then travel over wires toward their destination. The receiving
telephone decodes the electromagnetic waves back into sound waves. Our brains then decode the
sound waves into the words we hear. Computer modems use the same principle. Analog signals
can be represented digitally. For instance, a high electromagnetic voltage could be interpreted as
1 and low voltage as 0.
BE
A
&
Digital signals are discrete rather than continuous. Either there is a signal or there isn't a signal.
Telegraphs transmit data with discrete signals. You either hear a tap or you do not hear a tap.
Discrete signals can be represented by on and off pulses. The duration of a discrete signal can be
varied, as with dots and dashes in Morse Code.
Discrete signals can also be represented digitally. The presence of a signal could be coded as a 1
and the absence of a signal coded as a 0. The digits 0 and 1 are used because computer circuitry
is based on binary digital data. Codes are used to group a set number of bits together and have a
group of bits represent a letter, number, or other character. The computers brain, the central
processing unit (CPU), transforms these codes of 0s and 1s into the voice, video and data we see.
One coding scheme, ASCII, codes an a as the binary number 0110-0001.
D igital data is based on two states, on or off. The binary numbering system uses only two digits,
0 and 1, so it makes sense to use the binary numbering system. One digit, 0 represents off, the
106
Computers
other digit represents on. A single 0 or 1 is called a bit. One byte is equal to eight bits (also called
an octet when discussing TCP/IP). In ASCII code, one octet is the equivalent of one alphabetic
or numeric character. In order to appreciate how computers communicate over networks, it is
necessary to be aware of how they encode information.
Types of Transmission
Synchronous and Asynchronous Transmission
Synchronous
Asynchronous
GA
IN
Computers need to know when to expect data and where a character begins and ends. When
receiving data, timing on both computer devices must be coordinated if they are to work together
efficiently. This coordination is called clocking, timing, or framing. There are two protocols for
the timing or coordination of data signals:
When transferring data, both the transmitting and receiving nodes need to agree when the signal
begins and ends so the signals can be correctly measured and interpreted. This timing process is
called bit synchronization, framing, or clocking.
&
BE
A
Clocking is somewhat like timing in music. There are a specific number of beats expected per
bar. When computer devices are synchronized, a specific number of signals or beats are
expected within a set amount of time. Timing is important because it helps you be prepared. In
many schools, every 50 minutes, a new class period starts. Students watch the clock and expect a
signal. Usually, they are already prepared to leave the classroom. That is because they expected
the signal.
Synchronous transmission requires the communicating devices to maintain synchronous clocks
during the entire connection. The sending device transmits on a specific schedule and the
receiving device accepts the data on that same fixed schedule. The receiving device knows the
timing of the sending device because the timing information is embedded within the preamble of
the frame. Synchronous transmissions are common in internal computer communications and
usually are sent as entire frames. Synchronous transmission is common when large blocks of
data are transferred, since it is efficient and has a low overhead (number of bytes of data/control
+ data bytes).
Asynchronous data transmission does not involve synchronizing the clocks of the sending and
receiving devices. Instead, start and stop bits are used for synchronization of data signals. The
start and stop bits tell the Lesson 2-2: Data Transmission 148 ST0025803A Internetworking
107
Computers
Fundamentals receiving device how to interpret the data. Asynchronous sends one character at a
time.
Data transmission may be half-duplex; meaning data is transferred in only one direction at a
time. An example of half-duplex is a CB radio where only one person can talk at a time. Or,
transmission may be full duplex, transmitted in two directions simultaneously. A telephone
conversation illustrates full-duplex communication.
OSI MODEL IN NETWORKING
&
GA
IN
When transmitting data over networks, conforming to the OSI model is important. Data is
encapsulated at each layer of the transmitting device from top to bottom and stripped at the
receiving device in the reverse direction. The protocols of the OSI model are used to organize the
data into packets, with headers and trailers.
Each layer communicates with layers both immediately above and below it.
Each layer from the sending (source) station also communicates with its peer layer at the
receiving (destination) computer.
Data starts at the application layer of the source device and descends through the
remaining layers before being transmitted to the destination device.
As each layer receives the data from the layer above, it adds, in the form of headers, its
data. This data contains various protocols that enable communication.
The original data, with the new header and the headers from the previous layers, is then
sent to the next layer down.
When the data reaches the Physical Layer, it is transmitted across various media to the
destination device.
The destination device receives the entire frame and sends it up through the layers, one
after the other in sequence.
Each layer strips the header added by its peer layer at the source device.
BE
A
Ethernet packets can contain approximately 1,000 bytes. If the data being transmitted is larger
than 1,000 bytes then the computer breaks it down into packets. Each packet is transmitted and
108
Computers
received separately. Packets are sequentially numbered. This allows the receiving computer to
recreate the data in the correct order. Depending upon the protocols used, packet size can change.
Feature of OSI
Big picture of communication over network is understandable through this OSI model.
2.
3.
4.
5.
IN
1.
GA
Physical layer is the lowest layer of all. It is responsible for sending bits from one computer to
another. This layer is not concerned with the meaning of the bits and deals with the physical
connection to the network and with transmission and reception of signals.
&
This layer defines electrical and physical details represented as 0 or a 1. How many pins a
network will contain, when the data can be transmitted or not and how the data would be
synchronized.
BE
A
Representation of Bits: Data in this layer consists of stream of bits. The bits must be encoded into signals
for transmission. It defines the type of encoding i.e. how 0s and 1s are changed to signal.
Data Rate: This layer defines the rate of transmission which is the number of bits per second.
Synchronization: It deals with the synchronization of the transmitter and receiver. The sender and
receiver are synchronized at bit level.
Interface: The physical layer defines the transmission interface between devices and transmission
medium.
Line Configuration: This layer connects devices with the medium: Point to Point configuration and
Multipoint configuration.
109
Computers
Topologies: Devices must be connected using the following topologies: Mesh, Star, Ring and Bus.
Transmission Modes: Physical Layer defines the direction of transmission between two devices:
Simplex, Half Duplex, Full Duplex.
&
GA
IN
2.
3.
4.
5.
6.
BE
A
1.
It is responsible for transmission and reception of the unstructured raw data over network.
Voltages and data rates needed for transmission is defined in the physical layer.
It converts the digital/analog bits into electrical signal or optical signals.
110
Computers
Error detection bits are used by the data link layer. It also corrects the errors. Outgoing messages
are assembled into frames. Then the system waits for the acknowledgements to be received after
the transmission. It is reliable to send message.
Function of Data Link Layer
Framing: Frames are the streams of bits received from the network layer into manageable
data units. This division of stream of bits is done by Data Link Layer.
IN
Physical Addressing: The Data Link layer adds a header to the frame in order to define
physical address of the sender or receiver of the frame, if the frames are to be distributed to
different systems on the network.
GA
Flow Control: A flow control mechanism to avoid a fast transmitter from running a slow
receiver by buffering the extra bit is provided by flow control. This prevents traffic jam at the
receiver side.
Error Control: Error control is achieved by adding a trailer at the end of the frame.
Duplication of frames are also prevented by using this mechanism. Data Link Layers adds
mechanism to prevent duplication of frames.
BE
A
&
Access Control: Protocols of this layer determine which of the devices has control over the
link at any given time, when two or more devices are connected to the same link.
111
Computers
IN
The main aim of this layer is to deliver packets from source to destination across multiple links
(networks). If two computers (system) are connected on the same link then there is no need for a
network layer. It routes the signal through different channels to the other end and acts as a
network controller.
BE
A
&
GA
It also divides the outgoing messages into packets and to assemble incoming packets into
messages for higher levels.
1.
2.
3.
4.
It routes the signal through different channels from one node to other.
It acts as a network controller. It manages the Subnet traffic.
It decides by which route data should take.
It divides the outgoing messages into packets and assembles the incoming packets into
messages for higher levels.
112
Computers
and flow control at the source to destination level. It decides if data transmission should be on
parallel path or single path
GA
IN
Transport layer breaks the message (data) into small units so that they are handled more
efficiently by the network layer and ensures that message arrives in order by checking error and
flow control.
BE
A
&
1. Service Point Addressing : Transport Layer header includes service point address which
is port address. This layer gets the message to the correct process on the computer unlike
Network Layer, which gets each packet to the correct computer.
2. Segmentation and Reassembling : A message is divided into segments; each segment
contains sequence number, which enables this layer in reassembling the message.
Message is reassembled correctly upon arrival at the destination and replaces packets
which were lost in transmission.
3. Connection Control : It includes 2 types :
a. Connectionless Transport Layer : Each segment is considered as an independent
packet and delivered to the transport layer at the destination machine.
b. Connection Oriented Transport Layer : Before delivering packets, connection is
made with transport layer at the destination machine.
4. Flow Control : In this layer, flow control is performed end to end.
5. Error Control : Error Control is performed end to end in this layer to ensure that the
complete message arrives at the receiving transport layer without any error. Error
Correction is done through retransmission.
113
Computers
IN
marked and are resynchronized properly, so that the ends of the messages are not cut prematurely
and data loss is avoided.
GA
Dialog Control : This layer allows two systems to start communication with each other in halfduplex or full-duplex.
&
Synchronization : This layer allows a process to add checkpoints which are considered as
synchronization points into stream of data. Example: If a system is sending a file of 800 pages,
adding checkpoints after every 50 pages is recommended. This ensures that 50 page unit is
successfully received and acknowledged. This is beneficial at the time of crash as if a crash
BE
A
The primary goal of this layer is to take care of the syntax and semantics of the information
exchanged between two communicating systems. Presentation layer takes care that the data is
sent in such a way that the receiver will understand the information (data) and will be able to use
the data. Languages (syntax) can be different of the two communicating systems. Under this
condition presentation layer plays a role translator.
114
Computers
IN
GA
BE
A
&
It is the top most layer of OSI Model. Manipulation of data (information) in various ways is done
in this layer which enables user or software to get access to the network. Some services provided
by this layer includes: E-Mail, transferring of files, distributing the results to user, directory
services, network resource etc.
115
Computers
IN
&
GA
1. Mail Services: This layer provides the basis for E-mail forwarding and storage.
2. Network Virtual Terminal: It allows a user to log on to a remote host. The application
creates software emulation of a terminal at the remote host. Users computer talks to the
software terminal which in turn talks to the host and vice versa. Then the remote host
believes it is communicating with one of its own terminals and allows user to log on.
3. Directory Services: This layer provides access for global information about various
services.
4. File Transfer, Access and Management (FTAM): It is a standard mechanism to access
files and manages it. Users can access files in a remote computer and manage it. They can
also retrieve files from a remote computer.
The TCP/IP Reference Model
BE
A
TCP/IP means Transmission Control Protocol and Internet Protocol. It is the network model used
in the current Internet architecture as well. Protocols are set of rules which govern every possible
communication over a network. These protocols describe the movement of data between the
source and destination or the internet. These protocols offer simple naming and addressing
schemes.
116
Computers
The TCP/IP architectural model has four layers that approximately match six of the seven layers
in the OSI Reference Model. The TCP/IP model does not address the physical layer, which is
where hardware devices reside. The next three layersnetwork interface, internet and (host-tohost) transportcorrespond to layers 2, 3 and 4 of the OSI model. The TCP/IP application layer
conceptually blurs the top three OSI layers. Its also worth noting that some people consider
certain aspects of the OSI session layer to be arguably part of the TCP/IP host-to-host transport
layer.
Application Layer
IN
The application layer is concerned with providing network services to applications. There are
many application network processes and protocols that work at this layer, including HyperText
Transfer Protocol (HTTP), Simple Mail Transport Protocol (SMTP) and File Transfer Protocol
(FTP).
GA
At this layer sockets and port numbers are used to differentiate the path and sessions which
applications operate. Most application layer protocols, especially on the server side, have
specially allocated port numbers, e.g. HTTP = 80 and SMTP = 25, and FTP = 20 (Control), 21
(Data).
&
Transport Layer
BE
A
This layer is concerned with the transmission of the data. The two main protocols that operate at
this layer are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). TCP is
regarded as being the reliable transmission protocol and it guarantees that the proper data transfer
will take place. UDP is not as complex as TCP and as such is not designed to be reliable or
guarantee data delivery. UDP is generally thought of as being a best effort data delivery, i.e. once
the data is sent, UDP will not carry out any checks to see that it has safely arrived.
The Internet Layer
This is the layer that contains the packet construct that will be transmitted. This takes the form of
the Internet Protocol (IP) which describes a packet that contains a source IP Address, destination
IP Address and the actual data to be delivered.
Network Access Layer
This is the lowest level of the TCP/IP protocol stack and functions carried out here include
encapsulation of IP packets into frames for transmission, mapping IP addresses to physical
hardware addresses (MAC Addresses) and the use of protocols for the physical transmission of
data.
117
Computers
BE
A
&
GA
IN
118
Computers
Modems
A modem is a device or program that enables a computer to transmit data over, for example,
telephone or cable lines. Computer information is stored digitally, whereas information
transmitted over telephone lines is transmitted in the form of analog waves. A modem converts
between these two forms.
Two Modems Must Follow Same Standards
Speed standards (modulation method)
Error correction and compression standards
Facsimile standards
Modern modem standards are created by the ITU-T
IN
Modem Standards
GA
V.22:
Provides 1200 bits per second at 600 baud (state changes per second).
V.22bis:
The first true world standard, it allows 2400 bits per second at 600 baud.
&
V.32:
Provides 4800 and 9600 bits per second at 2400 baud.
V.32bis:
Provides 14,400 bits per second or fallback to 12,000, 9600, 7200, and 4800 bits per second.
BE
A
V.32terbo:
Provides 19,200 bits per second or fallback to 12,000, 9600, 7200, and 4800 bits per second; can
operate at higher data rates with compression; was not a CCITT/ITU standard.
V.34:
Provides 28,800 bits per second or fallback to 24,000 and 19,200 bits per second and backwards
compatibility with V.32 and V.32bis.
V.34bis:
Provides up to 33,600 bits per second or fallback to 31,200 or V.34 transfer rates.
V.35:
The trunk interface between a network access device and a packet network at data rates greater
than 19.2 Kbps. V.35 may use the bandwidths of several telephone circuits as a group. There are
V.35 Gender Changers and Adapters.
119
Computers
V.42:
Same transfer rate as V.32, V.32bis, and other standards but with better error correction and
therefore more reliable.
V.90:
Provides up to 56,000 bits per second downstream (but in practice somewhat less). Derived from
the x2 technology of 3Com (US Robotics) and Rockwell's K56flex technology.
IN
x2 is a technology from US Robotics (now 3Com) for the downstream transmission of data over
ordinary phone lines at 56 Kbps (thousands of bits per second). The 56 Kbps speed is achieved in
the downstream direction only (to your home or business). Upstream speed is at the regular
maximum speed of 33.6 Kbps. (The actual achieved downstream speed is reported by users to be
about 53 Kbps.) x2 provided input to and has been replaced by the V.90 ITU standard.
&
GA
K56flex: Rockwell Corporation's K56flex modem chipset gave users the capability to receive
data on ordinary phone lines at 56 Kbps (thousand bits per second). K56flex was similar in
capability to US Robotics' x2 modem and transmission technology. K56flex and X2 contributed
to and were replaced by the ITU V.90 standard. Modems built with K56flex can be upgraded to
the V.90 standard by getting a software update from the modem manufacturer. (Note that
Rockwell does not build modems itself, but only the chipsets for them.) Conexant, a Rockwell
subsidiary company, now builds V.90 chipsets
V.92:
V.92 is the new dial-up modem specification from the ITU (International Telecommunications
Union) that introduces three new features that will add convenience and performance for the
modem user. The three features are Quick Connect, Modem-On-Hold and PCM Upstream.
BE
A
Quick Connect: Quick Connect will shorten the time it takes to make a connection by
remembering ("training") the phone line characteristics and storing them for later usage.
Typically, the modem handshake (all that noise you hear) takes from 25 to 27 seconds. Surveys
indicate that people are quite irritated at this length of time. Quick Connect will cut the modem
handshake time in half for most calls, a significant improvement.
Modem-On-Hold: Many households use the same phone line for both voice calls and data
(Internet), so when the user is browsing the Internet, an incoming call cannot get through.
Modem-on-Hold allows you to receive an incoming call and stay connected to the Internet (CallWaiting service from your phone company is all that is required). It also works in reverse; you
can initiate a voice call while connected and keep the modem connection.
PCM Upstream: PCM Upstream boosts the upstream data rates between the user and ISP to
reduce upload times for large files and email attachments. A maximum of 48 Kbps upstream rate
120
Computers
is supported. PCM Upstream will work particularly well with new equipment such as Internetconnected digital cameras, which primarily upload rather than download information.
DBMS
Database Management System or DBMS in short refers to the technology of storing and
retrieving users data with utmost efficiency along with appropriate security measures. DBMS
allows its users to create their own databases as per their requirement. These databases are highly
configurable and offer a bunch of options.
IN
Database is a collection of related data and data is a collection of facts and figures that can be processed
to produce information. Mostly data represents recordable facts.
GA
Data aids in producing information, which is based on facts. For example, if we have data about marks
obtained by all students, we can then conclude about toppers and average marks.
A database management system stores data in such a way that it becomes easier to retrieve, manipulate,
and produce information.
&
BE
A
121
Computers
BE
A
&
GA
IN
Characteristics
122
Computers
BE
A
&
GA
IN
Users
123
Computers
IN
GA
3-tier Architecture
&
An n-tier architecture divides the whole system into related but independent n modules, which
can be independently modified, altered, changed, or replaced.
BE
A
In 1-tier architecture, the DBMS is the only entity where the user directly sits on the DBMS and
uses it. Any changes done here will directly be done on the DBMS itself. It does not provide
handy tools for end-users. Database designers and programmers normally prefer to use singletier architecture.
If the architecture of DBMS is 2-tier, then it must have an application through which the DBMS
can be accessed. Programmers use 2-tier architecture where they access the DBMS by means of
an application. Here the application tier is entirely independent of the database in terms of
operation, design, and programming.
A 3-tier architecture separates its tiers from each other based on the complexity of the users and
how they use the data present in the database. It is the most widely used architecture to design a
DBMS.
Database (Data) Tier: At this tier, the database resides along with its query processing
languages. We also have the relations that define the data and their constraints at this
level.
Application (Middle) Tier: At this tier reside the application server and the programs that
access the database. For a user, this application tier presents an abstracted view of the
database. End-users are unaware of any existence of the database beyond the application.
At the other end, the database tier is not aware of any other user beyond the application
124
Computers
GA
IN
tier. Hence, the application layer sits in the middle and acts as a mediator between the
end-user and the database.
&
User (Presentation) Tier: End-users operate on this tier and they know nothing about any
existence of the database beyond this layer. At this layer, multiple views of the database can be
provided by the application. All views are generated by applications that reside in the application
tier.
Multiple-tier database architecture is highly modifiable, as almost all its components are
independent and can be changed independently.
Entity-Relationship Model
BE
A
The entity-relationship (E-R) data model is based on a perception of a real world that consists of
a collection of basic objects, called entities, and of relationships among these objects. An entity
is a thing or object in the real world that is distinguishable from other objects. For example,
each person is an entity, and bank accounts can be considered as entities.
Entities are described in a database by a set of attributes. For example, the attributes accountnumber and balance may describe one particular account in a bank, and they form attributes of
the account entity set. Similarly, attributes customer-name, customerstreet address and customercity may describe a customer entity.
An extra attribute customer-id is used to uniquely identify customers (since it may be possible to
have two customers with the same name, street address, and city). A unique customer identifier
must be assigned to each customer. In the United States, many enterprises use the social-security
number of a person (a unique number the U.S. government assigns to every person in the United
States) as a customer identifier.
A relationship is an association among several entities. For example, a depositor relationship
associates a customer with each account that she has. The set of all entities of 11 the same type
125
Computers
Entity
GA
IN
and the set of all relationships of the same type are termed an entity set and relationship set,
respectively. The overall logical structure (schema) of a database can be expressed graphically
by an E-R diagram.
&
For example, in a school database, a student is considered as an entity. Student has various
attributes like name, age, class, etc.
Relationship
BE
A
The logical association among entities is called relationship. Relationships are mapped with
entities in various ways. Mapping cardinalities define the number of association between two
entities.
Mapping cardinalities:
one to one
one to many
many to one
many to many
Super Key: A set of attributes (one or more) that collectively identifies an entity in an entity
set.
Candidate Key: A minimal super key is called a candidate key. An entity set may have more
than one candidate key.
Primary Key: A primary key is one of the candidate keys chosen by the database designer to
uniquely identify the entity set.
126
Computers
Relational Model
&
GA
IN
The most popular data model in DBMS is the Relational Model. It is more scientific a model
than others. This model is based on first-order predicate logic and defines a table as an n-ary
relation.
BE
A
Concept of RDBMS
Tables: In relational data model, relations are saved in the format of Tables. This format stores
the relation among entities. A table has rows and columns, where rows represent records and
columns represent the attributes.
Tuple: A single row of a table, which contains a single record for that relation is called a tuple.
127
Computers
Relation instance: A finite set of tuples in the relational database system represents relation
instance. Relation instances do not have duplicate tuples.
Relation schema: A relation schema describes the relation name (table name), attributes, and
their names.
Relation key: Each row has one or more attributes, known as relation key, which can identify the
row in the relation (table) uniquely.
Attribute domain: Every attribute has some predefined value scope, known as attribute domain.
Constraints
IN
Every relation has some conditions that must hold for it to be a valid relation. These conditions
are called Relational Integrity Constraints. There are three main integrity constraints:
GA
Key constraints
Domain constraints
Key Constraints
&
There must be at least one minimal subset of attributes in the relation, which can identify a tuple
uniquely. This minimal subset of attributes is called key for that relation. If there are more than
one such minimal subsets, these are called candidate keys. Key constraints force that:
BE
A
in a relation with a key attribute, no two tuples can have identical values for key attributes.
a key attribute cannot have NULL values.
Key constraints are also referred to as Entity Constraints.
Domain Constraints
Attributes have specific values in real-world scenario. For example, age can only be a positive
integer. The same constraints have been tried to employ on the attributes of a relation. Every
attribute is bound to have a specific range of values. For example, age cannot be less than zero
and telephone numbers cannot contain a digit outside 0-9.
Referential Integrity
Constraints Referential integrity constraints work on the concept of Foreign Keys. A foreign key
is a key attribute of a relation that can be referred in other relation.
128
Computers
Referential integrity constraint states that if a relation refers to a key attribute of a different or
same relation, then that key element must exist.
Relational Algebra
Relational algebra is a procedural query language, which takes instances of relations as input and
yields instances of relations as output. It uses operators to perform queries. An operator can be
either unary or binary. They accept relations as their input and yield relations as their output.
Relational algebra is performed recursively on a relation and intermediate results are also
considered relations.
The fundamental operations of relational algebra are as follows:
IN
Select
Project
GA
Union
Set different
Rename
&
Cartesian product
BE
A
129
Computers
BE
A
&
GA
IN
130
Computers
BE
A
&
GA
IN
131
Computers
GA
IN
Historically, two other data models, the network data model and the hierarchical data model,
preceded the relational data model. These models were tied closely to the underlying
implementation, and complicated the task of modeling data. As a result they are little used now,
except in old database code that is still in service in some places.
Types of Database System
&
Several criteria are normally used to classify DBMSs. The first is the data model on which the
DBMS is based. The main data model used in many current commercial DBMSs is the relational
data model. The object data model was implemented in some commercial systems but has not
had widespread use.
BE
A
Many legacy (older) applications still run on database systems based on the hierarchical and
network data models. The relational DBMSs are evolving continuously, and, in particular, have
been incorporating many of the concepts that were developed in object databases. This has led to
a new class of DBMSs called object-relational DBMSs. We can hence categorize DBMSs based
on the data model: relational, object, object-relational, hierarchical, network, and other.
The second criterion used to classify DBMSs is the number of users supported by the system.
Single-user systems support only one user at a time and are mostly used with personal
computers. Multiuser systems, which include the majority of DBMSs, support multiple users
concurrently. A third criterion is the number of sites over which the database is distributed. A
DBMS is centralized if the data is stored at a single computer site. A centralized DBMS can
support multiple users, but the DBMS and the database themselves reside totally at a single
computer site. A distributed DBMS (DDBMS) can have the actual database and DBMS software
distributed over many sites, connected by a computer network.
Homogeneous DDBMSs use the same DBMS software at multiple sites. A recent trend is to
develop software to access several autonomous preexisting databases stored under heterogeneous
llBMSs. This leads to a federated DBMS (or multidatabase system), in which the participating
DBMSs are loosely coupled and have a degree of local autonomy. Many DBMSs use a clientserver architecture.
132
Computers
Database Schema
A database schema is the skeleton structure that represents the logical view of the entire
database. It defines how the data is organized and how the relations among them are associated.
It formulates all the constraints that are to be applied on the data.
BE
A
&
GA
IN
A database schema defines its entities and the relationship among them. It contains a descriptive
detail of the database, which can be depicted by means of schema diagrams. Its the database
designers who design the schema to help programmers understand the database and make it
useful.
133
Computers
Data Independence
&
GA
IN
A database system normally contains a lot of data in addition to users data. For example, it
stores data about data, known as metadata, to locate and retrieve data easily. It is rather difficult
to modify or update a set of metadata once it is stored in the database. But as a DBMS expands,
it needs to change over time to satisfy the requirements of the users. If the entire data is
dependent, it would become a tedious and highly complex job.
Metadata itself follows a layered architecture, so that when we change data at one layer, it does
not affect the data at another level. This data is independent but mapped to each other.
BE
A
Logical data is data about database, that is, it stores information about how data is managed
inside. For example, a table (relation) stored in the database and all its constraints applied on that
relation.
Logical data independence is a kind of mechanism, which liberalizes itself from actual data
stored on the disk. If we do some changes on table format, it should not change the data residing
on the disk.
Physical Data Independence
All the schemas are logical, and the actual data is stored in bit format on the disk. Physical data
independence is the power to change the physical data without impacting the schema or logical
data.
For example, in case we want to change or upgrade the storage system itself suppose we want
to replace hard-disks with SSD it should not have any impact on the logical data or schemas.
134
Computers
BE
A
&
GA
IN
135
Computers
BE
A
&
GA
IN
136
Computers
BE
A
&
GA
IN
137
Computers
IN
GA
PASCAL Overview
&
Pascal is a general-purpose, high-level language that was originally developed by Niklaus Wirth
in the early 1970s. It was developed for teaching programming as a systematic discipline and to
develop reliable and efficient programs.
Pascal is Algol-based language and includes many constructs of Algol. Algol 60 is a subset of
Pascal. Pascal offers several data types and programming structures. It is easy to understand and
maintain the Pascal programs.
Pascal has grown in popularity in the teaching and academics arena for various reasons:
Easy to learn.
Structured language.
BE
A
It offers several data types like arrays, records, files and sets.
138
Computers
Pascal is based on the block structured style of the Algol programming language.
Pascal was the primary high-level language used for development in the Apple Lisa, and
in the early years of the Mac.
In 1986, Apple Computer released the first Object Pascal implementation, and in 1993,
the Pascal Standards Committee published an Object-Oriented Extension to Pascal.
&
GA
IN
BE
A
Pascal allows nested procedure definitions to any level of depth. This truly provides a great
programming environment for learning programming as a systematic discipline based on the
fundamental concepts.
Among the most amazing implementations of Pascal are
Skype
Total Commander
TeX
Macromedia Captivate
Apple Lisa
Various PC Games
Embedded Systems
139
Computers
Example:
program HelloWorld;
uses crt;
(* Here the main program block starts *)
begin
writeln('Hello, World!');
readkey;
IN
end.
GA
There are several Pascal compilers and interpreters available for general use. Among these are
Turbo Pascal provides an IDE and compiler for running Pascal programs on CP/M,
CP/M-86, DOS, Windows and Macintosh.
Delphi provides compilers for running Object Pascal and generates native code for 32-
Free Pascal it is a free compiler for running Pascal and Object Pascal programs. Free
Pascal compiler is a 32- and 64-bit Turbo Pascal and Delphi compatible Pascal compiler
&
and 64-bit Windows operating systems, as well as 32-bit Mac OS X and iOS.
Embarcadero is planning to build support for the Linux and Android operating system.
BE
A
for Linux, Windows, OS/2, FreeBSD, Mac OS X, DOS and several other platforms.
Turbo51 It is a free Pascal compiler for the 8051 family of microcontrollers, with
Turbo Pascal 7 syntax.
Oxygene It is an Object Pascal compiler for the .NET and Mono platforms.
GNU Pascal (GPC) It is a Pascal compiler composed of a front end to GNU Compiler
Collection.
140