Sie sind auf Seite 1von 140

BEAM & GAIN 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.

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.

IN
Components of a Computer
The five classic components of a computer are briefly described below. The operation of the
GA
processor is best understood in terms of these components.
The major hardware components of a computer system are:

 Processor(CPU)
 Storage unit
&
 Input devices
 Output devices
 Hardware
 Software
M

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
A

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
BE

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

BSNL JE STUDY MATERIAL 1


BEAM & GAIN Computers

individual switches, each switch physically constructed as a transistor, with only two states: on
or off I Recent CPU’s in mainstream PC’s 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.

 To store the input data until the CPU is ready for processing.

IN
 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.

Secondary storage Secondary storage Computer’s primary storage or main memory is volatile
M

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

Magnetic storage media fulfills these requirements and most common storage devices are disks
and tapes.
BE

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

BSNL JE STUDY MATERIAL 2


BEAM & GAIN 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.
 Touchpad: A touch pad is a device for pointing (controlling input positioning) on a
computer display screen. It is an alternative to the mouse. Originally incorporated in
laptop computers, touch pads are also being made for use with desktop computers. A

IN
touch pad works by sensing the user’s finger movement and downward pressure.
 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
GA
used on ATM machines, retail point-of-sale terminals, car navigation systems, medical
monitors and industrial control panels.
 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,
M

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
A

used in super markets, bookshops etc.


 Optical Scanner: These devices are used for automatic data collection. The devices of
BE

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 computer’s 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.

BSNL JE STUDY MATERIAL 3


BEAM & GAIN Computers

OUTPUT DEVICES

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

IN
are used with microcomputers, which are as follows: 1. CRT 2. LCD

 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
GA
formats. Some of the most commonly used printers are: 1. Laser Printer 2. Ink Jet Printer
3. Dot Matrix Printer 4. Line Printer.

 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
M

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

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

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

BSNL JE STUDY MATERIAL 4


BEAM & GAIN 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.
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

IN
integrates all parts into a unitary system. An example of a system software is an operating
system.

Application software serves more specific purposes, such as creating databases and spreadsheets
GA
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.
M

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
A

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
BE

activities of a computer system. It consists of the following:


• Central processing unit (CPU)
• Memory (primary and secondary storage)
• Input technologies
• Output technologies
• Communication technologies.

BSNL JE STUDY MATERIAL 5


BEAM & GAIN 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.
Mainframes

IN
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
GA
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.

At one time, supercomputer designers focused on building specialized, very fast, and very large
M

CPUs. Today, most supercomputer CPUs are constructed from thousands of microprocessors. Of
the 500 fastest supercomputers in the world, the majority use microprocessor technology.
A

Mini Computers
These computers are smaller and less experience than Mainframe and medium sized computers.
BE

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.

BSNL JE STUDY MATERIAL 6


BEAM & GAIN Computers

• Palmtop Computer/Digital Diary /Notebook /PDAs: a hand-sized computer. Palmtops have


no keyboard but the screen serves both as an input and output device.

DOS, FILE, DIRECTORY & FOLDER


DOS: short for disk operating system is an acronym for several computer operating systems that
are operated by using the command line. MS-DOS dominated the IBM PC compatible market
between 1981 and 1995 or until about 2001 including the partially MS-DOS-based Microsoft
Windows (95, 98, and Millennium Edition).
DOS is a single-user, single-tasking operating system with basic kernel functions that are non-
reentrant: only one program at a time can use them and DOS itself has no functionality to allow

IN
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
GA
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.
Some command:
&

CLS= This command is use to clear the terminal screen


DATE: Displays the system date and prompts the user to enter a new date. Complements
M

the TIME command.


DEL & ERASE: DEL (or the alternative form ERASE) is used to delete one or more files.
A

Cd: The cd command is the shorthand version of the ch dir command.


DIR: The DIR command displays the contents of a directory.
BE

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.

BSNL JE STUDY MATERIAL 7


BEAM & GAIN 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.

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.

IN
File Structure
File structure is a structure, which is according to a required format that operating system can
understand.


GA
A file has a certain defined structure according to its type.

 A text file is a sequence of characters organized into lines.


&
 A source file is a sequence of procedures and functions.

 An object file is a sequence of bytes organized into blocks that are understandable by the
M

machine.

 When operating system defines different file structures, it also contains the code to
A

support these file structure. Unix, MS-DOS support minimum number of file structure.
BE

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.

BSNL JE STUDY MATERIAL 8


BEAM & GAIN Computers

Number System

Conversation Between Number System

IN
 Decimal – To – Binary
GA
&
A M
BE

BSNL JE STUDY MATERIAL 9


BEAM & GAIN Computers

 Decimal - To - Octal

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 10


BEAM & GAIN Computers

 Decimal-to-Hexadecimal

IN
GA
&

 Binary-to-Decimal
A M
BE

BSNL JE STUDY MATERIAL 11


BEAM & GAIN Computers

 Octal-To-Decimal Conversion

IN
GA
 Hexadecimal-To-Decimal
&
A M
BE

BSNL JE STUDY MATERIAL 12


BEAM & GAIN Computers

 Fractional Conversion

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 13


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 14


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 15


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 16


BEAM & GAIN Computers

IN

GA
&
A M
BE

BSNL JE STUDY MATERIAL 17


BEAM & GAIN Computers

IN
GA
&
A M


BE

BSNL JE STUDY MATERIAL 18


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 19


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 20


BEAM & GAIN 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
nest, and these sequences of characters are not interpreted as comment delimiters if they appear
inside string or character literals.

IN
Character set

The basic C source character set includes the following characters:


 Decimal digits: 0 – 9
GA
Lowercase and uppercase letters: a – z A – Z

 Graphic characters: ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~


 Whitespace characters: space, horizontal tab, vertical tab, form feed, newline
&
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.
Keywords
M

C has 32 keywords. These keywords can’t be used as variable name.


A

Example: do, double, int, size of, while

Data Types
BE

C have four variables data types:

Int, char, float, double.

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.

BSNL JE STUDY MATERIAL 21


BEAM & GAIN 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];
char course[128];

IN
int age;
int year;
} student;

Unions
GA
&
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 –
M

union stud struct stud


