BCE NOTES RGPV - TRINITY INST OF TECH AND RESEARCH BHOPAL (RGTU)

mikbpl 5,566 views 190 slides Apr 26, 2018
Slide 1
Slide 1 of 201
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135
Slide 136
136
Slide 137
137
Slide 138
138
Slide 139
139
Slide 140
140
Slide 141
141
Slide 142
142
Slide 143
143
Slide 144
144
Slide 145
145
Slide 146
146
Slide 147
147
Slide 148
148
Slide 149
149
Slide 150
150
Slide 151
151
Slide 152
152
Slide 153
153
Slide 154
154
Slide 155
155
Slide 156
156
Slide 157
157
Slide 158
158
Slide 159
159
Slide 160
160
Slide 161
161
Slide 162
162
Slide 163
163
Slide 164
164
Slide 165
165
Slide 166
166
Slide 167
167
Slide 168
168
Slide 169
169
Slide 170
170
Slide 171
171
Slide 172
172
Slide 173
173
Slide 174
174
Slide 175
175
Slide 176
176
Slide 177
177
Slide 178
178
Slide 179
179
Slide 180
180
Slide 181
181
Slide 182
182
Slide 183
183
Slide 184
184
Slide 185
185
Slide 186
186
Slide 187
187
Slide 188
188
Slide 189
189
Slide 190
190
Slide 191
191
Slide 192
192
Slide 193
193
Slide 194
194
Slide 195
195
Slide 196
196
Slide 197
197
Slide 198
198
Slide 199
199
Slide 200
200
Slide 201
201

About This Presentation

COMPLETE NOTES OF BCE (BT 2005) AS PER SYLLABUS OF BTECH - RGPV BHOPAL.


Slide Content

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 1



UNIT I

Computer: Definition, Classification, Organization i.e. CPU, register, Bus architecture,
Instruction set,Memory & Storage Systems, I/O Devices, and System & Application Software.
Computer Application ine-Business, Bio-Informatics, health Care, Remote Sensing & GIS,
Meteorology and Climatology,Computer Gaming, Multimedia and Animation etc. Operating
System: Definition, Function, Types, Management of File, Process & Memory. Introdcution
to MS word, MS powerpoint, MS Excel

UNIT II

Introduction to Algorithms, Complexities and Flowchart, Introduction to Programming,
Categories ofProgramming Languages, Program Design, Programming Paradigms,
Characteristics or Concepts of OOP,Procedure Oriented Programming VS object oriented
Programming.Introduction to C++: Character Set, Tokens, Precedence and Associativity,
Program Structure, Data Types,Variables, Operators, Expressions, Statements and control
structures, I/O operations, Array, Functions,

UNIT III

Object & Classes, Scope Resolution Operator, Constructors & Destructors, Friend Functions,
Inheritance,Polymorphism, Overloading Functions & Operators, Types of Inheritance,
Virtual functions.Introduction to Data Structures.

UNIT IV

Computer Networking: Introduction, Goals, ISO-OSI Model, Functions of Different Layers.
Internetworking Concepts, Devices, TCP/IP Model. Introduction to Internet, World Wide
Web, Ecommerce

Computer Security Basics: Introduction to viruses, worms, malware, Trojans, Spyware and Anti-
Spyware Software, Different types of attacks like Money Laundering, Information Theft,
CyberPornography, Email spoofing, Denial of Service (DoS), Cyber Stalking, ,Logic bombs,
HackingSpamming, Cyber Defamation , pharming Security measures Firewall, Computer Ethics

& Good Practices, Introduction of Cyber Laws about Internet Fraud, Good Computer
Security Habits,

UNIT V

Data base Management System: Introduction, File oriented approach and Database approach,
DataModels, Architecture of Database System, Data independence, Data dictionary, DBA,
Primary Key, Datadefinition language and Manipulation Languages.

Cloud computing: definition, cloud infrastructure, cloud segments or service delivery models
(IaaS, PaaSand SaaS), cloud deployment models/ types of cloud (public, private, community
and hybrid clouds), Prosand Cons of cloud computing

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 2





UNIT –I

Computer

Computer is an advanced electronic device that takes raw data as an input from the user and
processes it under the control of a set of instructions (called program), produces a result
(output), and saves it for future use

Functionalities of a Computer

If we look at it in a very broad sense, any digital computer carries out the following five
functions −
Step 1 − Takes data as input.
Step 2 − Stores the data/instructions in its memory and uses them as required.

Step 3 − Processes the data and converts it into useful information.

Step 4 − Generates the output.
Step 5 − Controls all the above four steps.









Advantages of Computers

Following are certain advantages of computers.
High Speed
 Computer is a very fast device.
 It is capable of performing calculation of very large amount of data.

 The computer has units of speed in microsecond, nanosecond, and even the
picosecond.

 It can perform millions of calculations in a few seconds as compared to man who will
spend many months to perform the same task.
Accuracy
 In addition to being very fast, computers are very accurate.
 The calculations are 100% error free.

 Computers perform all jobs with 100% accuracy provided that the input is
correct. Storage Capability
 Memory is a very important characteristic of computers.

 A computer has much more storage capacity than human beings.
 It can store large amount of data.
 It can store any type of data such as images, videos, text, audio, etc.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 3


Diligence

 Unlike human beings, a computer is free from monotony, tiredness, and lack of
concentration.
 It can work continuously without any error and boredom.
 It can perform repeated tasks with the same speed and accuracy.
Versatility
 A computer is a very versatile machine.
 A computer is very flexible in performing the jobs to be done.
 This machine can be used to solve the problems related to various fields.

 At one instance, it may be solving a complex scientific problem and the very next
moment it may be playing a card game.
Reliability
 A computer is a reliable machine.
 Modern electronic components have long lives.

 Computers are designed to make maintenance easy.
Automation
 Computer is an automatic machine.

 Automation is the ability to perform a given task automatically. Once the computer
receives a program i.e., the program is stored in the computer memory, then the

program and instruction can control the program execution without human
interaction.
Reduction in Paper Work and Cost

 The use of computers for data processing in an organization leads to reduction in paper
work and results in speeding up the process.

 As data in electronic files can be retrieved as and when required, the problem of
maintenance of large number of paper files gets reduced.

 Though the initial investment for installing a computer is high, it substantially reduces
the cost of each of its transaction.

Disadvantages of Computers
Following are certain disadvantages of computers.

No I.Q.
 A computer is a machine that has no intelligence to perform any task.
 Each instruction has to be given to the computer.
 A computer cannot take any decision on its own.
Dependency
 It functions as per the user’s instruction, thus it is fully dependent on humans.
Environment

 The operating environment of the computer should be dust free and
suitable. No Feeling
 Computers have no feelings or emotions.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 4






 It cannot make judgment based on feeling, taste, experience, and knowledge unlike
humans.


Computer – Generations
Generation in computer terminology is a change in technology a computer is/was being used.
Following are the main five generations of computers.

S.No Generation & Description

1 First Generation

The period of first generation: 1946-1959. Vacuum tube based.

2 Second Generation
The period of second generation: 1959-1965. Transistor based.


3 Third Generation
The period of third generation: 1965-1971. Integrated Circuit based.

4 Fourth Generation
The period of fourth generation: 1971-1980. VLSI microprocessor based.

5 Fifth Generation
The period of fifth generation: 1980-onwards. ULSI microprocessor based.


first generation


The period of first generation was from 1946-1959. The computers of first generation used
vacuum tubes as the basic components for memory and circuitry for CPU (Central Processing
Unit). These tubes, like electric bulbs, produced a lot of heat and the installations used to fuse
frequently. Therefore, they were very expensive and only large organizations were able to
afford it.

In this generation, mainly batch processing operating system was used. Punch cards, paper
tape, and magnetic tape was used as input and output devices. The computers in this
generation used machine code as the programming language.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 5

































The main features of the first generation are −
 Vacuum tube technology
 Unreliable
 Supported machine language only
 Very costly
 Generated a lot of heat
 Slow input and output devices

 Huge size
 Need of AC
 Non-portable
 Consumed a lot of electricity
Some computers of this generation were −
 ENIAC
 EDVAC
 UNIVAC
 IBM-701
 IBM-650


second generation

The period of second generation was from 1959-1965. In this generation, transistors were
used that were cheaper, consumed less power, more compact in size, more reliable and faster
than the first generation machines made of vacuum tubes. In this generation, magnetic cores

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 6


were used as the primary memory and magnetic tape and magnetic disks as secondary storage
devices. In this generation, assembly language and high-level programming languages like
FORTRAN, COBOL were used. The computers used batch processing and multiprogramming
operating system.

























The main features of second generation are −
 Use of transistors
 Reliable in comparison to first generation computers
 Smaller size as compared to first generation computers
 Generated less heat as compared to first generation computers
 Consumed less electricity as compared to first generation computers
 Faster than first generation computers

 Still very costly
 AC required
 Supported machine and assembly languages
Some computers of this generation were −
 IBM 1620
 IBM 7094
 CDC 1604
 CDC 3600
 UNIVAC 1108


third generation

The period of third generation was from 1965-1971. The computers of third generation used
Integrated Circuits (ICs) in place of transistors. A single IC has many transistors, resistors, and
capacitors along with the associated circuitry.

The IC was invented by Jack Kilby. This development made computers smaller in size, reliable,
and efficient. In this generation remote processing, time-sharing, multiprogramming operating

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 7




system were used. High-level languages (FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC,
ALGOL-68 etc.) were used during this generation.






















The main features of third generation are −
 IC used
 More reliable in comparison to previous two generations
 Smaller size
 Generated less heat
 Faster
 Lesser maintenance
 Costly

 AC required
 Consumed lesser electricity
 Supported high-level language
Some computers of this generation were −
 IBM-360 series
 Honeywell-6000 series
 PDP (Personal Data Processor)
 IBM-370/168
 TDC-316


fourth generation

The period of fourth generation was from 1971-1980. Computers of fourth generation used
Very Large Scale Integrated (VLSI) circuits. VLSI circuits having about 5000 transistors and other
circuit elements with their associated circuits on a single chip made it possible to have
microcomputers of fourth generation.

Fourth generation computers became more powerful, compact, reliable, and affordable. As a
result, it gave rise to Personal Computer (PC) revolution. In this generation, time sharing, real

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 8


time networks, distributed operating system were used. All the high-level languages like C,
C++, DBASE etc., were used in this generation.


























The main features of fourth generation are −
 VLSI technology used
 Very cheap
 Portable and reliable
 Use of PCs
 Very small size
 Pipeline processing

 No AC required
 Concept of internet was introduced
 Great developments in the fields of networks
 Computers became easily available
Some computers of this generation were −
 DEC 10
 STAR 1000
 PDP 11
 CRAY-1(Super Computer)
 CRAY-X-MP(Super Computer)


fifth generation

The period of fifth generation is 1980-till date. In the fifth generation, VLSI technology became
ULSI (Ultra Large Scale Integration) technology, resulting in the production of microprocessor
chips having ten million electronic components.

This generation is based on parallel processing hardware and AI (Artificial Intelligence)
software. AI is an emerging branch in computer science, which interprets the means and

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 9




method of making computers think like human beings. All the high-level languages like C and
C++, Java, .Net etc., are used in this generation.



























AI includes −
 Robotics
 Neural Networks
 Game Playing
 Development of expert systems to make decisions in real-life situations
 Natural language understanding and generation
The main features of fifth generation are −
 ULSI technology

 Development of true artificial intelligence
 Development of Natural language processing
 Advancement in Parallel Processing
 Advancement in Superconductor technology
 More user-friendly interfaces with multimedia features
 Availability of very powerful and compact computers at cheaper rates
Some computer types of this generation are −
 Desktop
 Laptop
 NoteBook
 UltraBook
 ChromeBook

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 10



Computer – Types

Computers can be broadly classified by their speed and computing power.

S.No.

Type

Specifications



1
PC (Personal It is a single user computer system having moderately powerful

Computer)

microprocessor

It is also a single user computer system, similar to personal computer
2 Workstation however has a more powerful microprocessor.

3


Mini Computer
It is a multi-user computer system, capable of supporting hundreds of

users simultaneously.


It is a multi-user computer system, capable of supporting hundreds of
4 Main Frame users simultaneously. Software technology is different from
minicomputer.

5

Supercomputer
It is an extremely fast computer, which can execute hundreds of

millions of instructions per second.


PC (Personal Computer)

















A PC can be defined as a small, relatively inexpensive computer designed for an individual user.
PCs are based on the microprocessor technology that enables manufacturers to put an entire
CPU on one chip. Businesses use personal computers for word processing, accounting, desktop
publishing, and for running spreadsheet and database management applications. At home, the
most popular use for personal computers is playing games and surfing the Internet.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 11



Although personal computers are designed as single-user systems, these systems are normally
linked together to form a network. In terms of power, now-a-days high-end models of the
Macintosh and PC offer the same computing power and graphics capability as low-end
workstations by Sun Microsystems, Hewlett-Packard, and Dell.


Workstation














Workstation is a computer used for engineering applications (CAD/CAM), desktop publishing,
software development, and other such types of applications which require a moderate amount
of computing power and relatively high quality graphics capabilities.

Workstations generally come with a large, high-resolution graphics screen, large amount of
RAM, inbuilt network support, and a graphical user interface. Most workstations also have
mass storage device such as a disk drive, but a special type of workstation, called diskless
workstation, comes without a disk drive.

Common operating systems for workstations are UNIX and Windows NT. Like PC, workstations
are also single-user computers like PC but are typically linked together to form a local-area
network, although they can also be used as stand-alone systems.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 12






Minicomputer
It is a midsize multi-processing system capable of supporting up to 250 users simultaneously.































Mainframe

Mainframe is very large in size and is an expensive computer capable of supporting hundreds or even
thousands of users simultaneously. Mainframe executes many programs concurrently and supports many
simultaneous execution of programs.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 13


Supercomputer

Supercomputers are one of the fastest computers currently available. Supercomputers are very expensive
and are employed for specialized applications that require immense amount of mathematical calculations
(number crunching).




















For example, weather forecasting, scientific simulations, (animated) graphics, fluid dynamic
calculations, nuclear energy research, electronic design, and analysis of geological data (e.g. in
petrochemical prospecting).


Computer – Components

All types of computers follow the same basic logical structure and perform the following five
basic operations for converting raw input data into information useful to their users.


S.No.

Operation

Description



1

Take Input
The process of entering data and instructions into the computer system.


2

Store Data
Saving data and instructions so that they are available for processing as

and when required.


3

Processing Data
Performing arithmetic, and logical operations on data in order to convert

them into useful information.


4
Output The process of producing useful information or results for the user, such

Information

as a printed report or visual display.

5
Control the Directs the manner and sequence in which all of the above operations are

workflow

performed.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 14



























Input Unit

This unit contains devices with the help of which we enter data into the computer. This unit
creates a link between the user and the computer. The input devices translate the information
into a form understandable by the computer.


CPU (Central Processing Unit)

CPU is considered as the brain of the computer. CPU performs all types of data processing
operations. It stores data, intermediate results, and instructions (program). It controls the
operation of all parts of the computer.

CPU itself has the following three components −
 ALU (Arithmetic Logic Unit)
 Memory Unit
 Control Unit


Output Unit

The output unit consists of devices with the help of which we get the information from the
computer. This unit is a link between the computer and the users. Output devices translate the
computer's output into a form understandable by the users.

Central Processing Unit (CPU) consists of the following features −
 CPU is considered as the brain of the computer.
 CPU performs all types of data processing operations.
 It stores data, intermediate results, and instructions (program).
 It controls the operation of all parts of the computer.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 15












CPU itself has following three components.
 Memory or Storage Unit
 Control Unit
 ALU(Arithmetic Logic Unit)



Memory or Storage Unit

This unit can store instructions, data, and intermediate results. This unit supplies information
to other units of the computer when needed. It is also known as internal storage unit or the
main memory or the primary storage or Random Access Memory (RAM).

Its size affects speed, power, and capability. Primary memory and secondary memory are two
types of memories in the computer. Functions of the memory unit are −
 It stores all the data and the instructions required for processing.
 It stores intermediate results of processing.

 It stores the final results of processing before these results are released to an output
device.
 All inputs and outputs are transmitted through the main memory.

Control Unit

this unit controls the operations of all parts of the computer but does not carry out any actual
data processing operations.
Functions of this unit are −

 It is responsible for controlling the transfer of data and instructions among other units
of a computer.
 It manages and coordinates all the units of the computer.

 It obtains the instructions from the memory, interprets them, and directs the operation
of the computer.

 It communicates with Input/Output devices for transfer of data or results from storage.
 It does not process or store data.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 16


ALU (Arithmetic Logic Unit)

This unit consists of two subsections namely,
 Arithmetic Section
 Logic Section
Arithmetic Section

Function of arithmetic section is to perform arithmetic operations like addition, subtraction,
multiplication, and division. All complex operations are done by making repetitive use of the
above operations.

Logic Section

Function of logic section is to perform logic operations such as comparing, selecting, matching,
and merging of data.


Input Devices

Following are some of the important input devices which are used in a computer −
 Keyboard
 Mouse
 Joy Stick
 Light pen
 Track Ball
 Scanner
 Graphic Tablet
 Microphone
 Magnetic Ink Card Reader(MICR)
 Optical Character Reader(OCR)

 Bar Code Reader
 Optical Mark Reader(OMR)

Keyboard

Keyboard is the most common and very popular input device which helps to input data to the
computer. The layout of the keyboard is like that of traditional typewriter, although there are
some additional keys provided for performing additional functions.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 17


Keyboards are of two sizes 84 keys or 101/102 keys, but now keyboards with 104 keys or 108
keys are also available for Windows and Internet.
The keys on the keyboard are as follows –

Typing Keys
These keys include the letter keys (A-Z) and digit keys (09) which generally give the
Numeric Keypad
It is used to enter the numeric data or cursor movement. Generally, it consists of a set
of 17 keys that are laid out in the same configuration used by most adding machines

Function Keys
The twelve function keys are present on the keyboard which are arranged in a row at
the top of the keyboard. Each function key has a unique meaning and is used for

Control keys
These keys provide cursor and screen control. It includes four directional arrow keys.
Control keys also include Home, End, Insert, Delete, Page Up, Page Down, Control(Ctrl),
Alternate(Alt), Escape(Esc).


Special Purpose Keys

Keyboard also contains some special purpose keys such as Enter, Shift, Caps Lock, Num Lock,
Space bar, Tab, and Print Screen.





Mouse

Mouse is the most popular pointing device. It is a very famous cursor-control device having a
small palm size box with a round ball at its base, which senses the movement of the mouse and
sends corresponding signals to the CPU when the mouse buttons are pressed.

Generally, it has two buttons called the left and the right button and a wheel is present between
the buttons. A mouse can be used to control the position of the cursor on the screen, but it
cannot be used to enter text into the computer.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 18




Advantages
 Easy to use
 Not very expensive

 Moves the cursor faster than the arrow keys of the keyboard.

Joystick

Joystick is also a pointing device, which is used to move the cursor position on a monitor
screen. It is a stick having a spherical ball at its both lower and upper ends. The lower spherical
ball moves in a socket. The joystick can be moved in all four directions.





















The function of the joystick is similar to that of a mouse. It is mainly used in Computer Aided
Designing (CAD) and playing computer games.


Light Pen

Light pen is a pointing device similar to a pen. It is used to select a displayed menu item or
draw pictures on the monitor screen. It consists of a photocell and an optical system placed in
a small tube.










When the tip of a light pen is moved over the monitor screen and the pen button is pressed,
its photocell sensing element detects the screen location and sends the corresponding signal
to the CPU.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 19


Track Ball

Track ball is an input device that is mostly used in notebook or laptop computer, instead of a
mouse. This is a ball which is half inserted and by moving fingers on the ball, the pointer can
be moved.















Since the whole device is not moved, a track ball requires less space than a mouse. A track ball
comes in various shapes like a ball, a button, or a square.


Scanner

Scanner is an input device, which works more like a photocopy machine. It is used when some
information is available on paper and it is to be transferred to the hard disk of the computer
for further manipulation.
























Scanner captures images from the source which are then converted into a digital form that can
be stored on the disk. These images can be edited before they are printed.

Digitizer

Digitizer is an input device which converts analog information into digital form. Digitizer can
convert a signal from the television or camera into a series of numbers that could be stored in

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 20




a computer. They can be used by the computer to create a picture of whatever the camera
had been pointed at.















Digitizer is also known as Tablet or Graphics Tablet as it converts graphics and pictorial data
into binary inputs. A graphic tablet as digitizer is used for fine works of drawing and image
manipulation applications.

Microphone
Microphone is an input device to input sound that is then stored in a digital form.








The microphone is used for various applications such as adding sound to a multimedia
presentation or for mixing music.









Magnetic Ink Card Reader (MICR)

MICR input device is generally used in banks as there are large number of cheques to be
processed every day. The bank's code number and cheque number are printed on the cheques
with a special type of ink that contains particles of magnetic material that are machine
readable.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 21


























this reading process is called Magnetic Ink Character Recognition (MICR). The main advantages
of MICR is that it is fast and less error prone.

Optical Character Reader (OCR)
OCR is an input device used to read a printed text.

















OCR scans the text optically, character by character, converts them into a machine readable
code, and stores the text on the system memory.

Bar Code Readers

Bar Code Reader is a device used for reading bar coded data (data in the form of light and dark
lines). Bar coded data is generally used in labelling goods, numbering the books, etc. It may be
a handheld scanner or may be embedded in a stationary scanner.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 22



















Bar Code Reader scans a bar code image, converts it into an alphanumeric value, which is then
fed to the computer that the bar code reader is connected to.


Optical Mark Reader (OMR)

OMR is a special type of optical scanner used to recognize the type of mark made by pen or
pencil. It is used where one out of a few alternatives is to be selected and marked.












It is specially used for checking the answer sheets of examinations having multiple choice
questions.


Output Devices

Following are some of the important output devices used in a computer.
 Monitors
 Graphic Plotter
 Printer

Monitors

Monitors, commonly called as Visual Display Unit (VDU), are the main output device of a
computer. It forms images from tiny dots, called pixels that are arranged in a rectangular form.
The sharpness of the image depends upon the number of pixels.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 23


There are two kinds of viewing screen used for monitors.

 Cathode-Ray Tube (CRT)

 Flat-Panel Display
Cathode-Ray Tube (CRT) Monitor

The CRT display is made up of small picture elements called pixels. The smaller the pixels, the
better the image clarity or resolution. It takes more than one illuminated pixel to form a whole
character, such as the letter ‘e’ in the word help.























A finite number of characters can be displayed on a screen at once. The screen can be divided
into a series of character boxes - fixed location on the screen where a standard character can
be placed. Most screens are capable of displaying 80 characters of data horizontally and 25
lines vertically.
There are some disadvantages of CRT −

 Large in Size

 High power consumption 
 Flat-Panel Display 



The flat-panel display refers to a class of video devices that have reduced volume, weight and
power requirement in comparison to the CRT. You can hang them on walls or wear them on
your wrists. Current uses of flat-panel displays include calculators, video games, monitors,
laptop computer, and graphics display.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 24
























The flat-panel display is divided into two categories −

 Emissive Displays − Emissive displays are devices that convert electrical energy into
light. For example, plasma panel and LED (Light-Emitting Diodes).

 Non-Emissive Displays − Non-emissive displays use optical effects to convert sunlight or
light from some other source into graphics patterns. For example, LCD (Liquid-Crystal
Device).

Printers
Printer is an output device, which is used to print information on paper.
There are two types of printers −
 Impact Printers

 Non-Impact Printers
Impact Printers

Impact printers print the characters by striking them on the ribbon, which is then pressed on
the paper.

Characteristics of Impact Printers are the following −
 Very low consumable costs
 Very noisy
 Useful for bulk printing due to low cost
 There is physical contact with the paper to produce an image
These printers are of two types −
 Character printers
 Line printers
Character Printers

Character printers are the printers which print one character at a time.
These are further divided into two types:
 Dot Matrix Printer(DMP)

 Daisy Wheel

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 25



Dot Matrix Printer

In the market, one of the most popular printers is Dot Matrix Printer. These printers are
popular because of their ease of printing and economical price. Each character printed is in the
form of pattern of dots and head consists of a Matrix of Pins of size (5*7, 7*9, 9*7 or 9*9)
which come out to form a character which is why it is called Dot Matrix Printer.





