{ {
A

int roll; int roll;


char name[4]; char name[4];
BE

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

BSNL JE STUDY MATERIAL 22


BEAM & GAIN Computers

All Union Members Occupy Same Memory Area

IN
GA
For the union maximum memory allocated will be equal to the data member with maximum size.
&
In the example character array ‘name’ have maximum size thus maximum memory of the union
will be 4 Bytes. Example:
M

union stud
{
A

int roll;
char name[4];
BE

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.

BSNL JE STUDY MATERIAL 23


BEAM & GAIN Computers

Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 24


BEAM & GAIN Computers

IN
GA
&
A M

Loops
Loop control statements in C are used to perform looping operations until the given condition is true. Control comes
BE

out of the loop statements once condition becomes false. There are 3 types of loops:

I. Control statements

II. decision making control statements


III. Case Control Statements

There are 3 types of loop control statements in C language. They are,

1. for
2. while
3. do-while

BSNL JE STUDY MATERIAL 25


BEAM & GAIN Computers

There are 3 types of decision making control statements in C language. They are,
1. if statements
2. if else statements
3. nested if statements
There are 4 types of case control statements in C language. They are,

1. switch
2. break
3. continue
4. goto

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 26


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 27


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 28


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 29


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 30


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 31


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 32


BEAM & GAIN Computers

IN
Result is: GA
&
A M
BE

BSNL JE STUDY MATERIAL 33


BEAM & GAIN Computers

IN
GA
&
A M
BE

Example

BSNL JE STUDY MATERIAL 34


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 35


BEAM & GAIN Computers

IN
GA
Example
&
A M
BE

BSNL JE STUDY MATERIAL 36


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 37


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 38


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 39


BEAM & GAIN Computers

Example

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 40


BEAM & GAIN Computers

IN
GA
Example
&
A M
BE

BSNL JE STUDY MATERIAL 41


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 42


BEAM & GAIN Computers

IN
GA
&
A M
BE

Example

BSNL JE STUDY MATERIAL 43


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 44


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 45


BEAM & GAIN Computers

IN
Example GA
&
A M
BE

BSNL JE STUDY MATERIAL 46


BEAM & GAIN Computers

IN
Function
GA
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.

Why we need functions


&
Functions are used because of following reasons –
a) To improve the readability of code.
b) Improves the reusability of the code, same function can be used in any program rather than
M

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.
d) Reduces the size of the code, duplicate set of statements are replaced by function calls.
A

Depending on whether a function is defined by the user or already included in C


BE

compilers, there are two types of functions in C programming:-

 Standard library functions


 User defined functions

Standard library functions


The standard library functions are in-built functions in C programming to handle tasks
such as mathematical computations, I/O processing, string handling etc.

BSNL JE STUDY MATERIAL 47


BEAM & GAIN 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.

User-defined functions

IN
As mentioned earlier, C language allows programmer to define functions. Such
functions created by the user are called user-defined functions.

GA
Depending upon the complexity and requirement of the program, you can create as
many user-defined functions as you want.

#include <stdio.h>
&

void functionName()
M

{
A

... .. ...
BE

int main()

... .. ...

functionName();

... .. ...

BSNL JE STUDY MATERIAL 48


BEAM & GAIN Computers

The execution of a C program begins from the main() function.

When the compiler encounters functionName(); inside the main function, control of
the program jumps to

void functionName()

IN
And, the compiler starts executing the codes inside the user-defined function.

The control of the program jumps to statement next to functionName(); once all the
GA
codes inside the function definition are executed.

Syntax of Defining a function


&
return_type function_name (argument list)
{
Set of statements – Block of code
}
M

return_type: Return type can be of any data type such as int, double, char, void, short etc. Don’t
worry you will understand these terms better once you go through the below examples.
A

function_name: It can be anything, however it is advised to have a meaningful name for the
BE

functions so that it would be easy to understand the purpose of function just by seeing it’s 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.

BSNL JE STUDY MATERIAL 49


BEAM & GAIN Computers

Advantages of user-defined function

1. The program will be easier to understand, maintain and debug.


2. Reusable codes that can be used in other programs
3. A large program can be divided into smaller modules. Hence, a large project can be
divided among many programmers.

Example :-

int square(int x)

IN
{
int square_of_x;
square_of_x = x * x;

}
return square_of_x; GA
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
when we square an integer we get an integer, and we are returning this integer, and so we write int as the return
type.
M

Next is the name of the function. It is good practice to use meaningful and descriptive names for functions you
may write. It may help to name the function after what it is written to do. In this case we name the function
A

"square", because that's what it does - it squares a number.


BE

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.

BSNL JE STUDY MATERIAL 50


BEAM & GAIN 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

Pointers are used in C program to access the memory and manipulate the address.

IN
When, argument is passed using pointer, address of the memory location is passed
instead of value.

Reference operator(&)
GA
If var is a variable then, &var is the address in memory.
&
/* Example to demonstrate use of reference operator in C programming. */
#include <stdio.h>
int main(){
M

int var=5;
printf("Value: %d\n",var);
A

printf("Address: %d",&var); //Notice, the ampersand(&) before var.


return 0;
BE

Output

Value: 5

Address: 2686778

Note: You may obtain different value of address while using this code.

BSNL JE STUDY MATERIAL 51


BEAM & GAIN 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
Dereference operator(*) are used for defining pointer variable

IN
data_type* pointer_variable_name;

int* p;
GA
Commonly done mistakes in pointers
&

Suppose, the programmer want pointer pc to point to the address of c. Then,


M

int c, *pc;
A

pc=c; /* pc is address whereas, c is not an address. */


BE

*pc=&c; /* &c is address whereas, *pc is not an address. */

Reference operator(*) and Pointer variables


Pointer variable or simply pointer are the special types of variables that holds memory
address rather than data, that is, a variable that holds address value is called a pointer
variable or simply a pointer.

Key points to remember about pointers in C:


 Normal variable stores the value whereas pointer variable stores the address of the variable.

BSNL JE STUDY MATERIAL 52


BEAM & GAIN Computers

 The content of the C pointer always be a whole number i.e. address.


 Always C pointer is initialized to null, i.e. int *p = null.
 The value of null pointer is 0.
 & symbol is used to get the address of the variable.
 * symbol is used to get the value of the variable that the pointer is pointing to.
 If pointer is assigned to NULL, it means it is pointing to nothing.
 Two pointers can be subtracted to know how many elements are available between these two pointers.
 But, Pointer addition, multiplication, division are not allowed.
 The size of any pointer is 2 byte (for 16 bit compiler).

 Function call by value in C programming

IN
This is the default way of calling a function in C.

Formal arguments: while declaring a function, the arguments list of parameters we specify are
known as formal parameters.
GA
Actual arguments: The parameter’s value (or arguments) we provide while calling a function is
known as actual arguments.
&
For example:

int sum(int a, int b)


M

{
int c=a+b;
return c;
}
A

int main(
{
BE

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

BSNL JE STUDY MATERIAL 53


BEAM & GAIN 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 doesn’t affect actual parameters. It may sound
confusing but let me explain this with the help of an example –

int increment(int var)


{
var = var+1;
return var;
}

IN
int main()
{
int num1=20;
int num2 = increment(num1);
printf("num1 value is: %d", num1);

}
printf("num2 value is: %d", num2);

return 0;
GA
Output:
&
num1 value is: 20
num2 value is: 21
Why did it happen? num1 is still have 20 even after increment operation, why?
M

The reason is simple, function is called by value in above program, which means num1’s value
gets copied into var and the variable var got incremented (not variable num1), which later stored
A

in num2, via call.


BE

 Function call by reference in C Programming

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 –

I’m taking the same example, which I took while explaining call by value method, however here
I’m using call by reference method –

int increment(int *var)

BSNL JE STUDY MATERIAL 54


BEAM & GAIN 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:

num1 value is: 21

IN
num2 value is: 21

Unlike “call by value”, in this method the value of num1 got changed because the address of
GA
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);
M

/*calling swap function*/


swapnum ( &num1, &num2 );
A

printf("After swapping: num1 value is %d and num2 value is %d", num1, num2);
}
BE

swapnum ( int *var1, int *var2 )


{
int tempnum ;

tempnum = *var1 ;
*var1 = *var2 ;
*var2 = tempnum ;
}
Output:

Before swapping: num1 value is 35 and num2 value is 45


After swapping: num1 value is 45 and num2 value is 35

BSNL JE STUDY MATERIAL 55


BEAM & GAIN Computers

When we tried to write the above code using call by value method, the value of both the integer
variables didn’t 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 low-
level 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
 C++ is derived from C Language. It is a Superset of C.
 Earlier C++ was known as C with classes.
 In C++, the major change was the addition of classes and a mechanism for inheriting class objects into
other classes.

GA
Most C Programs can be compiled in C++ compiler.
 C++ expressions are the same as C expressions.
 All C operators are valid in C++.
&
A M
BE

BSNL JE STUDY MATERIAL 56


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 57


BEAM & GAIN Computers

IN
GA
C++
C++ is an object-oriented language based on the C programming language. It can be viewed as a
&
superset of C. Almost all of the features and constructs available in C are also available in C++.
However, C++ is more than just an extension of C. Its additional features support the
programming style known as object-oriented programming. Several features that are already
available in C, such as input and output may be implemented differently in C++. In C++ you
M

may use the conventional C input and output routines or you may use object oriented input and
output by using the I/O Stream class library.
A

C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories. It was originally based on
the definition of the C language stated in The C Programming Language by Brian W. Kernighan
BE

and Dennis M. Ritchie. This C language definition is commonly called K&R C. Since then, the
International Standards Organization C language definition (referred to here as ISO/ANSI C )
has been approved. It specifies many of the features that K&R left unspecified. Some features of
ISO/ANSI C have been incorporated into the current definition of C++, and some parts of the
ISO/ANSI C definition have been motivated by C++. C++ is also called as “C with classes“.

C++ supports for the Structured programming and also it fully supports OOP

1. Encapsulation

2. Abstraction

BSNL JE STUDY MATERIAL 58


BEAM & GAIN Computers

3. Inheritance

4. Polymorphism.

IN
GA
&
C++ is a

1. Statically typed
M

2. Free-form

3. Multi-paradigm
A

4. Compiled
BE

5. General-purpose programming language.

6. Intermediate-level language,

BSNL JE STUDY MATERIAL 59


BEAM & GAIN Computers

OOPS Concept Definitions


Object-oriented programming (OOP) is a programming paradigm based on the concept of
"objects", which may contain data, in the form of fields, often known as attributes; and code, in
the form of procedures, often known as methods. A feature of objects is that an object's

IN
procedures can access and often modify the data fields of the object with which they are
associated (objects have a notion of "this" or "self"). In OOP, computer programs are designed
by making them out of objects that interact with one another. There is significant diversity of
OOP languages, but the most popular ones are class-based, meaning that objects are instances of
GA
classes, which typically also determine their type.

Now, let us discuss some of the main features of Object Oriented Programming which you will be using in
C++(technically).
&
1. Objects

2. Classes
M

3. Abstraction

4. Encapsulation
A

5. Inheritance
BE

6. Overloading

7. Exception Handling

 Objects: An object can be considered a "thing" that can perform a set


of related activities. The set of activities that the object performs defines the object's
behavior. For example, the Hand (object) can grip something, or a Student(object) can
give their name or address.

In pure OOP terms an object is an instance of a class.

 Classes: It is similar to structures in C language. Class can also be defined as user


defined data type but it also contains functions in it. So, class is basically a blueprint for
object. It declare & defines what data variables the object will have and what operations

BSNL JE STUDY MATERIAL 60


BEAM & GAIN Computers

can be performed on the class's object. A class is simply a representation of a type


of object. It is the blueprint, or plan, or template, that describes the details of an object. A
class is the blueprint from which the individual objects are created. Class is composed of
three things: a name, attributes, and operations.

 Class variables - belong to the class as a whole; there is only one copy of each one
 Instance variables or attributes - data that belongs to individual objects; every object has
its own copy of each one
 Member variables - refers to both the class and instance variables that are defined by a
particular class
 Class methods - belong to the class as a whole and have access only to class variables
and inputs from the procedure call

IN
 Instance methods - belong to individual objects, and have access to instance variables for
the specific object they are called on, inputs, and class variables.

{
public class Student
GA
}

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
M

the outside world and hiding their background details, i.e., to represent the needed
information in program without presenting the details.
A

Data abstraction is a programming (and design) technique that relies on the separation of
interface and implementation.
BE

 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).

BSNL JE STUDY MATERIAL 61


BEAM & GAIN 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.

Real world Example of Abstraction: -


Suppose you have an object Mobile Phone.

IN
Suppose you have 3 mobile phones as following:-

Nokia 1400 (Features:- Calling, SMS)


Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera)
GA
Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video
Recording, Reading E-mails)