Advantages
 Inexpensive
 Widely Used
 Other language characters can be printed
Disadvantages

 Slow Speed
 Poor Quality
Daisy Wheel

Head is lying on a wheel and pins corresponding to characters are like petals of Daisy (flower)
which is why it is called Daisy Wheel Printer. These printers are generally used for word-
processing in offices that require a few letters to be sent here and there with very nice quality.
















Advantages

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 26



 More reliable than DMP

 Better quality
 Fonts of character can be easily changed
Disadvantages
 Slower than DMP
 Noisy
 More expensive than DMP
Line Printers
Line printers are the printers which print one line at a time.



















These are of two types −

 Drum Printer
 Chain Printer
Drum Printer

This printer is like a drum in shape hence it is called drum printer. The surface of the drum is
divided into a number of tracks. Total tracks are equal to the size of the paper, i.e. for a paper
width of 132 characters, drum will have 132 tracks. A character set is embossed on the track.
Different character sets available in the market are 48 character set, 64 and 96 characters set.
One rotation of drum prints one line. Drum printers are fast in speed and can print 300 to 2000
lines per minute.

Advantages
 Very high speed
Disadvantages
 Very expensive
 Characters fonts cannot be changed

Chain Printer

In this printer, a chain of character sets is used, hence it is called Chain Printer. A standard
character set may have 48, 64, or 96 characters.
Advantages
 Character fonts can easily be changed.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 27



 Different languages can be used with the same printer.

Disadvantages
 Noisy
Non-impact Printers
Non-impact printers print the characters without using the ribbon. These printers print a
complete page at a time, thus they are also called as Page Printers.
These printers are of two types −
 Laser Printers
 Inkjet Printers
Characteristics of Non-impact Printers
 Faster than impact printers
 They are not noisy
 High quality
 Supports many fonts and different character size
Laser Printers

These are non-impact page printers. They use laser lights to produce the dots needed to form
the characters to be printed on a page.



























Advantages
 Very high speed
 Very high quality output
 Good graphics quality

 Supports many fonts and different character size
Disadvantages

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 28



 Expensive

 Cannot be used to produce multiple copies of a document in a single printing
Inkjet Printers

Inkjet printers are non-impact character printers based on a relatively new technology. They
print characters by spraying small drops of ink onto paper. Inkjet printers produce high quality
output with presentable features.






















They make less noise because no hammering is done and these have many styles of printing
modes available. Color printing is also possible. Some models of Inkjet printers can produce
multiple copies of printing also.

Advantages
 High quality printing
 More reliable
Disadvantages
 Expensive as the cost per page is high
 Slow as compared to laser printer

Computer - Memory

A memory is just like a human brain. It is used to store data and instructions. Computer
memory is the storage space in the computer, where data is to be processed and instructions
required for processing are stored. The memory is divided into large number of small parts
called cells. Each location or cell has a unique address, which varies from zero to memory size
minus one. For example, if the computer has 64k words, then this memory unit has 64 * 1024

= 65536 memory locations. The address of these locations varies from 0 to 65535.
Memory is primarily of three types −
 Cache Memory
 Primary Memory/Main Memory
 Secondary Memory

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 29



Cache Memory

Cache memory is a very high speed semiconductor memory which can speed up the CPU. It
acts as a buffer between the CPU and the main memory. It is used to hold those parts of data
and program which are most frequently used by the CPU. The parts of data and programs are
transferred from the disk to cache memory by the operating system, from where the CPU can
access them.
























Advantages
The advantages of cache memory are as follows −
 Cache memory is faster than main memory.
 It consumes less access time as compared to main memory.

 It stores the program that can be executed within a short period of time.
 It stores data for temporary use.
Disadvantages
The disadvantages of cache memory are as follows −
 Cache memory has limited capacity.
 It is very expensive.

Primary Memory (Main Memory)

Primary memory holds only those data and instructions on which the computer is currently
working. It has a limited capacity and data is lost when power is switched off. It is generally
made up of semiconductor device. These memories are not as fast as registers. The data and
instruction required to be processed resides in the main memory. It is divided into two
subcategories RAM and ROM.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 30
























Characteristics of Main Memory

 These are semiconductor memories.
 It is known as the main memory.
 Usually volatile memory.
 Data is lost in case power is switched off.
 It is the working memory of the computer.
 Faster than secondary memories.
 A computer cannot run without the primary memory.

Secondary Memory

This type of memory is also known as external memory or non-volatile. It is slower than the
main memory. These are used for storing data/information permanently. CPU directly does not
access these memories, instead they are accessed via input-output routines. The contents of
secondary memories are first transferred to the main memory, and then the CPU can access it.
For example, disk, CD-ROM, DVD, etc.















Characteristics of Secondary Memory
 These are magnetic and optical memories.
 It is known as the backup memory.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 31



 It is a non-volatile memory.

 Data is permanently stored even if power is switched off.
 It is used for storage of data in a computer.
 Computer may run without the secondary memory.
 Slower than primary memories.
Random Access Memory

RAM (Random Access Memory) is the internal memory of the CPU for storing data, program,
and program result. It is a read/write memory which stores data until the machine is working.
As soon as the machine is switched off, data is erased.




















Access time in RAM is independent of the address, that is, each storage location inside the
memory is as easy to reach as other locations and takes the same amount of time. Data in the
RAM can be accessed randomly but it is very expensive.

RAM is volatile, i.e. data stored in it is lost when we switch off the computer or if there is a
power failure. Hence, a backup Uninterruptible Power System (UPS) is often used with
computers. RAM is small, both in terms of its physical size and in the amount of data it can
hold.

RAM is of two types −
 Static RAM (SRAM)
 Dynamic RAM (DRAM)
Static RAM (SRAM)

The word static indicates that the memory retains its contents as long as power is being
supplied. However, data is lost when the power gets down due to volatile nature. SRAM chips
use a matrix of 6-transistors and no capacitors. Transistors do not require power to prevent
leakage, so SRAM need not be refreshed on a regular basis.

There is extra space in the matrix, hence SRAM uses more chips than DRAM for the same
amount of storage space, making the manufacturing costs higher. SRAM is thus used as cache
memory and has very fast access.

Characteristic of Static RAM

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 32


 Long life

 No need to refresh
 Faster
 Used as cache memory
 Large size
 Expensive
 High power consumption

Dynamic RAM (DRAM)

DRAM, unlike SRAM, must be continually refreshed in order to maintain the data. This is done
by placing the memory on a refresh circuit that rewrites the data several hundred times per
second. DRAM is used for most system memory as it is cheap and small. All DRAMs are made
up of memory cells, which are composed of one capacitor and one transistor. Characteristics of
Dynamic RAM

 Short data lifetime

 Needs to be refreshed continuously
 Slower as compared to SRAM
 Used as RAM
 Smaller in size
 Less expensive
 Less power consumption

Computer - Read Only Memory

ROM stands for Read Only Memory. The memory from which we can only read but cannot
write on it. This type of memory is non-volatile. The information is stored permanently in such
memories during manufacture. A ROM stores such instructions that are required to start a
computer. This operation is referred to as bootstrap. ROM chips are not only used in the
computer but also in other electronic items like washing machine and microwave oven.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 33


Let us now discuss the various types of ROMs and their characteristics.

MROM (Masked ROM);

The very first ROMs were hard-wired devices that contained a pre-programmed set of data or
instructions. These kind of ROMs are known as masked ROMs, which are inexpensive.

PROM (Programmable Read Only Memory):

PROM is read-only memory that can be modified only once by a user. The user buys a blank
PROM and enters the desired contents using a PROM program. Inside the PROM chip, there
are small fuses which are burnt open during programming. It can be programmed only once
and is not erasable.

EPROM (Erasable and Programmable Read Only Memory):

EPROM can be erased by exposing it to ultra-violet light for a duration of up to 40 minutes.
Usually, an EPROM eraser achieves this function. During programming, an electrical charge is
trapped in an insulated gate region. The charge is retained for more than 10 years because the
charge has no leakage path. For erasing this charge, ultra-violet light is passed through a quartz
crystal window (lid). This exposure to ultra-violet light dissipates the charge. During normal
use, the quartz lid is sealed with a sticker.

EEPROM (Electrically Erasable and Programmable Read Only Memory):

EEPROM is programmed and erased electrically. It can be erased and reprogrammed about ten
thousand times. Both erasing and programming take about 4 to 10 ms (millisecond). In
EEPROM, any location can be selectively erased and programmed. EEPROMs can be erased
one byte at a time, rather than erasing the entire chip. Hence, the process of reprogramming is
flexible but slow.


Advantages of ROM

The advantages of ROM are as follows −
 Non-volatile in nature
 Cannot be accidentally changed
 Cheaper than RAMs
 Easy to test
 More reliable than RAMs
 Static and do not require refreshing
 Contents are always known and can be verified

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 34


Computer - Software

Software is a set of programs, which is designed to perform a well-defined function. A program
is a sequence of instructions written to solve a particular problem.
There are two types of software −

 System Software
 Application Software

System Software

The system software is a collection of programs designed to operate, control, and extend the
processing capabilities of the computer itself. System software is generally prepared by the
computer manufacturers. These software products comprise of programs written in low-level
languages, which interact with the hardware at a very basic level. System software serves as
the interface between the hardware and the end users.

Some examples of system software are Operating System, Compilers, Interpreter, Assemblers,
etc.















Here is a list of some of the most prominent features of a system software −
 Close to the system
 Fast in speed

 Difficult to design
 Difficult to understand
 Less interactive
 Smaller in size

 Difficult to manipulate
 Generally written in low-level language

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 35



Application Software

Application software products are designed to satisfy a particular need of a particular
environment. All software applications prepared in the computer lab can come under the
category of Application software.

Application software may consist of a single program, such as Microsoft's notepad for writing
and editing a simple text. It may also consist of a collection of programs, often called a
software package, which work together to accomplish a task, such as a spreadsheet package.
Examples of Application software are the following −

 Payroll Software
 Student Record Software
 Inventory Management Software
 Income Tax Software
 Railways Reservation Software
 Microsoft Office Suite Software
 Microsoft Word

 Microsoft Excel
 Microsoft PowerPoint
















Features of application software are as follows −
 Close to the user
 Easy to design
 More interactive
 Slow in speed
 Generally written in high-level language
 Easy to understand

 Easy to manipulate and use
 Bigger in size and requires large storage space

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 36




Computer - Applications

Business




















A computer has high speed of calculation, diligence, accuracy, reliability, or versatility which
has made it an integrated part in all business organizations.

Computer is used in business organizations for −
 Payroll calculations
 Budgeting
 Sales analysis
 Financial forecasting

 Managing employee database
 Maintenance of stocks, etc.


Banking

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 37


Today, banking is almost totally dependent on computers.
Banks provide the following facilities −

 Online accounting facility, which includes checking current balance, making deposits
and overdrafts, checking interest charges, shares, and trustee records.

 ATM machines which are completely automated are making it even easier for
customers to deal with banks.

Insurance




















Insurance companies are keeping all records up-to-date with the help of computers. Insurance
companies, finance houses, and stock broking firms are widely using computers for their
concerns.

Insurance companies are maintaining a database of all clients with information showing −
 Procedure to continue with policies

 Starting date of the policies
 Next due installment of a policy
 Maturity date
 Interests due
 Survival benefits
 Bonus

Education













The computer helps in providing a lot of facilities in the education system.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 38



 The computer provides a tool in the education system known as CBE (Computer Based
Education).
 CBE involves control, delivery, and evaluation of learning.
 Computer education is rapidly increasing the graph of number of computer students.

 There are a number of methods in which educational institutions can use a computer to
educate the students.

 It is used to prepare a database about performance of a student and analysis is carried
out on this basis.

Marketing
In marketing, uses of the computer are following −
















 Advertising − With computers, advertising professionals create art and graphics, write
and revise copy, and print and disseminate ads with the goal of selling more products.

 Home Shopping − Home shopping has been made possible through the use of
computerized catalogues that provide access to product information and permit direct

entry of orders to be filled by the customers.
Healthcare

Computers have become an important part in hospitals, labs, and dispensaries. They are being
used in hospitals to keep the record of patients and medicines. It is also used in scanning and
diagnosing different diseases. ECG, EEG, ultrasounds and CT scans, etc. are also done by
computerized machines.

Following are some major fields of health care in which computers are used.














 Diagnostic System − Computers are used to collect data and identify the cause of
illness.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 39



 Lab-diagnostic System − All tests can be done and the reports are prepared by
computer.

 Patient Monitoring System − These are used to check the patient's signs for
abnormality such as in Cardiac Arrest, ECG, etc.

 Pharma Information System − Computer is used to check drug labels, expiry dates,
harmful side effects, etc.
 Surgery − Nowadays, computers are also used in performing surgery.

Engineering Design
Computers are widely used for Engineering purpose.

One of the major areas is CAD (Computer Aided Design) that provides creation and
modification of images. Some of the fields are −














 Structural Engineering − Requires stress and strain analysis for design of ships,
buildings, budgets, airplanes, etc.

 Industrial Engineering − Computers deal with design, implementation, and
improvement of integrated systems of people, materials, and equipment.

 Architectural Engineering − Computers help in planning towns, designing buildings,
determining a range of buildings on a site using both 2D and 3D drawings.

Military

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 40























Computers are largely used in defence. Modern tanks, missiles, weapons, etc. Military also
employs computerized control systems. Some military areas where a computer has been used
are −

 Missile Control

 Military Communication
 Military Operation and Planning
 Smart Weapons

Communication

Communication is a way to convey a message, an idea, a picture, or speech that is received
and understood clearly and correctly by the person for whom it is meant. Some main areas in
this category are −













 E-mail
 Chatting
 Usenet
 FTP
 Telnet
 Video-conferencing

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 41


Government

Computers play an important role in government services. Some major fields in this category
are −














 Budgets
 Sales tax department
 Income tax department
 Computation of male/female ratio
 Computerization of voters lists
 Computerization of PAN card
 Weather forecasting

Instruction set


An instruction set is a group of commands for a CPU in machine language. The term can refer to
all possible instructions for a CPU or a subset of instructions to enhance its performance in
certain situations.


All CPUs have instruction sets that enable commands to the processor directing the CPU to
switch the relevant transistors. Some instructions are simple read, write and movecommands
that direct data to different hardware.


In CISC (Complex Instruction Set Computer) processors there is also a microcode layer, which
involves programmable instructions stored in fast memory that may be updated. The RISC
(Reduced Instruction Set Computer) architecture, on the other hand, has hard-wired control; it
does not require microcode but has a greater base instruction set.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 42



BUS

Inside computers, there are many internal components. In order for these components to
communicate with each other they make use of wires that are known as a ‘bus’ .

A bus is a common pathway through which information flows from one computer component
to another. This pathway is used for communication purpose and it is established between two
or more computer components

functions of buses in computers

1. Data sharing - All types of buses found in a computer transfer data between the
computer peripherals connected to it.

The buses transfer or send data in either serial or parallel method of data transfer. This allows
for the exchange of 1, 2, 4 or even 8 bytes of data at a time. (A byte is a group of 8 bits). Buses
are classified depending on how many bits they can move at the same time, which means
that we have 8-bit, 16-bit, 32-bit or even 64-bit buses.


2. Addressing - A bus has address lines, which match those of the processor. This allows data
to be sent to or from specific memory locations.

3. Power - A bus supplies power to various peripherals connected to it.

4. Timing - The bus provides a system clock signal to synchronize the peripherals attached to it
with the rest of the system.



Computers have two major types of buses:

1. System bus:- This is the bus that connects the CPU to main memory on the
motherboard. The system bus is also called the front-side bus, memory bus, local bus, or
host bus.

2. A number of I/O Buses, (I/O is an acronym for input / output), connecting various peripheral
devices to the CPU. These devices connect to the system bus via a ‘bridge’ implemented in the
processors chipset. Other names for the I/O bus include “expansion bus", "external bus” or
“host bus”.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 43




The System Bus

The System Bus is one of the four major components of a computer.





















A data bus will contain actual data that has either just been read from memory or is about to
be written to a memory location. A data bus is bi-directional, which means that information can
either be written or read using the bus lines.

An address bus contains location information. Address bus is unidirectional and usually the
main processing unit writes location information on it of where data will be read from or
written to.

A control bus will transmit commands or control signals between different components. The
data present on a control bus will determine the period for which a device can access the other
busses and one or more command signals that will determine what kind of operation the
device has to execute.

Expansion Bus Types

These are some of the common expansion bus types that have ever been used in computers:

 ISA - Industry Standard Architecture

 EISA - Extended Industry Standard Architecture

 MCA - Micro Channel Architecture

 VESA - Video Electronics Standards Association

 PCI - Peripheral Component Interconnect

 PCMCIA - Personal Computer Memory Card Industry Association (Also called PC bus)

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 44



 AGP - Accelerated Graphics Port

 SCSI - Small Computer Systems Interface.

Operating System

The Operating System is a program with the following features −

 An operating system is a program that acts as an interface between the software and
the computer hardware.

 It is an integrated set of specialized programs used to manage overall resources and
operations of the computer.

 It is a specialized software that controls and monitors the execution of all other
programs that reside in the computer, including application programs and other system
software.





























Objectives of Operating System
The objectives of the operating system are −
 To make the computer system convenient to use in an efficient manner.
 To hide the details of the hardware resources from the users.
 To provide users a convenient interface to use the computer system.

 To act as an intermediary between the hardware and its users, making it easier for the
users to access and use other resources.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 45



 To manage the resources of a computer system.

 To keep track of who is using which resource, granting resource requests, and
mediating conflicting requests from different programs and users.
 To provide efficient and fair sharing of resources among users and programs.

Characteristics of Operating System
Here is a list of some of the most prominent characteristic features of Operating Systems −

 Memory Management − Keeps track of the primary memory, i.e. what part of it is in
use by whom, what part is not in use, etc. and allocates the memory when a process or
program requests it.

 Processor Management − Allocates the processor (CPU) to a process and deallocates
the processor when it is no longer required.

 Device Management − Keeps track of all the devices. This is also called I/O controller
that decides which process gets the device, when, and for how much time.

 File Management − Allocates and de-allocates the resources and decides who gets the
resources.

 Security − Prevents unauthorized access to programs and data by means of passwords
and other similar techniques.
 Job Accounting − Keeps track of time and resources used by various jobs and/or users.

 Control Over System Performance − Records delays between the request for a service
and from the system.

 Interaction with the Operators − Interaction may take place via the console of the
computer in the form of instructions. The Operating System acknowledges the same,
does the corresponding action, and informs the operation by a display screen.

 Error-detecting Aids − Production of dumps, traces, error messages, and other
debugging and error-detecting methods.

 Coordination Between Other Software and Users − Coordination and assignment of
compilers, interpreters, assemblers, and other software to the various users of the
computer systems


Operating system types

 Batch operating system

 Time-sharing operating systems

 Distributed operating System

 Network operating System

 Real Time operating System

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 46


Batch operating system

The users of a batch operating system do not interact with the computer directly. Each user
prepares his job on an off-line device like punch cards and submits it to the computer operator.
To speed up processing, jobs with similar needs are batched together and run as a group. The
programmers leave their programs with the operator and the operator then sorts the programs
with similar requirements into batches.

The problems with Batch Systems are as follows −

 Lack of interaction between the user and the job.

 CPU is often idle, because the speed of the mechanical I/O devices is slower than
the CPU.
 Difficult to provide the desired priority.

Time-sharing operating systems

Time-sharing is a technique which enables many people, located at various terminals, to use a
particular computer system at the same time. Time-sharing or multitasking is a logical
extension of multiprogramming. Processor's time which is shared among multiple users
simultaneously is termed as time-sharing.

The main difference between Multiprogrammed Batch Systems and Time-Sharing Systems is
that in case of Multiprogrammed batch systems, the objective is to maximize processor use,
whereas in Time-Sharing Systems, the objective is to minimize response time.

Multiple jobs are executed by the CPU by switching between them, but the switches occur so
frequently. Thus, the user can receive an immediate response. For example, in a transaction
processing, the processor executes each user program in a short burst or quantum of
computation. That is, if nusers are present, then each user can get a time quantum. When the
user submits the command, the response time is in few seconds at most.

The operating system uses CPU scheduling and multiprogramming to provide each user with a
small portion of a time. Computer systems that were designed primarily as batch systems have
been modified to time-sharing systems.

Advantages of Timesharing operating systems are as follows −
 Provides the advantage of quick response.
 Avoids duplication of software.
 Reduces CPU idle time.

Disadvantages of Time-sharing operating systems are as follows −
 Problem of reliability.
 Question of security and integrity of user programs and data.
 Problem of data communication.


Distributed operating System

Distributed systems use multiple central processors to serve multiple real-time applications
and multiple users. Data processing jobs are distributed among the processors accordingly.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 47



The processors communicate with one another through various communication lines (such as
high-speed buses or telephone lines). These are referred as loosely coupled systems or
distributed systems. Processors in a distributed system may vary in size and function. These
processors are referred as sites, nodes, computers, and so on.

The advantages of distributed systems are as follows −

 With resource sharing facility, a user at one site may be able to use the
resources available at another.
 Speedup the exchange of data with one another via electronic mail.

 If one site fails in a distributed system, the remaining sites can potentially
continue operating.
 Better service to the customers.
 Reduction of the load on the host computer.
 Reduction of delays in data processing.

Network operating System


A Network Operating System runs on a server and provides the server the capability to
manage data, users, groups, security, applications, and other networking functions. The
primary purpose of the network operating system is to allow shared file and printer access
among multiple computers in a network, typically a local area network (LAN), a private
network or to other networks.

Examples of network operating systems include Microsoft Windows Server 2003, Microsoft
Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.
The advantages of network operating systems are as follows −
 Centralized servers are highly stable.
 Security is server managed.
 Upgrades to new technologies and hardware can be easily integrated into the system.
 Remote access to servers is possible from different locations and types of systems.
The disadvantages of network operating systems are as follows −
 High cost of buying and running a server.
 Dependency on a central location for most operations.
 Regular maintenance and updates are required.

Real Time operating System

A real-time system is defined as a data processing system in which the time interval required
to process and respond to inputs is so small that it controls the environment. The time taken
by the system to respond to an input and display of required updated information is termed as
the response time. So in this method, the response time is very less as compared to online
processing.

Real-time systems are used when there are rigid time requirements on the operation of a
processor or the flow of data and real-time systems can be used as a control device in a
dedicated application. A real-time operating system must have well-defined, fixed time
constraints, otherwise the system will fail. For example, Scientific experiments, medical

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 48


imaging systems, industrial control systems, weapon systems, robots, air traffic control
systems, etc.

There are two types of real-time operating systems.

>> Hard real-time systems

Hard real-time systems guarantee that critical tasks complete on time. In hard real-time
systems, secondary storage is limited or missing and the data is stored in ROM. In these
systems, virtual memory is almost never found.

>> Soft real-time systems

Soft real-time systems are less restrictive. A critical real-time task gets priority over other tasks
and retains the priority until it completes. Soft real-time systems have limited utility than hard
real-time systems. For example, multimedia, virtual reality, Advanced Scientific Projects like
undersea exploration and planetary rovers, etc



MS WORD


MS WORD is used for Word Processing. It is windows version developed by Microsoft. It is a
part of MS-Office package.

It is an application Software that is designed for the entry, editing, and printing of documents


Word processing documents include: E-mail , One page flyers , Reports , Mail Merges , Faxes ,
Memorandums , Letters

Features

 Character formatting

 Paragraph formatting
 Wizards- step by step tutorial
 Thesaurus
 Spell checker
 Grammar Checker
 Mail merge

 Auto correct
 Auto text
 Etc

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 49










































Microsoft Excel

It is a spreadsheet developed by Microsoft for Windows, macOS, Android and iOS. It features
calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic
for Applications. It has been a very widely applied spreadsheet for these platforms, especially
since version 5 in 1993, and it has replaced Lotus 1-2-3 as the industry standard for
spreadsheets.

Microsoft Excel is an Electronic Spreadsheet Computer Program.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 50


Microsoft Excel is a spreadsheet program that is used to record and analyse numerical data.
Think of a spreadsheet as a collection of columns and rows that form a table. Alphabetical
letters are usually assigned to columns and numbers are usually assigned to rows. The point
where a column and a row meet is called a cell. The address of a cell is given by the letter
representing the column and the number representing a row. Let's illustrate this using the
following image.

We all deal with numbers in one way or the other. We all have daily expenses which we pay for
from the monthly income that we earn. For one to spend wisely, they will need to know their
income vs. expenditure. Microsoft Excel comes in handy when we want to record, analyze and
store such numeric data.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 51












































Ribbon and Tabs in Excel

Ribbon is on the top of worksheet, below the title bar or name of the excel file. It
contains seven tabs: Home, Insert, Page Layout, Formulas, Data, Review and View.

Each tab has its own specific groups of related commands. These groups have several additional
commands that can be viewed by clicking the arrow at the right bottom corner of any group.

There are many tabs available in Microsoft Excel: Home, Insert, Page Layout, Formula,
Data, Review and View. Each tab has different features.
The features of the Home tab are:
Clipboard, Font, Alignment, Number, Cells and Editing

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 52























The features of the Insert tab are:

Tables, Illustrations, Charts, Links, Text



















The features of the Page Layout tab are:
Themes, Page Setup, Scale to Fit, Sheet Options and Arrange

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 53

























The features in the Formula tab are:
Function Library, Defined Names, Formula Auditing, Calculation





















The features in the Data tab are:
Get External Data, Connections, Sort & Filter, Data Tools and Outline

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 54

























The features of the Review tab are:
Proofing, Comments and Changes





















The features of the View tab are:
Workbook Views, Show/Hide, Zoom, Window and Macros

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 55



























Worksheet

Worksheet is also called spreadsheet. It is made up of rows, columns and cells.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 56


Rows

Rows run horizontally across the worksheet and ranges from 1 to 1048576. A row is identified
by the number that is on left side of the row, from where the row originates.
Columns

Columns run vertically downward across the worksheet and ranges from A to XFD - 1 to
16384. A column is identified by a column header that is on the top of the column, from where
the column originates.

Cells

Cells are small boxes in the worksheet where we enter data. A cell is the intersection of a row
and column. It is identified by row number and column header such as A1, A2.


How to enter data in Excel

Select a cell with a single click where you want to enter data; cell B3 is selected in the image
given below. Then double click in the cell to enter data. You can enter text, numbers and
formulas in the cell.

After entering data, you can press Tab key to move to next column and can press Enter key
to move to next row. You can press arrow keys for more options to move to other cells.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 57



How to select data in Excel

There are various options to select data. The most common way is a left click on the cell then
dragging the mouse over the data you want to select. Start from the upper-left cell of the data,
as cell B3 in the image given below:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 58



MS- PowerPoint

PowerPoint is the powerful and ubiquitous presentation program from Microsoft. It gives you
the facility to create stunning presentations that incorporate video and PowerPoint animations.
The image editing capabilities that PowerPoint offer get better and better with every new
version.

Microsoft PowerPoint is a software program developed by Microsoft to produce effective
presentations. It is a part of Microsoft Office suite. The program comprises slides and various
tools like word processing, drawing, graphing and outlining. Thus it can display text, table,
chart, graphics and media in the slides.

There are three main features of the Microsoft PowerPoint window that you need to focus
upon while learning PowerPoint. These features are Microsoft Office Button, Quick Access
Toolbar and Ribbon.


Microsoft Office Button is located on the upper-left corner of the PowerPoint window.
See the image:






























When you click the button it displays a menu with multiple options to perform different tasks.
See the image:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 59








































New: To create a new presentation
Open: To open an existing presentation
Save: To save changes made in the open presentation
Save As: To save the presentation with a specific name to a preferred location in the computer
Print: To print the hard copy of the open presentation
Prepare: To prepare the presentation for distribution
Send: To send the copy of the presentation to others

Publish: To distribute the presentation to others
Close: To close the open presentation


Quick Access Toolbar

It is located beside the Microsoft Office Button. By default it shows three commands; Save,
Undo and Redo.
See the image:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 60


















When you click the drop-down arrow at the right end of Quick Access Toolbar it offers more
commands. The desired command out of these commands can be added to Quick Access
Toolbar with a left click on it.
See the image:






























You can also add the Office Button and Ribbon commands. Just right click the command
and select the "Add to Quick Access Toolbar" option. See the image, the command New
Slide is added to Quick Access Toolbar.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 61


























Ribbon and Tabs

Ribbon is located on the top of the PowerPoint window just below the Title bar. It is made up of
seven tabs; Home, Insert, Design, Animations, Slide Show, Review and View. Each tab is divided
into groups of related commands that are displayed on the Ribbon. To view additional
commands of a group click the arrow at the right bottom corner of the group.

See the image:












Slide, Placeholder and Notes

Slide: Presentation is created on slides. It lies in the centre of the PowerPoint window.

Placeholder: By default two placeholders appear in the slide when you open the PowerPoint.

Click to add notes: This space is provided to create notes if needed.

See the image:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 62

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 63

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 64


UNIT II

Introduction to Algorithms, Complexities and Flowchart, Introduction to Programming,
Categories of Programming Languages, Program Design, Programming Paradigms,
Characteristics or Concepts of OOP,Procedure Oriented Programming VS object
oriented Programming.Introduction to C++: Character Set, Tokens, Precedence and
Associativity, Program Structure, Data Types,Variables, Operators, Expressions,
Statements and control structures, I/O operations, Array, Functions,


Algorithm

Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output. Algorithms are generally created
independent of underlying languages, i.e. an algorithm can be implemented in more
than one programming language.

From the data structure point of view, following are some important categories of
algorithms −

 Search − Algorithm to search an item in a data structure.
 Sort − Algorithm to sort items in a certain order.
 Insert − Algorithm to insert item in a data structure.
 Update − Algorithm to update an existing item in a data structure.
 Delete − Algorithm to delete an existing item from a data structure.
Characteristics of an Algorithm

Not all procedures can be called an algorithm. An algorithm should have the following
characteristics −
 Unambiguous − Algorithm should be clear and unambiguous. Each of its steps

(or phases), and their inputs/outputs should be clear and must lead to only one
meaning.
 Input − An algorithm should have 0 or more well-defined inputs.

 Output − An algorithm should have 1 or more well-defined outputs, and should
match the desired output.

 Finiteness − Algorithms must terminate after a finite number of steps.
 Feasibility − Should be feasible with the available resources.

 Independent − An algorithm should have step-by-step directions, which should
be independent of any programming code.


Example− Design an algorithm to add two numbers and display the result.


the algorithm can be written as −


step 1 − START
step 2 − get values of a & b

step 3 − c ← a + b

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 65







step 4 − display c

step 5 − STOP



Algorithm Analysis

Efficiency of an algorithm can be analyzed at two different stages, before
implementation and after implementation. They are the following −

 A Priori Analysis − This is a theoretical analysis of an algorithm. Efficiency of an
algorithm is measured by assuming that all other factors, for example, processor
speed, are constant and have no effect on the implementation.

 A Posterior Analysis − This is an empirical analysis of an algorithm. The
selected algorithm is implemented using programming language. This is
then executed on target computer machine. In this analysis, actual statistics
like running time and space required, are collected.


We shall learn about a priori algorithm analysis. Algorithm analysis deals with the
execution or running time of various operations involved.


Algorithm Complexity

Suppose X is an algorithm and n is the size of input data, the time and space used by
the algorithm X are the two main factors, which decide the efficiency of X.

 Time Factor − Time is measured by counting the number of key operations
such as comparisons in the sorting algorithm.

 Space Factor − Space is measured by counting the maximum memory space
required by the algorithm.

The complexity of an algorithm f(n) gives the running time and/or the storage space
required by the algorithm in terms of n as the size of input data.


Space Complexity

Space complexity of an algorithm represents the amount of memory space required by
the algorithm in its life cycle. The space required by an algorithm is equal to the sum of
the following two components −

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 66


 A fixed part that is a space required to store certain data and variables, that
are independent of the size of the problem. For example, simple variables and
constants used, program size, etc.
 A variable part is a space required by variables, whose size depends on the size
of the problem. For example, dynamic memory allocation, recursion stack
space, etc.

Space complexity S(P) of any algorithm P is S(P) = C + SP(I),

where C is the fixed part and S(I) is the variable part of the algorithm, which depends
on instance characteristic I.

Following is a simple example that tries to explain the concept −


Algorithm: SUM(A, B)


Step 1 - START



Step 2 - C ← A + B + 10


Step 3 - Stop

Here we have three variables A, B, and C and one constant. Hence S(P) = 1 + 3.
Now, space depends on data types of given variables and constant types and it will be
multiplied accordingly.


Time Complexity

Time complexity of an algorithm represents the amount of time required by
the algorithm to run to completion.

Time requirements can be defined as a numerical function T(n), where T(n) can be
measured as the number of steps, provided each step consumes constant time.

For example, addition of two n-bit integers takes n steps. Consequently, the total
computational time is T(n) = c ∗ n, where c is the time taken for the addition of two bits.
Here, we observe that T(n) grows linearly as the input size increases.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 67


Example Space Complexity:

Suppose we want to add two integer numbers. To solve this problem we have following
two algorithms:

Algorithm 1: Algorithm
2:Step 1- Input A. Step 1- Input A.
Step 2- Input B. Step 2- Input B.
Step 3- Set C: = A+ B. Step 3- Write: ‗Sum is ‗, A+B.
Step 4- Write: ‗Sum is ‗, C. Step 4- Exit.
Step 5- Exit.

Both algorithms will produce the same result. But first takes 6 bytes and second takes 4
bytes (2 bytes for each integer). And first has more instructions than the second one. So
we will choose the second one as it takes less space than the first one.


Example Time Complexity:

Suppose we want to add two integer numbers. To solve this problem we have following
two algorithms:

Algorithm 1: Algorithm 2:
Step 1- Input A. Step 1- Input A.
Step 2- Input B. Step 2- Input B.
Step 3- Set C: = A+ B. Step 3- Write: ‗Sum is ‗, A+B.
Step 4- Write: ‗Sum is ‗, C. Step 4- Exit.
Step 5- Exit.

Suppose 1 second is required to execute one instruction. So the first algorithm will take
4 seconds and the second algorithm will take 3 seconds for execution. So we will
choose the second one as it will take less time.

Asymptotic Analysis for Algorithm Complexity

Asymptotic analysis of an algorithm refers to defining the mathematical
boundation/framing of its run-time performance. Using asymptotic analysis, we can very
well conclude the best case, average case, and worst case scenario of an algorithm.

Asymptotic analysis is input bound i.e., if there's no input to the algorithm, it is
concluded to work in a constant time. Other than the "input" all other factors are
considered constant.

Asymptotic analysis refers to computing the running time of any operation in
mathematical units of computation. For example, the running time of one operation is
computed as f(n) and may be for another operation it is computed as g(n
2
). This means
the first operation running time will increase linearly with the increase in n and the
running time of the second operation will increase exponentially when n increases.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 68


Similarly, the running time of both operations will be nearly the same if n is significantly
small.

Usually, the time required by an algorithm falls under three types −

 Best Case − Minimum time required for program execution.

 Average Case − Average time required for program execution.

 Worst Case − Maximum time required for program execution.

Asymptotic Notations

The running time of an algorithm depends on how long it takes a computer to run the
lines of code of the algorithm—and that depends on the speed of the computer, the
programming language, and the compiler that translates the program from the
programming language into code that runs directly on the computer, among other
factors.


Let's think about the running time of an algorithm more carefully. We can use a
combination of two ideas. First, we need to determine how long the algorithm takes, in
terms of the size of its input. This idea makes intuitive sense, doesn't it? We've already
seen that the maximum number of guesses in linear search and binary search
increases as the length of the array increases. Or think about a GPS. If it knew about
only the interstate highway system, and not about every little road, it should be able to
find routes more quickly, right? So we think about the running time of the algorithm as
a function of the size of its input.

The second idea is that we must focus on how fast a function grows with the input
size. We call this the rate of growth of the running time. To keep things manageable,
we need to simplify the function to distill the most important part and cast aside the
less important parts. For example, suppose that an algorithm, running on an input of

size nnn, takes 6n^2 + 100n + 3006n2+100n+3006, n, start superscript, 2, end
superscript, plus, 100, n, plus, 300 machine instructions. The 6n^26n26, n, start
superscript, 2, end superscript term becomes larger than the remaining terms, 100 n +
300100n+300100, n, plus, 300, once nnn becomes large enough, 20 in this case.
Here's a chart showing values of 6n^26n26, n, start superscript, 2, end

superscript and 100n + 300100n+300100, n, plus, 300 for values of nnn from 0 to 100:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 69





























6n^2 vs 100n+300

We would say that the running time of this algorithm grows as n^2n2n, start superscript,
2, end superscript, dropping the coefficient 6 and the remaining terms 100n +

300100n+300100, n, plus, 300. It doesn't really matter what coefficients we use; as
long as the running time is an^2 + bn + can2+bn+ca, n, start superscript, 2, end
superscript, plus, b, n, plus, c, for some numbers a > 0a>0a, is greater than, 0, bbb,
and ccc, there will always be a value of nnn for which an^2an2a, n, start superscript, 2,
end superscript is greater than bn + cbn+cb, n, plus, c, and this difference increases

as nnn increases. For example, here's a chart showing values of 0.6n^20.6n20, point, 6,
n, start superscript, 2, end superscript and 1000n + 30001000n+30001000, n, plus,
3000 so that we've reduced the coefficient of n^2n2n, start superscript, 2, end
superscript by a factor of 10 and increased the other two constants by a factor of 10:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 70





























6n^2 vs 100n+300

The value of nnn at which 0.6n^20.6n20, point, 6, n, start superscript, 2, end
superscript becomes greater than 1000n + 30001000n+30001000, n, plus, 3000 has
increased, but there will always be such a crossover point, no matter what the
constants.

By dropping the less significant terms and the constant coefficients, we can focus on
the important part of an algorithm's running time—its rate of growth—without getting
mired in details that complicate our understanding. When we drop the constant
coefficients and the less significant terms, we use asymptotic notation. We'll see three
forms of it: big-\ThetaΘ notation, big-O notation, and big-\OmegaΩ notation.

Common Asymptotic Notations

Following is a list of some common asymptotic notations −

constant − Ο(1)

logarithmic − Ο(log n)

linear − Ο(n)

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 71






n log n − Ο(n log n)


quadratic − Ο(n
2
)


cubic − Ο(n
3
)


polynomial − n
Ο(1)


exponential − 2
Ο(n)




flowchart

A flowchart is a type of diagram that represents an algorithm

Flowcharts use special shapes to represent different types of actions or steps in a
process. Lines and arrows show the sequence of the steps, and the relationships
among them. These are known as flowchart symbols.

The type of diagram dictates the flowchart symbols that are used. For example, a data
flow diagram may contain an Input/Output Symbol (also known as an I/O Symbol), but
you wouldn't expect to see it in most process flow diagrams.

Over the years, as technology has evolved, so has flowcharting. Some flowchart
symbols that were used in the past to represent computer punchcards, or punched tape,
have been relegated to the dustbin of history.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 72










































Example.

1. Flowchart to Add 10 and 20

To solve this problem we will take a variable sum and set it to zero. Then we will take
the two numbers 10 and 20 as input. Next we will add both the numbers and save the
result in the variable sum i.e., sum = 10 + 20. Finally, we will print the value stored in the
variable sum.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 73


































2. Find the sum of 5 numbers

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 74





3. Print Hello World 10 times






























4. Draw a flowchart to log in to facebook account

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 75


Introduction to Programming

Computer programming is the act of writing computer programs, which are
a sequence of instructions written using a Computer Programming
Language to perform a specified task by the computer.

A computer program is a sequence of instructions written using a Computer
Programming Language to perform a specified task by the computer.

 A computer program is also called a computer software, which can
range from two lines to millions of lines of instructions.

 Computer program instructions are also called program source code
and computer programming is also called program coding.

 A computer without a computer program is just a dump box; it
is programs that make computers active.


here are hundreds of programming languages, which can be used to write
computer programs and following are a few of them −

 Java
 C
 C++
 Python
 PHP
 Perl

 Ruby
Etc.

Today computer programs are being used in almost every field, household,
agriculture, medical, entertainment, defense, communication, etc. Listed
below are a few applications of computer programs −

 MS Word, MS Excel, Adobe Photoshop, Internet Explorer,
Chrome, etc., are examples of computer programs.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 76



 Computer programs are being used to develop graphics and special
effects in movie making.

 Computer programs are being used to perform Ultrasounds, X-Rays,
and other medical examinations.

 Computer programs are being used in our mobile phones for SMS,
Chat, and voice communication.

Types of Computer Languages with T heir Advantages and
Disadvantages


Low-Level Language/Machine Language

Machine language is the lowest and most elementary level of programming language
and was the first type of programming language to be developed. Machine language is
basically the only language that a computer can understand and it is usually written in
hex.
In fact, a manufacturer designs a computer to obey just one language, its machine
code, which is represented inside the computer by a string of binary digits (bits) 0 and 1.
The symbol 0 stands for the absence of an electric pulse and the 1 stands for the
presence of an electric pulse. Since a computer is capable of recognizing electric
signals, it understands machine language.
Advantages Disadvantages



Machine language makes fast
and efficient use of the
computer.
All operation codes have to be
remembered


It requires no translator to
translate the code. It is directly
understood by the computer.

All memory addresses have to
be remembered.


It is hard to amend or find

errors in a program written in

the machine language.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 77


Assembly Language

Assembly language was developed to overcome some of the many inconveniences of
machine language. This is another low-level but very important language in which
operation codes and operands are given in the form of alphanumeric symbols instead of
0‘s and l‘s.


These alphanumeric symbols are known as mnemonic codes and can combine in a
maximum of five-letter combinations e.g. ADD for addition, SUB for subtraction, START,
LABEL etc. Because of this feature, assembly language is also known as ‗Symbolic
Programming Language.'

This language is also very difficult and needs a lot of practice to master it because there
is only a little English support in this language. Mostly assembly language is used to
help in compiler orientations. The instructions of the assembly language are converted
to machine codes by a language translator and then they are executed by the computer.

Advantages Disadvantages

Assembly language is easier
Like machine language, it is
to understand and use as


also machine
compared to machine



dependent/specific.

language.







It is easy to locate and correct
errors.

Since it is machine dependent,
the programmer also needs to
understand the hardware.



It is easily modified.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 78


High-Level Languages

High-level computer languages use formats that are similar to English. The purpose of
developing high-level languages was to enable people to write programs easily, in their
own native language environment (English).

High-level languages are basically symbolic languages that use English words and/or
mathematical symbols rather than mnemonic codes. Each instruction in the high-level
language is translated into many machine language instructions that the computer can
understand.


Advantages Disadvantages

A high-level language has to
High-level languages are user- be translated into the machine
friendly language by a translator, which
takes up time


They are similar to English and
The object code generated by

a translator might be inefficient
use English vocabulary and


compared to an equivalent
well-known symbols



assembly language program




They are easier to learn

They are easier to maintain

They are problem-oriented
rather than 'machine'-based

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 79






Advantages Disadvantages



A program written in a high-

level language can be

translated into many machine

languages and can run on any

computer for which there

exists an appropriate translator



The language is independent

of the machine on which it is

used i.e. programs developed

in a high-level language can

be run on any computer text




Program Design

It is the process that organizations use to develop a program. Ideally, the process is
collaborative, iterative, and tentative—stakeholders work together to repeat, review, and
refine a program until they believe it will consistently achieve its purpose.

A program design is also the plan of action that results from that process. Ideally, the
plan is developed to the point that others can implement the program in the same way
and consistently achieve its purpose.

There are three fundamental steps you should perform when you have a program to
write:

1. Define the output and data flows.
2. Develop the logic to get to that output.
3. Write the program.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 80



Programming paradigms

Paradigm commonly refers to a new method of thinking about a problem or situation.
A programming paradigm is a style, or ―way,‖ of programming.

There are 4 Programming paradigms


 The imperative paradigm
 Declarative paradigm
 The functional paradigm
 The logical paradigm
 The object-oriented paradigm


imperative paradigm

Imperative programming is a paradigm of computer programming in which the
program describes a sequence of steps that change the state of the computer.
imperative programming explicitly tells the computer "how" to accomplish it. Programs
written this way often compile to binaryexecutables that run more efficiently since all
CPUinstructions are themselves imperative statements. commands show how the
computation takes place, step by step. Each step affects the global state of the
computation.

To make programs simpler for a human to read and write, imperative statements can be
grouped into sections known as code blocks. In the 1950s, the idea of grouping a
program's code into blocks was first implemented in the ALGOL programming language.
They were originally called "compound statements," but today these blocks of code are
known as procedures. Once a procedure is defined, it can be used as a single
imperative statement, abstracting the control flow of a program and allowing the
developer to express programming ideas more naturally. This type of imperative
programming is called procedural programming,

Imperative programming languages are

Ada ,ALGOL,Assembly language, BASIC, Blue, C, C#, C++, COBOL, D, FORTRAN,
Go, Groovy, Java,Julia ,Lua, MATLAB, Modula,MUMPS,
Nim,Oberon,OCaml,Pascal ,Perl,PHP,PROSE, Python, Ruby,Rust

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 81


Declarative programming

Programming by specifying the result you want, not how to get it. Declarative
programming is when you write your code in such a way that it describes what you want
to do, and not how you want to do it.
declarative programming languages are SQL and Prolog.
Ex:
select upper(name)
from people

where length(name) > 5
order by name

Functional programming

It is a style of computer programming that is based upon the evaluation of mathematical
functions.
Functional programming is based on mathematical functions.
Some of the popular functional programming languages include: Lisp, Python,
Erlang, Haskell, Clojure, etc.

The most prominent characteristics of functional programming are as follows −
 Functional programming languages are designed on the concept of mathematical
functions that use conditional expressions and recursion to perform computation.

 Functional programming supports higher-order functions and lazy
evaluation features.

 Functional programming languages don‘t support flow Controls like loop
statements and conditional statements like If-Else and Switch Statements. They
directly use the functions and functional calls.

 Like OOP, functional programming languages support popular concepts such
as Abstraction, Encapsulation, Inheritance, and Polymorphism.

Example : in Closure language

Function powerFunctionfactory(int power) {
int powerFuncion(int base) {
return pow(base, power);
}
return powerFunction;
Function square = powerFunctionFactory (2);
square(3); // returns 9


Function cube = powerFunctionFactory (3);
cube(3); // returns 27

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 82


Logic programming

Logic programming is a computer programming paradigm in

which program statements express facts and rules about problems within a system of
formal logic. Rules are written as logical clauses with a head and a body; for instance,
"H is true if B1, B2, and B3 are true." Facts are expressed similar to rules, but without a
body; for instance, "H is true."


Logic programming is characterized by programming with relations and inference.

A logic program consists of a set of axioms and a goal statement. The rules of inference
are applied to determine whether the axioms are sufficient to ensure the truth of the
goal statement. The execution of a logic program corresponds to the construction of a
proof of the goal statement from the axioms.

Some logis programming languages are Absys , Alice,ECLiPSe,F -
logic,Mercury,Oz,PROGOL etc

Example In Prolog language

likes(alice,bob).
likes(bob,carol).
likes(james,mary).
likes(mary,james).

If we write a program file called facts.pl containing the four clauses above, you can
load it on your shell by calling

consult('facts.pl').

We can ask Prolog if alice likes bob.

?- likes(alice,bob). /* our first query! */
true. /* Prolog matches it with the known fact that alice likes bob. */


where ?- is the Prolog Shell. Let‘s make some more queries.

?- likes(bob,alice).
false.

?- likes(mary,john).

false.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 83


Object-Oriented Programming

It is also known as OOP , is a programming that incorporates other segments of
external code. A good example of an object-oriented programming language is Java.

Object-oriented programming (OOP) is a programming paradigm based

upon objects (having both data and methods) that aims to incorporate the advantages
of modularity and reusability. Objects, which are usually instances of classes, are used
to interact with one another to design applications and computer programs..


Classes and objects are the two main aspects of object oriented programming. A class
creates a new type where objects are instances of the class

The important features of object–oriented programming are:

 Bottom–up approach in program design
 Programs organized around objects, grouped in classes
 Focus on data with methods to operate upon object‘s data
 Interaction between objects through functions

 Reusability of design through creation of new classes by adding features to
existing classes

Some examples of object-oriented programming languages are C++, Java,
Smalltalk, Delphi, C#, Perl, Python, Ruby, and PHP.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 84




Difference Between Procedure Oriented Programming (POP) & Object
Oriented Programming (OOP)

Procedure Oriented Object Oriented Programming
Programming

Divided Into In POP, program is divided into In OOP, program is divided into
small parts called functions. parts called objects.

Importance In POP,Importance is not given In OOP, Importance is given to the
to data but to functions as well data rather than procedures or
as sequence of actions to be functions because it works as
done. a real world.


Approach POP follows Top Down approach. OOP follows Bottom Up
approach.


Access POP does not have any access OOP has access specifiers named
Specifiers specifier. Public, Private, Protected, etc.


Data Moving In POP, Data can move freely from In OOP, objects can move and
function to function in the system. communicate with each other
through member functions.


Expansion To add new data and function in OOP provides an easy way to add
POP is not so easy. new data and function.


Data Access In POP, Most function uses Global In OOP, data can not move easily
data for sharing that can be from function to function,it can be
accessed freely from function to kept public or private so we can
function in the system. control the access of data.


Data Hiding POP does not have any proper OOP provides Data Hiding so
way for hiding data so it is less provides more security.
secure.


Overloading In POP, Overloading is not
possible.


In OOP, overloading is possible in
the form of Function Overloading
and Operator Overloading.

Examples Example of POP are : C, VB,
FORTRAN, Pascal.

Example of OOP are : C++,
JAVA, VB.NET, C#.NET.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 85



OOPs Concepts

Object means a real word entity such as pen, chair, table etc. Object-Oriented
Programming is a methodology or paradigm to design a program using classes and
objects. It simplifies the software development and maintenance by providing some
concepts:





















o Object

o Class

o Inheritance

o Polymorphism

o Abstraction

o Encapsulation




1) Class