Abstract information (Necessary and Common Information) for the object


"Mobile Phone" is make a call to any number and can send SMS."
&
so that, for mobile phone object you will have abstract class like following:-

abstract class MobilePhone


{
M

public void Calling();


public void SendSMS();
}
A

public class Nokia1400 : MobilePhone


BE

public class Nokia2700 : MobilePhone


{
public void FMRadio();
public void MP3();
public void Camera();
}

public class BlackBerry : MobilePhone


{
public void FMRadio();

BSNL JE STUDY MATERIAL 62


BEAM & GAIN Computers

public void MP3();


public void Camera();
public void Recording();
public void ReadAndSendEmails();

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

IN
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?
GA
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.
&
 Encapsulation: Data encapsulation is a mechanism of bundling the data, and the
functions that use them and data abstraction is a mechanism of exposing only the
interfaces and hiding the implementation details from the user.
M

Wrapping up data member and method together into a single unit (i.e. Class)
is called Encapsulation.
A

Encapsulation is like enclosing in a capsule. That is enclosing the related


operations and data related to an object into that object.
BE

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();
}

Encapsulation means hiding the internal details of an object, i.e. how an


object does something.

BSNL JE STUDY MATERIAL 63


BEAM & GAIN 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;
}
private:
double length;
double breadth;
// Length of a box
// Breadth of a box
GA
double height; // Height of a box
};
&
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
M

encapsulation is achieved.

To make parts of a class public (i.e., accessible to other parts of your program), you must
A

declare them after the public keyword. All variables or functions defined after the public
specifier are accessible by all other functions in your program.
BE

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.

BSNL JE STUDY MATERIAL 64


BEAM & GAIN Computers

IN
GA
&
M

 Polymorphisms: Polymorphisms is a generic term that means 'many shapes'. More


A

precisely Polymorphisms means the ability to request that the same operations be
performed by a wide range of different types of things. Polymorphism is the 3rd main
pillar of OOP without it the object oriented programming is incomplete. Lets go in the
BE

depth of Polymorphism.

Compile-time binding ( Static binding ) : Compile-time binding is to associate a


function’s name with the entry point of the function at compile time.

Run-time binding ( Dynamic binding ) : Run-time binding is to associate a function’s


name with the entry point at run-time. C++ supports run-time binding through virtual
functions. Polymorphism is thus implemented by virtual functions and run-time binding
mechanism in C++. A class is called polymorphic if it contains virtual functions.

BSNL JE STUDY MATERIAL 65


BEAM & GAIN 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

• A constructor cannot be virtual since it is used to construct an object.


GA
• A destructor can be virtual. Virtual destructors are very useful when some derived
classes have cleanup code.

Example:
&
class B

{
M

public:

virtual B(); // error


A

virtual ~B(); // ok
BE

virtual void f(); // ok

};

 Inheritance: One of the most important concepts in object-oriented programming is