Class is the template of an object. That logically encapsulates data members and
member functions into a single unit. Classes are data type based on which objects are
created.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 86


2) Object

object is a basic unit of OOPS. It has unique name. An object represents a particular
instance of a class. We can create more than one objects of a class. The size of class is
size of total number of data members of class.

3) Inheritance

Inheritance is the process of creating new class from existing class or base class. By
using the concept of Inheritance, we can use implemented (existing) features of a class
into another class).


Base class is also known as parent class or super class. The new class that is formed is
called derived class. The derived class is also known as sub class or child class.
Inheritance is basically used for reducing the overall code size of the program.

4) Data Encapsulation

Data encapsulation combines data members and member functions into a single unit
that is called class. The advantage of encapsulation is that data cannot access directly.
It is only accessible through the member functions of the class.

5) Data Abstraction

Data abstraction specifies hiding the implementation detail for simplicity. It increases the
power of programming language by creating user define data types.

6) Polymorphism

Polymorphism is basic and important concept of OOPS. Polymorphism specifies the
ability to assume several forms. It allows routines to use variables of different types at
different times. In C++, an operator or function can be given different meanings or
functions. Polymorphism refers to a single function or multi-functioning operator
performing in different ways.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 87



Introduction to C++

C++ is a multi-paradigm programming language that supports object-oriented
programming (OOP), created by BJarne Stroustrup in 1983 at Bell Labs, C++ is an
extension(superset) of C programming and the programs written in C language can run
in C++ compilers.

Features of C++


 The main focus remains on data rather than procedures.
 Object oriented programs are segmented into parts called objects.
 Data structures are designed to categorized the objects.
 Data member and functions are tied together as a data structure.

 Data can be hidden and cannot be accessed by external functions using access
specifier.
 Objects can communicate among themselves using functions.

 New data and functions can be easily added anywhere within a program
whenever required.

 Since this is an object-oriented programming language, it follows bottom up
approach, i.e. the execution of codes starts from the main which resides at the
lower section and then based on the member function call the working is done
from the classes.

Use of C++

 C++ is used by hundreds of thousands of programmers in essentially every
application domain.

 C++ is being highly used to write device drivers and other software that rely on
direct manipulation of hardware under realtime constraints.

 C++ is widely used for teaching and research because it is clean enough for
successful teaching of basic concepts.

 Anyone who has used either an Apple Macintosh or a PC running Windows has
indirectly used C++ because the primary user interfaces of these systems are
written in C++.


Character set

Character set is a set of valid characters that a language can recognise. A character
represents any letter, digits, or any other sign.

C++ has the following character set :

 Letters : A-Z, a-z

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 88



 Digits : 0-9

 Special Symbols : Space + - ∗ ⁄ ^ \ ( ) [ ] { } = != < > . ′ ″ $ , ; : % ! & _ # <= >= @

 White Spaces : Blank space, Horizontal tab (→), Carriage return (↵), Newline,
Form feed

 Other Characters : C++ can process any of the 256 ASCII characters as data or
as literals.


Tokens

A token is a group of characters that logically belong together. The programmer can
write a program by using tokens. C++ uses the following types of tokens. Keywords,
Identifiers, Literals, Punctuators, Operators.

1. Keywords

These are some reserved words in C++ which have predefined meaning to compiler
called keywords. It is discussed in previous section.

2. Identifiers

Symbolic names can be used in C++ for various data items used by a programmer in
his program. A symbolic name is generally known as an identifier. The identifier is a
sequence of characters taken from C++ character set. The rule for the formation of an
identifier are:

 An identifier can consist of alphabets, digits and/or underscores.
 It must not start with a digit

 C++ is case sensitive that is upper case and lower case letters are considered
different from each other.
 It should not be a reserved word.

3. Literals

Literals (often referred to as constants) are data items that never change their value
during the execution of the program. The following types of literals are available in C++.

 Integer-Constants
 Character-constants
 Floating-constants
 Strings-constants

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 89



Integer Constants

Integer constants are whole number without any fractional part. C++ allows three
types of integer constants.

Decimal integer constants : It consists of sequence of digits and should not begin
with 0 (zero). For example 124, - 179, +108.

Octal integer constants: It consists of sequence of digits starting with 0 (zero).
For example. 014, 012.

Hexadecimal integer constant: It consists of sequence of digits preceded by ox or OX.

Character constants

A character constant in C++ must contain one or more characters and must be
enclosed in single quotation marks. For example 'A', '9', etc. C++ allows nongraphic
characters which cannot be typed directly from keyboard, e.g., backspace, tab, carriage
return etc. These characters can be represented by using an escape sequence. An
escape sequence represents a single character.


Floating constants

They are also called real constants. They are numbers having fractional parts. They
may be written in fractional form or exponent form. A real constant in fractional form
consists of signed or unsigned digits including a decimal point between digits. For
example 3.0, -17.0, -0.627 etc.

String Literals

A sequence of character enclosed within double quotes is called a string literal. String
literal is by default (automatically) added with a special character ‗\0' which denotes the
end of the string. Therefore the size of the string is increased by one character. For
example "COMPUTER" will re represented as "COMPUTER\0" in the memory and its
size is 9 characters.

4. Punctuators

The following characters are used as punctuators in C++.



Opening and closing brackets indicate single and


Brackets [ ]


multidimensional array subscript.



Parentheses Opening and closing brackets indicate functions

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 90






( ) calls,; function parameters for grouping expressions
etc.


Opening and closing braces indicate the start and
Braces { }


end of a compound statement.



Comma , It is used as a separator in a function argument list.


Semicolon ; It is used as a statement terminator.


It indicates a labeled statement or conditional
Colon :


operator symbol.






Asterisk *


Equal sign =
Pound sign #

It is used in pointer declaration or as multiplication
operator.

It is used as an assignment operator.

It is used as pre-processor directive.


5. Operators

Operators are special symbols used for specific purposes. C++ provides six types of
operators. Arithmetical operators, Relational operators, Logical operators, Unary
operators, Assignment operators, Conditional operators, Comma operator

Precedence and Associativity

Precedence and Associativity are two characteristics of operators that determine the
evaluation order of subexpressions in absence of brackets.

Precedence of operators

If more than one operators are involved in an expression, C language has a predefined
rule of priority for the operators. This rule of priority of operators is called operator
precedence.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 91



precedence of arithmetic operators( *, %, /, +, -) is higher than relational operators(==,
!=, >, <, >=, <=) and precedence of relational operator is higher than logical
operators(&&, || and !).




Associativity of operators

If two operators of same precedence (priority) is present in an expression, Associativity
of operators indicate the order in which they execute.





Summary of operators with precedence and associativity



Operator Meaning of operator Associativity


Functional call


()



[]

Array element reference

Left to right



->

Indirect member selection


. Direct member selection