that of inheritance. Inheritance allows us to define a class in terms of another class,
which makes it easier to create and maintain an application. This also provides an
opportunity to reuse the code functionality and fast implementation time.

BSNL JE STUDY MATERIAL 66


BEAM & GAIN 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.

When a class acquire the property of another class is known as inheritance.


Inheritance is process of object reusability.
For example, A Child acquire property of Parents.

IN
public class ParentClass
{
public ParentClass()
{

}
GA
Console.WriteLine("Parent Constructor.");

public void print()


{
Console.WriteLine("I'm a Parent Class.");
&
}
}

public class ChildClass : ParentClass


M

{
public ChildClass()
{
A

Console.WriteLine("Child Constructor.");
}
BE

public static void Main()


{
ChildClass child = new ChildClass();

child.print();
}
}

BSNL JE STUDY MATERIAL 67


BEAM & GAIN Computers

Output:
Parent Constructor.
Child Constructor.
I'm a Parent Class.

Base & Derived Classes:


A class can be derived from more than one classes, which means it can inherit data and
functions from multiple base classes. To define a derived class, we use a class derivation list to
specify the base class(es). A class derivation list names one or more base classes and has the
form:

IN
class derived-class: access-specifier base-class

Where access-specifier is one of public, protected, or private, and base-class is the name of a
GA
previously defined class. If the access-specifier is not used, then it is private by default.

Consider a base class Shape and its derived class Rectangle as follows:

#include <iostream>
&

using namespace std;


M

// Base class
class Shape
A

{
public:
BE

void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;

BSNL JE STUDY MATERIAL 68


BEAM & GAIN Computers

int height;
};

// Derived class
class Rectangle: public Shape
{
public:
int getArea()
{
return (width * height);

IN
}
};

int main(void)
GA
{
Rectangle Rect;
&

Rect.setWidth(5);
Rect.setHeight(7);
M

// Print the area of the object.


A

cout << "Total area: " << Rect.getArea() << endl;


BE

return 0;
}

When the above code is compiled and executed, it produces the following result:

Total area: 35

Access Control and Inheritance:


A derived class can access all the non-private members of its base class. Thus base-class
members that should not be accessible to the member functions of derived classes should be
declared private in the base class.

BSNL JE STUDY MATERIAL 69


BEAM & GAIN Computers

We can summarize the different access types according to who can access them in the following
way:

IN
A derived class inherits all base class methods with the following exceptions:

 Constructors, destructors and copy constructors of the base class.


GA
Overloaded operators of the base class.

 The friend functions of the base class.

Type of Inheritance:
&
When deriving a class from a base class, the base class may be inherited through public,
protected or private inheritance. The type of inheritance is specified by the access-specifier as
M

explained above.

We hardly use protected or private inheritance, but public inheritance is commonly used.
A

While using different type of inheritance, following rules are applied:


BE

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

 Protected Inheritance: When deriving from a protected base class,


public and protected members of the base class become protected members of the
derived class.

BSNL JE STUDY MATERIAL 70


BEAM & GAIN Computers

 Private Inheritance: When deriving from a private base class,


public and protected members of the base class become private members of the
derived class.

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

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:

IN
#include <iostream>

using namespace std; GA


// Base class Shape
class Shape
&
{
public:
void setWidth(int w)
M

{
width = w;
A

}
void setHeight(int h)
BE

{
height = h;
}
protected:
int width;
int height;
};

// Base class PaintCost


class PaintCost

BSNL JE STUDY MATERIAL 71


BEAM & GAIN Computers

{
public:
int getCost(int area)
{
return area * 70;
}
};

// Derived class
class Rectangle: public Shape, public PaintCost

IN
{
public:
int getArea()
{
GA
return (width * height);
}
&
};

int main(void)
M

{
Rectangle Rect;
A

int area;
BE

Rect.setWidth(5);
Rect.setHeight(7);

area = Rect.getArea();

// Print the area of the object.


cout << "Total area: " << Rect.getArea() << endl;

// Print the total cost of painting


cout << "Total paint cost: $" << Rect.getCost(area) << endl;

BSNL JE STUDY MATERIAL 72


BEAM & GAIN 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

1. Single Inheritance

IN
2. Multiple Inheritance
3. Multilevel Inheritance
4. Hybrid Inheritance
5. Hierarchical Inheritance GA
&
A M
BE

BSNL JE STUDY MATERIAL 73


BEAM & GAIN 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.

Characteristics of a Data Structure


 Correctness − Data Structure implementation should implement its interface correctly.

 Time Complexity − Running time or execution time of operations of data structure must
be as small as possible.

IN
 Space Complexity − Memory usage of a data structure operation should be as little as
possible.

Need for Data Structure


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

 Multiple requests − As thousands of users can search data simultaneously on a web


server,even very fast server fails while searching the data.
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
BE

searched almost instantly.

Execution Time Cases


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.

BSNL JE STUDY MATERIAL 74


BEAM & GAIN 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.

 Data Item − Data item refers to single unit 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

IN
which may be assigned values.

 Entity Set − Entities of similar attributes form an entity set.


entity.
GA
Field − Field is a single elementary unit of information representing an attribute of an

 Record − Record is a collection of field values of a given entity.

 File − File is a collection of records of the entities in a given entity set.


&

Stack

A stack is an abstract data type (ADT), commonly used in most programming languages. It is
M

named stack as it behaves like a real-world stack, for example − deck of cards or pile of plates
etc.
A

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
BE

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.

BSNL JE STUDY MATERIAL 75


BEAM & GAIN Computers

IN
GA
&

Basic Operations
Stack operations may involve initializing the stack, using it and then de-initializing it. Apart
M

from these basic stuffs, a stack is used for the following two primary operations −

 push() − pushing (storing) an element on the stack.


A

 pop() − removing (accessing) an element from the stack.


BE

 isFull() − check if stack is full.

 isEmpty() − check if stack is empty.

isfull()
Algorithm of isfull() function −

begin procedure isfull

if top equals to MAXSIZE


return true
else

BSNL JE STUDY MATERIAL 76


BEAM & GAIN Computers

return false
endif

end procedure

Implementation of isfull() function in C programming language −

bool isfull() {
if(top == MAXSIZE)
return true;

IN
else
return false;
} GA
isempty()
Algorithm of isempty() function −

begin procedure isempty


&

if top less than 1


M

return true
else
A

return false
endif
BE

end procedure

Implementation of isempty() function in C programming language is slightly different. We


initialize top at -1, as index in array starts from 0. So we check if top is below zero or -1 to
determine if stack is empty. Here's the code −

bool isempty() {
if(top == -1)
return true;
else

BSNL JE STUDY MATERIAL 77


BEAM & GAIN 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 2 − If stack is full, produce error and exit.

 Step 3 − If stack is not full, increment top to point next empty space.

IN
 Step 4 − Add data element to the stack location, where top is pointing.

 Step 5 − return success.

GA
&
M

if linked-list is used to implement stack, then in step 3, we need to allocate space dynamically.
A

Algorithm for PUSH operation


BE

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

BSNL JE STUDY MATERIAL 78


BEAM & GAIN 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;
stack[top] = data;

IN
}else {
printf("Could not insert data, Stack is full.\n");
} GA
}

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.

A POP operation may involve the following steps −


M

 Step 1 − Check if stack is empty.


A

 Step 2 − If stack is empty, produce error and exit.

 Step 3 − If stack is not empty, access the data element at which topis pointing.
BE

 Step 4 − Decrease the value of top by 1.

 Step 5 − return success.

BSNL JE STUDY MATERIAL 79


BEAM & GAIN Computers

IN
Algorithm for POP operation
A simple algorithm for Pop operation can be derived as follows −

begin procedure pop: stack


GA
if stack is empty
&
return null
endif
M

data ← stack[top]
A

top ← top - 1
BE

return data

end procedure

Implementation of this algorithm in C, is shown below −

int pop(int data) {

if(!isempty()) {

BSNL JE STUDY MATERIAL 80


BEAM & GAIN Computers

data = stack[top];
top = top - 1;
return data;
}else {
printf("Could not retrieve data, Stack is empty.\n");
}
}

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

IN
of expression. These notations are −

 Infix Notation
 Prefix (Polish) Notation
 Postfix (Reverse-Polish) Notation
GA
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.
M

Prefix Notation
In this notation, operator is prefixed to operands, i.e. operator is written ahead of operands. For
A

example +ab. This is equivalent to its infix notation a+b. Prefix notation is also known
as Polish Notation.
BE

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.

BSNL JE STUDY MATERIAL 81


BEAM & GAIN Computers

IN
Parsing Expressions
GA
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.
&

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 −
A M

Postfix Evaluation Algorithm


BE

We shall now look at the algorithm on how to evaluate postfix notation −

Step 1 − scan the expression from left to right


Step 2 − if it is an operand push it to stack
Step 3 − if it is an operator pull operand from stack and perform operation
Step 4 − store the output of step 3, back to stack
Step 5 − scan the expression until all operands are consumed
Step 6 − pop the stack and perform operation

Queue Representation

Queue is an abstract data structure, somewhat similar to Queue. In contrast to Queue, queue is
opened at both end. One end is always used to insert data (enqueue) and the other is used to

BSNL JE STUDY MATERIAL 82


BEAM & GAIN Computers

remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored
first will be accessed first.

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

IN
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.
GA
C Program source code to help you get an idea of how a queue is implemented in code.

Algorithm:

Queue structure is defined with fields capacity, size, *elements (pointer to the array of
&
elements), front and rear.

Functions –
M

1. createQueue function– This function takes the maximum number of elements


A

(maxElements) the Queue can hold as an argument, creates a Queue according to it


and returns a pointer to the Queue.
BE

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.
 isfull() − checks if queue is full.

 isempty() − checks if queue is empty.

isfull()

BSNL JE STUDY MATERIAL 83


BEAM & GAIN 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



 if rear equals to MAXSIZE
 return true
 else
 return false
 endif

IN
 end procedure

Properties:
GA
1. Each function runs in O(1) time.
2. It has two basic implementations
&
Array-based implementation – It’s simple and efficient but the maximum size of
the queue is fixed.
Singly Linked List-based implementation – It’s complicated but there is no limit
M

on the queue size, it is subjected to the available memory.


A
BE

BSNL JE STUDY MATERIAL 84


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 85


BEAM & GAIN Computers

Linked Lists
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.

IN
Linked List is a sequence of links which contains items. Each link contains a connection to
another link. Linked list the second most used data structure after array. Following are


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

Linked List Representation


M

Linked list can be visualized as a chain of nodes, where every node points to the next node.
A
BE

As per above shown illustration, following are the important points to be considered.

 LinkedList contains an link element called first.


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

BSNL JE STUDY MATERIAL 86


BEAM & GAIN Computers

 Last Link carries a Link as null to mark the end of the list.
Types of Linked List
Following are the various flavours of linked list.

 Simple Linked List − Item Navigation is forward only.

IN
 Doubly Linked List − Items can be navigated forward and backward way.
GA
&

Circular Linked List − Last item contains link of the first element as next and and first
M


element has link to last element as prev.
A
BE

BSNL JE STUDY MATERIAL 87


BEAM & GAIN Computers

Basic Operations
Following are the basic operations supported by a list.

 Insertion − add an element at the beginning of the list.

 Deletion − delete an element at the beginning of the list.

 Display − displaying complete list.

 Search − search an element using given key.

 Delete − delete an element using given key.

IN
Insertion Operation
Insertion is a three step process −

 Create a new Link with provided data.


GA
 Point New Link to old First Link.
 Point First Link to this New Link.
&

//insert link at the first location


M

void insertFirst(int key, int data){


//create a link
A

struct node *link = (struct node*) malloc(sizeof(struct node));


BE

link->key = key;
link->data = data;

//point it to old first node


link->next = head;

//point first to new first node


head = link;
}

BSNL JE STUDY MATERIAL 88


BEAM & GAIN Computers

IN
GA
&
A M

Deletion Operation
Deletion is a two step process −
BE

 Get the Link pointed by First Link as Temp Link.


 Point First Link to Temp Link's Next Link.

BSNL JE STUDY MATERIAL 89


BEAM & GAIN Computers

//delete first item


struct node* deleteFirst(){
//save reference to first link

IN
struct node *tempLink = head;

//mark next to first link as first GA


head = head->next;

//return the deleted link


&
return tempLink;
}
M

Advantages of Linked Lists


A

 They are a dynamic in nature which allocates the memory when required.
 Insertion and deletion operations can be easily implemented.
BE

 Stacks and queues can be easily executed.


 Linked List reduces the access time.

Disadvantage of Linked Lists

 The memory is wasted as pointers require extra memory for storage.


 No element can be accessed randomly; it has to access each node sequentially.
 Reverse Traversing is difficult in linked list.

Graphs
A graph is a set of vertices and edges which connect them. We write:

BSNL JE STUDY MATERIAL 90


BEAM & GAIN Computers

G = (V,E)

where V is the set of vertices and the set of edges,

E = { (vi,vj) }

where vi and vj are in V.

IN
In the above graph,
GA
V = {a, b, c, d, e}
&
E = {ab, ac, bd, cd, de}
M

Paths

A path, p, of length, k, through a graph is a sequence of connected vertices:


A