! Logical negation
~ Bitwise(1 's) complement
+ Unary plus
- Unary minus

++

Increment


Right to left


--

Decrement


& Dereference Operator(Address)
* Pointer reference
sizeof Returns the size of an object
(type) Type cast(conversion)

* Multiply
/ Divide Left to right
% Remainder

+ Binary plus(Addition)
Left to right

-

Binary minus(subtraction)

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 92







Summary of operators with precedence and associativity


Operator Meaning of operator Associativity

<< Left shift
Left to right

>>

Right shift



< Less than
<= Less than or equal
Left to right

>

Greater than


>= Greater than or equal


Equal to

Left to right


==




!=

Not equal to




Bitwise AND

Left to right


&





Bitwise exclusive OR

Left to right


^




Bitwise OR

Left to right


|




Logical AND

Left to right


&&




Logical OR

Left to right


||



?: Conditional Operator Right to left

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 93



Summary of operators with precedence and associativity



Operator Meaning of operator Associativity


Simple assignment



=


Assign product


*=


Assign quotient


/=


Assign remainder


%=


Assign sum


-=


Assign difference

Right to left

&=


Assign bitwise AND


^=


Assign bitwise XOR


|=


Assign bitwise OR


<<=


Assign left shift


>>=


Assign right shift





Left to right

Separator of expressions





Example in C++
#include <conio.h>
main() {
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = (a + b) * c / d; // ( 30 * 15 ) / 5
cout<< "Value of (a + b) * c / d is :" << e ;
e = ((a + b) * c) / d; // (30 * 15 ) / 5
cout << "Value of ((a + b) * c) / d is :" << e ;
e = (a + b) * (c / d); // (30) * (15/5)
cout<< "Value of (a + b) * (c / d) is : %d\n" << e ;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 94


e = a + (b * c) / d; // 20 + (150/5)
cout<< "Value of a + (b * c) / d is : %d\n" << e ;

return 0;
}

When you compile and execute the above program, it produces the following result −

Value of (a + b) * c / d is : 90

Value of ((a + b) * c) / d is : 90
Value of (a + b) * (c / d) is : 90
Value of a + (b * c) / d is : 50





Structure of C++ Program ( Layout of C++ Program)


C++ Programming language is most popular language after C Programming language.

C++ is first Object oriented programming language.We have summarize structure of

C++ Program in the following Picture –


























Structure of C++ Program

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 95



Section 1 : Header File Declaration Section


1. Header files used in the program are listed here.
2. Header File provides Prototype declaration for different library functions.
3. We can also include user define header file.
4. Basically all preprocessor directives are written in this section.




Section 2 : Global Declaration Section


1. Global Variables are declared here.
2. Global Declaration may include –

o Declaring Structure
o Declaring Class
o Declaring Variable

Section 3 : Class Declaration Section

1. Actually this section can be considered as sub section for the global declaration
section.
2. Class declaration and all methods of that class are defined here.

Section 4 : Main Function

1. Each and every C++ program always starts with main function.

2. This is entry point for all the function. Each and every method is called indirectly
through main.
3. We can create class objects in the main.
4. Operating system call this function automatically.

Section 5 : Method Definition Section



1. This is optional section . Generally this method was used in C Programming.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 96



Data types

Data types in any of the language means that what are the various type of data the
variables can have in that particular language. Information is stored in a computer
memory with different data types. Whenever a variable is declared it becomes
necessary to define data type that what will be the type of data that variable can hold
























There are 4 types of data types in C++ language.


Types

Data Types




Basic Data Type int, char, float, double, etc


Derived Data Type

array, pointer, etc



Enumeration Data Type enum


User Defined Data Type

structure

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 97



Basic Data Types

The basic data types are integer-based and floating-point based. C++ language
supports both signed and unsigned literals.

The memory size of basic data types may change according to 32 or 64 bit operating
system.

Let's see the basic data types. It size is given according to 32 bit OS.


Data Types

Memory Size

Range






char 1 byte -128 to 127


signed char

1 byte

-128 to 127






unsigned char

1 byte

0 to 127




short

2 byte

-32,768 to 32,767




signed short

2 byte

-32,768 to 32,767




unsigned short

2 byte

0 to 32,767




int 2 byte -32,768 to 32,767


signed int

2 byte

-32,768 to 32,767



unsigned int 2 byte 0 to 32,767


short int

2 byte

-32,768 to 32,767




signed short int 2 byte -32,768 to 32,767

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 98






unsigned short int

2 byte

0 to 32,767



long int 4 byte


signed long int

4 byte




unsigned long int 4 byte


float

4 byte





double

8 byte





long double

10 byte








C++ Keywords

A keyword is a reserved word. You cannot use it as a variable name, constant name
etc.

to, break, case, char, const, continue, default, do, double, elsee, num, extern , float,

for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch,
typedef, union, unsigned, void, volatile, while etc.

Variable

From a programmer's point of view, a variable is a location in your computer's memory
in which you can store a value and from which you can later retrieve that value.

A variable provides us with named storage that our programs can manipulate. Each
variable in C++ has a specific type, which determines the size and layout of the
variable's memory; the range of values that can be stored within that memory; and the
set of operations that can be applied to the variable.

Rules of Declaring variables in C++

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 99





 Variable name can consist of Capital letters A-Z, lowercase letters a-z, digits 0-9,
and the underscore character.

 The first character must be a letter or underscore.

 Blank spaces cannot be used in variable names.

 Special characters like #, $ are not allowed.

 C++ keywords can not be used as variable names.

 Variable names are case sensitive.

 A variable name can be consist of 31 characters only if we declare a
variable more than 1 characters compiler will ignore after 31 characters.

 Variable type can be bool, char, int, float, double, void or wchar_t.


Variable Definition in C++

Variable Definition in C++

A variable definition tells the compiler where and how much storage to create for the
variable. A variable definition specifies a data type, and contains a list of one or more
variables of that type as follows −

type variable_list;

Here, type must be a valid C++ data type including char, w_char, int, float, double, bool
or any user-defined object, etc., and variable_list may consist of one or more identifier
names separated by commas. Some valid declarations are shown here –

int i, j, k;

char c, ch;
float f, salary;
double d;


variable definition and initialization :

int width, height=5;
char letter='A';

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 100




Operators

C++ operator is a symbol that is used to perform mathematical or logical manipulations.
C++ language is rich with built-in operators.





















1. Assignment Operator
2. Mathematical Operators
3. Relational Operators
4. Logical Operators
5. Bitwise Operators
6. Shift Operators
7. Unary Operators
8. Ternary Operator
9. Comma Operator





Assignment Operator ( = )

Operates '=' is used for assignment, it takes the right-hand side (called rvalue) and copy
it into the left-hand side (called lvalue). Assignment operator is the only operator which
can be overloaded but cannot be inherited.

= Simple assignment operator, Assigns
C = A + B will assign value of A
values from right side operands to left
+ B into C
side operand.

+= Add AND assignment operator, It adds C += A is equivalent to C = C +

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 101



right operand to the left operand and A
assign the result to left operand.

-= Subtract AND assignment operator, It
subtracts right operand from the left
C -= A is equivalent to C = C - A

operand and assign the result to left
operand.

*= Multiply AND assignment operator, It
multiplies right operand with the left
C *= A is equivalent to C = C * A
operand and assign the result to left
operand.

/= Divide AND assignment operator, It
divides left operand with the right operand C /= A is equivalent to C = C / A
and assign the result to left operand.

%= Modulus AND assignment operator, It
C %= A is equivalent to C = C %
takes modulus using two operands and

A
assign the result to left operand.


<<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2

>>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2

&= Bitwise AND assignment operator. C &= 2 is same as C = C & 2

^= Bitwise exclusive OR and assignment
C ^= 2 is same as C = C ^ 2
operator.

|= Bitwise inclusive OR and assignment
C |= 2 is same as C = C | 2
operator.




Example,

int x=10;

x += 4 // will add 4 to 10, and hence assign 14 to X.


x -= 5 // will subtract 5 from 10 and assign 5 to x.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 102


Mathematical Operators

There are operators used to perform basic mathematical operations. Addition (+) , subtraction
(-) , diversion (/) multiplication (*) and modulus (%) are the basic mathematical operators.
Modulus operator cannot be used with floating-point numbers.

C++ and C also use a shorthand notation to perform an operation and assignment at same
type.


+ Adds two operands A + B will give 30

- Subtracts second operand from the first A - B will give -10

* Multiplies both operands A * B will give 200

/ Divides numerator by de-numerator B / A will give 2

% Modulus Operator and remainder of after an integer division B % A will give 0




Relational Operators

These operators establish a relationship between operands. The relational operators are : less
than (<) , grater thatn (>) , less than or equal to (<=), greater than equal to (>=), equivalent
(==) and not equivalent (!=).

You must notice that assignment operator is (=) and there is a relational operator, for
equivalent (==). These two are different from each other, the assignment operator assigns the
value to any variable, whereas equivalent operator is used to compare values, like in if-else
conditions,

Example

int x = 10; //assignment operator
x=5; // again assignment operator

if(x == 5) // here we have used equivalent relational operator, for comparison

{

cout <<"Successfully compared";

}

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 103


Logical Operators

The logical operators are AND (&&) and OR (||). They are used to combine two different
expressions together.


If two statement are connected using AND operator, the validity of both statements will be
considered, but if they are connected using OR operator, then either one of them must be
valid. These operators are mostly used in loops (especially while loop) and in Decision
making.

Assume variable A = 1 and variable B = 0, then

&& Called Logical AND operator. If both the operands are non- (A && B) is
zero, then condition becomes true. false.

|| Called Logical OR Operator. If any of the two operands is (A || B) is true.
non-zero, then condition becomes true.

! Called Logical NOT Operator. Use to reverses the logical !(A && B) is true.
state of its operand. If a condition is true, then Logical NOT
operator will make false.




Bitwise Operators


There are used to change individual bits into a number. They work with only integral data
types like char, int and long and not with floating point values.

 Bitwise AND operators &
 Bitwise OR operator |
 And bitwise XOR operator ^
 And, bitwise NOT operator ~

They can be used as shorthand notation too, & = , |= , ^= , ~= etc.

& Binary AND Operator copies a bit Assume A=60 , B=13
to the result if it exists in both
operands. (A & B) will give 12 which is 0000 1100

| Binary OR Operator copies a bit if Assume A=60 , B=13
it exists in either operand.
(A | B) will give 61 which is
0011 1101

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 104



^ Binary XOR Operator copies the Assume A=60 , B=13
bit if it is set in one operand but
not both. (A ^ B) will give 49 which is 0011 0001

~ Binary Ones Complement Assume A=60 , B=13
Operator is unary and has the
effect of 'flipping' bits. (~A ) will give -61 which is 1100 0011 in 2's
complement form due to a signed binary
number.




Shift Operators

Shift Operators are used to shift Bits of any variable. It is of three types,

1. Left Shift Operator <<
2. Right Shift Operator >>


<< Binary Left Shift Operator. The left operands value is moved Assume A=60 , B=13
left by the number of bits specified by the right operand.
A << 2 will give 240
which is 1111 0000

>> Binary Right Shift Operator. The left operands value is Assume A=60 , B=13
moved right by the number of bits specified by the right
operand. A >> 2 will give 15
which is 0000 1111



Unary Operators

These are the operators which work on only one operand. There are many
unary operators, but increment ++ and decrement -- operators are most used.

++ Increment operator, increases integer value by one A++ will give 11

-- Decrement operator, decreases integer value by one A-- will give 9

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 105


Other Unary Operators :

address of &,

dereference *,

new and delete,

bitwise not ~,

logical not !,

unary minus - and

unary plus +.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 106





Ternary Operator

The ternary if-else

? : is an operator which has three operands.

int a = 10;

a > 5 ? cout << "true" : cout << "false"





Comma Operator


This is used to separate variable names and to separate expressions. In case of
expressions, the value of last expression is produced and used.

Example :

int a,b,c; // variables declaration using comma operator

a=b++, c++; // a = c++ will be done.

Eexpression.

An expression can be defined as a combination of variables, constants and operators
that represents a computation

Arithmetic expression is an expression in which arithmetic operators are used is
called arithmetic expression

Modes of Arithmetic Expressions

1.Mixed arithmetic
2.Real arithmetic
3.Integer arithmetic

Integer arithmetic mode

In this mode when arithmetic operation perform by using integer values it
always result an integer value.

for example:
a=5 , b=5

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 107




a*b=25 , a/b=1 , a+b=10 , a-b=0

Real arithmetic mode
In this mode when a arithmetic operation is performed by using

floating point numbers it always result an floating value.
a=10.0 , b=5.0
a*b=50.0 a/b=2.0 a+b=15.0 a-b=5.0

Mixed arithmetic mode

In this mode when an arithmetic operation performed on float and integer values it
always result a float value.

For example:
a=10 , b=5.0
a*b=50.0,a/b=2.0,a+b=15.0,a-b=5.0


Relational expression - A relational operator with constants and variables makes
relational expression or An expressions in which relational operators are use is
called relational expression.

Statements and Control structures

A simple C++ statement is each of the individual instructions of a program, like the
variable declarations and expressions .

They always end with a semicolon (;), and are executed in the same order in which they
appear in a program..

A compound statement is a grouping of statements in which each individual statement
ends with a semi-colon. The group of statements is called block. Compound statements
are enclosed between the pair of braces ({}.). The opening brace ({) signifies the
beginning and closing brace (}) signifies the end of the block.

But programs are not limited to a linear sequence of statements. During its process,
a program may repeat segments of code, or take decisions and bifurcate. For that
purpose, C++ provides flow control statements that serve to specify what has to be
done by our program, when, and under which circumstances.

Control Structure

A. Conditional Statements
B. Looping statement
C. Jump Statements

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 108



A .Conditional Statements

Sometimes the program needs to be executed depending upon a particular condition.
C++ provides the following statements for implementing the selection control structure.

 if statement
 if else statement
 nested if statement
 switch statement

if statement

syntax of the if statement

if (condition)

{
statement(s);
}

From the flowchart it is clear that if the if condition is true, statement is executed;
otherwise it is skipped. The statement may either be a single or compound statement.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 109




if else statement

syntax of the if - else statement

if (condition)
statement1;
else
statement2;

From the above flowchart it is clear that the given condition is evaluated first. If the
condition is true, statement1 is executed. If the condition is false, statement2 is
executed. It should be kept in mind that statement and statement2 can be single or
compound statement.


if example

if else example





if (x == 100)

if (x == 100)


cout << "x is 100"; cout << "x is 100";

else


cout << "x is not 100";



Nested if statement

The if block may be nested in another if or else block. This is called nesting of if or
else block.

syntax of the nested if statement

if(condition 1)
{
if(condition 2)
{
statement(s);
}
}

if(condition 1)
statement 1;
else if (condition 2)
statement2;
else
statement3;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 110



if-else-if example


if(percentage>=60)

cout<<"Ist division";

else if(percentage>=50)

cout<<"IInd division";

else if(percentage>=40)

cout<<"IIIrd division";

else

cout<<"Fail" ;



switch statement

The if and if-else statements permit two way branching whereas switch statement
permits multiple branching. The syntax of switch statement is:

switch (var / expression)
{
case constant1 : statement 1;
break;
case constant2 : statement2;
break;
.
.
default: statement3;
break;

}

The execution of switch statement begins with the evaluation of expression. If the value
of expression matches with the constant then the statements following this statement
execute sequentially till it executes break. The break statement transfers control to the
end of the switch statement. If the value of expression does not match with any
constant, the statement with default is executed.

Some important points about switch statement

 The expression of switch statement must be of type integer or character type.
 The default case need not to be used at last case. It can be placed at any place.
 The case values need not to be in specific order.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 111




B. Looping statement

It is also called a Repetitive control structure. Sometimes we require a set of
statements to be executed a number of times by changing the value of one or more
variables each time to obtain a different result. This type of program execution is called
looping. C++ provides the following construct

 while loop
 do-while loop
 for loop

While loop

Syntax of while loop


while(condition)
{
statement(s);
}

The flow diagram indicates that a condition is first evaluated. If the condition is true,
the loop body is executed and the condition is re-evaluated. Hence, the loop body is
executed repeatedly as long as the condition remains true. As soon as the condition
becomes false, it comes out of the loop and goes to the statement next to the ‗while‘
loop.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 112



do-while loop

Syntax of do-while loop

do
{
statements;
} while (condition);

Note : That the loop body is always executed at least once. One important difference
between the while loop and the do-while loop the relative ordering of the conditional test
and loop body execution. In the while loop, the loop repetition test is performed before
each execution the loop body; the loop body is not executed at all if the initial test fail. In
the do-while loop, the loop termination test is Performed after each execution of the
loop body. hence, the loop body is always executed least once.



for loop

It is a count controlled loop in the sense that the program knows in advance how many
times the loop is to be executed.

syntax of for loop
for (initialization; decision; increment/decrement)
{
statement(s);
}

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 113





The flow diagram indicates that in for loop three operations take place:

 Initialization of loop control variable
 Testing of loop control variable
 Update the loop control variable either by incrementing or decrementing.

Operation (i) is used to initialize the value. On the other hand, operation (ii) is used to
test whether the condition is true or false. If the condition is true, the program executes
the body of the loop and then the value of loop control variable is updated. Again it
checks the condition and so on. If the condition is false, it gets out of the loop.




C. Jump Statements / Branching Statement

The jump statements unconditionally transfer program control within a function.

 goto statement
 break statement
 continue statement

The goto statement
goto allows to make jump to another point in the program.
goto pqr;

pqr: pqr is known as label. It is a user defined identifier. After the execution of goto
statement, the control transfers to the line after label pqr.

The break statement

The break statement, when executed in a switch structure, provides an immediate
exit from the switch structure. Similarly, you can use the break statement in

any of the loop. When the break statement executes in a loop, it immediately exits
from the loop.

The continue statement

The continue statement is used in loops and causes a program to skip the rest of the
body of the loop.
while (condition)
{
Statement 1;
If (condition)
continue;
statement;
}
The continue statement skips rest of the loop body and starts a new iteration.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 114



The exit ( ) function

The execution of a program can be stopped at any point with exit ( ) and a status code
can be informed to the calling program. The general format is exit (code) ;

where code is an integer value. The code has a value 0 for correct execution. The
value of the code varies depending upon the operating system.

Input/Output (I/O)

The standard C++ library includes the header file iostream, which can be used to feed
new data into the computer or obtain output on an output device such as: VDU, printer
etc. The following C++ stream objects can be used for the input/output purpose.

 cout console output
 cin console input

cout object

cout is used to print message on screen in conjunction with the insertion operator <<

cout << "Hello World"; // prints Hello world on screen
cout << 250; // prints number 250 on screen

cout << sum; // prints the content of variable sum on screen

To print constant strings of characters we must enclose them
between double quotes (").

If we want to print out a combination of variables and constants, the insertion operator

(<<) may be used more than once in a single statement cout
<< "Area of rectangle is " << area << " square meter" ;

If we assume the area variable to contain the value 24 the output of the
previous statement would be:

Area of rectangle is 24 square meter

cin object

cin can be used to input a value entered by the user from the keyboard. However, the
extraction operator >> is also required to get the typed value from cin and store it in
the memory location.

Let us consider the following program segment:
int marks;
cin >> marks;

In the above segment, the user has defined a variable marks of integer type in the first
statement and in the second statement he is trying to read a value from the keyboard.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 115


// input output example
#include <iostream>
using namespace std;

int main ()
{

int length;
int breadth;
int area;

cout << "Please enter length of rectangle: ";
cin >> length;

cout << "Please enter breadth of rectangle:
"; cin >> breadth;

area = length * breadth;

cout << "Area of rectangle is " << area;
return 0;
Output :
Please enter length of rectangle: 6
Please enter breadth of rectangle: 4
Area of rectangle is 24
You can also use cin to request more than one input from the user:
cin >> length >> breadth;

is equivalent to:

cin >> length;
cin >> breadth;

cin and strings


We can use cin to get strings with the extraction operator (>>) as we do
with fundamental data type variables:

cin >> mystring;

However, cin extraction stops reading as soon as if finds any blank space character, so
in this case we will be able to get just one word for each extraction.

for example if we want to get a sentence from the user, this extraction operation would
not be useful.

In order to get entire lines, we can use the function getline, which is the more
recommendable way to get user input with cin:

// cin and strings
#include <iostream>

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 116


#include <string>
using namespace std;

int main ()
{
string name;
cout << "Enter your name";
getline (cin, name);
cout << "Hello " << name << "!\n";
return 0;
}

Output
Enter your name : Aniket Rajput
Hello Aniket Rajput!

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 117



Array

C++ provides a data structure, the array, which stores a fixed-size sequential collection
of elements of the same type. An array is used to store a collection of data, but it is
often more useful to think of an array as a collection of variables of the same type.

Instead of declaring individual variables, such as number0, number1, ..., and
number99, you declare one array variable such as numbers and use numbers[0],
numbers[1], and ..., numbers[99] to represent individual variables. A specific element
in an array is accessed by an index.

All arrays consist of contiguous memory locations. The lowest address corresponds
to the first element and the highest address to the last element.

Declaring Arrays


To declare an array in C++, the programmer specifies the type of the elements and
the number of elements required by an array as follows −

type arrayName [ arraySize ];

This is called a single-dimension array. The arraySize must be an integer constant
greater than zero and type can be any valid C++ data type. For example, to declare
a 10-element array called balance of type double, use this statement −

double balance[10];

For example,
int Age[5] ;
float cost[30];


















Initializing Arrays

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 118






You can initialize C++ array elements either one by one or using a single statement
as follows −

double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};

The number of values between braces { } can not be larger than the number of
elements that we declare for the array between square brackets [ ]. Following is
an example to assign a single element of the array −

If you omit the size of the array, an array just big enough to hold the initialization
is created. Therefore, if you write −

double balance[] = {1000.0, 2.0, 3.4, 17.0, 50.0};

You will create exactly the same array as you did in the previous example.


balance[4] = 50.0;

The above statement assigns element number 5
th
in the array a value of 50.0. Array
with 4
th
index will be 5
th
, i.e., last element because all arrays have 0 as the index of
their first element which is also called base index. Following is the pictorial
representaion of the same array we discussed above −










Accessing Array Elements

An element is accessed by indexing the array name. This is done by placing the index
of the element within square brackets after the name of the array. For example −

double salary = balance[9];

The above statement will take 10
th
element from the array and assign the value to
salary variable. Following is an example, which will use all the above-mentioned three
concepts viz. declaration, assignment and accessing arrays −

#include <iostream>
using namespace std;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 119




#include <iomanip>
using std::setw;

int main () {

int n[ 10 ]; // n is an array of 10 integers

// initialize elements of array n to
0 for ( int i = 0; i < 10; i++ ) {
n[ i ] = i + 100; // set element at location i to i + 100
}
cout << "Element" << setw( 13 ) << "Value" << endl;

// output each array element's value
for ( int j = 0; j < 10; j++ ) {

cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl;
}

return 0;
}

This program makes use of setw() function to format the output. When the
above code is compiled and executed, it produces the following result −

Element Value

0 100

1 101

2 102

3 103

4 104

5 105

6 106

7 107

8 108

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 120



9 109




Multidimensional arrays

Multidimensional arrays can be described as "arrays of arrays". For example, a
bidimensional array can be imagined as a two-dimensional table made of elements,
all of them of a same uniform data type.









jimmy represents a bidimensional array of 3 per 5 elements of type int. The C++ syntax
for this is:


int jimmy [3][5];




and, for example, the way to reference the second element vertically and
fourth horizontally in an expression would be:


jimmy[1][3]














(remember that array indices always begin with zero).

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 121


Function


A function is a group of statements that together perform a task. Every C++ program
has at least one function, which is main(), and all the most trivial programs can define
additional functions.

You can divide up your code into separate functions. How you divide up your code
among different functions is up to you, but logically the division usually is such that
each function performs a specific task.

A function declaration tells the compiler about a function's name, return type, and
parameters. A function definition provides the actual body of the function.

The C++ standard library provides numerous built-in functions that your program can
call. For example, function strcat() to concatenate two strings, function memcpy() to
copy one memory location to another location and many more functions.

A function is known with various names like a method or a sub-routine or a procedure
etc.

Defining a Function


The general form of a C++ function definition is as follows −

return_type function_name( parameter list )
{ body of the function

}

A C++ function definition consists of a function header and a function body.

Here are all the parts of a function −

 Return Type − A function may return a value. The return_type is the data type of
the value the function returns. Some functions perform the desired operations
without returning a value. In this case, the return_type is the keyword void.

 Function Name − This is the actual name of the function. The function name
and the parameter list together constitute the function signature.

 Parameters − A parameter is like a placeholder. When a function is invoked,
you pass a value to the parameter. This value is referred to as actual parameter
or argument. The parameter list refers to the type, order, and number of the
parameters of a function. Parameters are optional; that is, a function may
contain no parameters.

 Function Body − The function body contains a collection of statements
that define what the function does.

Example

Following is the source code for a function called max(). This function takes two
parameters num1 and num2 and returns the maximum between the two −

// function returning the max between two
numbers int max(int num1, int num2) {

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 122



// local variable
declaration int result;

if (num1 > num2)
result = num1;
else
result = num2;

return result;

}

Function Declarations

A function declaration tells the compiler about a function name and how to call the
function. The actual body of the function can be defined separately.


A function declaration has the following parts −

return_type function_name( parameter list );

For the above defined function max(), following is the function declaration −

int max(int num1, int num2);

Parameter names are not important in function declaration only their type is required,
so following is also valid declaration −

int max(int, int);

Function declaration is required when you define a function in one source file and you
call that function in another file. In such case, you should declare the function at the top
of the file calling the function.

Calling a Function

While creating a C++ function, you give a definition of what the function has to do. To
use a function, you will have to call or invoke that function.

When a program calls a function, program control is transferred to the called function. A
called function performs defined task and when it‘s return statement is executed or
when its function-ending closing brace is reached, it returns program control back to the
main program.

To call a function, you simply need to pass the required parameters along with
function name, and if function returns a value, then you can store returned value.

For example −
#include <iostream>
using namespace std;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 123



// function declaration
int max(int num1, int num2);

int main () {

// local variable
declaration: int a = 100;

int b = 200;
int ret;

// calling a function to get max
value. ret = max(a, b);
cout << "Max value is : " << ret << endl;

return 0;

}

// function returning the max between two numbers
int max(int num1, int num2) {
// local variable declaration
int result;

if (num1 > num2)
result = num1;
else
result = num2;

return result;
}

I kept max() function along with main() function and compiled the source code. While
running final executable, it would produce the following result −

Max value is : 200
Function Arguments

If a function is to use arguments, it must declare variables that accept the values of
the arguments. These variables are called the formal parametersof the function.

The formal parameters behave like other local variables inside the function and
are created upon entry into the function and destroyed upon exit.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 124






While calling a function, there are two ways that arguments can be passed to a function



Sr.No Call Type & Description

1 Call by Value

This method copies the actual value of an argument into the formal parameter
of the function. In this case, changes made to the parameter inside the
function have no effect on the argument.


2 Call by Pointer

This method copies the address of an argument into the formal parameter.
Inside the function, the address is used to access the actual argument used in
the call. This means that changes made to the parameter affect the argument.



3 Call by Reference

This method copies the reference of an argument into the formal parameter.
Inside the function, the reference is used to access the actual argument used
in the call. This means that changes made to the parameter affect the
argument.


By default, C++ uses call by value to pass arguments. In general, this means that code
within a function cannot alter the arguments used to call the function and above
mentioned example while calling max() function used the same method.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 125





UNIT III

Object & Classes, Scope Resolution Operator, Constructors & Destructors, Friend Functions,
Inheritance, Polymorphism, Overloading Functions & Operators, Types of Inheritance,
Virtual functions. Introduction to Data Structures.

Classes and Objects

The classes are the most important feature of C++ that leads to Object Oriented programming.
Class is a user defined data type, which holds its own data members and member functions,
which can be accessed and used by creating instance of that class.

The variables inside class definition are called as data members and the functions are
called member functions.


 A class is an abstract data type similar to ‘C structure‘.

 Class representation of objects and the sets of operations that can be applied to
such objects.
 Class consists of Data members and methods.

For example : Class of birds, all birds can fly and they all have wings and beaks. So here flying is
a behavior and wings and beaks are part of their characteristics. And there are many different
birds in this class with different names but they all posses this behavior and characteristics.

Similarly, class is just a blue print, which declares and defines characteristics and behavior,
namely data members and member functions respectively. And all objects of this class will
share these characteristics and behavior.

Primary purpose of a class is to held data/information. This is achieved with attributes which is
also know as data members.

The member functions determine the behavior of the class i.e. provide definition for
supporting various operations on data held in form of an object.

Definition of a class
Syntax:
Class class_name
{
Data Members;
Methods;
}

1. Class name must start with an uppercase letter (Although this is not mandatory). If
class name is made of more than one word, then first letter of each word must be in
uppercase.
Example,

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 126




class Study, class StudyTonight etc

2. Classes contain, data members and member functions, and the access of these data
members and variable depends on the access specifiers (discussed in next section).

3. Class's member functions can be defined inside the class definition or outside the class
definition.

4. Class in C++ are similar to structures in C, the only difference being, class defaults to
private access control, where as structure defaults to public.

5. All the features of OOPS, revolve around classes in C++. Inheritance, Encapsulation,
Abstraction etc.

6. Objects of class holds separate copies of data members. We can create as many
objects of a class as we need.

7. Classes do posses more characteristics, like we can create abstract classes,
immutable classes, all this we will study later.



Two keywords: private and public are used in the class

The private keyword makes data and functions private. Private data and functions can be
accessed only from inside the same class.

The public keyword makes data and functions public. Public data and functions can be
accessed out of the class.




Objects

Class is mere a blueprint or a template. No storage is assigned when we define a class.
Objects are instances of class, which holds the data variables declared in class and the
member functions work on these class objects.

Each object has different data variables. Objects are initialised using special class
functions called Constructors.

Define C++ Objects :

A class provides the blueprints for objects, so basically an object is created from a class. We
declare objects of a class with exactly the same sort of declaration that we declare variables
of basic types.

Following statements declare two objects of class Box −
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 127





Both of the objects Box1 and Box2 will have their own copy of data members.

Example:
class Abc
{
int x;
void display(){} //empty function
};

in main()
{
Abc obj; // Object of class Abc created
}



Accessing the Data Members

The public data members of objects of a class can be accessed using the direct member
access operator (.).

Example −

#include <iostream>
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box

double height; // Height of a box
};

int main() {
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box
double volume = 0.0; // Store the volume of a box here

// box 1 specification
Box1.height = 5.0;
Box1.length = 6.0;
Box1.breadth = 7.0;

// box 2 specification
Box2.height = 10.0;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 128



Box2.length = 12.0;

Box2.breadth = 13.0;

// volume of box 1

volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;

// volume of box 2

volume = Box2.height * Box2.length *
Box2.breadth; cout << "Volume of Box2 : " <<
volume <<endl; return 0;

}



Example -

class Test
{
private:
int data1;
float data2;

public:
void function1()
{ data1 = 2; }

float function2()

{
data2 = 3.5;
return data2;
}
};

int main()
{
Test o1, o2;
}
Here, two objects o1 and o2 of Test class are created.

In the above class Test, data1 and data2 are data members and function1() and function2() are
member functions.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 129



Scope resolution operator

Scope resolution operator(::) is used to define a function outside a class or when we want to
use a global variable but also has a local variable with same name.

C++ programming code

#include <iostream>
char c = 'a'; // global variable

int main() {
char c = 'b'; //local variable

cout << "Local variable: " << c << "\n";

cout << "Global variable: " << ::c << "\n"; //using scope resolution operator

return 0;
}
Output of program:
Local variable: b
Global variable: a
Scope resolution operator in class
#include <iostream>
using namespace std;

class programming {
public:
void output(); //function declaration
};

// function definition outside the class

void programming::output() {
cout << "Function defined outside the class.\n";
}

int main() {
programming x;
x.output();

return 0;
}

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 130



Constructors

Constructors is a special member functions of class and it is used to initialize the objects of its
class. It is treated as a special member function because its name is the same as the class name.
These constructors get invoked whenever an object of its associated class is created. It is
named as “constructor” because it constructs the value of data member of a class. Initial values
can be passed as arguments to the constructor function when the object is declared.

The declaration and definition of constructor is as
follows class class_name
{
int g, h;
public: class_name(void); // Constructor Declared . . .
};

class_name :: class_name()

{
g=1;
h=2; // Constructor defined
}

C++ offers three types of constructors. These are:
1. Default constructor
2. Parameterized constructor
3. Copy constructor

1.Default Constructor

Default constructor is the constructor which doesn’t take any argument. It has no
parameter but programmer can write some initialization statement there.

Syntax:


class_name()

{

// Constructor Definition ;
}


#include <iostream>

using namespace std;

class Calc

{

int val;

public:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 131


Calc()

{

val = 20;

}

};


int main()

{

Calc c1;

cout << c1.val;

}


2. Parameterized Constructor

A default constructor does not have any parameter, but programmers can add and use
parameters within a constructor if required. This helps programmers to assign initial values
to an object at the time of creation.

Example-
#include <iostream>
using namespace std;

class Calc
{
int val2;
public:
Calc(int x)
{
val2=x;
}
};
int main()
{
Calc c1(10);
Calc c2(20);
Calc c3(30);

cout << c1.val2;
cout << c2.val2;
cout << c3.val2; }

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 132



3. Copy Constructor

C++ provides a special type of constructor which takes an object as argument, and is used to
copy values of data members of one object into other object. In this case, copy constructors
are used to declare and initialize object from another object.

#include <iostream>
using namespace std;
class CopyCon
{
int a, b;
public:
CopyCon(int x, int y)
{
a = x;
b = y;

cout << "\nHere is the initialization of Constructor";

}
void Display()
{
cout << "\nValues : \t" << a << "\t" << b;
}
};

void main()
{
CopyCon Object(30, 40); //Copy Constructor
CopyCon Object2 = Object;
Object.Display();
Object2.Display();
}
Destructors:

As the name implies, destructors are used to destroy the objects that have been created by the
constructor within the C++ program. Destructor names are same as the class name but they
are preceded by a tilde (~). It is a good practice to declare the destructor after the end of using
constructor.

Here’s the basic declaration procedure of a destructor:
~Cube()
{

}

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 133



The destructor neither takes a argument nor returns any value and the compiler implicitly
invokes upon the exit from the program for cleaning up storage that is no longer accessible.

friend function

A friend function of a class is defined outside that class' scope but it has the right to access
all private and protected members of the class. Even though the prototypes for friend
functions appear in the class definition, friends are not member functions.

To declare a function as a friend of a class, precede the function prototype in the
class definition with keyword friend

class class_name
{
... .. ...

friend return_type function_name(argument/s);

... .. ...
}

Example-
#include<iostream.h>
#include<conio.h>

class base {
int val1, val2;
public:
void get() {
cout << "Enter two values:";
cin >> val1>>val2;
}
friend float mean(base b);

};

float mean(base b) {
return float(b.val1 + b.val2) / 2;
}

void main() {
clrscr();
base obj;
obj.get();
cout << "\n Mean value is : " << mean(obj);

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 134


getch();

}
Output-
Enter two values: 10, 20
Mean Value is: 15

Example-
#include <iostream.h>
using namespace std;

class A{
private:
int x;
public:

A(){

x = 0;
}
friend int show( A ); // declaring friend function
};

int show(A s){ // friend function definition
s.x = 5;
return s.x;
}
int main(){
A obj;
cout<<"Value of a : "<< show(obj);
return 0;
}

Output :
Value of a : 5


Polymorphism

Polymorphism is derived from 2 greek words: poly and morphs. The word "poly" means
many and morphs means forms. So polymorphism means many forms.


There are two types of polymorphism in C++:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 135


Compile time polymorphism: It is achieved by function overloading and operator overloading
which is also known as static binding or early binding.

o Runtime polymorphism: It is achieved by method overriding which is also known as
dynamic binding or late binding.


Compile time polymorphism

In C++ programming you can achieve compile time polymorphism in two way, which is
given below;

 Function/method overloading
 Operator Overloading

Method Overloading in C++

Whenever same method name is exiting multiple times in the same class with different number
of parameter or different order of parameters or different types of parameters is known

as method overloading. In below example method "sum()" is present in Addition class
with same name but with different signature or arguments.

Example of Method Overloading in C++

#include<iostream.h>
#include<conio.h>

class Addition
{
public:
void sum(int a, int b)
{
cout<<a+b;
}
void sum(int a, int b, int c)
{
cout<<a+b+c;
}

};
void main()
{
clrscr();
Addition obj;
obj.sum(10, 20);
cout<<endl;
obj.sum(10, 20, 30);

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 136



}

Output
30
60


Operators Overloading

Operator overloading is used to overload or redefine most of the operators available in C++.
It is used to perform operation on user define data type.

The advantage of Operators overloading is to perform different operations on the
same operand.


Almost any operator can be overloaded in C++. However there are few operator which can
not be overloaded. Operator that are not overloaded are follows

scope operator - ::
sizeof
member selector - .
member pointer selector - *
ternary operator - ?:
Operator Overloading Syntax

Syntax of operator overloading(inside class)

Return type operator operator-symbol(argument list)
{
…….
…….

}


Syntax of operator overloading(outside class)













Example

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 137



Let's see the simple example of operator overloading in C++. In this example, void operator
++ () operator function is defined (inside Test class).

#include <iostream>
using namespace std;
class Test
{
private:
int num;
public:
Test()

{

Num=8;
}
void operator ++()
{
num = num+2;
}
void Print() {
cout<<"The Count is: "<<num;
}
};
int main()
{
Test tt;
++tt; // calling of a function "void operator ++()"
tt.Print();

return 0;
}
Output:

The Count is: 10

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 138


perform subtraction using +

#include <iostream>
using namespace std;
class NUM
{
private:
int x;
public:
num (int k)

{

X = k;
}
NUM operator +(NUM n)
{
NUM s;
S.X =X-.n.X;
Return S;

}
void Print() {
cout<<"X= "<<X;
}
};
int main()
{
NUM a(10),b(5),c;
C=a+b;
c.print();
}
Output:

The Count is: 5

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 139




Method Overriding :

Define any method in both base class and derived class with same name, same parameters or
signature, this concept is known as method overriding.


In below example same method "show()" is present in both base and derived class with
same name and signature.

Example of Method Overriding in C++
#include<iostream.h>
#include<conio.h>

class Base
{
public:
void show()
{
cout<<"Base class";

}

};
class Derived:public Base
{
public:
void show()
{
cout<<"Derived Class";
}
}

int mian()
{
Base b; //Base class object
Derived d; //Derived class object
b.show(); //Early Binding Ocuurs

d.show();
getch();
}
Output
Base class
Derived Class

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 140



Inheritance

The technique of deriving a new class from an old one is called inheritance. The old class is
referred to as base class and the new class is referred to as derived class or sub class.

Inheritance concept allows programmers to define a class in terms of another class, which
makes creating and maintaining application easier. When writing a new class, instead of writing
new data member and member functions all over again, programmers can make a bonding of
the new class with the old one that the new class should inherit the members of the existing
class. A class can get derived from one or more classes, which means it can inherit data and
functions from multiple base classes.

syntax how inheritance is performed in C++:

class derived-class: visibility-mode base-class

Visibility mode is used in inheritance of C++ to show or relate how base classes are viewed with
respect to derived class. When one class gets inherited from another, visibility mode is used to
inherit all the public and protected members of the base class. Private members never get
inherited and hence do not take part in visibility. By default, visibility mode remains “private”.


What are Base class and Derived class?

The existing class from which the derived class gets inherited is known as the base class. It acts
as a parent for its child class and all its properties i.e. public and protected members get
inherited to its derived class.

A derived class can be defined by specifying its relationship with the base class in addition to
its own detains, i.e. members.

The general form of defining a derived class is:

class derived-class_name : visivility-mode base-class_name
{
. . . . // members of the derived class
. . . .
};

C++ offers five types of Inheritance. They are:
 Single Inheritance
 Multiple Inheritance
 Hierarchical Inheritance
 Multilevel Inheritance
 Hybrid Inheritance (also known as Virtual Inheritance)

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 141









































Single Inheritance

In single inheritance there is only one base class and one derived class. The Derived class
gets inherited from its base class. This is the simplest form of inheritance.

Example-
Step 1: Start the program.
Step 2: Declare the base class emp.
Step 3: Define and declare the function get() to get the employee details.
Step 4: Declare the derived class salary.
Step 5: Declare and define the function get1() to get the salary details.
Step 6: Define the function calculate() to find the net pay.
Step 7: Define the function display().

Step 8: Create the derived class object.
Step 9: Read the number of employees.
Step 10: Call the function get(),get1() and calculate() to each employees.

Step 11: Call the display().

#include<iostream.h>

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 142




#include<conio.h>

class emp {
public:
int eno;
char name[20], des[20];

void get() {
cout << "Enter the employee number:";
cin>>eno;
cout << "Enter the employee name:";
cin>>name;
cout << "Enter the designation:";
cin>>des;

}

};

class salary : public emp
{
float bp, hra, da, pf, np;
public:
void get1() {
cout << "Enter the basic pay:";
cin>>bp;

cout << "Enter the Humen Resource
Allowance:"; cin>>hra;
cout << "Enter the Dearness Allowance :";
cin>>da;
cout << "Enter the Profitablity Fund:";
cin>>pf;

}

void calculate() {
np = bp + hra + da - pf;
}

void display() {
cout << eno << "\t" << name << "\t" << des << "\t" << bp << "\t" << hra << "\t" << da << "\t"
<< pf << "\t" << np << "\n";
}
};

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 143




void main() {
int i, n;
char ch;
salary s[10];
clrscr();
cout << "Enter the number of employee:";
cin>>n;

for (i = 0; i < n; i++) {
s[i].get();
s[i].get1();
s[i].calculate();
}

cout << "\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for (i = 0; i < n; i++) {

s[i].display();
}
getch();
}

Multiple Inheritance -
In this type of inheritance, a single derived class may inherit from two or more base classes

Example:
#include <iostream>
using namespace std;

class stud {
protected:
int roll, m1, m2;

public:
void get()
{
cout << "Enter the Roll No.: "; cin >> roll;
cout << "Enter the two highest marks: "; cin >> m1 >> m2;
}
};
class extracurriculam
{
protected:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 144




int xm;

public:
void getsm()
{
cout << "\nEnter the mark for Extra Curriculam Activities: "; cin >> xm;
}
};

class output : public stud,public extracurriculam
{
int tot, avg;
public:
void display()

{

tot = (m1 + m2 + xm);
avg = tot / 3;
cout << "\n\n\tRoll No : " << roll << "\n\tTotal : " << tot;
cout << "\n\tAverage : " << avg;
}
};
int main()
{
output O;
O.get();
O.getsm();
O.display();
}


Hierarchical Inheritance
In this type of inheritance, multiple derived classes get inherited from a single base class

Class base_classname
{
properties;
methods;
};
Class derived_class1 : visibility_mode base_classname
{
properties;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 145





methods;

};
class derived_class2 : visibility_mode base_classname
{
properties;
methods;
};
... ... ... ... ... ...

class derived_classN : visibility_mode base_classname
{
properties;
methods;
};


#include <iostream>

#include <string.h>
using namespace std;
class member
{
char gender[10];
int age;
public:
void get()
{
cout << "Age: ";
cin >> age;
cout << "Gender: ";
cin >> gender;
}
void disp()

{
cout << "Age: " << age << endl;
cout << "Gender: " << gender << endl;
}
};

class stud : public member
{
char level[20];
public:
void getdata()

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 146




member::get();
cout << "Class: ";
cin >> level;
}
void disp2()
{
member::disp();

cout << "Level: " << level << endl;
}
};

class staff : public member
{

float salary;

public:
void getdata()
{
member::get();
cout << "Salary: Rs.";
cin >> salary;
}

void disp3()
{
member::disp();
cout << "Salary: Rs." << salary << endl;
}
};

int main()
{
member M;
staff S;
stud s;
cout << "Student" << endl;
cout << "Enter data" << endl;
s.getdata();
cout << endl << "Displaying data" << endl;
s.disp();
cout << endl << "Staff Data" << endl;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 147




cout << "Enter data" << endl;

S.getdata();
cout << endl << "Displaying data" << endl;
S.disp();
}

Multilevel Inheritance

The classes can also be derived from the classes that are already derived. This type
of inheritance is called multilevel inheritance.

#include <iostream>
using namespace std;

class base {

public:

void display1()
{
cout << "\nBase class content.";
}
};
class derived : public base {
public:
void display2(){
cout << "1st derived class content.";
}
};

class derived2 : public derived {
void display3()

{
cout << "\n2nd Derived class content.";
}
};
int main()
{
derived2 D;
//D.display3();
D.display2();
D.display1();
}

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 148




Virtual function.

- A virtual function is a member function that is declared within a base class and redefined by a
derived class. To create virtual function, precede the function’s declaration in the base class
with the keyword virtual. When a class containing virtual function is inherited, the derived
class redefines the virtual function to suit its own needs.

- Base class pointer can point to derived class object. In this case, using base class pointer if we
call some function which is in both classes, then base class function is invoked. But if we want to
invoke derived class function using base class pointer, it can be achieved by defining the function
as virtual in base class, this is how virtual functions support runtime polymorphism.

- Consider the following program code :
Class A
{

int a;

public:
A()
{
a = 1;
}
virtual void show()
{
cout <<a;
}
};
Class B: public A
{
int b;
public:
B()

{
b = 2;
}
virtual void show()
{
cout <<b;
}
};
int main()
{
A *pA;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 149




B oB;

pA = &oB;
pA→show();
return 0;
}
- Output is 2 since pA points to object of B and show() is virtual in base class A.

Difference between Overloading and Overriding

- Overloading is defining functions that have similar signatures, yet have
different parameters.

- Overriding is only pertinent to derived classes, where the parent class has
defined a method and the derived class wishes to override that function.

Overriding Overloading
Methods name and signatures must be same. Having same method name with different
Signatures.
Overriding is the concept of runtime polymorphism Overloading is the concept of compile time polymorphism
When a function of base class is re-defined in the derived Two functions having same name and return type, but
class called as Overriding with different type and/or number of arguments is called
as Overloading
It needs inheritance. It doesn't need inheritance.
Method should have same data type. Method can have different data types
Method should be public. Method can be different access specifies



Introduction to Data Structure

Data Structure : A data structure is a collection (grouping) of simple or structured data
types and a set of rules (operations) for organising and accessing the collection. Some
examples of data structures would be: an array, structs, classes, lists, strings, stacks,
queues, files and tables. The underlying theme here is that each structure has a defined
organisation and a set of rules that implement and control the organisation.

What is Data Structure?

1. A data structure is a systematic way of organizing and accessing data.
2. A data structure tries to structure data!

 Usually more than one piece of data
 Should define legal operations on the data
 The data might be grouped together (e.g. in an linked list)

3. When we define a data structure we are in fact creating a new data type of our
own.
 i.e. using predefined types or previously user defined types.
 Such new types are then used to reference variables type within a
program

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 150





Why Data Structures?

1. Data structures study how data are stored in a computer
so that operations can be implemented efficiently

2. Data structures are especially important when you have a
large amount of information

3. Conceptual and concrete ways to organize data for
efficient storage and manipulation.


Data Definition

Data Definition defines a particular data with following characteristics.

 Atomic − Definition should define a single concept

 Traceable − Definition should be be able to be mapped to some data element.

 Accurate − Definition should be unambiguous.

 Clear and Concise − Definition should be understandable.

Data Object ; Data Object represents an object having a data.


Data Type

A data type is a type of data , a better definition of a data type is a data storage format
that can contain a specific type or range of values.

When computer programs store data in variables, each variable must be assigned a
specific data type. Some common data types include integers, floating point
numbers,characters, strings, and arrays.

Data type is way to classify various types of data such as integer, string etc. which
determines the values that can be used with the corresponding type of data, the type of
operations that can be performed on the corresponding type of data. Data type of two
types −

 Built-in Data Type

 Derived Data Type

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 151


Built-in Data Type

Those data types for which a language has built-in support are known as Built-in Data
types. For example, most of the languages provides following built-in data types.

 Integers

 Boolean (true, false)

 Floating (Decimal numbers)

 Character and Strings


Derived Data Type

Those data types which are implementation independent as they can be implemented
in one or other way are known as derived data types. These data types are normally
built by combination of primary or built-in data types and associated operations on
them. For example −


 List

 Array

 Stack

 Queue


Basic Operations

The data in the data structures are processed by certain operations. The particular data
structure chosen largely depends on the frequency of the operation that needs to be
performed on the data structure.

 Traversing

 Searching

 Insertion

 Deletion

 Sorting

 Merging



Linear vs Nonlinear Data Structures


A data structure is a method for organizing and storing data, which would allow efficient
data retrieval and usage. Linear data structure is a structure that organizes its data

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 152



elements one after the other. Linear data structures are organized in a way similar to
how the computer‘s memory is organized. Nonlinear data structures are constructed by
attaching a data element to several other data elements in such a way that it reflects a
specific relationship among them. Nonlinear data structures are organized in a different
way than the computer‘s memory.


Linear data structures


Linear data structures organize their data elements in a linear fashion, where data
elements are attached one after the other. Data elements in a liner data structure are
traversed one after the other and only one element can be directly reached while
traversing. Linear data structures are very easy to implement, since the memory of the
computer is also organized in a linear fashion. Some commonly used linear data
structures are arrays, linked lists, stacks and queues. An arrays is a collection of data
elements where each element could be identified using an index. A linked list is a
sequence of nodes, where each node is made up of a data element and a reference to
the next node in the sequence. A stack is actually a list where data elements can only
be added or removed from the top of the list. A queue is also a list, where data elements
can be added from one end of the list and removed from the other end of the list.

Nonlinear data structures


In nonlinear data structures, data elements are not organized in a sequential fashion. A
data item in a nonlinear data structure could be attached to several other data elements
to reflect a special relationship among them and all the data items cannot be traversed
in a single run. Data structures like multidimensional arrays, trees and graphs are some
examples of widely used nonlinear data structures. A multidimensional array is simply a
collection of one-dimensional arrays. A tree is a data structure that is made up of a set
of linked nodes, which can be used to represent a hierarchical relationship among data
elements. A graph is a data structure that is made up of a finite set of edges and
vertices. Edges represent connections or relationships among vertices that stores data
elements.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 153



Difference between Linear and Nonlinear Data Structures




Main difference between linear and nonlinear data structures lie in the way they
organize data elements. In linear data structures, data elements are organized
sequentially and therefore they are easy to implement in the computer‘s memory. In
nonlinear data structures, a data element can be attached to several other data
elements to represent specific relationships that exist among them. Due to this
nonlinear structure, they might be difficult to be implemented in computer‘s linear
memory compared to implementing linear data structures. Selecting one data structure
type over the other should be done carefully by considering the relationship among the
data elements that needs to be stored.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 154



UNIT IV

Computer Networking: Introduction, Goals, ISO-OSI Model, Functions of Different Layers.
Internetworking Concepts, Devices, TCP/IP Model. Introduction to Internet, World Wide Web,
E-commerce . Introduction to viruses, worms, malware, Trojans, Spyware and Anti-Spyware
Software, Different types of attacks like Money Laundering, Information Theft, Cyber
Pornography, Email spoofing, Denial of Service (DoS), Cyber Stalking, ,Logic bombs, Hacking
Spamming, Cyber Defamation , pharming Security measures Firewall, Computer Ethics

& Good Practices, Introduction of Cyber Laws about Internet Fraud, Good Computer Security
Habits

Introduction

A computer network is a system in which multiple computers are connected to each other
to share information and resources.



















Characteristics of a Computer Network
 Share resources from one computer to another.

 Create files and store them in one computer, access those files from the
other computer(s) connected over the network.

 Connect a printer, scanner, or a fax machine to one computer within the network and let
other computers of the network use the machines available over the network.

Following is the list of hardware's required to set up a computer network.
 Network Cables
 Distributors

 Routers
 Internal Network Cards
 External Network Cards

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 155



GOALS OF NETWORKING

 Resource and load sharing
o Programs do not need to run on a single machine
 Reduced cost
o Several machines can share printers, tape drives, etc.
 High reliability

o If a machine goes down, another can take over
 Mail and communication

OSI Model

The OSI Model is a theoretical, seven-layered model of how networks work. The Open Systems
Interconnect Model (the OSI Model) is a theoretical model of networking that organizes
network functions into seven layers (physical layer, datalink layer, network layer, transport
layer, session layer, presentation layer and application layer) and specifies the communication
interfaces between the OSI Model's layers and between network endpoints utilizing an OSI
Model-based protocol suite.

 The OSI Model is a way of thinking about how networks 'work'
 THEORY: The OSI Model is a theoretical model

o The OSI Model is not a technology.
o The OSI Model is not a protocol.

o The OSI Model is not a program or software.

The OSI model is not a networking standard in the same sense that Ethernet and TCP/IP are
networking standards. Rather, the OSI model is a framework into which the various networking
standards can fit. The OSI model specifies what aspects of a network’s operation can be
addressed by various network standards. So, in a sense, the OSI model is sort of a standard of
standards.

The Seven Layers of the OSI Model


Layer Name Description
1 Physical Governs the layout of cables and devices such as repeaters
and hubs.

2 Data Link Provides MAC addresses to uniquely identify network nodes
and a means for data to be sent over the Physical layer in the
form of packets. Bridges and switches are layer 2 devices.

3 Network Handles routing of data across network segments.

4 Transport Provides for reliable delivery of packets.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 156


5 Session Establishes sessions between network applications.

6 Presentation Converts data so that systems that use different data formats
can exchange information.


7

Application

Allows applications to request network services.




Functions of Different Layers :

Layer 1: The Physical Layer :
1. It is the lowest layer of the OSI Model.
2. It activates, maintains and deactivates the physical connection.

3. It is responsible for transmission and reception of the unstructured raw data over
network.
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.


Layer 2: 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.
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.

Layer 3: The 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.

Layer 4: Transport Layer :
1. It decides if data transmission should be on parallel path or single path.

2. Functions such as Multiplexing, Segmenting or Splitting on the data are done by
this layer

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 157




3. It receives messages from the Session layer above it, convert the message into
smaller units and passes it on to the Network layer.

4. Transport layer can be very complex, depending upon the network requirements.
Transport layer breaks the message (data) into small units so that they are handled
more efficiently by the network layer.

Layer 5: The Session Layer :

1. Session layer manages and synchronize the conversation between two
different applications.

2. Transfer of data from source to destination session layer streams of data are marked
and are resynchronized properly, so that the ends of the messages are not cut
prematurely and data loss is avoided.

Layer 6: The Presentation Layer :

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

2. While receiving the data, presentation layer transforms the data to be ready for the
application layer.

3. Languages(syntax) can be different of the two communicating systems. Under
this condition presentation layer plays a role of translator.
4. It performs Data compression, Data encryption, Data conversion etc.

Layer 7: Application Layer :
1. It is the topmost layer.

2. Transferring of files disturbing the results to the user is also done in this layer. Mail
services, directory services, network resource etc are services provided by
application layer.

3. This layer mainly holds application programs to act upon the received and to be
sent data.


FCS means FRAME CHECK SEQUENCE

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 158


TCP/IP Protocol Architecture

TCP/IP protocols map to a four-layer conceptual model known as the DARPA model , named
after the U.S. government agency that initially developed TCP/IP. The four layers of the DARPA
model are: Application, Transport, Internet, and Network Interface. Each layer in the DARPA
model corresponds to one or more layers of the seven-layer Open Systems Interconnection
(OSI) model.












Network Interface Layer

The Network Interface layer (also called the Network Access layer) is responsible for placing
TCP/IP packets on the network medium and receiving TCP/IP packets off the network medium.
TCP/IP was designed to be independent of the network access method, frame format, and
medium. In this way, TCP/IP can be used to connect differing network types. These include LAN
technologies such as Ethernet and Token Ring and WAN technologies such as X.25 and Frame
Relay. Independence from any specific network technology gives TCP/IP the ability to be
adapted to new technologies such as Asynchronous Transfer Mode (ATM).

The Network Interface layer encompasses the Data Link and Physical layers of the OSI model.
Note that the Internet layer does not take advantage of sequencing and acknowledgment
services that might be present in the Data-Link layer. An unreliable Network Interface layer is
assumed, and reliable communications through session establishment and the sequencing
and acknowledgment of packets is the responsibility of the Transport layer.

Internet Layer

The Internet layer is responsible for addressing, packaging, and routing functions. The
core protocols of the Internet layer are IP, ARP, ICMP, and IGMP.

 The Internet Protocol (IP) is a routable protocol responsible for IP addressing, routing,
and the fragmentation and reassembly of packets.

 The Address Resolution Protocol (ARP) is responsible for the resolution of the Internet
layer address to the Network Interface layer address such as a hardware address.

 The Internet Control Message Protocol (ICMP) is responsible for providing diagnostic
functions and reporting errors due to the unsuccessful delivery of IP packets.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 159


The Internet Group Management Protocol (IGMP) is responsible for the management of

IP multicast groups.
The Internet layer is analogous to the Network layer of the OSI model.

Transport Layer

The Transport layer (also known as the Host-to-Host Transport layer) is responsible for
providing the Application layer with session and datagram communication services. The core
protocols of the Transport layer are Transmission Control Protocol (TCP) and the User Datagram
Protocol (UDP).

 TCP provides a one-to-one, connection-oriented, reliable communications service. TCP is
responsible for the establishment of a TCP connection, the sequencing and
acknowledgment of packets sent, and the recovery of packets lost during transmission.

 UDP provides a one-to-one or one-to-many, connectionless, unreliable communications
service. UDP is used when the amount of data to be transferred is small (such as the
data that would fit into a single packet), when the overhead of establishing a TCP
connection is not desired or when the applications or upper layer protocols provide

reliable delivery.

The Transport layer encompasses the responsibilities of the OSI Transport layer and some
of the responsibilities of the OSI Session layer.

Application Layer

The Application layer provides applications the ability to access the services of the other layers
and defines the protocols that applications use to exchange data. There are many Application
layer protocols and new protocols are always being developed.

The most widely-known Application layer protocols are those used for the exchange of
user information:

 The Hypertext Transfer Protocol (HTTP) is used to transfer files that make up the
Web pages of the World Wide Web.

 The File Transfer Protocol (FTP) is used for interactive file transfer.

 The Simple Mail Transfer Protocol (SMTP) is used for the transfer of mail messages
and attachments.

 Telnet, a terminal emulation protocol, is used for logging on remotely to network
hosts. Additionally, the following Application layer protocols help facilitate the use and
management of TCP/IP networks:

 The Domain Name System (DNS) is used to resolve a host name to an IP address.

 The Routing Information Protocol (RIP) is a routing protocol that routers use
to exchange routing information on an IP internetwork.

 The Simple Network Management Protocol (SNMP) is used between a network
management console and network devices (routers, bridges, intelligent hubs) to collect
and exchange network management information.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 160



Internetwork

An internetwork is a collection of individual networks, connected by intermediate networking
devices, that functions as a single large network. Internetworking refers to the industry,
products, and procedures that meet the challenge of creating and administering internetworks.
Figure illustrates some different kinds of network technologies that can be interconnected by
routers and other networking devices to create an internetwork:

Figure : Different network technologies can be connected to create an internetwork.


















Networking devices:

Network Hub:

Network Hub is a networking device which is used to connect multiple network hosts. A
network hub is also used to do data transfer. The data is transferred in terms of packets on a
computer network. So when a host sends a data packet to a network hub, the hub copies the
data packet to all of its ports connected to. Like this, all the ports know about the data and
the port for whom the packet is intended, claims the packet.

However, because of its working mechanism, a hub is not so secure and safe. Moreover,
copying the data packets on all the interfaces or ports makes it slower and more congested
which led to the use of network switch.

Network Switch:

Like a hub, a switch also works at the layer of LAN (Local Area Network) but you can say that a
switch is more intelligent than a hub. While hub just does the work of data forwarding, a switch
does ‘filter and forwarding’ which is a more intelligent way of dealing with the data packets. So,
when a packet is received at one of the interfaces of the switch, it filters the packet and sends only
to the interface of the intended receiver. For this purpose, a switch also maintains a

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 161



CAM (Content Addressable Memory) table and has its own system configuration and memory.

CAM table is also called as forwarding table or forwarding information base (FIB).

Modem:

A Modem is somewhat a more interesting network device in our daily life. So if you have
noticed around, you get an internet connection through a wire (there are different types of
wires) to your house. This wire is used to carry our internet data outside to the internet world.

However, our computer generates binary data or digital data in forms of 1s and 0s and on
the other hand, a wire carries an analog signal and that’s where a modem comes in.

A modem stands for (Modulator+Demodulator). That means it modulates and demodulates
the signal between the digital data of a computer and the analogue signal of a telephone line.

Network Router:

A router is a network device which is responsible for routing traffic from one to another
network. These two networks could be a private company network to a public network. You can
think of a router as a traffic police who directs different network traffic to different directions.


Repeater:

A repeater is an electronic device that amplifies the signal it receives. In other terms, you
can think of repeater as a device which receives a signal and retransmits it at a higher level
or higher power so that the signal can cover longer distances.

Bridge:
A bridge operates on two layers of OSI model that are, physical layer and a data link layer. A
bridge can divide a large network into smaller segments and is also used to connect two
originally separated LANs. The purpose of a bridge is to transmit the frame between two
separate LANs.
When a bridge receives a frame, it regenerates the signal and checks the destination address
of the frame and forwards the new copy of the frame only to the segment to which it
belongs. A bridge does not broadcast the frame to all the stations in receiver segment; it
only forwards the frame to destination/receiver station.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 162


Let us understand the working of a bridge in following steps:-
 A bridge receives a frame which contains its destination address on it.
 A bridge maintains a look-up table which contains the physical address of all the
stations that are connected to it.
 It compares the destination address in the frame, with the addresses in the look-up
table.
 If a match is found, then the bridge recognises to which segment the packet belongs
and forward the packet to its destination station.

There are three types of the bridges:-
Simple Bridge: – It is the least expensive bridge. Connects only two LANs. Addresses in the
lookup table are fed manually. Maintenance is time-consuming than cost saving.
Multiport Bridge: -Connects more than two LANs.
Transparent Bridge: – Dynamically builds its look-up table and keeps the table updating
during its bridging operations.

Gateway:
A Gateway operates on all seven layers of OSI model. A gateway work as a “protocol
converter”. A router can accept and transfer packets only across a network using similar
protocols. But, a gateway can accept and transfer the packet across networks using a
different protocol. A gateway is a software installed within a router.

The steps performed by a gateway when it accepts a packet formatted in a protocol are as
follow:-
 A gateway accepts a packet which is formatted for a protocol (e.g. Apple Talk), used
by the sender’s network.
 It then converts that packet to be formatted for another protocol (e.g. TCP/IP), used
by the receiver’s network.
 After converting the format of the packet, a gateway forward that packet to its
destination/receivers network.
Sometimes the modification is needed only to header and trailer of the packet and
sometimes a gateway has to adjust the data rate, size, and format of the packet.

Key Differences Between Bridge and Gateway
1. A bridge is always used to regenerate the signal and find the most efficient path to
transmit the frame. A gateway is used to increase the compatibility to establish the
communication between two networks using two different protocol.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 163


2. A bridge always operates on frames, and the gateway operates on packets.
3. Bridge operates on physical layer and data link layer whereas, a gateway can operate
on all the layers of OSI model.




The Internet

The Internet is a vast, electronic network connecting many millions of computers from every
corner of the world. The Internet is a publicly-accessible network that "consists of millions
of smaller domestic, academic, business, and government networks" .