p = <v0,v1,...,vk>
where, for all i in (0,k-1:
BE

(vi,vi+1) is in E.
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.

BSNL JE STUDY MATERIAL 91


BEAM & GAIN Computers

Next important set is E, which is called edge-set. E is a subset of V x V. Simply speaking,


each edge connects two vertices, including a case, when a vertex is connected to itself
(such an edge is called a loop). All graphs are divided into two big groups: directed and
undirected graphs. The difference is that edges in directed graphs, called arcs, have a
direction. These kinds of graphs have much in common with each other, but significant
differences are also present. We will accentuate which kind of graphs is considered in the
particular algorithm description. Edge can be drawn as a line. If a graph is directed, each
line has an arrow.

IN
GA
Now, we present some basic graph definitions.

 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.
A M
BE

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.

BSNL JE STUDY MATERIAL 92


BEAM & GAIN Computers

IN
Recognizing a graph problem
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 don’t usually spell it
out for you. Nearly all graph problems will somehow use a grid or network in the problem,
GA
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.
&
Graph Data Structure
Mathematical graphs can be represented in data-structure. We can represent a graph using an
array of vertices and a two dimensional array of edges. Before we proceed further, let's
familiarize ourselves with some important terms −
M

 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
A

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

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

BSNL JE STUDY MATERIAL 93


BEAM & GAIN Computers

IN
Tree
GA
Basic Operations
&
Following are basic primary operations of a Graph which are following.

 Add Vertex − add a vertex to a graph.


M

 Add Edge − add an edge between two vertices of a graph.


A

 Display Vertex − display a vertex of a graph.


BE

BSNL JE STUDY MATERIAL 94


BEAM & GAIN 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:

( Here index is a pointer to an address )


GA
&
A M

The concept of a logical address space that is bound to a separate physical address space is
central to proper memory management.
BE

 Logical address – generated by the CPU; also referred to as virtual address


 Physical address – address seen by the memory unit

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?

BSNL JE STUDY MATERIAL 95


BEAM & GAIN Computers

• This is called mapping logical to physical addresses.

• This binding can be done at compile/link time. Converts symbolic to relocatable. Data used
within compiled source is offset within object module.

Compiler: If it’s known where the program will reside, then absolute code is generated.
Otherwise compiler produces relocatable code.

Load: Binds relocatable to physical. Can find best physical location.

Execution: The code can be moved around during execution. Means flexible virtual mapping.

Memory hierarchy

IN
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 very-
high-speed memory to increase the processing speed.
GA
&
A M
BE

Multiprogramming - enable the CPU to process a number of independent program


concurrently.

Memory Management System - supervise the flow of information between auxiliary memory
and main memory.

Main Memory (RAM) Organisation


Computers employ many different types of memory (semi-conductor, magnetic disks, USB
sticks, DVDs etc.) to hold data and programs. Each type has its own characteristics and uses. We
will look at the way that Main Memory (RAM) is organised and briefly at the characteristics of

BSNL JE STUDY MATERIAL 96


BEAM & GAIN Computers

Register Memory and Disk Memory. Let us locate these 3 types of memory in a simplified
model of a computer:

IN
GA
&
Registers

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
M

than 64 bits; 32-bit and more recently 64-bit are common in desktops.

The contents of a register can be “read” or “written” very quickly however, often an order of
A

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
BE

general use by the programmer. Unless the context implies otherwise we‟ll use the term
"register" to refer to a General Purpose Register within the CPU. Most modern CPU‟s 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

BSNL JE STUDY MATERIAL 97


BEAM & GAIN 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.

Main Memory (RAM)

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.

IN
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
GA
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.
M

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

Disk memory
BE

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

BSNL JE STUDY MATERIAL 98


BEAM & GAIN Computers

Classification of Computer memory

Memory is an essential element of a computer. Without its memory, a computer is of hardly any
use. Memory plays an important role in saving and retrieving data. The performance of the
computer system depends upon the size of the memory. Memory is of following types:

1. Primary Memory / Volatile Memory.


2. Secondary Memory / Non Volatile Memory.

IN
GA
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:
&

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
M

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
A

.So now we can say that RAM is volatile memory.


BE

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

BSNL JE STUDY MATERIAL 99


BEAM & GAIN 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.

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

IN
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.
GA
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.
&

Secondary Memory / Non-Volatile Memory: Secondary memory is external and permanent in


nature. The secondary memory is concerned with magnetic memory. Secondary memory can be
M

stored on storage media like floppy disks, magnetic disks, magnetic tapes, This memory can also
be stored optically on Optical disks - CD-ROM. The following terms comes under secondary
memory of a computer are discussed below:
A

Magnetic Tape: Magnetic tapes are used for large computers like mainframe computers where
large volume of data is stored for a longer time. In PC also you can use tapes in the form of
BE

cassettes. The cost of storing data in tapes is inexpensive. Tapes consist of magnetic materials
that store data permanently. It can be 12.5 mm to 25 mm wide plastic film-type and 500 meter to
1200 meter long which is coated with magnetic material. The deck is connected to the central
processor and information is fed into or read from the tape through the processor. It’s similar to
cassette tape recorder.

Magnetic Disk: You might have seen the gramophone record, which is circular like a disk and
coated with magnetic material. Magnetic disks used in computer are made on the same principle.
It rotates with very high speed inside the computer drive. Data is stored on both the surface of
the disk. Magnetic disks are most popular for direct access storage device. Each disk consists of
a number of invisible concentric circles called tracks. Information is recorded on tracks of a disk
surface in the form of tiny magnetic spots. The presence of a magnetic spot represents one bit
and its absence represents zero bit. The information stored in a disk can be read many times

BSNL JE STUDY MATERIAL 100


BEAM & GAIN 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

What is Operating System?

IN
An operating system or OS is a software program that enables the computer hardware to
communicate and operate with the computer software. Without a computer operating system, a
computer and software programs would be useless. The picture is an example
of MicrosoftWindows XP, a popular operating system and what the box may look like if you
GA
were to visit a local retail store to purchase it.

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.
&
Examples of computer operating systems

Microsoft Windows 7 - PC and IBM compatible operating system. Microsoft Windows is the
M

most common and used operating system.


Apple MacOS - Apple Mac operating system. The only Apple computer operating system
A

is MacOS.
BE

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.

Classification of Operating systems


Multi-user: Allows two or more users to run programs at the same time. Some operating
systems permit hundreds or even thousands of concurrent users.

Multiprocessing: Supports running a program on more than one CPU.

Multitasking: Allows more than one program to run concurrently.

BSNL JE STUDY MATERIAL 101


BEAM & GAIN Computers

Multithreading: Allows different parts of a single program to run concurrently.

Real time: Responds to input instantly. General-purpose operating systems, such


as DOS and UNIX, are not real-time.

Data Communication
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

IN
computers to exchange data.

GA
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
M

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.
A
BE

Components of data communication system

A Communication system has following components:

1. Message: It is the information or data to be communicated. It can consist of text, numbers,


pictures, sound or video or any combination of these.

2. Sender: It is the device/computer that generates and sends that message.

BSNL JE STUDY MATERIAL 102


BEAM & GAIN 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.

A protocol performs the following functions:

IN
1. Data sequencing. It refers to breaking a long message into smaller packets of fixed size. Data
sequencing rules define the method of numbering packets to detect loss or duplication of packets,
GA
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
M

the flow of data on communication lines.

5. Error control. These rules are designed to detect errors in messages and to ensure
A

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
BE

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.

BSNL JE STUDY MATERIAL 103


BEAM & GAIN Computers

IN
8. Data security. Providing data security and privacy is also built into most communication
GA
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.
&

Types of Data Transmission Modes


M

Different types of data transmission modes are as follows:

1. Simplex mode
A

2. Half-duplex mode
3. Full-duplex mode
BE

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.

BSNL JE STUDY MATERIAL 104


BEAM & GAIN 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.

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.

IN
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
GA
server to the user's computer. At a time a user can a request or receive the data of web page.

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.
A M
BE

Data Transmission

Data transmission, digital transmission or digital communications is the physical transfer of


over a point-to-point or point-to-multipoint communication channel. Examples of such channels
are copper wires, optical fibers, wireless communication channels, storage media and computer buses. The
data are represented as an electromagnetic signal, such as an electrical voltage, radiowave, microwave,
or infrared signal.

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.

BSNL JE STUDY MATERIAL 105


BEAM & GAIN Computers

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.

IN
GA
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.
A M
BE

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 computer’s 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

BSNL JE STUDY MATERIAL 106


BEAM & GAIN 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

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: ·

IN
 Synchronous
 Asynchronous

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

Imagine howdifficultitwouldbetoreadifyoudidnotknowwhenawordstartedan dwhenaworden


dediftherewerenopunctuationandnospacesyoucandoitbecaus ethereareseveraldifferent
&
charactersanditisnotincodewhatifthiswerecodedas zerosandonesthenyouwouldhaverealproblems.
As you can see, synchronization of data is very important.

Clocking is somewhat like timing in music. There are a specific number of beats expected per
M

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
A

signal. Usually, they are already prepared to leave the classroom. That is because they expected
the signal.
BE

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

BSNL JE STUDY MATERIAL 107


BEAM & GAIN 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

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.

IN
GA
&

OSI communication is as follows: ·


M

 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.
A

 Data starts at the application layer of the source device and descends through the
remaining layers before being transmitted to the destination device.
BE

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

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

BSNL JE STUDY MATERIAL 108


BEAM & GAIN 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

1. Big picture of communication over network is understandable through this OSI model.
2. We see how hardware and software work together.
3. We can understand new technologies as they are developed.
4. Troubleshooting is easier by separate networks.
5. Can be used to compare basic functional relationships on different networks.

IN
 PHYSICAL Layer - OSI Model
Physical layer is the lowest layer of all. It is responsible for sending bits from one computer to
GA
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.

Function of Physical layer


M

Representation of Bits: Data in this layer consists of stream of bits. The bits must be encoded into signals
A

for transmission. It defines the type of encoding i.e. how 0’s and 1’s are changed to signal.
BE

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.

BSNL JE STUDY MATERIAL 109


BEAM & GAIN 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.

Deals with baseband and broadband transmission.

IN
GA
&

Overview of physical layer


M

1. It is the lowest layer of the OSI Model.


2. It activates, maintains and deactivates the physical connection.
A

3. It is responsible for transmission and reception of the unstructured raw data over network.
BE

4. Voltages and data rates needed for transmission is defined in the physical layer.
5. It converts the digital/analog bits into electrical signal or optical signals.
6. Data encoding is also done in this layer.

 DATA LINK Layer - OSI Model

Data link layer is most reliable node to node delivery of data. It forms frames from the packets
that are received from network layer and gives it to physical layer. It also synchronizes the
information which is to be transmitted over the data. Error controlling is easily done. The
encoded data are then passed to physical.

BSNL JE STUDY MATERIAL 110


BEAM & GAIN 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.

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.

IN
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.
GA
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.

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.
&
A M
BE

Function Of Data Link Layer

1. Data link layer synchronizes the information which is to be transmitted over the physical
layer.
2. The main function of this layer is to make sure data transfer is error free from one node to
another, over the physical layer.

BSNL JE STUDY MATERIAL 111


BEAM & GAIN Computers

3. Transmitting and receiving data frames sequentially is managed by this layer.


4. This layer sends and expects acknowledgements for frames received and sent
respectively. Resending of non-acknowledgement received frames is also handled by this
layer.
5. This layer establishes a logical layer between two nodes and also manages the Frame
traffic control over the network. It signals the transmitting node to stop, when the frame
buffers are full.

 Network Layer - OSI Model


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.

IN
It also divides the outgoing messages into packets and to assemble incoming packets into
messages for higher levels.

GA
&
A M
BE

Function Of Network Layer

1. It routes the signal through different channels from one node to other.
2. It acts as a network controller. It manages the Subnet traffic.
3. It decides by which route data should take.
4. It divides the outgoing messages into packets and assembles the incoming packets into
messages for higher levels.

 Transport Layer - OSI Model


The main aim of transport layer is to be delivered the entire message from source to destination.
Transport layer ensures whole message arrives intact and in order, ensuring both error control

BSNL JE STUDY MATERIAL 112


BEAM & GAIN Computers

and flow control at the source to destination level. It decides if data transmission should be on
parallel path or single path
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.

IN
Function Of Transport Layer
GA
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.
M

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

a. Connectionless Transport Layer : Each segment is considered as an independent


packet and delivered to the transport layer at the destination machine.
BE

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.

 Session Layer - OSI Model


Its main aim is to establish, maintain and synchronize the interaction between communicating
systems. Session layer manages and synchronize the conversation between two different
applications. Transfer of data from one destination to another session layer streams of data are

BSNL JE STUDY MATERIAL 113


BEAM & GAIN Computers

marked and are resynchronized properly, so that the ends of the messages are not cut prematurely
and data loss is avoided.

IN
Function Of Session Layer
GA
Dialog Control : This layer allows two systems to start communication with each other in half-
duplex 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
M

successfully received and acknowledged. This is beneficial at the time of crash as if a crash
happens at page number 110; there is no need to retransmit 1 to100 pages.
A
BE

 Presentation Layer - OSI Model


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.

BSNL JE STUDY MATERIAL 114


BEAM & GAIN Computers

IN
Function of Presentation Layer
GA
1. Translation : Before being transmitted, information in the form of characters and
numbers should be changed to bit streams. The presentation layer is responsible for
interoperability between encoding methods as different computers use different encoding
methods. It translates data between the formats the network requires and the format the
computer.
&
2. Encryption : It carries out encryption at the transmitter and decryption at the receiver.
3. Compression : It carries out data compression to reduce the bandwidth of the data to be
transmitted. The primary role of Data compression is to reduce the number of bits to be
M

0transmitted. It is important in transmitting multimedia such as audio, video, text etc.


A

 Application Layer - OSI Model


It is the top most layer of OSI Model. Manipulation of data (information) in various ways is done
BE

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.

BSNL JE STUDY MATERIAL 115


BEAM & GAIN Computers

Functions of Application Layer

IN
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. User’s computer talks to the
GA
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.
M

The TCP/IP Reference Model


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
A

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
BE

schemes.

BSNL JE STUDY MATERIAL 116


BEAM & GAIN 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 layers—network interface, internet and (host-to-
host) transport—correspond to layers 2, 3 and 4 of the OSI model. The TCP/IP application layer
conceptually “blurs” the top three OSI layers. It’s 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

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

IN
Transfer Protocol (HTTP), Simple Mail Transport Protocol (SMTP) and File Transfer Protocol
(FTP).

At this layer sockets and port numbers are used to differentiate the path and sessions which
GA
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
&

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
M

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
A

the data is sent, UDP will not carry out any checks to see that it has safely arrived.
BE

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.

BSNL JE STUDY MATERIAL 117


BEAM & GAIN Computers

Difference between OSI and TCP/IP Model

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 118


BEAM & GAIN 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
V.22:
Provides 1200 bits per second at 600 baud (state changes per second).

V.22bis:
GA
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.
M

V.32terbo:
Provides 19,200 bits per second or fallback to 12,000, 9600, 7200, and 4800 bits per second; can
A

operate at higher data rates with compression; was not a CCITT/ITU standard.
BE

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.

BSNL JE STUDY MATERIAL 119


BEAM & GAIN 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.

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.

IN
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
GA
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
M

modem user. The three features are Quick Connect, Modem-On-Hold and PCM Upstream.

Quick Connect: Quick Connect will shorten the time it takes to make a connection by
A

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
BE

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 (Call-
Waiting 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

BSNL JE STUDY MATERIAL 120


BEAM & GAIN Computers

is supported. PCM Upstream will work particularly well with new equipment such as Internet-
connected 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.

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.

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

GA
A database management system stores data in such a way that it becomes easier to retrieve, manipulate,
and produce information.

 Collection of interrelated data


 Set of programs to access the data
&
 DBMS provides an environment that is both convenient and efficient to use.
A M
BE

BSNL JE STUDY MATERIAL 121


BEAM & GAIN Computers

Characteristics

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 122


BEAM & GAIN Computers

IN
GA
&
A M

Users
BE

BSNL JE STUDY MATERIAL 123


BEAM & GAIN Computers

IN
3-tier Architecture GA
The design of a DBMS depends on its architecture. It can be centralized or decentralized or
hierarchical. The architecture of a DBMS can be seen as either single tier or multi-tier.

An n-tier architecture divides the whole system into related but independent n modules, which
&
can be independently modified, altered, changed, or replaced.

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
M

handy tools for end-users. Database designers and programmers normally prefer to use single-
tier architecture.
A

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
BE

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

BSNL JE STUDY MATERIAL 124


BEAM & GAIN Computers

tier. Hence, the application layer sits in the middle and acts as a mediator between the
end-user and the database.

IN
GA
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
M

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
A

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

Entities are described in a database by a set of attributes. For example, the attributes account-
number 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 customer-
city 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

BSNL JE STUDY MATERIAL 125


BEAM & GAIN Computers

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.

IN
 Entity
GA
An entity in an ER Model is a real-world entity having properties called attributes. Every
attribute is defined by its set of values called domain.

For example, in a school database, a student is considered as an entity. Student has various
attributes like name, age, class, etc.
&
 Relationship

The logical association among entities is called relationship. Relationships are mapped with
M

entities in various ways. Mapping cardinalities define the number of association between two
entities.
A

Mapping cardinalities:

 one to one
BE

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

BSNL JE STUDY MATERIAL 126


BEAM & GAIN Computers

Relational Model

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.

IN
GA
&
M

The main highlights of this model are:

 Data is stored in tables called relations.


A

 Relations can be normalized.


BE

 In normalized relations, values saved are atomic values.

 Each row in a relation contains a unique value.

 Each column in a relation contains values from a same domain.

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.

BSNL JE STUDY MATERIAL 127


BEAM & GAIN 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

Every relation has some conditions that must hold for it to be a valid relation. These conditions

IN
are called Relational Integrity Constraints. There are three main integrity constraints:

 Key constraints

 Domain constraints
GA
 Referential integrity 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:
M

 in a relation with a key attribute, no two tuples can have identical values for key attributes.
A

 a key attribute cannot have NULL values.


BE

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.

BSNL JE STUDY MATERIAL 128


BEAM & GAIN 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:

 Select

IN
 Project

 Union GA
 Set different

 Cartesian product
&
 Rename

We will discuss all these operations in the following sections.


A M
BE

BSNL JE STUDY MATERIAL 129


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 130


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 131


BEAM & GAIN Computers

Other Data Models

The object-oriented data model is another data model that has seen increasing attention. The
object-oriented model can be seen as extending the E-R model with notions object oriented data
model.

The object-relational data model combines features of the object-oriented data model and
relational data model. Semi structured data models permit the specification of data where
individual data items of the same type may have different sets of attributes. This is in contrast
with the data models mentioned earlier, where every data item of a particular type must have the
same set of attributes. The extensible markup language (XML) is widely used to represent semi
structured data.

Historically, two other data models, the network data model and the hierarchical data model,

IN
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


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

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
M

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

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
BE

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 client-
server architecture.

BSNL JE STUDY MATERIAL 132


BEAM & GAIN 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.

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. It’s the database
designers who design the schema to help programmers understand the database and make it
useful.

IN
GA
&
A M
BE

A database schema can be divided broadly into two categories:

 Physical Database Schema: This schema pertains to the actual storage of data and its form of
storage like files, indices, etc. It defines how the data will be stored in a secondary storage.

 Logical Database Schema: This schema defines all the logical constraints that need to be
applied on the data stored. It defines tables, views, and integrity constraints.

BSNL JE STUDY MATERIAL 133


BEAM & GAIN Computers

Data Independence

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.

IN
GA
&

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

Logical Data Independence


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
BE

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.

BSNL JE STUDY MATERIAL 134


BEAM & GAIN Computers

ER Model To Relational Model

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 135


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 136


BEAM & GAIN Computers

IN
GA
&
A M
BE

BSNL JE STUDY MATERIAL 137


BEAM & GAIN Computers

 Declare foreign key constraints

IN
PASCAL Overview
GA
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.
M

Pascal has grown in popularity in the teaching and academics arena for various reasons:

 Easy to learn.
A

 Structured language.
BE

 It produces transparent, efficient and reliable programs.

 It can be compiled on a variety of computer platforms.

Features of the Pascal Language


Pascal has the following features −

 Pascal is a strongly typed language.

 It offers extensive error checking.

 It offers several data types like arrays, records, files and sets.

 It offers a variety of programming structures.

BSNL JE STUDY MATERIAL 138


BEAM & GAIN Computers

 It supports structured programming through functions and procedures.

 It supports object oriented programming.

Facts about Pascal


 The Pascal language was named for Blaise Pascal, French mathematician and pioneer in
computer development.

 Niklaus Wirth completed development of the original Pascal programming language in


1970.

 Pascal is based on the block structured style of the Algol programming language.

 Pascal was developed as a language suitable for teaching programming as a systematic

IN
discipline, whose implementations could be both reliable and efficient.

 The ISO 7185 Pascal Standard was originally published in 1983.


in the early years of the Mac.
GA
Pascal was the primary high-level language used for development in the Apple Lisa, and

 In 1986, Apple Computer released the first Object Pascal implementation, and in 1993,
the Pascal Standards Committee published an Object-Oriented Extension to Pascal.
&
Why to use Pascal?
Pascal allows the programmers to define complex structured data types and build dynamic and
recursive data structures, such as lists, trees and graphs. Pascal offers features like records,
enumerations, subranges, dynamically allocated variables with associated pointers and sets.
M

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
A

fundamental concepts.

Among the most amazing implementations of Pascal are −


BE

 Skype

 Total Commander

 TeX

 Macromedia Captivate

 Apple Lisa

 Various PC Games

 Embedded Systems

BSNL JE STUDY MATERIAL 139


BEAM & GAIN Computers

Example:

program HelloWorld;
uses crt;

(* Here the main program block starts *)


begin
writeln('Hello, World!');
readkey;
end.

IN
There are several Pascal compilers and interpreters available for general use. Among these are −


CP/M-86, DOS, Windows and Macintosh.
GA
Turbo Pascal − provides an IDE and compiler for running Pascal programs on CP/M,

 Delphi − provides compilers for running Object Pascal and generates native code for 32-
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.

 Free Pascal − it is a free compiler for running Pascal and Object Pascal programs. Free
M

Pascal compiler is a 32- and 64-bit Turbo Pascal and Delphi compatible Pascal compiler
for Linux, Windows, OS/2, FreeBSD, Mac OS X, DOS and several other platforms.
A

 Turbo51 − It is a free Pascal compiler for the 8051 family of microcontrollers, with
Turbo Pascal 7 syntax.
BE

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

BSNL JE STUDY MATERIAL 140

Das könnte Ihnen auch gefallen