The Internet began as ARPANET back in 1969. ARPANET was a large wide-area network created
by the United States Department of Defense Advanced Research Project Agency (ARPA). It
served as a testbed for new networking technologies. It linked many universities and research
centers.

A computer connected to the Internet is commonly referred to as a host. Connections are made
using telephone lines, cable data lines, fiber-optic, or even wireless signals. This connected-ness
allows computers to send and receive information in the form of digitized data on demand. The
data is passed back and forth between host computers using packets and protocols, such as
electronic mail (e-mail) for messaging, file transfer protocol (FTP) for moving files, telnet for
accessing information, hypertext transfer protocol (HTTP) for serving up Web sites, custom

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 164




protocols, etc. Other common services of the Internet include the World Wide Web (WWW),
Voice Over IP (VoIP), Instant Messaging (IM), streaming media, etc.

The Internet itself is decentralized---no one entity is completely responsible or has total control;
however, your connection to the Internet is probably controlled by an Internet Service Provider
(ISP).

When your computer is connected to the Internet you are online. Nowadays one typically has
to plug-in to a network outlet, or select an active wireless signal, or dial into a service provider
using a modem to get online. Sometimes one must authenticate one's computer with the
controlling ISP in order to gain connectivity.

In order for host computers to share information there needs to be a way to identify each
computer. This is where the IP address comes in. IP stands for Internet Protocol and is
metaphorically the postal address of your machine, identifying its location on the Internet. An
IP address looks something like this: 199.199.254.254. The problem is that people have a hard
time remembering an IP address, so along came Domain Name Services to make it easier on us.
DNS: Names are Easier than Numbers

Domain Name Services (DNS) attach text to our numeric IP addresses, allowing users to use the
DNS as a proxy for the IP address. While IP addresses are often provided by your ISP, one must
register a domain name for a cost through a DNS hosting service. DNS host servers then are
used to convert our text DNS address to its digital IP address equivalent. For example:

 161.28.224.138 is equivalent to www.uvsc.edu
 216.239.57.104 is equivalent to www.google.com
 66.94.230.41 is equivalent to www.yahoo.com

World Wide Web

The Internet is not the same as the World Wide Web (WWW or just the Web), though this is a
common and understandable misperception. The World Wide Web consists of all the Web sites
and pages served on the Internet via HTTP. In addition to the fact that Web pages are served by
HTTP, a central identifying feature of Web pages is their use of hyperlinks, which allow a user to
quickly move from one web page to another, even if the pages are on different servers in
different parts of the world! Though the Web relies on the Internet to connect your web
browser to different web servers, the Web is just a part of a number of systems that make up
the Internet.

What is WWW?

WWW stands for World Wide Web. A technical definition of the World Wide Web is − All the
resources and users on the Internet that are using the Hypertext Transfer Protocol (HTTP).

A broader definition comes from the organization that Web inventor Tim Berners-Lee helped
found, the World Wide Web Consortium (W3C): The World Wide Web is the universe of
network-accessible information, an embodiment of human knowledge.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 165



In simple terms, The World Wide Web is a way of exchanging information between computers
on the Internet, tying them together into a vast collection of interactive multimedia resources.

What is HTTP?

HTTP stands for Hypertext Transfer Protocol. This is the protocol being used to transfer
hypertext documents that makes the World Wide Web possible.

A standard web address such as Yahoo.com is called a URL and here the prefix http indicates its
protocol

What is URL?

URL stands for Uniform Resource Locator, and is used to specify addresses on the World Wide
Web. A URL is the fundamental network identification for any resource connected to the web
(e.g., hypertext pages, images, and sound files).

A URL will have the following format − protocol://hostname/other_information

The protocol specifies how information is transferred from a link. The protocol used for web
resources is HyperText Transfer Protocol (HTTP). Other protocols compatible with most web
browsers include FTP, telnet, newsgroups, and Gopher.

The protocol is followed by a colon, two slashes, and then the domain name. The domain name
is the computer on which the resource is located.

Links to particular files or subdirectories may be further specified after the domain name. The
directory names are separated by single forward slashes.


What is Website?

website is a collection of various pages written in HTML markup language. This is a location on
the web where people can find tutorials on latest technologies. Similarly, there are millions of
websites available on the web.

Each page available on the website is called a web page and first page of any website is called
home page for that site.

What is Web Server?

Every Website sits on a computer known as a Web server. This server is always connected to
the internet. Every Web server that is connected to the Internet is given a unique address made
up of a series of four numbers between 0 and 256 separated by periods. For example,
68.178.157.132 or 68.122.35.127.

When you register a Web address, also known as a domain name. you have to specify the IP
address of the Web server that will host the site.
What is Web Browser?

Web Browsers are software installed on your PC. To access the Web you need a web browsers,
such as Netscape Navigator, Microsoft Internet Explorer or Mozilla Firefox.

Currently you must be using any sort of Web browser while you are navigating through my site
tutorialspoint.com. On the Web, when you navigate through pages of information this is
commonly known as browsing or surfing.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 166



What is SMTP Server?
SMTP stands for Simple Mail Transfer Protocol Server. This server takes care of delivering
emails from one server to another server. When you send an email to an email address, it is
delivered to its recipient by a SMTP Server.
What is ISP?

ISP stands for Internet Service Provider. They are the companies who provide you service in
terms of internet connection to connect to the internet.

You will buy space on a Web Server from any Internet Service Provider. This space will be used
to host your Website.

What is HTML?

HTML stands for Hyper Text Markup Language. This is the language in which we write web
pages for any Website. Even the page you are reading right now is written in HTML.

This is a subset of Standard Generalized Mark-Up Language (SGML) for electronic publishing,
the specific standard used for the World Wide Web.
What is Hyperlink?

A hyperlink or simply a link is a selectable element in an electronic document that serves as an
access point to other electronic resources. Typically, you click the hyperlink to access the linked
resource. Familiar hyperlinks include buttons, icons, image maps, and clickable text links.
What is DNS?

DNS stands for Domain Name System. When someone types in your domain name,
www.example.com, your browser will ask the Domain Name System to find the IP that hosts
your site. When you register your domain name, your IP address should be put in a DNS along
with your domain name. Without doing it your domain name will not be functioning properly.
What is W3C?

W3C stands for World Wide Web Consortium which is an international consortium of
companies involved with the Internet and the Web.

The W3C was founded in 1994 by Tim Berners-Lee, the original architect of the World Wide
Web. The organization's purpose is to develop open standards so that the Web evolves in a
single direction rather than being splintered among competing factions. The W3C is the chief
standards body for HTTP and HTML.

Malware

“Malware” is short for “malicious software” – it is a computer programs designed to
infiltrate(घसपैठु) and damage computers without the users consent. “Malware” is the general

term covering all the different types of threats to your computer safety such as viruses,
spyware, worms, trojans, rootkits and so on.


 Virus: A computer virus is a type of malware that propagates by inserting a copy of itself
into and becoming part of another program. It spreads from one computer to another,
leaving infections as it travels . the virus may exist on a system but will not be active or
able to spread until a user runs or opens the malicious host file or program. When the
host code is executed, the viral code is executed as well. Normally, the host program

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 167


keeps functioning after it is infected by the virus. However, some viruses overwrite
other programs with copies of themselves, which destroys the host program altogether.
Viruses spread when the software or document they are attached to is transferred from
one computer to another using the network, a disk, file sharing, or infected e-mail. They
usually appear as an executable file.

 Worms: Computer worms are similar to viruses in that they replicate functional copies
of themselves and can cause the same type of damage. In contrast to viruses, which
require the spreading of an infected host file, worms are standalone software and do
not require a host program or human help to propagate. Worms infect entire networks
of devices, either local or across the internet, by using network interfaces. It uses each
consecutive infected machine to infect more. worms are standalone software and do
not require a host program or human help to propagate.


 Trojans: This kind of malware disguises itself as legitimate software, or is included in
legitimate software that has been tampered with. Trojans are also known to create back
doors to give malicious users access to the system. Unlike viruses and worms, Trojans
do not reproduce by infecting other files nor do they self-replicate. Trojans must spread
through user interaction such as opening an e-mail attachment or downloading and
running a file from the Internet.


 Spyware: No surprise here: spyware is malware designed to spy on you. It hides in the
background and takes notes on what you do online, including your passwords, credit
card numbers, surfing habits and more.


 Ransomware: Also called scareware, this kind of malware can lock down your
computer and threaten to erase everything — unless a ransom is paid to its owner.


 Adware: Though not always malicious in nature, particularly aggressive advertising
software can undermine your security just to serve you ads — which can give a lot of
other malware a way in. Plus, let’s face it: pop-ups are really annoying.


 Botnets: An Internet Bot, also known as web robot, WWW robot or simply bot, is
a software application that runs automated tasks (scripts) over the Internet. Typically,
bots perform tasks that are both simple and structurally repetitive, at a much higher
rate than would be possible for a human alone. The largest use of bots is in web
spidering (web crawler), in which an automated script fetches, analyzes and files
information from web servers at many times the speed of a human. A typical use of
bots is to gather information (such as web crawlers), or interact automatically
with instant messaging (IM), Internet Relay Chat (IRC), or other web interfaces. They
may also be used to interact dynamically with websites.
Bots can be used for either good or malicious intent.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 168


 There are malicious bots (and botnets) of the following types:
1. Spambots that harvest email addresses from contact or guestbook pages
2. Downloader programs that suck bandwidth by downloading entire websites
3. Website scrapers that grab the content of websites and re-use it without permission
on automatically generated doorway pages
4. Viruses and worms
5. DoS attacks
6. Botnets, zombie computers, etc.
 Bots are also used to buy up good seats for concerts, particularly by ticket brokers who
resell the tickets. Bots are employed against entertainment event-ticketing sites. The
bots are used by ticket brokers to unfairly obtain the best seats for themselves while
depriving the general public of also having a chance to obtain the good seats. The bot
runs through the purchase process and obtains better seats by pulling as many seats
back as it can.
 Bots are often used in Massively Multiplayer Online Roleplaying Games to farm for
resources that would otherwise take significant time or effort to obtain; this is a concern
for most online in-game economies.
Bots are also used to increase views for YouTube videos.

Botnets are networks of infected computers that are made to work together under the
control of an attacker.


The most widely used anti-bot technique is the use of CAPTCHA(Completely Automated Public Turing test to
tell Computers and Humans Apart"), which is a form of Turing test used to distinguish between a human
user and a less-sophisticated AI-powered bot, by the use of graphically-encoded human-
readable text.

Email spoofing

Email spoofing is the forgery of an email header so that the message appears to have originated
from someone or somewhere other than the actual source. Email spoofing is a tactic used

in phishing and spam campaigns because people are more likely to open an email when they
think it has been sent by a legitimate source. The goal of email spoofing is to get recipients to
open, and possibly even respond to, a solicitation.

Denial-of-Service (DoS) attack

A Denial-of-Service (DoS) attack is an attack meant to shut down a machine or network, making
it inaccessible to its intended users. DoS attacks accomplish this by flooding the target with
traffic, or sending it information that triggers a crash. In both instances, the DoS attack
deprives legitimate users (i.e. employees, members, or account holders) of the service or
resource they expected.

There are two general methods of DoS attacks:
1) flooding services

2) crashing services.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 169


flooding services : Flood attacks occur when the system receives too much traffic for the server
to buffer, causing them to slow down and eventually stop.

crashing services : In these attacks, input is sent that takes advantage of bugs in the target that
subsequently crash or severely destabilize the system, so that it can’t be accessed or used.


Logic bombs

A logic bomb, also known as “slag code”, is a malicious piece of code which is intentionally
inserted into software to execute a malicious task when triggered by a specific event. It’s not a
virus, although it usually behaves in a similar manner. It is stealthily inserted into the program
where it lies dormant until specified conditions are met. Malicious software such as viruses and
worms often contain logic bombs which are triggered at a specific payload or at a predefined
time. The payload of a logic bomb is unknown to the user of the software, and the task that it
executes unwanted. Program codes that are scheduled to execute at a particular time are
known as “time-bombs”. For example, the infamous “Friday the 13th” virus which attacked the
host systems only on specific dates; it “exploded” (duplicated itself) every Friday that happened
to be the thirteenth of a month, thus causing system slowdowns.

Cyber stalking (stalking means irritation, annoyance)

Cyber stalking is a new form of internet crime in our society when a person is pursued or
followed online. A cyber stalker doesn’t physically follow his victim; he does it virtually by
following his online activity to harvest information about the stalkee and harass him or her and
make threats using verbal intimidation(threat). It’s an invasion(attack) of one’s online privacy.

Cyber stalking uses the internet or any other electronic means and is different from offline
stalking, but is usually accompanied by it. Most victims of this crime are women who are
stalked by men and children who are stalked by adult predators and pedophiles. Cyber stalkers
thrive on inexperienced web users who are not well aware of netiquette and the rules of
internet safety. A cyber stalker may be a stranger, but could just as easily be someone you
know.

Cyber stalkers harass their victims via email, chat rooms, web sites, discussion forums and open
publishing web sites (e.g. blogs). The availability of free email / web site space and the
anonymity provided by chat rooms and forums has contributed to the increase of cyber stalking
incidents. Everyone has an online presence nowadays, and it’s really easy to do a Google search
and get one’s name, alias, contact number and address, contributing to the menace that is
cyber stalking. As the internet is increasingly becoming an integral part of our personal and
professional lives, stalkers can take advantage of the ease of communications and the
availability of personal information only a few mouse clicks away


Hacking

Hacking is identifying weakness in computer systems or networks to exploit its weaknesses to
gain access. Example of Hacking: Using password cracking algorithm to gain access to a system.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 170


A Hacker is a person who finds and exploits the weakness in computer systems and/or
networks to gain access. Hackers are usually skilled computer programmers with knowledge
of computer security.

Ethical Hacking is identifying weakness in computer systems and/or computer networks and
coming with countermeasures that protect the weaknesses. Ethical hackers must abide by
the following rules.

 Get written permission from the owner of the computer system and/or computer
network before hacking.
 Protect the privacy of the organization been hacked.

 Transparently report all the identified weaknesses in the computer system to the
organization.

 Inform hardware and software vendors of the identified weaknesses.

Spamming

Spamming is the use of electronic messaging systems like e-mails and other digital delivery
systems and broadcast media to send unwanted bulk messages indiscriminately.

Spam is usually not targeted to specific email addresses. Instead, the email addresses are
collected at random for the purpose of emailing promotions and other junk. Since the email
addresses are not targeted, the idea of mailing the promotions is a numbers game in the eyes
of the spammer.

Sending out spam is a really easy and inexpensive process, which is why a lot of marketers who
are lazy and want to find a get-rich-quick way to make money resort to spamming. The reality
is, it is not a quick way to make money and you face a lot of headaches in the aftermath of a
spam promotion.

Spammers use software that is specifically designed for spamming. The software has the
capability to weave its way down through the layers in the Internet to collect hundreds of
thousands of email addresses from websites, social networking groups, and any other sorces
where people reveal their email addresses. The addresses are collected in a very short amount
of time. Once the addresses are collected, the spammer simply enters the sales message into
the software, creates a title, and then presses "Send." It is that easy.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 171



Cyber defamation (defamation means insult, offence)

Cyber defamation is a new concept but the traditional definition of the term is defamation of a
person through a new and a potential medium. The term defamation is used to define the
injury that incurred to the reputation of a person in the eyes of a third person. The so called
injury can be done by verbally or written, or by signs or visible representations. The intention of
the person, making the defamatory statement against whom, must be to lower the reputation
of that person in the eyes of the general public.

Cyber Defamation is also a cyber crime. Penalties for this crime vary from country to country.
Stopping or addressing defamation can be difficult. If the person has no serious resentment,
then a cease and discontinue letter may stop the behavior and get the statements removed
from the Internet. On the other hand, if the person is acting out of meanness, it may be
necessary to file a report with the police depending on local law. INDIAN PENAL CODE, 1860
contains provisions to deal with the menace of Cyber defamation in India.

Pharming

Pharming is yet another way hackers attempt to manipulate users on the Internet. While
phishing attempts to capture personal information by getting users to visit a fake website,
pharming redirects users to false websites without them even knowing it.

While a typical website uses a domain name for its address, its actual location is determined by
an IP address. When a user types a domain name into his or her Web browser's address field
and hits enter, the domain name is translated into an IP address via a DNS server. The Web
browser then connects to the server at this IP address and loads the Web page data. After a
user visits a certain website, the DNS entry for that site is often stored on the user's computer
in a DNS cache. This way, the computer does not have to keep accessing a DNS server
whenever the user visits the website.

Phishing and Spoofing:
In practical terms, phishing is a form of spoofing in that it deceives with legitimate-looking
messages. Unlike spoofing, a phishing scam
usually provides a link to a bogus website
where the end-user is required to enter
sensitive account information. The site may ask
you to provide your social security number, tax
ID or bank account information. Releasing this
information could result in damage to your
assets.

“phishing” downloads malware to your
computer or network, and the “spoofing”
tricks you into giving up sensitive financial
information to a cyber crook. Phishing is a
method of retrieval, while spoofing is a means
of delivery.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 172




Security Measures

 Firewalls.

 Antivirus systems.

 Intrusion-detection systems.

 Patching and updating.

 General network tools.

 Port scanners.

 Network sniffers.

 Vulnerability scanners.


Firewalls

Broadly speaking, a computer firewall is a software program that prevents unauthorized access
to or from a private network. Firewalls are tools that can be used to enhance the security of
computers connected to a network, such as LAN or the Internet. They are an integral part of a
comprehensive security framework for your network.
A firewall absolutely isolates your computer from the Internet using a "wall of code" that
inspects each individual "packet" of data as it arrives at either side of the firewall — inbound to
or outbound from your computer — to determine whether it should be allowed to pass or be
blocked.
.















firewalls perform the following tasks:
 Defend resources
 Validate access
 Manage and control network traffic
 Record and report on events
 Act as an intermediary

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 173



Firewalls generally use two or more of the following methods:
 Packet Filtering: Firewalls filter packets that attempt to enter or leave a network and
either accept or reject them depending on the predefined set of filter rules.

 Application Gateway: The application gateway technique employs security methods
applied to certain applications such as Telnet and File Transfer Protocol servers.


 Circuit-Level Gateway: A circuit-level gateway applies these methods when a connection
such as Transmission Control Protocol is established and packets start to move.

 Proxy Servers: Proxy servers can mask real network addresses and intercept every
message that enters or leaves a network. a proxy server is any computer system
offering a service that acts as an
intermediary between the two
communicating parties, the client
and the server. In the presence of a
proxy server, there is no direct
communication between the client
and the server. Instead, the client
connects to the proxy server and
sends requests for resources such as
a document, web page or a file that
resides on a remote server. The
proxy server handles this request by
fetching the required resources from
the remote server and forwarding the same to the client.

 Stateful Inspection or Dynamic Packet Filtering: This method compares not just the
header information, but also a packet’s most important inbound and outbound data
parts. These are then compared to a trusted information database for characteristic
matches. This determines whether the information is authorized to cross the firewall
into the network.

Computer Ethics

Computer ethics deals with the procedures, values and practices that govern the process of
consuming computing technology and its related disciplines without damaging or violating the
moral values and beliefs of any individual, organization or entity.

Computer ethics is a concept in ethics that addresses the ethical issues and constraints that
arise from the use of computers, and how they can be mitigated or prevented.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 174


1. Do not use the computer in ways that may harm other people..
2. Do not use computer technology to cause interference in other users' work..
3. Do not spy on another person's computer data.
4. Do not use computer technology to steal information.
5. Do not contribute to the spread of misinformation using computer technology.
6. Refrain from copying software or buying pirated copies. Pay for software unless it is
free.
7. Do not use someone else's computer resources unless authorized to.
8. It is wrong to claim ownership on a work which is the output of someone else's intellect.
9. Before developing a software, think about the social impact it can have.

10. In using computers for communication, be respectful and courteous with the
fellow members.

Cyber laws

In India, cyber laws are contained in the Information Technology Act, 2000 ("IT Act") which
came into force on October 17, 2000. The main purpose of the Act is to provide legal
recognition to electronic commerce and to facilitate filing of electronic records with the
Government.

Cyber law encompasses laws relating to

 Cyber crimes
 Electronic and digital signatures
 Intellectual property
 Data protection and privacy

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 175





Section under IT Act, 2000 Offence Penalty
Sec.43 Damage to computer, computer Compensation not exceeding one crore
system, etc. rupees to the person so affected
Sec.43A Body corporate failure to protect Compensation not exceeding five crore
data rupees to the person so affected
Sec.44(a) Failure to furnish document, return Penalty not exceeding one lakh and fifty
or report to the Controller or the thousand rupees for each such failure
Certifying Authority
Sec.44(b) Failure to file any return or furnish Penalty not exceeding five thousand
any information, books or other rupees for every day during which such
documents within the time specified failure continues
Sec.44(c) Failure to maintain books of account Penalty not exceeding ten thousand rupees
or records for every day during which the failure
continues
Sec.66 Hacking with Computer systems, Imprisonment for a term which may
Data alteration etc. extend to three years or with fine which
may extend to five lakh rupees or with
both
Sec.66A Sending offensive messages through Imprisonment for a term which may
communication service etc. extend to three years and with fine
Sec.66E Publishing obscene images Imprisonment which may extend to three
years or with fine not exceeding two lakh
rupees, or with both
Sec.66F Cyber terrorism Imprisonment which may extend to
imprisonment for life
Sec.67A Publishes or transmits sexually Imprisonment for a term which may
explicit material extend to five years and with fine which
may extend to ten lakh rupees and in the
event of second or subsequent conviction
with imprisonment of either description for
a term which may extend to seven years
and also with fine which may extend to ten
lakh rupees
Sec.72 Breach of Confidentiality and Imprisonment for a term which may
Privacy extend to two years, or with fine which
may extend to one lakh rupees, or with
both
Sec.73 & 74 Publishing false digital signature Imprisonment for a term which may
certificates extend to two years, or with fine which
may extend to one lakh rupees, or with
both

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 176




GOOD COMPUTER SECURITY HABITS


1. Lock your computer when you are not using it. Even if you are away from your computer for
just a few moments, your data could be compromised. Close your computer and make sure
the screen locks.


2. Disconnect from the Internet. Most broadband connections allow us to stay permanently
connected to the Internet, but this convenience comes with risks. The chances of your
computer being attacked is much higher if you are always connected. This is particularly true
if you are using your computer at home without an adequate firewall.

3. Adjust your security settings. The Windows XP, Windows 7, and Mac OS operating systems
all have multiple security settings, as do the popular browsers like Internet Explorer, Safari and
Firefox. Make sure the settings are appropriate for your computer and are adjusted for each
individual user.


4. Check for security patches and software updates. Microsoft and other popular operating
systems offer regular updates and software patches to protect against viruses and security
flaws. Make sure your computer regularly checks for updates or visit the appropriate web page
to get the latest download. (Windows users can get security updates here.)


5. Change your passwords. Change your passwords regularly, particularly for financially
sensitive accounts and web sites. Don’t use the same password for multiple accounts. Do
not keep a copy of all your passwords on your computer. It will be much harder to re-create
or access accounts if data is lost.

6. Protect against power surges and outages. Computers are easily damaged by power surges.
Make sure you are protected and consider disconnecting your computer during thunderstorms.

7. Back up your data. Set aside a few minutes a week to back up your files and personal data

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 177



UNIT V

Data base Management System: Introduction, File oriented approach and Database
approach, Data Models, Architecture of Database System, Data independence, Data
dictionary, DBA, Primary Key, Datadefinition language and Manipulation Languages.
Cloud computing: definition, cloud infrastructure, cloud segments or service delivery
models (IaaS, PaaSand SaaS), cloud deployment models/ types of cloud (public,
private, community and hybrid clouds), Prosand Cons of cloud computing

Introduction


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. Data aids in producing information, which is
based on facts. For example, if we have data about marks obtained by all students, we
can then conclude about toppers and average marks.

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

Advantages of Database Management System (DBMS)

1. Improved data sharing

An advantage of the database management approach is, the DBMS helps to create an
environment in which end users have better access to more and better-managed data.
Such access makes it possible for end users to respond quickly to changes in their
environment.

2. Improved data security

The more users access the data, the greater the risks of data security breaches.
Corporations invest considerable amounts of time, effort, and money to ensure that
corporate data are used properly. A DBMS provides a framework for better
enforcement of data privacy and security policies.

3. Better data integration

Wider access to well-managed data promotes an integrated view of the
organization‘s operations and a clearer view of the big picture. It becomes much
easier to see how actions in one segment of the company affect other segments.
4. Minimized data inconsistency

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 178


Data inconsistency exists when different versions of the same data appear in different
places. For example, data inconsistency exists when a company‘s sales department
stores a sales representative‘s name as ― sanjay mishra and the company‘s
personnel department stores that same person‘s name as ― sanjay kumar mishra or
when the company‘s regional sales office shows the price of a product as Rs.45.95
and its national sales office shows the same product‘s price as Rs.43.95. The
probability of data inconsistency is greatly reduced in a properly designed database.

5. Improved data access

The DBMS makes it possible to produce quick answers to ad hoc queries. From a
database perspective, a query is a specific request issued to the DBMS for data
manipulation—for example, to read or update the data. Simply put, a query is a
question, and an ad hoc query is a spur-of-the-moment question. The DBMS sends
back an answer (called the query result set) to the application. For example, end
users, when dealing with large amounts of sales data, might want quick answers to
questions (ad hoc queries) such as:

- What was the dollar volume of sales by product during the past six months?

- What is the sales bonus figure for each of our salespeople during the past
three months?
- How many of our customers have credit balances of 3,000 or more?
6. Improved decision making

Better-managed data and improved data access make it possible to generate better-
quality information, on which better decisions are based. The quality of the information
generated depends on the quality of the underlying data. Data quality is a
comprehensive approach to promoting the accuracy, validity, and timeliness of the
data. While the DBMS does not guarantee data quality, it provides a framework to
facilitate data quality initiatives.

7. Increased end-user productivity

The availability of data, combined with the tools that transform data into usable
information, empowers end users to make quick, informed decisions that can make
the difference between success and failure in the global economy.

Users

A typical DBMS has users with different rights and permissions who use it for different
purposes. Some users retrieve data and some back it up. The users of a DBMS can be
broadly categorized as follows −

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 179





 Administrators − Administrators maintain the DBMS and are responsible for
administrating the database. They are responsible to look after its usage and by whom it
should be used. They create access profiles for users and apply limitations to maintain
isolation and force security. Administrators also look after DBMS resources like system
license, required tools, and other software and hardware related maintenance.

 Designers − Designers are the group of people who actually work on the designing part
of the database. They keep a close watch on what data should be kept and in what
format. They identify and design the whole set of entities, relations, constraints, and
views.

 End Users − End users are those who actually reap the benefits of having a

DBMS. End users can range from simple viewers who pay attention to the logs or
market rates to sophisticated users such as business analysts.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 180





































Database Model

A Database model defines the logical design of data. The model describes the relationships
between different parts of the data. Historically, in database design, three models are
commonly used. They are,

 Hierarchical Model

 Network Model

 Relational Model

Hierarchical Model

In this model each entity has only one parent but can have several children . At the top of
hierarchy there is only one entity which is called Root.

In Hierarchical model data elements are linked as an inverted tree structure (root at the top
with branches formed below). Below the single root data element are subordinate elements
each of which in turn has its own subordinate elements and so on, the tree

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 181



can grow to multiple levels. Data elements has parent child relationship as in a family
tree.

For Example in an organization employees are categorized by their department and
within a department they are categorized by their job function such as managers,
engineers, technicians and support staff.



















Advantages

 The hierarchical database model is a very efficient one when the database
contains a large number of 1: n relationships and when the users require large
number of transactions, using data whose relationships are fixed.

 Hierarchical model was the first database model that offered the data security
that is provided and enforced by DBMS.

Disadvantages

 Although the hierarchical database model is conceptually simple and easy to
design , it is quite complex to implement.

 If you make any changes in the database structure of hierarchical database, then
you need to make the necessary changes in all the application programs that
access the database. Thus maintaining the database and the applications can
become very difficult.

Network Model

In the network model, entities are organised in a graph,in which some entities can be
accessed through several path

This model is the extension of hierarchical data model. In this model also there exist a
parent child relationship but a child data element can have more than one parent
element or no parent at all. The main difference of the network model from the
hierarchical model is its ability to handle many –to – many (n: n) relationships or in
other words it allows a record to have more than one parent.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 182



Example of Network model is given below where there are relationships among courses
offered and students enrolled for each course in a college. Each student can be enrolled for
several courses and each course may have a number of students enrolled for it.

The students enrolled for English are Miya and Priyanka and Miya has taken three
courses English, Math and Science. The example also shows a child element that has
no parent element i.e he has not taken any course in this semester, he might be a
research student.

















Advantages
 It is conceptually simple and easy to design.
 It can handle one to many (1:n) and many to many (n: n) relationships

 The changes in data characteristics do not require changes to the application
programs.
 The data access is easier and flexible than the hierarchical model.
Disadvantages
 Detailed structural knowledge is required.
 There is lack of structural independence.

 The insertion, deletion and updating operations of any record require large
number of pointers adjustments.



Relational Model

In this model, data is organised in two-dimesional tables called relations. The tables or
relation are related to each other.

The relational database was invented by E. F. Codd at IBM in 1970.The relational
model represents data and relationships among data by a collection of tables, each of
which has a number of columns with unique names. Relational data model is used
widely around the world for data storage and processing. This model is simple and it
has all the properties and capabilities required to process data with storage efficiency.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 183


For example the following figure shows a relational database showing customers and
their accounts. The customer Nina has two accounts with Rs. 50000 and 30000
balance.

Table Name: Customer


Name

Street

City

Account


Number

Neena Tagore Delhi 101
Garden

Neena Tagore Delhi 201
Garden


Jacqueline Janakpuri Delhi 402



Peter Connaught Delhi 506
Place


Table Name : Account info
Account Number Balance


101 50000



201 30000



402 150000



506 80000





Advantages

 The revision of any information as tables consisting of rows and columns is
much easier to understand.

 In rational database, changes in the database structure do not affect the data
access. So relational database has structural independence.

 The relational database model achieves both data independence and structural
independence making the database design, maintenance, administration and
usage much easier that the oher models.
 It is simpler to navigate

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 184


Disadvantages

 A major constraint and therefore disadvantage in the use of relational database
system is machine performance. If the number of tables between which
relationships to be established are large and the tables themselves effect the
performance in responding to the sql queries.

 Slower processing times than hierarchical and network models.


Example-



















Entity-Relationship Model

E-R Model was developed by Peter
Chen in 1976. E-R Model can be
expressed as the collection
of entities, also called as real
word objects and relations between
those entities. No two entities
should be identical. E-R Model
shows the conceptual view of the
database.

E-R Model is formed by the entity set, relationship set and the attributes.



Key Differences Between E-R Model and Relational Model :

1. The basic difference between E-R Model and Relational Model is that E-R model
specifically deals with entities and their relations. On the other hand, the
Relational Model deals with Tables and relation between the data of those tables.
2. An E-R Model describes the data with entity set, relationship set and attributes.
However, the Relational model describes the data with the tuples, attributes and
domain of the attribute.
3. One can easily understand the relationship among the data in E-R Model as
compared to Relational Model.
4. E-R Model has Mapping Cardinality as a constraint whereas Relational Model
does not have such constraint.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 185



DBMS architecture

There are following three levels or layers of DBMS architecture:

• External Level
•Conceptual Level

• Internal Level

The objective of the three level architecture is to separate each user's view of the
database from the Way the database is physically represented. There are several
reasons why this separation is desirable:

• Each user should be able to access the same data, but have a different customized
view of the data. Each user should be able to change the way he or she views the data,
and this change should not affect other users.

• Users should not have to deal directly with physical database storage details, such as
indexing or hashing. In other words a user's interaction with the database should be
independent of storage considerations.

• The Database Administrator (DBA) should be able to change the database storage
structures without affecting the user's views.

. The internal structure of the database should be unaffected by changes to the physical
aspects of storage, such as the changeover to a new storage device.

. The DBA should be able to change the conceptual structure of the database without
affecting all users.


External Level:

It is the users' view of the database. This level describes that part of the database that is
relevant to each user. External level is the one which is closest to the end users. This
level deals with the way in which individual users vie\v data. Individual users are given
different views according to the user's requirement.
Conceptual Level :

It is the community view of the database. This level describes what data is stored in the
database and the relationships among the data. The middle level in the three level
architecture is the conceptual level. This level contains the logical structure of the
entire database as seen by the DBA. It is a complete view of the data requirements of
the organization that is independent of any storage considerations.
Internal Level:

It is the physical representation of the database on the computer. This level describes
how the data is stored in the database. The internal level is the one that concerns the
way the data are physically stored on the hardware.


A schema is defined as an outline or a plan that describes the records and relationships
existing at the particular level.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 186

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 187


Data independence

A major objective for three-level architecture is to provide data independence, which
means that upper levels are unaffected by changes in lower levels.

There are two kinds of data independence:
• Logical data independence
• Physical data independence

Logical Data Independence

Logical data is data about database, that is, it stores information about how data is managed
inside. For example, a table (relation) stored in the database and all its constraints, applied
on that relation.

Logical data independence is a kind of mechanism, which liberalizes itself from actual data
stored on the disk. If we do some changes on table format, it should not change the data
residing on the disk.

Physical Data Independence

All the schemas are logical, and the actual data is stored in bit format on the disk. Physical
data independence is the power to change the physical data without impacting the schema
or logical data.

For example, in case we want to change or upgrade the storage system itself − suppose we
want to replace hard-disks with SSD − it should not have any impact on

the logical data or schemas.

Data dictionary


A data dictionary (also called the metadata) is the data about the data. It is the self
describing nature of the database that provides program-data independence. It is also called
as the System Catalog. It holds the following information about each data element in the
databases, it normally includes:

 Name
 Type
 Range of values
 Source
 Access authorization

Data dictionary is used to actually control the database operation, data integrity and
accuracy. Metadata is used by developers to develop the programs, queries, controls and
procedures to manage and manipulate the data. Metadata is available to database
administrators (DBAs), designers and authorized user as on-line system documentation. This
improves the control of database administrators (DBAs) over the information system and the
user's understanding and use of the system.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 188


Data dictionary Types
 Active
 passive.

An active data dictionary (also called integrated data dictionary) is managed automatically
by the database management software. Consistent with the current structure and definition of
the database. Most of the relational database management systems contain active data
dictionaries that can be derived from their system catalog.

The passive data dictionary (also called non-integrated data dictionary) is the one used
only for documentation purposes. Data about fields, files, people and so on, in the
data processing environment are. Entered into the dictionary and cross-referenced. Passive
dictionary is simply a self-contained application. It is managed by the users of the system and
is modified whenever the structure of the database is changed.


DBA

Centralized control of the database is exerted by a person or group of persons under the
supervision of a highlevel administrator. This person or group is referred to as the database
administrator (DBA). They are the users who are most familiar with the database and are
responsible for creating, modifying, and maintaining its three levels.

Database Administrator is responsible to manage the DBMS‘s use and ensure that the
database is functioning properly.

Responsibilities of DBA


1.Deciding the information content of the database:

It is the DBA‘s job to decide exactly what information is to be held in the database - in
other words, to identify the entities of interest to the enterprise and to identify the
information to be recorded about those entities. Having done this, the DBA must then
define the content of the database by writing the conceptual schema.

2.Deciding the storage structure and access strategy:

The DBA must also decide how the data is to be represented in the database, and must
specify the representation by writing the storage structure definition. In addition, the
associated mapping between storage structure definition and the conceptual schema must
also be specified.

3. Liaising with the users:

It is the business of the DBA to liaise with users, to ensure that the data they require is
available, and to write the necessary external schemas. In addition, the mapping between
any given external schema and the conceptual schema must also be specified. In practice
the external DDL will probably include the means for specifying the mapping, but the schema
and the mapping should be clearly distinguishable.

4.Defining authorization checks and validation procedures:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 189


Authorization checks and validation procedures may be considered as logical extensions of
the conceptual schema. The conceptual DDL will include facilities for specifying such checks
and procedures.

5.Defining a strategy for backup and recovery:

Once an enterprise is committed to a database, it become critically dependent on the
successful operation of that system. In the event of damage to any portion of the database –
caused by human error, say, or a failure in the hardware or supportingoperating system – it is
essential to be able to repair the data concerned with a minimum of delay and with as little
effect as possible on the rest of the system

6.Monitoring performance and responsibilities to changes in requirements:

The DBA is responsible for so organizing the system as to get the performance that is
―best for the enterprise‖ and for making the appropriate adjustments change. Any
change to details of storage and access must be accompanied by a corresponding
change to the definition of the mapping to storage, so that the conceptual schema may
remain constant.


Primary Key

A primary key is a column/field (or combination of columns) of relational database
table designated to uniquely identify all table records.

A primary key‘s main features are:

 It must contain a unique value for each row of data.
 It cannot contain null values.

A primary key is either an existing table column or a column that is
specifically generated by the database according to a defined sequence

Example:
Student Table
Stu_roll No Stu_Name Stu_Age

101 Steve 23

102 John 24

103 Robert 28

104 Carl 22

In the above Student table, the Stu_Id column uniquely identifies each row of the table.


 We denote the primary key by underlining the column name.

 The value of primary key should be unique for each row of the table. Primary
key column cannot contain duplicate values.
 Primary key column should not contain nulls.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 190


 Primary keys are not necessarily to be a single column; more than one column
can also be a primary key for a table. For e.g. {Stu_Id, Stu_Name} collectively can
play a role of primary key in the above table, but that does not make sense
because Stu_Id alone is enough to uniquely identifies rows in a table then why to
make things complex. Having that said, we should choose more than one columns
as primary key only when there is no single column that can play the role of
primary key.

Database languages

Database languages are used for read, update and store data in a database. There are
several such languages that can be used for this purpose; one of them is SQL
(Structured Query Language).

Types of DBMS languages:


 Data Definition Language (DDL)
 Data Manipulation Language (DML)
 Data Control language (DCL)

 Transaction Control Language (TCL)





Data Definition Language (DDL): DDL is used for specifying the database schema.
Let‘s take SQL for instance to categorize the statements that comes under DDL.

 To create the database instance – CREATE
Syntax

CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);

Example

CREATE TABLE Employee
(
emp_id number(5),
name varchar(20),
salary number(10),
);

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 191


 To alter the structure of database – ALTER
Syntax:

ALTER TABLE table_name MODIFY
(

column 1 datatype(size),
column 2 datatype(size),
.........
);

Example:


ALTER TABLE Employee MODIFY
(
emp_name varchar(30),
);




 To drop database instances –
DROP Syntax:

drop table
<table_name> Example:

drop table Employee


 rename database instances – RENAME
RENAME old_table _name To new_table_name;

All these commands specify or update the database schema that‘s why they come
under Data Definition language.

Data Manipulation Language (DML): DML is used for accessing and manipulating
data in a database.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 192


To read records from table(s) – SELECT

Syntax:
SELECT "column_name1", "column_name2", "column_name3" FROM "table_name";

Example:
SELECT Store_Name FROM Store_Information;

• To insert record(s) into the table(s) – INSERT

Syntax:
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...);


Example:

NSERT INTO Store_Information (Store_Name, Manager_ID, Sales,
Txn_Date) VALUES ('Los Angeles', 10, 900, 'Jan-10-1999');

• Update the data in table(s) – UPDATE


Syntax:
UPDATE "table_name"
SET column_1 = [value1], column_2 = [value2], ...
WHERE "condition";

Example:
UPDATE Store_Information
SET Sales = 500

WHERE Store_Name = 'Los Angeles'
AND Txn_Date = 'Jan-08-1999';

• Delete all the records from the table – DELETE

Syntax:
DELETE FROM "table_name"
WHERE "condition";

Example:
DELETE FROM Store_Information
WHERE Store_Name = 'Los Angeles';

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 193



Data Control language (DCL): DCL is used for granting and revoking user access on a
database –

• To grant access to user – GRANT

grant create session to username;
grant create table to username;
grant drop any table to username


• To revoke access from user – REVOKE
revoke create table from username

Transaction Control Language (TCL)


TCL statements allow you to control and manage transactions to maintain the
integrity of data within SQL statements.

1.BEGIN Transaction – opens a transaction


2.COMMIT Transaction – commits a transaction

Syntax:

commit;


3. ROLLBACK Transaction – ROLLBACK a transaction in case of any error

Syntax:
rollback to savepoint-name;


4.savepoint

savepoint command is used to temporarily save a transaction so that you can rollback
to that point whenever necessary.


savepoint savepoint-name;

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 194



Cloud Computing


What is Cloud?

The term Cloud refers to a Network or Internet. In other words, we can say that Cloud
is something, which is present at remote location. Cloud can provide services over
public and private networks, i.e., WAN, LAN or VPN.

Applications such as e-mail, web conferencing, customer relationship management
(CRM) execute on cloud.

What is Cloud Computing?

Cloud Computing refers to manipulating, configuring, and accessing the hardware
and software resources remotely. It offers online data storage, infrastructure, and
application.
Cloud computing offers platform independency, as the software is not required to be
installed locally on the PC. Hence, the Cloud Computing is making our business
applications mobile and collaborative.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 195





History of Cloud Computing

The concept of Cloud Computing came into existence in the year 1950 with
implementation of mainframe computers, accessible via thin/static clients.Since then,
cloud computing has been evolved from static clients to dynamic ones and from
software to services. The following diagram explains the evolution of cloud computing:




















Cloud Models

There are certain services and models working behind the scene making the cloud
computing feasible and accessible to end users. Following are the working models
for cloud computing:

 Deployment Models

 Service Models

Deployment Models:


Deployment models define the type of access to the cloud, i.e., how the cloud is
located? Cloud can have any of the four types of access: Public, Private, Hybrid, and
Community.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 196

























PUBLIC CLOUD

The public cloud allows systems and services to be easily accessible to
the general public. Public cloud may be less secure because of its openness.

PRIVATE CLOUD

The private cloud allows systems and services to be accessible within an
organization. It is more secured because of its private nature.

COMMUNITY CLOUD

The community cloud allows systems and services to be accessible by a group
of organizations.

HYBRID CLOUD

The hybrid cloud is a mixture of public and private cloud, in which the critical
activities are performed using private cloud while the non-critical activities are
performed using public cloud.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 197


Service Models:


Cloud computing is based on service models. These are categorized into three basic
service models which are -

 Infrastructure-as–a-Service (IaaS)

 Platform-as-a-Service (PaaS)

 Software-as-a-Service (SaaS)


Anything-as-a-Service (XaaS) is yet another service model, which includes
Network-as-a-Service, Business-as-a-Service, Identity-as-a-Service, Database-as-
a-Service or Strategy-as-a-Service.

The Infrastructure-as-a-Service (IaaS) is the most basic level of service. Each of the
service models inherit the security and management mechanism from the underlying
model, as shown in the following diagram:

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 198



INFRASTRUCTURE -AS-A-SERVICE (IAAS)

IaaS provides access to fundamental resources such as physical
machines, virtual machines, virtual storage, etc.

Amzon is the pioneer of IaaS. Other leading providers

are Rackspace, GoGrid, Joyent, Rightscale and Terremark (bought by Verizon)

For India based IaaS – explore the following providers:

 NetMagic Solutions

 InstaCompute (from Tata Communications)



PLATFORM-AS-A-SERVICE (PAAS)

PaaS provides the runtime environment for applications, development
and deployment tools, etc.

 GAE is more popular with individual Java, Python developers.

 Microsoft Windows Azure is targeting its pool of enterprise class users. ASP.Net
(C#, VB.Net) developers will find easy to adopt it.

 Amazon has also moved one stack up to offer its PaaS – Beanstalk (one more
option for Java developers)

 A few of the India based PaaS providers like OrangeScape and Wolf
frameworksare making waves for their 5G visual PaaS. OrangeScape apps can
run on all the major cloud platforms - Google App Engine, Microsoft Azure, IBM
SmartCloud, Amazon EC2 or data center- without having to rewrite applications.

 Engine Yard and Heroku are leading cloud PaaS for Ruby on Rails (RoR).
Heroku (acquired by saleforce.com) is also a preferred PaaS for Facebook apps
creation.

 PHP developers can choose between PHP Fog and CloudControl.

 For a multi-language application platform explore DotCloud.

 India based Ozonetel Systems offers KooKoo PaaS for cloud telephony service.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 199



SOFTWARE-AS-A-SERVICE (SAAS)

SaaS model allows to use software applications as a service to end-users.

 Best use of SaaS is in productivity and collaboration apps in the cloud

like Google Apps, Online Project Management like DeskAway, Zoho Mail,
Chat, Docs, Project, Sheet, Writer etc.

 CRM apps – Impel CRM, Salesforce.com, Microsoft Dynamics.

 Cloud based Storage and Sharing services like Dropbox, Skydrive
(windows live), Amazon S3, Google Docs, Box.net, Mozy.

 SMEs/SMBs can opt for EazeWork (for HR, PayRoll and Sales)




Pros and Cons

Advantages

If used properly and to the extent necessary, working with data in the cloud can
vastly benefit all types of businesses. Mentioned below are some of the advantages
of this technology:

1.Cost Efficient

Cloud computing is probably the most cost efficient method to use, maintain and
upgrade. Traditional desktop software costs companies a lot in terms of finance. Adding
up the licensing fees for multiple users can prove to be very expensive for the
establishment concerned. The cloud, on the other hand, is available at much cheaper
rates and hence, can significantly lower the company‘s IT expenses. Besides, there are
many one-time-payment, pay-as-you-go and other scalable options available, which
makes it very reasonable for the company in question.


2.Almost Unlimited Storage

Storing information in the cloud gives you almost unlimited storage capacity.

Hence, you no more need to worry about running out of storage space or increasing
your current storage space availability.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 200


3.Backup and Recovery

Since all your data is stored in the cloud, backing it up and restoring the same is
relatively much easier than storing the same on a physical device. Furthermore,
most cloud service providers are usually competent enough to handle recovery
of information.

Hence, this makes the entire process of backup and recovery much simpler than
other traditional methods of data storage.

4.Automatic Software Integration

In the cloud, software integration is usually something that occurs automatically. This
means that you do not need to take additional efforts to customize and integrate your
applications as per your preferences. This aspect usually takes care of itself. Not only
that, cloud computing allows you to customize your options with great ease. Hence,
you can handpick just those services and software applications that you think will best
suit your particular enterprise.

5.Easy Access to Information

Once you register yourself in the cloud, you can access the information from anywhere,
where there is an Internet connection. This convenient feature lets you move beyond
time zone and geographic location issues.

6.Quick Deployment

Lastly and most importantly, cloud computing gives you the advantage of quick
deployment. Once you opt for this method of functioning, your entire system can be
fully functional in a matter of a few minutes. Of course, the amount of time taken here
will depend on the exact kind of technology that you need for your business.

Disadvantages of Cloud Computing


In spite of its many benefits, as mentioned above, cloud computing also has its
disadvantages. Businesses, especially smaller ones, need to be aware of these
cons before going in for this technology.

1.Technical Issues

Though it is true that information and data on the cloud can be accessed anytime and
from anywhere at all, there are times when this system can have some serious
dysfunction. You should be aware of the fact that this technology is always prone to
outages and other technical issues. Even the best cloud service providers run into
this kind of trouble, in spite of keeping up high standards of maintenance.

BTech- I Yr ..BASIC COMPUTER ENGINEERING (BT- 2005)

Compiled by - Dr Ilyas Khan

[Type text]
TRINITY INST OF TECH NOLOGY AND RESEARCH, BHOPAL Page | 201


Besides, you will need a very good Internet connection to be logged onto the server
at all times. You will invariably be stuck in case of network and connectivity problems.

2.Security in the Cloud

The other major issue while in the cloud is that of security issues. Before adopting this

technology, you should know that you will be surrendering all your company‘s sensitive

information to a third-party cloud service provider. This could potentially put your
company to great risk. Hence, you need to make absolutely sure that you choose
the most reliable service provider, who will keep your information totally secure.

3.Prone to Attack

Storing information in the cloud could make your company vulnerable to external hack
attacks and threats. As you are well aware, nothing on the Internet is completely
secure and hence, there is always the lurking possibility of stealth of sensitive data.