Computer
Computer
Chapter-1
TYPICAL CONFIGURATION OF COMPUTER SYSTEM
Introduction:
“Computer is an electronic machine that can store, recall and process data. It can perform tasks
or complex calculation according to a set of instructions or programs.
The terms and definitions in the study of computer system are:
Hardware: The physical parts of a computer system called as hardware. The hardware
components can be seen, touch and feel. Ex: Keyboard, Mouse, Monitor, RAM, CPU etc.
Software: A Set or collection of programs is known as software. Example Operating System,
Data: Data is the raw information or basic facts that computer can process.
User(s): People who use the computers are called users.
Control Unit
Input Unit Output Unit
Arithmetic &
Logic Unit
CPU
Memory Unit
Primary Memory
Secondary Memory
Input Unit:
Computers need to receive data and instructions in order to solve a problem. The Input unit
performs this operation.
The Input Unit basically links the external world or environment to the computer system.
The input unit may consist of one or more input devices.
Central Processing Unit (CPU):
The function of the CPU is to interpret the instructions in the program and execute them one by
one. It consists of two major units.
1. Control Unit: It controls and directs the transfer of program instructions and data between
various units.
2. Arithmetic and Logic Unit (ALU): Arithmetic and Logic Unit performs arithmetic and
logical operations and controls the speed of these operations.
Memory Unit:
The results generated from processing have to be preserved before it is displayed.
The memory units thus provide space to store input data, intermediate results and the final
output generated.
Note: The input unit, an output unit, and secondary storage devices are together known as
Peripheral Devices.
Output Unit:
It is used to print or display the results, which are stored in the memory unit. The actual
function of the output unit is just the reverse of the input unit.
Thus, the output unit links the computer to the outside world.
Motherboard:
The motherboard is a main circuit board of the computer, which contains the CPU, memory,
expansions slots, bus, video controller and other electronic components.
It is a large Printed Circuit Board (PCB). Important
3 Marks
Characteristics of Motherboard:
The motherboard may be characterized by the form factor, chipset and type of processor socket
used.
Form factor refers to the motherboard’s geometry, dimensions, arrangement and electrical
requirements.
Chipset controls the majority of resources of the computer. The function of chipset is to
coordinate data transfer between the various components of the computer.
2|Page Keerthi Kumar H.M
Chapter 1- Typical Configuration of Computer System II PUC, MDRPUC, Hassan
The processor socket may be a rectangular connector into which the processor is mounted
vertically, or a square shaped connector with many small connectors into which the processor
is directly inserted.
Types of Motherboard:
There are four different types in motherboard:
XT Motherboards:
o XT stands for Extended Technology.
o These are old model motherboards. In this we find old model processor socket like LIF
(Low Insertion Force) sockets, RAM slots: DIMM (Dual Inline Memory Modules) and ISA
(Industry Standards Architecture) slots, 12 pin power connector. They have slot type
processors and no ports.
o Ex: Pentium-I, Pentium-MMX, Pentium-II and Pentium-Pro.
AT Motherboards:
o AT stands for Advanced Technology.
o AT Motherboards have PGA (Pin Grid Array) socket, SD RAM slots, 20 pin power connector
PCI slots and ISA slots.
o Full AT is 12” wide X 13.8” deep. AT has 5-pin large keyboard connector.
o Ex: Pentium-III Processors.
Baby AT Motherboards:
o Baby AT motherboards have the combination of XT and AT.
o It was the first PC motherboard to build in sockets for I/O ports, which were cabled to
connectors on the back of the case.
o Ex: Pentium-III and Pentium-IV
ATX Motherboards:
o ATX motherboard stands for Advanced Technology Extended Motherboard.
o Latest Motherboard all are called as ATX motherboard, designed by ATX form factor.
o In this motherboard, MPGA Processor sockets, DDRRAM Slots, AGP Slots, SATA
Connectors, 20 pin and 24 pin ATX power connector and ports
o It is a full size board measuring 12” wide by 9.6” deep. Micro ATX is a small motherboard
size of 9.6” X 9.6”.
o Ex: Pentium-IV, Dual Core, Core 2 Duo, Quad Core, i3, i5 and i7.
Components of Motherboard:
The motherboard components are:
o Processors (CPU) o Disk Controllers
o BIOS o I/O Ports and Interfaces
Important
o CMOS 3 Marks o BUS
o Slots
Processors (CPU):
The processors or CPU is the main component on the motherboard and is called the brain of
the computer.
4|Page Keerthi Kumar H.M
Chapter 1- Typical Configuration of Computer System II PUC, MDRPUC, Hassan
Slots:
Slot: A slot is an opening space in a computer where we can insert a printed circuit board.
Slots are often called expansion slots.
There are several types of slots are:
ISA (Industry Standard Architecture):
o ISA slot is used to connect modem and input devices.
PCI (Peripheral Component Interconnect):
o PCI slots are used to connect graphics accelerators cards, sound card, internal modems
or SCSI cards.
o They are much faster than ISA cards.
Disk Controllers:
A device that connects a disk drive to the computer’s bus enabling the drive to exchange
data with other device.
Hard Disk Controller (HDC)
o The HDC is the interface that enables the computer to read and write information to the
hard disk drive.
o This connector is used to insert an Integrated Digital Electronics (IDE) cable.
o IDE cables connect devices such as hard drives, CD drives and DVD drives.
Floppy Disk Controller (FDC)
o FDC is the interface that directs and controls reading from and writing to computer
floppy disk drive.
o FDC usually performs data transmission in Direct Memory Access (DMA) mode.
o One main advantage is that data is sent and received over only two lines.
Parallel Port:
o Parallel ports are used to connect external input/output devices like printers or scanners.
o Also known as printer port
Important
o They carry 8 bit (one byte) at a time. 3 Marks
USB port :
o USB (Universal Serial BUS) port is used to connect a variety of newer peripherals like
printers, scanners, digital cameras, web cameras, speakers, etc. to a computer.
o USB port gives a single, standardized, easy-to-use way to connect a variety of newer
peripherals to a computer.
o USB is a plug-and-play interface between a computer and add-on devices such as
audio players, modem, scanner etc.
o With USB, a new device can be added to your computer without adding a adapter
card or even turning the computer off
o USB supports a data speed of 12 megabits per second
o USB supporting up to 127 devices.
PS-2 (Personal System) port:
o PS-2 port was developed by IBM to interface keyboards and pointing devices like
mouse, trackballs and touch pads.
IDE (Integrated Digital Electronics) port :
o It connects IDE devices like CD-ROM drives or hard disk drives to the motherboard.
AGP (Accelerated Graphics Port) port:
o It is used to connect to graphic card that provides high-speed video performance
typically required in games and other multimedia applications.
VGA (Visual Graphics Adaptor) port: It connects monitor to a computer’s video card.
Modem (Modulator demodulator)
connects a PC to the telephone
network.
Ethernet port connects to a network
and high speed Internet. It connects
network cable to a computer.
MIDI (Musical Instrument Digital
Interface) port is a system designed to
transmit information between electronic musical instruments.
Bus:
A bus is a collection of parallel wires that form a pathway to carry address, data and control
signal.
The functional features of bus are:
Important
o A bus is a set of wire and each wire can carry one bit of data. 3 Marks
o A bus width is defined by the number of wires in the bus
A computer bus can be divided into two types
o Internal Bus:
It connects major computer components like processor, memory & I/O.
It is also called as system bus.
o External Bus:
It connects the different external devices peripheral, expansion slots, I/O ports
to the rest of the computer.
It is also called the expansion bus and is slower than the system (internal) bus.
A system bus or expansion bus comprise of three kinds of buses:
Data Bus:
o It provides a path to transfer data between CPU and memory.
o The data bus may consists of 32, 64, 128 lines of wire.
Address Bus:
o It connects CPU & RAM with a set of lines similar to data bus.
o The address bus width determines the maximum number of memory location the
computer can address.
Control Bus:
o It is used to control the access to and the use of the data and address lines.
8|Page Keerthi Kumar H.M
Chapter 1- Typical Configuration of Computer System II PUC, MDRPUC, Hassan
Memory:
A computer memory refers to the electronic storing space for instructions and data.
Two kinds of memory are commonly used:
o Primary or Main Memory
o Secondary Memory
Primary Memory:
o Primary memory is the main memory of the computer.
o It stores programs and data which are currently needed by CPU.
o Functions of primary memory:
To contain a copy of the main software program i.e. operating system. This
program is loaded into the primary memory when the computer is turned on.
Temporarily store a copy of the application program.
Temporarily store the data input from the keyboard.
Temporarily store the result which is generated from processing until it is
transferred to output device.
o Primary memory is of two types.
1. RAM (Random Access Memory)
2. ROM (Read Only Memory)
RAM ROM
RAM stands for Random Access ROM stands for Read-Only
Memory Memory
Volatile Memory Non-volatile Memory
RAM require a flow of ROM will retain data without the
electrically to retain data flow of electricity
Type: DRAM, SRAM Type: PROM, EPROM
Secondary Memory:
The secondary memory is used as auxiliary memory. The secondary memory is used for bulk
storage or mass storage of programs, data, and other information.
It has much larger capacity than main memory.
The secondary memory retains the information once stored on it.
The magnetic memory such as Hard Disk Drive (HDD), Compact Disk, Pen Drive, Memory
cards is the most commonly used secondary memory in the computer.
Cache Memory:
The cache memory is a very high speed memory placed in between RAM and CPU.
Cache memory stores data that is used more often, temporarily and makes it available to CPU
at fast rate. Hence it is used to increase the speed of processing.
Cache memory is very expensive, so it is smaller in size. Important
Cache memory of sizes 256 KB to 2 MB. 3 Marks
It is categorized as “levels”.
Level 1 (L1) cache: It is extremely fast but relatively small and is usually present inside the
CPU. The size of L1 cache varies from 32 KB to 512 KB
Level 2 (L2) cache: It may be located outside the CPU on a separate chip a high speed system
bus interconnecting the cache to the CPU. The size of L2 cache varies from 1MB to 2MB.
Level 3 (L3) cache: It is typically specialized memory that works to improve the performance
of L1 and L2. It is slower the L1 or L2 but it is usually double the speed of RAM.
UPS:
UPS stands for “Uninterruptible Power Supply”.
An UPS is a power supply that includes a battery to maintain power in the event a power
failure.
An UPS keeps a computer running for several minutes to few hours after a power failure.
There are two types of UPS
Important
Offline UPS: 3 Marks
o Also known as “Standby UPS”
o Offline UPS monitors the power line and switches to battery power as soon as it detects
a problem.
Online UPS:
o An online UPS continuously provides power from its own inverter, even when the
power line is functioning properly.
o Online UPS is more costly than offline UPS.
Important Questions
1 Marks Question:
1. What is Microprocessor?
2. What is Motherboard? [June 2015]
3. Expand USB.
4. What is data bus? [March 2015]
5. Which memory is known as main memory?
6. Which memory is considered as working memory of CPU?
7. What is Cache Memory? [June 2016]
8. What is Bus? [March 2017]
9. Expand SDRAM.
10. Expand ISA [March 2016]
11. Expand SMPS.
3 Marks Question:
1. Explain the characteristics of motherboard. [March 2017]
2. Explain three types of motherboard. [June 2016]
3. Mention the components of the motherboard.
4. What is port? Explain serial port. [March 2015]
5. What is meant by plug and play device? Explain.
6. Write any three features of USB.
7. Explain Cache memory.
8. What is the function of UPS? Mention the different types of UPS. [June2015,March 2016]
Chapter-2
BOOLEAN ALGEBRA
Introduction:
An algebra that deals with binary number system is called “Boolean Algebra”.
It is very power in designing logic circuits used by the processor of computer system.
The logic gates are the building blocks of all the circuit in a computer.
Boolean algebra derives its name from the mathematician George Boole (1815-1864) who is
considered the “Father of symbolic logic”.
Boolean algebra deals with truth table TRUE and FALSE.
It is also called as “Switching Algebra”.
Truth Table:
A truth table is a mathematical table used in logic to computer functional values of logical
expressions.
A truth table is a table whose columns are statements and whose rows are possible scenarios.
Example: Consider the logical expression
Logical Statement: Meals = “Ram prefer rice and roti for the meal”
Y = A AND B (Logical Variables: Y, A, B, Logical Operator AND)
Ram Prefer Rice Ram Prefer Roti Meals
FALSE FALSE FALSE
FALSE TRUE FALSE
TRUE FALSE FALSE
TRUE TRUE TRUE
If result of any logical statement or expression is always TRUE or 1, it is called Tautology and
if the result is always FALSE or 0, it is called Fallacy.
Logical Operators:
There are three logical operator, NOT, OR and AND.
These operators are now used in computer construction known as switching circuits.
NOT Operator:
The Not operator is a unary operator. This operator operates on single variable.
The operation performed by Not operator is called complementation.
The symbol we use for it is bar.
𝐗 means complementation of X
If X=1, X=0 If X=0, X=1
The Truth table and the Venn diagram for the NOT operator is:
X X
1 0
0 1
OR Operator:
The OR operator is a binary operator. This operator operates on two variables.
The operation performed by OR operator is called logical addition.
The symbol we use for it is ‘+’.
Example: X + Y can be read as X OR Y
The Truth table and the Venn diagram for the NOT operator is:
X Y X+Y
0 0 0
0 1 1
1 0 1
1 1 1
AND Operator:
The AND operator is a binary operator. This operator operates on two variables.
The operation performed by AND operator is called logical multiplication.
The symbol we use for it is ‘.’.
Example: X . Y can be read as X AND Y
2|Page Keerthi Kumar H.M
Chapter 2- Boolean Algebra II PUC, MDRPUC, Hassan
The Truth table and the Venn diagram for the NOT operator is:
X Y X.Y
0 0 0
0 1 0
1 0 0
1 1 1
Exercise Problems:
1. Prepare a table of combination for the following Boolean algebra expressions.
a) X Y + XY b) XY Z + X Y Z
2. Verify using truth table for the following Boolean algebra.
a) X + XY = X b) X + Y = X . Y
Boolean Postulates:
The fundamental laws of Boolean algebra are called as the postulates of Boolean algebra.
These postulates for Boolean algebra originate from the three basic logic functions AND, OR
and NOT.
Properties of 0 and 1:
I. If X ≠ 0 then X = 1, and If X ≠1 then X = 0
II. OR relation ( Logical Addition)
a. 0 + 0 = 0 c. 1 + 0 = 1
b. 0 + 1 = 1 d. 1 + 1 = 1
III. AND relation ( Logical Multiplication)
a. 0 . 0 = 0 c. 1 . 0 = 0
b. 0 . 1 = 0 d. 1 . 1 = 1
IV. Complement Rules
a. 0 = 1 b. 1 = 0
Principle of Duality Theorem:
This is very important principle used in Boolean algebra.
Principle of Duality states that;
o Changing each OR sign (+) to an AND sign (.)
o Changing each AND sign (.) to an OR sign (+)
o Replacing each 0 by 1 and each 1 by 0.
The derived relation using duality principle is called dual of original expression.
Example: Take postulate II, related to logical addition:
1) 0 + 0 = 0 2) 0 + 1 = 1 3) 1 + 0 = 1 4) 1 + 1 = 1
2. Now working according to above relations, + is changed to . and 0’s replaced by 1’s
a) 1 . 1 = 1 b) 1 . 0 = 0 c) 0 . 1 = 0 d) 0 . 0 = 0
which are nothing but same as that of postulate III related to logical multiplication.
So 1, 2, 3, 4, are the duals of a, b, c, d.
Example: Find the duals for the following Boolean Expression
Sl No Boolean Expression Duals
1 X+0=X X.1=X
2 X+1=1 X.0=0
3 X.X=0 X+X=1
4 X . ( Y + Z) X + ( Y . Z)
5 X + X.Y = X + Y X.(X + Y) = X.Y
Boolean Theorems:
Boolean Theorem can be proved by substituting all possible values of the variable that are 0
and 1.
This technique of proving theorem is called Proof by perfect induction.
Sl No Theorem Sl No Theorem
Properties of 0 and 1 Associative Law
1 0+X=X 12 X .(Y.Z) = (X.Y).Z
2 1+X=1 13 (X+Y).Z = X+(Y.Z)
3 0.X=0 Distributive Law
4 1.X=X 14 X.(Y+Z) = X.Y + X.Z
Indempotence Law 15 X+Y.Z = (X+Y).(X+Z)
5 X+X=X Absorption Law
6 X.X=X 16 X + XY = X
Complementary Law 17 X(X+Y) = X
7 X+X=1 18 XY + XY = X
8 X.X=0 19 (X+Y)(X+Y)= X
Involution Law 20 X+XY = X+Y
9 X=X 21 X(X+Y) = XY
Commutative Law
10 X+Y=Y+X
11 X.Y=Y.X
Theorem 1: 0+X=X
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =0+X then LHS =0+X
0 X 0+X
=0+0 =0+1
0 0 0
=0 =1
0 1 1
= RHS = RHS
Theorem 2: 1+X=1
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =1+X then LHS =1+X
1 X 1+X
=1+0 =1+1
1 0 1
=1 =1
1 1 1
= RHS = RHS
5|Page Keerthi Kumar H.M
Chapter 2- Boolean Algebra II PUC, MDRPUC, Hassan
Theorem 3: 0.X=0
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =0.X then LHS =0.X
0 X 0.X
=0.0 =0.1
0 0 0
=0 =0
0 1 0
= RHS = RHS
Theorem 4: 1.X=X
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =1.X then LHS =1.X
1 X 0.X
=1.0 =1.1
1 0 0
=0 =1
1 1 1
= RHS = RHS
Indempotence Law: “This law states that when a variable is combines with itself
using OR or AND operator, the output is the same variable”.
Theorem 5: X+X=X
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =X+X then LHS =X+X
X X X+X
=0+0 =1+1
0 0 0
=0 =1
1 1 1
= RHS = RHS
Theorem 6: X.X=X
Proof: If X = 1 Using Truth Table
Proof: If X = 0
then LHS =X.X
then LHS =X.X X X X.X
=1.1
=0+0 0 0 0
=1
=0 1 1 1
= RHS
= RHS
Complementary Law: “This law states that when a variable is And ed with its
complement is equal to 0 and a variable is OR ed with its complement is equal to 1”.
Theorem 7: X+𝐗=1
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =X+X then LHS =X+X
X 𝐗 X+𝐗
=0+1 =1+0
0 1 1
=1 =1
1 0 1
= RHS = RHS
Theorem 8: X.𝐗=0
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS =X.X then LHS =X.X
X 𝐗 X.𝐗
=0.1 =1.0
0 1 0
=0 =0
1 0 0
= RHS = RHS
Involution Law: “This law states that when a variable is inverted twice is equal to
the original variable”.
Theorem 9: 𝐗=X
Proof: If X = 0, then X = 1 Using Truth Table
Take complement again, then X = 0 i.e. X 𝐗
X 𝐗
If X = 1, then X = 0
0 1 0
Take complement again, then X = 1 i.e. X 1 0 1
Commutative Law: “This law states that the order in which two variable are Or ed
or AND ed make no difference”.
Associative Law: “This law allows the removal of brackets from an expression and
regrouping of the variables”.
Distributive Law: “This law allows the multiplying or factoring out an expression”.
Theorem 14: X.(Y+Z) = XY + XZ
Proof: If X = 0 Proof: If X = 1
LHS = X.(Y+Z) LHS = X.(Y+Z)
= 0.(Y+Z) = 1.(Y+Z)
=0 = Y+Z
RHS = XY + XZ RHS = XY + XZ
= 0.Y+0.Z = 1.Y+1.Z
=0 = Y+Z
Therefore LHS = RHS Therefore LHS = RHS
Theorem 15: (𝑋 + 𝑌) (𝑋 + 𝑍) = 𝑋 + 𝑌𝑍
LHS: (𝑋 + 𝑌) (𝑋 + 𝑍) = 𝑋𝑋 + 𝑋𝑍 + 𝑋𝑌 +𝑌𝑍
= 𝑋 + 𝑋𝑍 + 𝑋𝑌 + 𝑌𝑍
= 𝑋(1 + 𝑍) + 𝑋𝑌 + 𝑌𝑍
Important
= 𝑋 + 𝑋𝑌 + 𝑌𝑍
2 Marks
= 𝑋(1 + 𝑌) + 𝑌𝑍
= 𝑋 + 𝑌𝑍
= RHS
DeMorgan’s Theorem:
DeMorgan’s First Theorem:
o Statement: “When the OR sum of two variables is inverted, this is same as inverting
each variable individually and then AND ing these inverted variables”
o This can be written as 𝐗 + 𝐘 = 𝐗. 𝐘
Important
o We can prove the DeMorgan’s First theorem by using Truth Table is 5 Marks
X Y 𝐗 𝐘 X+Y 𝐗 + 𝐘 𝐗. 𝐘
0 0 1 1 0 1 1
0 1 1 0 1 0 0
1 0 0 1 1 0 0
1 1 0 0 1 0 0
o Compare the column 𝐗 + 𝐘 and 𝐗. 𝐘. Both of these are identical. Hence the DeMorgan’s
first theorem is proved.
DeMorgan’s Second Theorem:
o Statement: “When the AND product of two variables is inverted, this is same as
inverting each variable individually and then OR ing these inverted variables”
o This can be written as 𝐗. 𝐘 = 𝐗+𝐘
o We can prove the DeMorgan’s Second theorem by using Truth Table is:
X Y 𝐗 𝐘 X.Y 𝐗. 𝐘 𝐗+𝐘
0 0 1 1 0 1 1
0 1 1 0 0 1 1
1 0 0 1 0 1 1
1 1 0 0 1 0 0
o Compare the column 𝐗. 𝐘 and 𝐗+𝐘. Both of these are identical. Hence the DeMorgan’s
Second theorem is proved.
Application of DeMorgan’s Theorem:
o It is used in simplification of Boolean expression.
o DeMorgan’s law commonly apply to text searching using Boolean operators AND, OR and
NOT.
o It is useful in the implementation of the basic gates operations with alternative gates.
1) 𝐗 𝐘 Z + 𝐗 Y Z + X 𝐘 2) XYZ + XYZW + XZ
=XYZ+XYZ+XY = XYZ (1 + W) + XZ
= XZ (Y + Y) + X Y = XYZ . 1 + XZ
= XZ 1 + X Y = XZ (Y + 1)
= XZ
= XZ + X Y
3) Z(Y+Z)(X+Y+Z)
= (ZY + ZZ) (X+Y+Z) 4) 𝐗 + 𝐗 𝐘 + 𝐘 + 𝐗 + 𝐘 𝐗 𝐘
2) AB + AB + A B
3) B(A+C) + AB + BC + C
Exercise Problems: Solving using DeMorgan’s Theorem
1) (A + C). B + D
2) AB + C)
Minterm:
Minterm is a product of all the literal (with or without bar) within the logic system.
(OR) A single variable or the logical product of several variables. The variables may or may not
be complemented.
A variable may appear either in its normal form (X) or in its complement form (X)
If a variable value is 0 then its complemented otherwise it is in its normal form.
For example, if you have two variables X & Y, there are four possible combination can be formed
with AND operation. Each of these four AND operations represents one of the Boolean
expressions terms and is called a Minterm or a standard product.
X Y Minterm Designation
0 0 XY m0
0 1 XY m1
1 0 XY m2
1 1 XY m3
A symbol for each Minterm is also shown in the table and is of the form mj where j denotes the
decimal equivalent of the binary number of the Minterm designated.
For example, the Minterm 𝐗 𝐘 𝐙 whose combination is 1 1 0 can be written as m6 as decimal
equivalent of 1 1 0 is 6.
A Boolean expression may be represented from a given truth table by forming a Minterm for each
combination of the variables which produces as 1 in the function, and then taking the OR
(Logical Addition) of all those terms.
Assume the truth table
X Y Z Output Minterm Designation
0 0 0 0 XYZ m0
0 0 1 0 XYZ m1
0 1 0 1 XYZ m2 Minterm
0 1 1 1 XYZ Results 1
m3
1 0 0 0 XYZ m4
1 0 1 0 XYZ m5
1 1 0 1 XYZ m6
1 1 1 0 XYZ m7
The Boolean function of truth table is obtained by OR ing (Add) three Minterm i.e. 010 (X Y Z),
011 (X Y Z), 110 (X Y Z). Since each of these Minterm results is 1 (output).
12 | P a g e Keerthi Kumar H.M
Chapter 2- Boolean Algebra II PUC, MDRPUC, Hassan
f (X, Y, Z) = 𝐗 𝐘 𝐙 + 𝐗 Y Z + 𝐗 𝐘 𝐙 = m2 + m3 + m6
The above Boolean function is the sum of three product terms. This type of expression is known as
Sum of Product (SOP) expression.
f (X, Y, Z) = ∑ (2, 3, 6)
Where f is a Boolean function with three variables (X, Y, Z) and it can be read as function f is sum
of 2nd, 3rd, and 6th Minterm.
Sum of Product (SOP): A Sum of product expression is a product term or several product terms
logically added.
What are the fundamental products for each of the input words; ABCD = 0010, ABCD =110,
Maxterm:
Maxterm is a sum of all the literal (with or without bar) within the logic system.
(OR) A single variable or the logical sum of several variables. The variables may or may not be
complemented.
A variable may appear either in its normal form (X) or in its complement form (X)
If a variable value is 1 then its complemented otherwise it is in its normal form.
For example, if you have two variables X & Y, there are four possible combination can be formed
with OR operation. Each of these four OR operations represents one of the Boolean expressions
1 0 0 0 𝐗+Y+Z M4
1 0 1 0 𝐗+ 𝐘+𝐙 M5
1 1 0 1 X+ Y+Z M6
1 1 1 0 𝐗+ 𝐘+ 𝐙 M7
The Boolean function of truth table is obtained by AND ing (Multiply) five Maxterm i.e. 000, 001,
100, 101, 111. Since each of these Maxterm results is 0 (output).
f (X, Y, Z) = (X + Y + Z)(𝐗 + 𝐘 + 𝐙)( 𝐗 + Y + Z)( 𝐗 + 𝐘 + 𝐙)( 𝐗 + 𝐘 + 𝐙)= M0.M1.M4.M5.M7
The above Boolean function is the product of three sum terms. This type of expression is known as
Product of Sum (POS) expression.
f (X, Y, Z) = π (0, 1, 4, 5, 7)
Where f is a Boolean function with three variables (X, Y, Z) and it can be read as function f is
product of 0th, 1st, 4th, 5th and 7th Maxterm.
Product of Sum (POS): A product of sum expression is a sum term or several sum terms
logically multiplied.
Canonical Form:
Boolean expression expressed as sum of Minterms or product of Maxterms are called
canonical forms.
For example, the following expressions are the Minterm canonical form and Maxterm canonical
form of two variables X and Y.
o Minterm Canonical = f(X, Y) = X + X Y + X Y + X Y + X Y
o Maxterm Canonical = f(X, Y) = X + Y X + Y (X + Y)
The Minterm canonical expression is the sum of all Minterms. Each Minterm contain all the
variables.
The maxterm canonical expression is the product of all Maxterms. Each Maxterm contain all the
variables.
Construction of K-Map:
The K-Map is a pictorial representation of a truth table made up of squares.
Each square represents a Minterm or Maxterm.
A K-Map for n variables is made up of 2n squares.
CD CD
CD CD CD CD 00 01 11 10
Important Questions
2 Marks Question:
1. Prove that X + XY = X [March 2015, March 2017]
2. Define Minterm and Maxterm [March 2015, March 2016]
3. State and prove Involution law. [June 2015]
4. State and prove Commutative law using truth table. [June 2016]
5. What is principle of duality? Give Example [June 2015, March 2017]
6. Prove algebraically that (𝑋+𝑌) (𝑋+𝑍)=𝑋+𝑌𝑍 [March 2016]
7. Prove: (X+Y) (X+(Y) = X [June 2016]
8. Prove algebraically that 𝑋+X𝑌=𝑋+𝑌
9. Draw a general K-map for four variables A, B, C and D.
5 Marks Question:
1. Give the Boolean function F (W, X, Y, Z) = ∑ (0, 4, 8, 9, 10, 11, 12, 13, 15). Reduce it by
using K-Map. [March 2015]
2. Reduce F (A, B, C, D) = ∑ (1, 2, 3, 4, 5, 7, 9, 11, 12, 13, 14, 15) using K-Map [June 2015]
3. Using K-Map, Simplify the following expression in four variables
F (A, B, C, D) = m1 + m2 + m4 + m5 + m9 + m11 + m12 + m13. [March 2016]
18 | P a g e Keerthi Kumar H.M
Chapter 3- Logic Gates II PUC, MDRPUC, Hassan
Chapter-3
LOGIC GATES
Introduction:
Gate: A Gate is a simply an electronic circuit which operates on one or more input signals and
always produces an output signal.
Gates are digital (two state) circuits because the input and output signals are either low voltage (0) or
high voltage (1).
Gates are often called logic circuits because they can be analyzed with Boolean algebra.
Gates are classified into two types:
Logic gates
Basic Gates:
NOT Gate:
A NOT gate has only one input and one output.
The output state is always the opposite of the input state.
A NOT Gate is also called as Inverter gate, because the output is not same as the input.
The output is sometimes called the complement (opposite) of the input.
The logical symbol and the truth table of NOT gate are given below.
X
X X 0 1
1 0
OR Gate:
A OR gate has two or more input signal but only one output signal.
If any of the input signals is 1 (high), then the output is 1 (high).
The logical symbol for two-input OR gate and the truth table is given below.
1|Page
Chapter 3- Logic Gates II PUC, MDRPUC, Hassan
X Y F = X+Y
X F=X+Y 0 0 0
0 1 1
Y
1 0 1
1 1 1
AND Gate:
A AND gate has two or more input signal but only one output signal.
When all the input signals are 1 (high), the output is 1 (high), otherwise the output is 0.
The logical symbol for two-input AND gate and the truth table is given below.
X Y F = X.Y
X F = X .Y 0 0 0
0 1 0
Y
1 0 0
1 1 1
NOR Gate:
A NOR gate has two or more input signal but only one output signal.
The NOR gate is a complemented of OR gate.
The output of NOR gate will be 1 only when all inputs are 0 and output will be 0 if any input
represents a 1.
NOR is short form of NOT-OR.
The symbol is used to represent a NOR operation. So X + Y can be written as X NOR Y or X Y.
The logical structure shows an OR gate and NOT gate. For input X and Y, the output of the OR gate
will be X+Y which is fed as input to the NOT gate. So the output of NOR gate is given by X + Y
which is equal to X . Y
X F=X+Y F=X+Y
Y
The logical symbol for two-input NOR gate and the truth table is given below.
X Y Z F= + +
X F=X+Y 0 0 0 1
0 0 1 0
Y 0 1 0 0
X Y F= + 0 1 1 0
0 0 1 1 0 0 0
0 1 0 1 0 1 0
1 0 0 1 1 0 0
1 1 0 1 1 1 0
2|Page
Chapter 3- Logic Gates II PUC, MDRPUC, Hassan
NAND Gate:
A NAND gate has two or more input signal but only one output signal.
The NAND gate is a complemented of AND gate.
The output of NAND gate will be 0 only when all inputs are 1 and output will be 0 if any input
represents a 0.
NAND is short form of NOT-AND.
The symbol is used to represent a NOR operation. So X . Y can be written as X NAND Y or X Y.
The logical structure shows an AND gate and NOT gate. For input X and Y, the output of the OR
gate will be X .Y which is fed as input to the NOT gate. So the output of NAND gate is given by
X . Y which is equal to X + Y
X F=X.Y F = X .Y
Y
The logical symbol for two-input NAND gate and the truth table is given below.
X F = X .Y
Y
X Y F= . X Y Z F= . .
0 0 1 0 0 0 1
0 1 1 0 0 1 1
1 0 1 0 1 0 1
1 1 0 0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
XOR (Exclusive-OR) Gate: 1 1 1 0
An exclusive-OR has two or more input signal but only one output signal.
Exclusive-OR gate is different form of OR gate.
Exclusive-OR gate produces output 1 for only those input combinations that have odd number of 1’s.
The output is 0 if there are even number of 1’s in the input.
The output is 1 if there are odd number of 1’s in the input.
In Boolean algebra, ϴ sign stands for XOR operation. Thus X XOR Y can be written as XϴY
If the output is given by:
F=XϴY
3|Page
Chapter 3- Logic Gates II PUC, MDRPUC, Hassan
F=XY+ XY
The XOR gate has a symbol similar to OR gate, except the additional curved line of the input side.
X F=XϴY=XY+ XY
Y
The following truth table illustrates XOR operation for 2 and 3 inputs.
NAND to NOT:
In the figure we have two input NAND gate whose inputs are purposely connected together so that
the same input is applied to both.
F = X .X = X
X
5|Page
Chapter 3- Logic Gates II PUC, MDRPUC, Hassan
NOR to NOT:
Figure shows that NOR gate with its inputs connected together behaves as a NOT gate.
F=X+X=X
X
6|Page
Chapter 3- Logic Gates II PUC, MDRPUC, Hassan
NAND to OR:
In the figure two NOR gates are arranged so that the OR operation is performed.
NOR gate 2 is used as NOT gate.
X F1 = X + Y F2 = X + Y = X + Y
Y
7|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Chapter-4
DATA STRUCTURES
Introduction:
Data Structure is the way of collecting and organizing the data in such a way that we can
perform operation on these data in an effective way.
For Example: We have the data student’s Name “Akash” and age “16”. Here “Akash” is a string
type data type and 16 are of integer. We can now organize this data as a record like a Student
Record. We can collect and store other Student’s Record in a file or a database as a data structure.
Data Representation:
Computer memory is used to store the data which is required for processing. This process is
known as data representation.
Data may be of same type or different type.
Data Structure provides efficient way of combining these data types and process data.
Data Structure
Linked List
Primitive Data structures:
Data structures that are directly operated upon the machine-level instructions are known as
primitive data structures.
The integers, float, character data, pointers are primitive data structures.
1|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
3. Deletion: The process of removing an existing data element from the given collection of data
elements is called deletion.
4. Searching: The process of finding the location of a data element in the given collection of data
elements is called as searching.
5. Sorting: The process of arrangement of data elements in ascending or descending order is called
sorting.
6. Merging: The process of combining the elements of two structures to form a single structure is
called merging.
Arrays:
An array is an ordered collection of elements of same data type that share common name.
The elements are arranged one after the other in adjacent memory location.
These elements are accessed by numbers called subscripts or indices.
The elements are accessed using subscripts; arrays are also called as subscripted variables.
There are three types of arrays
i. One-dimensional Array
ii. Two-dimensional Array
iii. Multi-dimensional Array
3|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
1002 C A[2]
1003 D A[3]
1004 E A[4] Upper Bound(UB)
Traversing an array:
Traversing is the process of visiting each subscript at least once from the beginning element to
last element.
For example, to find the maximum element of the array we need to access each element of the
array.
ALGORITHM: Traversal (A, LB, UB) A is an array with Lower Bound LB and
Upper Bound UB.
Step 1: for LOC = LB to UB do
Step 2: PROCESS A [LOC]
[End of for loop]
Step 3: Exit
4|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
ALGORITHM: Insert (A, N, ITEM, Pos) A is an array with N elements. ITEM is the
element to be inserted in the position Pos.
Step 1: for I = N-1 down to Pos
A[ I + 1] = A[I]
[End of for loop]
Step 2: A [Pos] = ITEM
Step 3: N = N+1
Step 4: Exit
For example: Let A[4] be an array with items 10, 20, 30, 40, 50 stored at consecutive locations.
Suppose item 30 has to be deleted at position 2. The following procedure is applied.
o Copy 30 to ITEM, i.e. Item = 30.
o Move Number 40 to the position 2.
o Move Number 50 to the position 3.
ALGORITHM: Delete (A, N, ITEM, Pos) A is an array with N elements. ITEM is the
element to be deleted in the position Pos and it is stored into variable Item.
Step 1: ITEM = A [Pos]
Step 2: for I = Pos down to N-1
A[ I ] = A[I+1]
[End of for loop]
Step 3: N = N-1
Step 4: Exit
Linear Search:
This is the simplest method in which the element to be searched is compared with each element of
the array by one from the beginning to end of the array.
Searching is one after the other, it is also called as sequential search.
6|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
LOC = I
Goto Step 3
[End if]
[End of for loop]
Step 3: if ( LOC >= 0 ) then
Print Element, “Found in Location”, LOC
else
Print Element, “Not Found”
Step 4: Exit
Example: Consider the following elements stored in an array and we are searching for the element
17. The trace of the algorithm is given below.
Index (I) Compare 17 Location
17 = 12
I=0 LOC = -1
(Does not match)
A[0] A[1] A[2] A[3] A[4] 17 = 23
I=1 LOC = -1
12 23 9 17 7 (Does not match)
17 = 9
I=2 LOC = -1
(Does not match)
17 = 17
I=3 LOC = 3
(Matches)
Binary Search:
When the elements of the array are in sorted order, the best method of searching is binary search.
This method compares the element to be searched with the middle element of the array.
If the comparison is searched either at the right half of the array or at the left half of the array.
Let the position of first (BEG) and last (END) elements of the array. The middle element A[MID]
can be obtained by find the middle location MID by MID= (BEG+END)/2.
If A[MID]= ELE, then search is successful. Otherwise a new segment is found as follows:
o If ELE<A[MID], searching is continued at left half of the array. Reset END=MID-1.
o If ELE>A[MID], searching is continued at right half of the array. Reset BEG=MID+1.
o If ELE not found then we get a condition BEG>END. This results in unsuccessful search.
MID = (BEG+END)/2
if ( ELE = A [ MID ] ) then
LOC = MID Important
Goto Step 3
else
if( ELE < A[MID])
END=MID-1;
else
BEG=MID+1;
[End if]
[End if]
[End of While loop]
Step 3: if ( LOC >= 0 ) then
Print Element, “Found in Location”, LOC
else
Print Element, “Search is Unsuccessful”
Step 4: Exit
Example: Consider the following elements stored in an array and we are searching for the element
47. The trace of the algorithm is given below.
MID =
BEG & END Compare Location
(BEG+END)/2
The search element i.e. 47 is greater than the element in the middle position i.e. 39 then
continues the search to the right portion of the middle element.
Since the element in the middle position is the same as the search element LOC gets the value 3.
Since the value of LOC is greater than 0, we get the output as 47 Found in location 3
8|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Example: Consider the following elements stored in an array and we are searching for the element
67. The trace of the algorithm is given below.
MID =
BEG & END Compare Location
(BEG+END)/2
A[0] A[1] A[2] A[3] A[4]
67>39
12 23 39 47 57 BEG = 0 MID = (0+4)/2 (Does not LOC = -1
END = 4 MID = 2
BEG MID END match)
The search element i.e. 67 is greater than the element in the middle position i.e. 39 then
continues the search to the right portion of the middle element.
The search element i.e. 67 is greater than the element in the middle position i.e. 47 then
continues the search to the right portion of the middle element.
A[0] A[1] A[2] A[3] A[4]
12 23 39 47 57 67>57
BEG = 4 MID = (4+4)/2 (Does not LOC = -1
BEGMID END = 4 MID = 4
match)
END
The search element i.e. 67 is greater than the element in the middle position i.e. 57 then
continues the search to the right portion of the middle element.
9|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Insertion Sort:
In Insertion sort, the first element of the array is assumed to be in the correct position next element
is considered as the key element and compared with the elements before the key element and is
inserted in its correct position.
Example: Consider the following array contains 8 elements as follows:
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7]
45 26 23 56 29 36 12 4
10 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Column-Major Method: All the first column elements are stored in sequential memory locations
and then all the second-column elements are stored and so on.
11 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Advantages of Array:
It is used to represent multiple data items of same type by using single name.
It can be used to implement other data structures like linked lists, stacks, queues, tree, graphs etc.
Two-dimensional arrays are used to represent matrices.
Many databases include one-dimensional arrays whose elements are records.
Disadvantages of Array:
We must know in advance the how many elements are to be stored in array.
Array is static structure. It means that array is of fixed size. The memory which is allocated to
array cannot be increased or decreased.
Array is fixed size; if we allocate more memory than requirement then the memory space will be
wasted.
The elements of array are stored in consecutive memory locations. So insertion and deletion are
very difficult and time consuming.
STACKS:
A stack is an ordered collection of items in which an element may be inserted or deleted only at
same end.
This end is called as the top of the stack.
The end opposite to top is known as the base.
Stacks are sometimes known as LIFO (Last In First Out).
Operation on Stacks:
Stack( ): It creates a new stack that is empty. It needs no parameter and returns an empty stack.
push(item): It adds a new item to the top of the stack.
pop( ): It removes the top item from the stack.
peek( ): It returns the top item from the stack but does not remove it.
isEmpty( ): It tests whether the stack is empty.
size( ): It returns the number of items on the stack. Important
PUSH Operation:
The process of adding one element or item to the stack is represented by an operation called as
the PUSH operation.
The new element is added at the topmost position of the stack.
ALGORITHM: PUSH (STACK, TOP, ITEM) STACK is the array with N elements. TOP is the
pointer to the top of the element of the array. ITEM to be inserted.
Step 1: if TOP = N-1 then [Check Overflow]
PRINT “ STACK is Full or Overflow”
Exit
[End if]
Step 2: TOP = TOP + 1 [Increment the TOP]
Step 3: STACK[TOP] = ITEM [Insert the ITEM]
Step 4: Return
POP Operation:
The process of deleting one element or item from the stack is represented by an operation called
as the POP operation.
ALGORITHM: POP (STACK, TOP, ITEM) STACK is the array with N elements. TOP is the
pointer to the top of the element of the array. ITEM to be inserted.
Application of Stacks:
It is used to reverse a word. You push a given word to stack – letter by letter and then pop letter
from the stack.
“Undo” mechanism in text editor.
Backtracking: This is a process when you need to access the most recent data element in a series of
elements. Once you reach a dead end, you must backtrack.
Language Processing: Compiler’ syntax check for matching braces in implemented by using stack.
Conversion of decimal number to binary.
Conversion of infix expression into prefix and postfix.
Quick sort
Runtime memory management.
Arithmetic Expression:
An expression is a combination of operands and operators that after evaluation results in a single
value.
Operand consists of constants and variables.
Operators consists of {, +, -, *, /, ), ] etc.
Expression can be
o Infix Expression
o Postfix Expression
o Prefix Expression
Infix Expression: If an operator is in between two operands, it is called infix expression.
Example: a + b, where a and b are operands and + is an operator.
Postfix Expression: If an operator follows the two operands, it is called postfix expression.
Example: ab +
Prefix Expression: an operator precedes the two operands, it is called prefix expression.
Example: +ab
14 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
15 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Sl No Infix Prefix
QUEUES:
A queue is an ordered collection of items where an item is inserted at one end called the “rear”
and an existing item is removed at the other end, called the “front”.
Queue is also called as FIFO list i.e. First-In First-Out.
In the queue only two operations are allowed enqueue and dequeue.
Enqueue means to insert an item into back of the queue.
Dequeue means removing the front item.
REAR FRONT
Dequeue
Enqueue
Types of Queues:
Queue can be of four types:
o Simple Queue
o Circular Queue
o Priority Queue
o Dequeue ( Double Ended Queue)
Simple Queue: In simple queue insertion occurs at the rear end of the list and deletion occurs at
the front end of the list.
Front Rear
A B C D Front = 1
Rear = 4
0 1 2 3 4 5
16 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Operation on Queues:
Queue( ): It creates a new queue that is empty.
enqueue(item): It adds a new item to the rear of the queue.
dequeue( ): It removes the front item from the queue.
isEmpty( ): It tests to see whether the queue is empty.
size( ): It returns the number of items in the queue.
A B C D Front = 1
Rear = 4
0 1 2 3 4 5
REAR = REAR + 1, QUEUE [REAR] = ‘E’
Front Rear
A B C D E Front = 1
Rear = 5
0 1 2 3 4 5
17 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
B C D E Front = 2
Rear = 5
0 1 2 3 4 5
Queue Insertion Operation (ENQUEUE):
Consider a queue Q with 5 elements.
Q[0] Q[1] Q[2] Q[3] Q[4] Initially Queue is Empty FRONT = -1, REAR= -1
If we want to add one element i.e. 8 in the queue, then FRONT and REAR Indicator are set to 0
and the element 8 would be stored at the position pointed by the REAR.
REAR = 0, FRONT = 0, Q[REAR]=Q[0]=8 Q[0] Q[1] Q[2] Q[3] Q[4]
8
If we want to add one more element i.e. 12 in the queue, then REAR Indicator would be
incremented by 1 and the element 12 would be stored at the position pointed by the REAR.
REAR = 1, FRONT = 0, Q[REAR]=Q[1]=12 Q[0] Q[1] Q[2] Q[3] Q[4]
8 12
ALGORITHM: ENQUEUE (QUEUE, REAR, FRONT, ITEM) QUEUE is the array with N
elements. FRONT is the pointer that contains the location of the element to be deleted and REAR
contains the location of the inserted element. ITEM is the element to be inserted.
If we want to delete an element i.e. 8 from the queue, then the value of FRONT will be
incremented by 1. Deletions are done from this end of the queue.
REAR = 2, FRONT = 1, Q[0] Q[1] Q[2] Q[3] Q[4]
12 4
If we want to delete an element i.e. 12 from the queue, then the value of FRONT will be
incremented by 1 i.e. 2.
REAR = 2, FRONT = 2 Q[0] Q[1] Q[2] Q[3] Q[4]
4
Observe that queue has only one element. When FRONT = REAR condition is true, then the queue
Q has only one element. If we want to this element also, then the queue Q becomes empty and set
the FRONT and REAR pointers to -1.
REAR = -1, FRONT = -1, Queue is Empty. Q[0] Q[1] Q[2] Q[3] Q[4]
ALGORITHM: DEQUEUE (QUEUE, REAR, FRONT, ITEM) QUEUE is the array with N
elements. FRONT is the pointer that contains the location of the element to be deleted and REAR
contains the location of the inserted element. ITEM is the element to be deleted.
19 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Application of Queue:
Simulation
Various features of Operating system
Multi-programming platform systems.
Different types of scheduling algorithms
Round robin technique algorithms
Printer server routines
Various application software’s is also based on queue data structure.
LINKED LIST:
A linked list is a linear collection of data elements called nodes.
Each nodes is divided into two parts:
o The first part contains the information of the element.
o The second part contains the memory address of the next node in the list. Also called Link
part.
In the above figure shows an representation if Linked List with three nodes, each node contains
two parts.
The left part of the node represents Information part of the node.
The right part represents the next pointer field. That contains the address of the next node.
A pointer START or HEAD gives the location of the first node.
The link field of the last node contains NULL.
AVAIL List
The operating system of the computer maintains a special list called AVAIL list that contains only
the unused deleted nodes.
Whenever node is deleted from the linked list, its memory is added to the AVAIL list.
AVAIL list is also called as the free-storage list or free-pool.
22 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
ALGORITHM: INS_BEG (START, P) START contains the address of the first node.
Step 1: P new Node;
Step 2: data(P) num;
Step 3: link(P) START
Step 4: START P
Step 5: Return
Garbage Collection:
The operating system of the computer periodically collects all the deleted space into the free-
storage list. This technique of collecting deleted space into free-storage list is called as garbage
collection.
ALGORITHM: DEL_END (P1, P2, START) This used two pointers P1 and P2. Pointer P2 is used to
traverse the linked list and pointer P1 keeps the location of the previous node of P2.
Step 1: START
Step 2: P2 START;
Step 3: while ( link(P2) ! = NULL)
P1 P2
23 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
P2 link(P2)
While end
Step 4: PRINT data(p2)
Step 5: link(P1) NULL
Free(P2)
Step 6: STOP
Trees:
A tree is a data structure consisting of nodes organized as a hierarchy.
Terminology of a tree:
Node: A node is a fundamental part of tree. Each element of a tree is called a node of the tree.
Root: The topmost node of the tree.
Edge: It connects two nodes to show that tree is a relationship between them.
Parent: It is an immediate predecessor a node. ( A is parent of B, C, D)
Child: A successor of parent node is called the child node. (E, F is a child of B)
Siblings: Nodes that are children of the same parent are called siblings. (B,C,D) (M,N)
Leaf or terminal node: Nodes that do not have any children are called leaf node. (J, K, L)
Internal Node: A node has one or more children is called an internal node. ( B, C, D, H )
24 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Path: A path is an ordered list of nodes that are connected by edges. In figure path A to O is A, D,
I, M, O.
Height: the height or depth of a tree is defined to be the maximum number of nodes in a branch of
tree. ( The height of tree is 5)
Ancestor: A node reachable by repeated proceeding from child to parent. (Ancestor of M is I, D,
and A)
Descendant: A node reachable by repeated proceedings from parent to child. (Descendent of I are
(M,O) and N)
Subtree: A Subtree is a set of nodes and edges comprised of parent and all the descendants of that
parent. In figure T1, T2 and T3 are subtrees.
Binary tree:
A binary tree is an ordered tree in which each internal node can have maximum of two child
nodes connected to it.
A binary tree consists of:
o A node ( called the root node)
o Left and right sub trees.
A Complete binary tree is a binary tree in which each leaf is at the same
distance from the root i.e. all the nodes have maximum two subtrees.
GRAPH
25 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan
Important Questions
1 Mark Questions:
1. Definition of Data Structure, Linear Data Structures, Array, Stack, Queue, Linked List,
Non Linear Data Structures.
2. Definition on Tree, Tree Terminologies, Binary Tree, Complete Binary Tree, Graph.
3 Marks Questions:
5 Marks Questions:
26 | P a g e
Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan
Chapter-6
Introduction:
Object oriented programming is the principle of design and development of programs using
modular approach.
Object oriented programming approach provides advantages in creation and development of
software for real life application.
The basic element of object oriented programming is the data.
The programs are built by combining data and functions that operate on the data.
Some of the OOP’s languages are C++, Java, C #, Smalltalk, Perl, and Python.
Procedural programming:
The procedural programming focuses on processing of
instructions in order to perform a desired computation.
Therefore it emphasizes more on doing things like algorithms.
This programming is lengthy, increases the complexity of
program, difficult to understand and modify the program.
This technique is used in a conventional programming language such as C and Pascal.
Structured programming:
An organized approach to programming involving
the use of three basic control structures – Sequence,
Conditional and loop.
The top-down concepts to decompose main
functions into lower level components for modular coding purpose.
The major drawback is that it is very difficult to model the real world scenario using this model.
member data and the functions that operate on these data known as member function.
OOP follows bottom-up design technique.
Class is the major concept that plays important role in this approach. Class is a template that
represents a group of objects which share common properties and relationships.
2|Page
Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan
Objects
Objects are basic building blocks for designing programs.
An object is a collection of data members and associated member functions.
An object may represent a person, place or a table of data.
Each object is identified by a unique name. Each object must be a member of a particular class.
Example: Apple, orange, mango are the objects of class fruit.
Objects take up space in memory and have address associated with them.
At the time of execution of a program, the objects interact by sending the messages to one another.
The objects can interact with one another without having to know details of data or functions
within an object.
Classes:
The objects can be made user defined data types with the help of a class.
A class is a collection of objects that have identical properties, common
behavior and shared relationship.
Once class is defined, any number of objects of that class is created.
Classes are user defined data types. A class can hold both data and
functions.
For example: Planets, sun, moon are member of class solar system.
Data Abstraction:
Data Abstraction refers to the process of representing essential features without including
background details or explanations.
Data Encapsulation:
The wrapping of data and functions into a single unit (class) is called
data encapsulation.
Data encapsulation enables data hiding and information hiding.
3|Page
Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan
Data hiding is a method used in object oriented programming to hide information within computer
code.
Inheritance:
Inheritance is the process by which one object can
acquire and use the properties of another object.
The existing class is known as base class or super
class.
The new class is known as derived class or sub class.
The derived class shares some of the properties of the base class. Therefore a code from a base
class can be reused by a derived class.
Overloading:
Overloading allows objects to have different meaning depending upon context.
There are two types of overloading viz.
o Operator Overloading
o Function Overloading
When an existing operator operates on new data type is called operator overloading.
Function overloading means two or more function have same, but differ in the number of
arguments or data type of arguments.
Polymorphism:
The ability of an operator and function to take
multiple forms is known as Polymorphism.
The different types of polymorphism are operator
overloading and function overloading.
Dynamic binding:
Binding is the process of connecting one program to another.
Dynamic binding is the process of linking the procedure call to a specific sequence of code or
function at run time or during the execution of the program.
Message Passing:
In OOP’s, processing is done by sending message to objects.
A message for an object is request for execution of procedure.
4|Page
Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan
Message passing involves specifying the name of the object, the name of the function (message)
and the information to be sent.
Important
Advantage of OOP’s
The programs are modularized based on the principles of classes and objects.
Linking code & object allows related objects to share common code. This reduces code
duplication and code reusability.
Creation and implementation of OOP code is easy and reduces software development time.
The concept of data abstraction separates object specification and object implementation.
Data encapsulated along with functions. Therefore external non-member function cannot access or
modify data, thus proving data security.
Easier to develop complex software, because complexity can be minimized through inheritance.
OOP can communicate through message passing which makes interface description with
outside system very simple.
Disadvantage of OOP’s
Larger program size: OOP’s typically involves more lines of code than procedural programs.
Slower Programs: OOP’s typically slower than procedure based programs, as they typically
require more instructions to be executed.
Not suitable for all types of programs.
To convert a real world problem into an object oriented model is difficult.
OOP’s software development, debugging and testing tools are not standardized.
Polymorphism and dynamic binding also requires processing time, due to overload of function
calls during run time.
Application of OOP’s
Computer graphics applications.
.CAD/CAM software
Object-oriented database.
User-Interface design such as windows
Real-time systems.
Simulation and Modeling
Artificial intelligence and expert systems.
Client-Server Systems.
5|Page
Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan
Important Questions
2 Marks Question:
5 Marks Question:
6|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
Chapter-7
Classes:
A class is a collection of objects that have identical properties, common behavior and shared
relationship.
A class binds the data and its related functions together.
Key word class is used to declare a class. User_Defined_Name is the name of the class.
Class body is enclosed in a pair of flower brackets. Class body contains the declaration of its
members (data and functions).
There are generally three types of members namely private, public and protected.
Example: Let us declare a class for representation of bank account.
class account
{
private:
1|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
int accno;
char name[20];
char acctype[4];
int bal_amt;
public:
void get_data( );
void display_data( );
};
Access Specifiers:
Every data member of a class is specified by three levels of access protection for hiding data and
function members internal to the class.
They help in controlling the access of the data members.
Different access specifiers such as private, public, and protected.
private:
private access means a member data can only be accessed by the class member function or friend
function.
The data members or member functions declared private cannot be accessed from outside the
class.
The objects of the class can access the private members only through the public member functions
of the class. This property is also called information hiding.
By default data members in a class are private.
Example:
private:
int x;
float y;
protected:
The members which are declared using protected can be accessed only by the member functions,
friend of the class and also the member functions derived from this class.
The members cannot be accessed from outside the class.
The protected access specifier is similar to private access specifiers.
public:
public access means that member can be accessed any function inside or outside the class.
Some of the public functions of a class provide interface for accessing the private and protected
members of the class.
2|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
Member Function:
Member functions are functions that are included within a class (Member functions are also called
Methods).
Member functions can be defined in two places.
o Inside class definition
Important
o Outside class definition 5 Marks
4|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
5|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
Example 2:
class num
{
private :
int x, y;
public :
int sum(int p, int q)
int diff(int p, int q)
};
void main( )
{
num s1, s2;
s1.sum ( 200,300);
s2.diff (600, 500);
}
6|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
Example:
class rectangle
{
int length, breadth, area;
public:
void get_data( )
{
cout<<”Enter the length and breadth”<<end;
cin>>length>>breadth;
}
void compute( )
{
area = length * breadth;
}
void display( )
{
cout<<”The area of rectangle is “<<area;
}
};
void main( )
{
rectangle r1;
OUTPUT:
clrscr( );
r1.get_data( ); Enter the length and breadth
r1.compute( ); 30 10
r1.display( );
The area of rectangle is 300
getch( );
}
void readarray( );
void displayarray( );
};
void array : : readarray( )
{
cout<<”Enter “<<m<<”Array elements”<<endl;
for(int i=0; i<m; i++)
cin>> a[i];
}
void array : : displayarray( )
{
cout<<”Array elements are:”<<endl;
for(int i=0; i<m i++)
cout<< a[i]<<”\t”;
}
void main( )
{
int n;
array a;
clrscr( ); OUTPUT:
cout<<”Input number of elements:”<<endl; Input number of elements: 5
cin>>n;
Enter 5 Array elements
a.setnoofelements(n);
a.readarray( ); 10 20 30 40 50
a.dispalyarray( ); Array elements are:
getch( );
10 20 30 40 50
}
8|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
private:
float phy, che, mat ;
public:
void readdata( )
{
cout<<”Input Physics, Chemistry, Maths marks : ” ;
cin>>phy>>che>>mat;
}
void total(exam PU , exam CT)
{
phy = PU.phy + CT.phy;
che = PU.che + CT.che;
mat = PU.mat + CT.mat;
}
void display( )
{
cout<< “Physics :” <<phy<<endl;
cout<< “Chemistry :” <<che<<endl;
cout<< “Maths :” <<mat<<endl;
}
};
void main( ); OUTPUT:
{
Enter PUC Marks
Exam PUC, CET, Puc_plus_Cet;
Input Physics, Chemistry, Maths marks :
clrscr( );
67 89 80
cout<<”Enter PUC Marks”<<endl;
Enter CET Marks
PUC.readdata( );
Input Physics, Chemistry, Maths marks :
cout<<”Enter CET Marks”<<endl;
60 76 91
CET.readdata( );
Total marks of PUC and CET is:
Puc_plus_Cet.total(PUC, CET);
Physics: 127
cout<<”Total marks of PUC and CET is:” <<endl;
Chemistry: 165
Puc_plus_Cet.display( );
} Maths: 171
In pass by reference, when an address of an object is passed to the function, the function directly
works on the original object used in function call.
This means changes made to the object inside the function will reflect in the original object,
because the function is making changes in the original object itself.
Pass by reference is more efficient, since it requires only passing the address of the object and not
the entire object.
11 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
IMPORTANT QUESTIONS:
1 Mark questions:
1. What is a Class, Objects, Data Member, Member Functions, Scope Resolution Operator, and
Array of objects?
2. Mention the access specifiers used with a class?
5 Mark questions:
1. Explain class definitions and class declaration with syntax and example.
2. Explain Member function.
a. Inside class definition
b. Outside class definition
3. Explain the array of objects. Important
5 Marks
Exercise programs
1. Write a C++ program to find the simple interest using class and objects.
#include<iostream.h>
#include<conio.h>
class SI
{
private:
float p, t, r, si;
public:
void readdata( )
{
cout<<”Enter the Principal Amount, Time & Rate”<<endl;
12 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
cin>>p>>t>>r;
}
void compute( )
{
si = (p * t * r)/100;
}
void display( )
{
cout<<”Simple Interest = “<<si;
}
};
void main( )
{
SI s;
clrscr( );
s.readdata( );
s.compute( );
s.display( );
getch( );
}
2. Let product list be a linear array of size N where each element of the array contains
following field Itemcode, Price and Quantity. Declare a class Product list with three data
members and member functions to perform the following
a. Add values to the product list
b. Printing that total stock values
#include<iostream.h>
#include<conio.h>
#include<iomainp.h>
class product
{
private:
char itemcode[6];
float price, quantity;
public:
void Addproduct( )
{
cout<<”Enter the Item Code”<<endl;
cin>>itemcode;
cout<<”Enter the Price”<<endl;
cin>>price;
cout<<”Enter the Quantity”<<endl;
cin>>quantity;
}
13 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
void display( )
{
cout<<itemcode<<”\t”<<price<<”\t”<<quantity<<endl;
}
};
void main( )
{
int N=0;
char ans;
product list[100];
clrscr( );
while(1)
{
cout<<”Item Code, Price and Quantity”<<endl;
List[N].Addproduct( );
cout<<”Do you want to add next item (Y/N)?”<<endl;
cin>>ans;
if(toupper(ans) == ‘N’)
break;
N++;
}
cout<<”Item Code \t Price \t Quantity”<<endl;
for(i=0; i<N; i++)
List[i].display( );
getch( );
}
3. A class cock has following member hours and minutes. Create member function
a. To initialize the data members
b. Display the time
c. To convert hours and minutes to minutes.
#include<iostream.h>
#include<conio.h>
class clock
{
private:
int hh, mm;
public:
void initialize( int h, int m)
{
hh = h;
mm = m;
}
void display( )
{
14 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
cout<<”Hours = “<<hh;
cout<<”Minutes = “<<mm;
}
void convert( )
{
mm = hh * 60 + mm;
cout<<”Total Minutes = “<<mm;
}
};
void main( )
{
int h, m;
clock c;
clrscr( );
cout<<”Enter the Hour and Minutes”<<endl;
cin>>h>>m;
c.intialize( );
c.display( );
c.convert( )
getch( );
}
4. Write a C++ program that receives arrival time and departure time and speed of an
automobile in kilometers/hours as input to a class. Compute the distance travelled in
meters/second and display the result using member functions.
#include<iostream.h>
#include<conio.h>
class Distance
{
private:
int Ahh, Amm, Dhh, Dmm;
float speed;
public:
void inputtime( )
{
cout<<”Enter the Arrival Time:”<<endl;
cout<<”Enter the Hour and Minutes”<<endl;
cin>>Ahh>>Amm;
cout<<”Enter the Departure Time:”<<endl;
cout<<”Enter the Hour and Minutes”<<endl;
cin>>Dhh>>Dmm;
cout<”Enter the speed in Kmph”<<endl;
cin>>speed;
}
void computedistance( )
15 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan
{
float dist;
dist = ( (Ahh * 60 + Amm) – (Dhh * 60 + Dmm) ) * speed/60;
dist = (dist * 1000 / (60 * 60);
cout<<”Distance Travelled = “<<dist<<”Meter/Second”;
}
};
void main( )
{
Distance d;
clrscr( );
d.inputtime( ):
d.computedistance( );
getch( );
}
**************
16 | P a g e
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan
Chapter-8
Introduction:
User defined function is a function defined by the user to solve his/her problem. Such a function
can be called from anywhere and any number of times in the program.
C++ implements polymorphism through function overloading and operator overloading.
Function overloading allows the user to create new abstract data type.
Function Overloading:
Function Overloading means two or more functions have same name, but differ in the number of
arguments or data types of arguments.
Function overloading is the process of defining same function name to carry out similar types of
activities with various data items.
2|Page
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan
Inline Function:
An Inline function is a special type of function whose body is inserted at the place where it is
called, instead of transferring the control to the function.
The keyword inline is used to define inline function.
Important
Rules:
5 Marks
o Inline function definition starts with keyword inline.
o The inline function should be defined before all function that call it.
o The compiler replaces the function call statement with the function code itself (expansion)
and then compiles the entire code.
The general format for the inline function declaration is given below:
inline Returntype Fun_Name ( [Argument] )
{
……….. ;
return expression ;
}
Program to find the cube of a number using inline function:
#include<iostream.h>
#include<conio.h>
inline int cube ( int a )
{
return a * a * a;
}
void main( )
{
int n ;
clrscr( ); OUTPUT:
cout<<”Enter the input number”<<endl;
cin>>n; Enter the input number
cout<<”Cube of “ <<n<<” = “<<cunbe(n); 4
getch(); Cube of 4 = 64
}
3|Page
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan
Note: The inline function may not work some times for one of the following reasons:
The inline function definition is too long or too complicated.
The inline function is recursive.
The inline function has looping constructs.
The inline function has a switch or goto.
Friend Function:
A friend function is a non-member function of a class has the access permission to the private
member of the class.
The friend function is declared within a class with the prefix friend.
But it should be defined outside the class like a normal function without the prefix friend.
The general format for the friend function is given below:
class class_name
Important
{
public:
5 Marks
friend return_type function_name ( [arguments] );
}
The friend functions have the following properties:
Friend function is not a member function of the class, has full access permission to private and
protected members of the class.
It can be declared either in public or private part of a class.
A friend function cannot be called using the object of that class. It can be invoked like any normal
function.
The function is declared with keyword friend. But while defining friend function it does not use
either keyword friend or : : operator.
They are normal external functions that are given special access privileges.
It cannot access the data member variables directly and has to use an object name.membername.
Use of friend function is rare, since it violates the rule of encapsulation and data hiding.
4|Page
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan
5|Page
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan
Important Questions
5 Marks Question:
6|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Chapter-9
CONSTRUCTORS AND DESTRUCTORS
Introduction:
It is sometimes convenient if an object can initialize itself when it is first created, without the need
to make a separate call to member functions.
Automatic initialization is carried out using special member functions called constructors.
Constructors:
A Constructor is a special member function that is called automatically when an object is
created.
The purpose of a constructor is to mainly initialize the member variables of a class.
The general syntax of a the constructor in C++ is:
In the above example class declaration, class Sum has a member function Sum( ) with the same
name of the class and which provides initial value to its data member s.
1|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
A class can have more than one constructor. However all constructor of a class should have the
same name.
It is not possible to refer to the address of the constructors.
The constructors make implicit calls to the operator new and delete when memory allocation is
required.
Example: Program to demonstrate how constructor is automatically executed at the time of
object creation.
#include<iostream.h>
#include<conio.h>
class Student
{
public:
Student( )
{
cout<<”Constructor called automatically”;
cout<<”at the time of object creation”<<endl;
}
};
void main( ) OUTPUT:
{ Constructor called automatically at the time of object creation
Student S1;
Constructor called automatically at the time of object creation
Student S2;
Student S3; Constructor called automatically at the time of object creation
}
Example: Program to demonstrate how a constructor is use to initialize data member of an
object.
#include<iostream.h>
#include<conio.h>
class Number
{
private:
int a;
public:
Number ( )
{
cout<<”I am in the Constructor”;
a = 100;
}
void display( )
{
cout<<”Value of a is =”<<a;
}
2|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
};
void main( ) OUTPUT:
{ I am in the Constructor
Number N;
Value of a is = 100 Important
N.display;
} 2 Marks
Need for a Constructor:
Constructors are named as constructors because they are getting called when an object is
constructed.
The use of a constructor can be cleverly done especially in those problems where it is necessary to
initialize certain data members compulsorily.
Instead of having separate member functions for initializing we can perform those operations
inside the constructor itself.
Example: A Program to find the sum of N natural numbers using a class constructor.
#include<iostream.h>
#include<conio.h>
class Sum
{
private:
int n, s;
public:
Sum ( )
{
s = 0;
}
void readdata( )
{
cout<<”Enter the input limit”<<endl;
cin>>n;
}
void display( )
{
for(int i =1; i<=n; i++)
s = s + i;
cout<<”Sum of Natural numbers =”<<s;
}
};
void main( ) OUTPUT:
{ Enter the input limit
Sum S1;
S1.readdata( ); 10
S1.display( ); Sum of Natural numbers = 55
}
3|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Types of constructor:
Constructors are normally classified as follows:
o Default Constructors. Important
o Parameterized Constructors 5 Marks
o Copy Constructors.
Default Constructors:
A default constructor is a special member function which is invoked by the C++ compiler
without any argument for initializing the object of a class.
It is also called as zero argument constructors.
Some of the features of the default constructors are:
o A default constructor function initializes the data member with no argument.
o It can be explicitly written in the public section of the class.
o In case, default constructor is not defined in a program, the C++ compiler automatically
generates it in a program.
o The purpose of the default constructor is to construct a default object of the class type.
The general format of default constructor is as follows:
Syntax Example
class Class_Name class Number
{ {
public: public:
Class_Name( ) Number( )
{ {
……. n = 0;
} }
}; };
Example: A program to display N natural numbers using a class default constructor.
#include<iostream.h>
#include<conio.h>
class Number
{
private:
int n;
public:
Number ( ) //Default Constructor with no arguments
{
n = 0;
}
void readdata( )
{
4|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Parameterized Constructors:
A constructor that takes one or more arguments is called parameterized constructor.
Using this constructor, it is possible to initialize different objects with different values.
Parameterized constructors are also invoked automatically, whenever objects with arguments are
created. The parameters are used to initialize the objects.
The keyword inline is used to define inline function.
The general format of parameterized constructor is as follows:
Syntax Example
class Class_Name class MAX
{ {
public: public:
Class_Name( argu1, argu2….) MAX(int a, int b )
{ {
……. if (a > b)
} big = a;
}; else
big = b;
}
};
5|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Invoking Constructors:
A Constructor is automatically invoked by C++ compiler with an object declaration. The
constructor can be invoked through the following methods.
o Implicit Call
Important
o Explicit Call
o Initialization at the time of declaration with “ = “ operator.
5 Marks
Implicit Call:
An Implicit call means the declaration of the object is followed by argument list enclosed in
parenthesis.
Example: Program to initialize the data members using implicit declaration
#include<iostream.h>
#include<conio.h>
class num
{
private:
int a, b;
public:
num ( int m, int n) //Parameterized Constructor
{
a = m;
b = n;
}
void display( )
{
cout<<” a = “ << a <<” b = “ << b;
}
};
void main( )
{ OUTPUT:
num obj1(10, 20); //Implicit Call a = 10 b = 20
num obj2(40, 50); //Implicit Call
obj1.display( ); a = 40 b = 50
obj2.display( );
}
6|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Explicit Call:
In explicit call, declaration of an object is followed by assignment operator, constructor name and
argument list enclosed in parenthesis.
Example: Program to initialize the data members using explicit declaration
#include<iostream.h>
#include<conio.h>
class num
{
private:
int a, b;
public:
num ( int m, int n) //Parameterized Constructor
{
a = m;
b = n;
}
void display( )
{
cout<<” a = “ << a <<” b = “ << b;
}
};
void main( )
{
num obj1 = num(10, 20); //Explicit Call OUTPUT:
num obj2 = num(40, 50); //Explicit Call
a = 10 b = 20
obj1.display( );
obj2.display( ); a = 40 b = 50
}
}
void display( )
{
cout<< a << endl ;
}
};
void main( )
{
num obj1 = 100
num obj2 = 200
cout<<”Object1 = “ ; OUTPUT:
obj1.display( );
Object1 = 100
cout<<”Object2 = “ ;
obj2.display( ); Object2 = 200
}
Copy Constructors:
Copy constructor is a parameterized constructor using one object can be copied to another
object.
Copy Constructors are used in the following situations:
o To initialize an object with the values of already existing objects.
o When objects must be returned as function values.
o To state objects as by value parameters of a function.
Copy Constructor can accept a single argument of reference to same class type. The argument
must be passed as a constant reference type.
The general format of copy constructor is as follows:
Syntax Example
class Class_Name class Number
{ {
public: public:
Number(int n)
Class_Name( Class_Name &ptr )
{ a = n; }
{ Number(Number & X)
……. {
} a = X.a;
}; cout<<”Copy Constructor invoked”;
}
};
Note that:
o Copy constructor is not invoked explicitly.
o Copy constructors are invoked automatically when a new object is created and equated to
an already existing object in the declaration statement itself.
8|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
9|Page
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Constructor Overloading:
A class has two or more constructor functions with the same name but different signatures are
called Constructors Overloading.
Depending upon the type of argument, the constructors will be invoked automatically by the
compiler to initialize the objects.
Example: Program to find simple interest using constructor overloading.
#include<iostream.h>
#include<conio.h>
class simpleinterset
{
private:
float p, r, t, si;
public:
simpleinterset( ) //Default constructor
{
}
simpleinterset(float x, float y, float z) //Parameterized Constructor
{
p = x;
r = y;
t = z;
}
void compute ( )
{
si = (p * t * r)/100;
cout<<”Simple Interest is = “<< si;
}
};
void main( )
{
OUTPUT:
simpleinterest S1, S2(10000.0, 12.0, 2.0);
S2.compute( ); Simple Interest is = 2400
}
Destructors:
A destructor is special member function that is executed when an object of that class is
destroyed.
Destroying an object means, de-allocating all the resources such as memory that was allocated for
the object by the constructor.
It will have like constructor, the name same as that of the class but preceded by a tilde (~).
The general format of destructor is as follows:
10 | P a g e
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
Syntax Example
class Class_Name class Counter
{ {
public: public:
Class_Name( ); Counter( ) //Constructor
~ Class_Name( ); {
}; n = 0;
}
~Counter ( ) //Destructor
{ }
};
11 | P a g e
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
} OUTPUT:
void main( )
{ In Constructor:
num a; Value of X = 100
a.display( ); In Destructor
}
Important Questions
5 Marks Question:
1. What is Constructor? Give the rules for writing a constructor function.
2. What is default constructor? Write a program to illustrate it.
3. Explain parameterized constructor with syntax and example.
4. Mention the different methods by which constructor are invoked. Explain anyone
with an illustrative example.
5. Explain the features of copy constructor.
6. Explain destructor with syntax and example.
7. Write a C++ program to find the sum of the series 1+X+X2+….+Xn using
constructor:
#include<iostream.h>
#include<conio.h>
class copy
{
private:
int x, n;
public:
int compute;
copy(int xx, int nn)
{
x = xx;
n = nn;
}
};
12 | P a g e
Chapter 9- Constructors and Destructors II PUC, MDRPUC, Hassan
*************
13 | P a g e
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
Chapter-10
INHERITANCE
Introduction:
Inheritance is another important aspect of object oriented programming.
C++ allows the user to create a new class (derived class) from an existing class (base class).
Inheritance:
Inheritance is the capability of one class to inherit properties from another class.
Base Class: It is the class whose properties are inherited by another class. It is also called Super
class.
Derived Class: It is the class that inherits the properties from base class. It is also called Sub
class.
Need of Inheritance:
Suppose X is a class already defined and we need to redefine another class Y has same properties
of X and in addition its own.
Suppose if we use direct option without using inheritance, it has following problems.
o Code written in X is repeated again in Y which leads to unnecessary wastage of memory.
o Testing to be done separately for both class X and class Y leads to waste of time.
The above problem can be solved by using the concept of inheritance.
If we use the code of X even in Y without rewriting it. The class Y inherits all the properties of X.
The class X is called base class and the class Y is called derived class.
The main advantages of Inheritance are:
o Reusing existing code
o Faster development time
o Easy to maintain
o Easy to extend
o Memory Utilization
The main disadvantage of Inheritance are:
o Inappropriate use of inheritance makes programs more complicated.
o Calling member functions using objects creates more compiler overheads.
1|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
Visibility mode:
Visibility mode can be public, private or protected. The private data of base class cannot be
inherited.
o public: If inheritance is done in public mode, public members of the base class become
the public member of derived class and protected member of base class become the
protected member of derived class..
2|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
o private: If inheritance is done in a private mode, public and protected members of base
class become the private members of derived class.
o protected: If inheritance is done in a protected mode, public and protected members of
base class become the protected members of the base class.
Derived Class
Visibility Mode public private protected
public public private protected
Base class private Not inherited Not inherited Not inherited
protected protected private protected
Public Inheritance:
When a base class is inherited as public, all public members of the base class become public
members of derived class.
The private members of the base class remain private to that class, and are nor accessible by
members of the derived class.
Example: A program illustrates public inheritance.
#include<iostream.h> Important
#include<conio.h> 5 Marks
class shape //Base Class
{
public:
int side1, side2;
};
class rectangle : public shape //Derived Class
{
public:
int area;
void compute( )
{
area = side1 * side2;
}
};
void main( )
{
rectangle R; // R is the object of derived class
R.side1 = 5; // Data directly accessed by object
R.side2 = 6;
OUTPUT:
R.compute( );
cout<< “Area of the rectangle = “ <<R.area; Area of the rectangle = 30
}
3|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
Private Inheritance:
When a base class is inherited as private, then all public and protected members of the base class
become private members of derived class.
This means that they are still accessible by member of the derived class, but cannot be accessed by
other parts of the program.
Example: A program illustrates private inheritance.
#include<iostream.h>
#include<conio.h>
class shape //Base Class
{
protected:
int side1, side2;
public:
int area;
void compute( )
{
area = side1 * side2;
}
};
class rectangle : private shape //Derived Class
{
public:
void readdata( )
{
cout << “ Enter the input first side :”;
cin>>side1;
cout << “ Enter the input second side :”;
cin>>side2;
}
void display( )
{
compute( ); // Calling base class
cout<< “Area of the rectangle = “ <<area;
}
};
void main( )
{ OUTPUT:
rectangle R; Enter the input first side : 9
R.readdata( ); Enter the input second side : 5
R.display( );
Area of the rectangle = 45
}
4|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
Protected Inheritance:
When a base class is inherited as protected, then all public and protected members of the base class
become protected members of derived class.
The private data members of base class are not visible to derived class.
They can only be accessed through public and protected member functions of base class.
Example: A program illustrates protected inheritance with the base class having protected and
public members.
#include<iostream.h>
#include<conio.h>
class shape //Base Class
{
protected:
int side1, side2;
public:
int compute( )
{
return(side1 * side2);
}
};
class rectangle : protected shape //Derived Class
{
public:
void readdata( )
{
cout << “ Enter the input first side :”;
cin>>side1;
cout << “ Enter the input second side :”;
cin>>side2;
}
void display( )
{
cout<< “Area of the rectangle = “ <<compute( );
}
}; OUTPUT:
void main( )
Enter the input first side : 7
{
rectangle R; Enter the input second side : 8
R.readdata( ); Area of the rectangle = 56
R.display( );
}
5|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
Types of Inheritance:
Based on the relationship, inheritance can be classified into five forms:
o Single Inheritance
o Multilevel Inheritance
Important
o Multiple Inheritance
5 Marks
o Hierarchical Inheritance
o Hybrid Inheritance
Single Inheritance:
Single Inheritance is the process of creating a new class from existing class base class.
It is very coomon in inheritance that a class is derived from the base class.
The data members and memberfunction of the base class are data member and member function
of the derived class.
{
cout << “ Enter Roll Number and Name “<<endl;
cin >> rollno >> name;
}
void display( )
{
cout << “ Roll No : “ << rollno <<endl;
cout << “ Name : “ << name <<endl;
}
};
class derived : public base
{
private:
int m1, m2, t;
public:
void read1( )
{
cout << “ Enter Maths and Computer marks “<<endl;
cin >> m1 >> m2;
t = m1 + m2;
}
void display1( )
{
cout << “ Maths : “ << m1 <<endl;
cout << “ Computer : “ << m2 <<endl;
cout << “Total Marks : “ << t <<endl;
}
};
OUTPUT:
void main( ) Enter Roll Number and Name
{ 1234 RAM
derived obj; Enter Maths and Computer marks
clrscr( ); 80 90
obj.read( ); Roll No : 1234
obj.read1( ); Name : RAM
obj.display( ); Maths : 80
obj.display1( ); Computer : 90
getch( ); Total Marks : 170
}
Multilevel Inheritance:
Derivation of a class from another derived class is called multilevel inheritance.
In the figure class A is the base class for class AB and class AB is the base class for class ABC.
The class AB provides a link for the inheritance between A and ABC, and is known as
7|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
8|Page
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
void displayAB( )
{
cout << “ Intermediate Base class AB”<<endl;
cout << “ Derived from A” << endl;
}
};
class ABC : public AB
{
public:
void displayABC( )
{
cout << “ Derived Class ABC”<<endl;
cout << “ Derived from AB” << endl;
}
void output( )
{
displayA( );
displayAB( );
displayABC( );
OUTPUT:
};
void main( ) Base Class A
{ Intermediate Base Class AB
ABC obj; Derived from A
clrscr( ); Derived Class ABC
obj.output( ); Derived from AB
getch( );
}
Multiple Inheritance:
A class can be derived from more than one base calss is known as multiple inheritance.
Hierarchical Inheritance:
If a number of classes are derived from a single base class, it is called as hierarchical
inheritance.
Hierarchical model exhibits top down approach by breaking up a complex class into simpler class.
Hybrid Inheritance:
Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.
10 | P a g e
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
Abstract Class:
An abstract class is one that is not used to create objects.
An abstract class is designed only to act as a base class (to be inherited by other classes).
Destroying an object means, de-allocating all the resources such as memory that was allocated for
the object by the constructor.
It will have like constructor, the name same as that of the class but preceded by a tilde (~).
Example: Program to illustrate the use of destructors in C++.
class Base
{
public:
Base( ); //Default constructor
{
cout<<”Inside Base Constructor”<<endl;
}
~ Base( ); //Destructor
{
cout<<”Inside Base Destructor”<<endl;
}
};
class Derived : public Base
{
public:
Derived( ); //Default constructor
{
cout<<”Inside Derived Constructor”<<endl;
}
~ Derived( ); //Destructor
{
cout<<”Inside Derived Destructor”<<endl;
}
}; OUTPUT:
void main( )
Inside Base Constructor
{
Derived x; Inside Derived Constructor
a.display( ); Inside Derived Destructor
} Inside Base Destructor
Important Questions
12 | P a g e
Chapter 10- Inheritance II PUC, MDRPUC, Hassan
5 Marks Question:
1. What is Inheritance? Explain any two types of Inheritance.
2. What are visibility modes? Explain.
3. What is the difference between public, private and protected access specifiers?
4. Explain single inheritance with a suitable C++ program.
5. What is Multilevel Inheritance? Explain with a suitable program example.
6. What is virtual base class? Give example.
7. What are the advantages of Inheritance? (Any five)
****************
13 | P a g e
Chapter 11- Pointers II PUC, MDRPUC, Hassan
Chapter-11
POINTERS
Introduction:
Pointers are a powerful concept in C++ and have the following advantages.
i. It is possible to write efficient programs.
ii. Memory is utilized properly.
iii. Dynamically allocate and de-allocate memory.
Pointer:
A pointer is a variable that holds a memory address of another variable.
The pointer has the following advantages.
o Pointers save memory space.
o Dynamically allocate and de-allocate memory.
Important
o Easy to deal with hardware components.
3 Marks
o Establishes communication between program and data.
o Pointers are used for file handling.
o Pointers are used to create complex data structures such as linked list, stacks, queues trees
and graphs.
Pointer Declaration:
Pointers are also variables and hence, they must be defined in a program like any other variable.
The general syntax of pointer declaration is given below.
Syntax: Data_Type *Ptr_Variablename;
Where,
o Data_Type is any valid data type supported by C++ or any user defined type.
o Ptr_Variablename is the name of the pointer variable. The presence of ‘*’ indicates that it
is a pointer variable.
Defining pointer variables:
o int *iptr; iptr is declared to be a pointer variable of int type.
o float *fptr; fptr is declared to be a pointer variable of float type.
o char *cptr; cptr is declared to be a pointer variable of character type.
Pointer Initialization:
Once we declare a pointer variable, we must make it to point to something.
We can do this by assigning or initializing to the pointer the address of the variable you want to
point to as in: iptr = #
The „&’ is the address operator and it represents address of the variable.
Example: A program to display the content of num and the address of the variable num using a
pointer variable.
#include<iostream.h>
void main( )
{
int num; // normal integer variable
int *iptr; // Pointer declaration, pointing to integer data
var”.
Example:
int num = 25;
int *iptr;
iptr = # //The address of operator &
num = 300;
iptr = & num;
val = *iptr; OUTPUT:
}
Pointer Arithmetic:
We can perform arithmetic operations on a pointer just as you can a numeric value.
There are four arithmetic operators that can be used on pointers:
o Increment ++
o Decrement --
o Addition +
o Subtraction -
Example:
int num, *iptr; iptr 1200 9
num = 9; 1201
iptr = # iptr++ 1202
iptr++; 1203
cout<<iptr;
The following operation can be performed on pointers.
o We can add integer value to a pointer.
o We can subtract an integer value from a pointer.
o We can compare two pointers, if they point the elements of the same array.
o We can subtract one pointer from another pointer if both point to the same array.
o We can assign one pointer to another pointer provided both are of same type.
The following operations cannot be performed on pointers.
o Addition of two pointers.
o Subtraction of one pointer from another pointer when they do not point to the same array.
o Multiplication of two pointers.
o Division of two pointers.
A program to illustrate the pointer expression and pointer arithmetic.
#include<iostream.h>
#include<conio.h>
void main( )
{ OUTPUT:
int a, b, x, y; Address of a = 65524
int *ptr1, *ptr2; Address of b = 65522
a = 30;
b = 6; a = 30 b=6
ptr1 = &a x = 30 y=6
ptr2 = &b; a = 100 b = 12
x = *ptr1 + *ptr2 – 6;
y = 6 - *ptr1 / *ptr2 + 30;
cout<<”Address of a = “<<ptr1<<endl;
cout<<”Address of b = “<<ptr2<<endl;
cout<<”a = “<<a<<”b = “<<b<<endl;
cout<<”x = “<<x<<”y = “<<y<<endl;
int a[10], i, n;
cout<<”Enter the input for array”;
cin>>n;
cout<<”Enter array elements:”; OUTPUT:
for(i=0; i<n; i++)
Enter the input for array 5
cin>>*(a+i);
cout<<The given array elements are :”; Enter array elements
for(i=0; i<n; i++) 1 2 3 4 5
cout<<”\t”<<*(a+i);
The given array elements are :
getch( );
} 1 2 3 4 5
Array of Pointers:
There is an array of integers; array of float, similarly there can be an array of pointers.
“An array of pointer means that it is a collection of address”.
The general form of array of pointers declaration is:
int *pint[5];
The above statement declares an array of 5 pointers where each of the pointer to integer variable.
Example: Program to illustrate the array of pointers of isolated variables.
#include<iostream.h>
#include<conio.h>
void main( )
{
int *pint[5];
OUTPUT:
int a = 10, b = 20, c = 30, d=40, e=50;
pint[0] = &a; Value 10 stored at 17500
pint[1] = &b; Value 20 stored at 17502
pint[2] = &c; Value 30 stored at 17504
pint[3] = &d;
Value 40 stored at 17506
pint[4] = &e;
Value 50 stored at 17508
for( int i=0; i<=4; i++)
cout<<”Value “ << *pint[i]<< “stored at “<<pint[i]<<endl;
}
void main()
{
void swap(int *m, int *n);
int a = 5, b = 6;
cout << “\n Value of a :” << a << “ and b :” << b;
swap(&a, &b);
cout << “\n After swapping value of a :” << a << “and b :” << b;
}
void swap(int *m, int *n)
{
int temp; OUTPUT:
temp = *m; Value of a : 5 and b : 6
*m = *n;
After swapping value of a : 6 and b : 5
*n = temp;
}
Memory Allocation of pointers:
Memory Allocation is done in two ways:
Important
o Static Allocation of memory
3 Marks
o Dynamic allocation of memory.
new operator:
We can allocate storage for a variable while program is running by using new operator.
It is used to allocate memory without having to define variables and then make pointers point to
them.
9|Page Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan
The following code demonstrates how to allocate memory for different variables.
To allocate memory type integer
int *pnumber;
pnumber = new int;
The first line declares the pointer, pnumber. The second line then allocates memory for an integer
and then makes pnumber point to this new memory.
To allocate memory for array, double *dptr = new double[25];
To allocates dynamic structure variables or objects, student sp = new student;
delete Operator:
The delete operator is used to destroy the variables space which has been created by using the
new operator dynamically.
Use delete operator to free dynamic memory as : delete iptr;
To free dynamic array memory: delete [] dptr;
To free dynamic structure, delete structure;
Memory Leak:
If the objects, that are allocated memory dynamically, are not deleted using delete, the memory
block remains occupied even at the end of the program.
Such memory blocks are known as orphaned memory blocks.
These orphaned memory blocks when increases in number, bring adverse effect on the system.
This situation is called memory leak.
10 | P a g e Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan
cout<<”Employee Number:”<<empno;
cout<<”Employee Name:”<<name;
cout<<”Employee Salary:”<<salary;
}
};
void main( )
{
employee e, * ep;
ep = &e;
clrscr( );
ep read( );
ep display ( );
getch( );
}
Here, employee is an already defined class. When accessing members of the class an object
pointer, the arrow operator () is used instead of dot (.) operator.
this pointers:
Every object in C++ has access to its own address through an important pointer called this
pointer.
The “this pointer” is an implicit parameter to all member functions.
Therefore, inside a member function, this may be used to refer to the invoking object.
Program 12: Create a class containing the following data members Register_No, Name and
Fees. Also create a member function to read and display the data using the concept of pointers to
objects.
#include<iostream.h>
#include<conio.h>
class Student
{
private:
long regno;
char name[20];
float fees;
public:
void readdata( );
void display( );
};
void Student::readdata( )
{
cout<<"Enter the Register Number:"<<endl;
cin>>regno;
12 | P a g e Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan
Important Questions
1 Marks Question:
1. Define pointer. [June 2016]
2. Write the declaration syntax for a pointer. [March 2015]
3. How do we initialize a pointer? [March 2016]
4. Write any one advantage of pointers. [June 2015, March 2017]
5. What is the purpose of new operator in C++? [June 2017]
6. What is a pointer variable?
13 | P a g e Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan
3 Marks Question:
1. What are the advantages of pointers? [June 2016]
2. What are the operations performed on pointers? [March 2015, June 2017]
3. What is array of pointer? Give example. [June 2015]
4. Explain the new and delete operator in pointers. [March 2016]
5. Define: [March 2017]
a. Pointer.
b. Static memory allocation.
c. Dynamic memory allocation
6. What is the relationship between pointers and arrays?
7. Explain with example call by reference.
8. Distinguish between static and dynamic memory allocation.
9. What is the relationship between pointers and objects? Give an example
10. Explain the use of “this pointer”.
****************
14 | P a g e Keerthi Kumar H M
Chapter 12- Data File Handling II PUC, MDRPUC, Hassan
Chapter-12
DATA FILE HANDLING
Introduction:
A file is a collection of related data stored in a particular area on the disk.
Programs can be designed to perform the read and write operations on these files.
In general a file is a sequence of bits, bytes, lines or records whose meaning is defined by its user.
C++ I/O occurs in streams, which are sequence of bytes.
If bytes flows from device like a keyboard, a disk drive, etc to main memory, this is called input
operation.
If bytes flow from main memory to devices like a display screen, a printer etc. this is called output
operation.
In C++, file input/output facilities are implemented through a header file fstream.h.
Stream in C++:
A stream is sequence of bytes. In C++, a stream is a general name given to flow of data.
Different streams are used to represent different kinds of data flow.
The three streams in C++ are as follows.
o Input Stream: The stream that supplies data to the program is known as input stream.
o Output Stream: The stream that receives data from the program is known as output
stream.
o Error Stream: Error streams basically an output stream used by the programs to the file or
on the monitor to report error messages.
Class Meanings
Text Files:
o A text file is a file that stores the information in ASCII characters.
o Each line of text is terminated by a special character, known as End of Line (EOL) or delimiter.
Binary Files:
o A binary file is a file that contains information in the same format as it is held in memory.
o In binary files, no delimiters are used for a line and no translations occur here.
The syntax of opening a file for output purpose only using an object ofstream class and open( )
member function is as follows:
oftream_object.open(“file name”);
Example: ofstream outfile;
outfile.open (“data”);
outfile.open (“text.dat”);
The syntax of opening a file for input purpose only using an object ifstream class and open( )
member function is as follows:
iftream_object.open(“file name”);
Example: ifstream ifile;
ifile.open (“data”);
To open a file for both input and output, we declare objects of fstream class. We know that the
class fstream is derived from both ifstream and ofstream,
The syntax for opening a file an object of type fstream class and the constructor is as follows:
fstream fstream-object(“file name’, mode);
The syntax for opening a file an object of type fstream class and the open( ) member function is as
follows:
fstream-object.open(“file name’, mode); Important
3 Marks
File Modes:
While using constructors or open( ), the files were created or opened in the default mode.
There was only one argument passed, i.e. the filename.
C++ provides a mechanism of opening a file in different modes in which case the second
parameter must be explicitly passed.
Syntax: stream_object.open(“filename”, mode);
Example: fout.open(“data”, ios::app) // This opens the file data in the append mode.
The lists of file modes are:
Example:
fstreamfout (“text”, ios::out); // open text in output mode
fstream fin(“text”, ios::in); // open text in input mode
fout.open(“data”, ios::app) // This opens the file data in the append mode
fout.open(“data”, ios::app | ios::nocreate)
// This opens the file in the append mode but fails to open if it does not exist
Closing File:
The member function close( ) on its execution removes the linkage between the file and the stream
object.
Syntax: stream_object.close( );
Example: ofstream.close( );
ifstream.close( );
get( ):
The get( ) member function belong to the class ifstream and reads a single character from the
associated stream.
getline( ):
It is used to read a whole line of text. It belongs to the class ifstream.
Syntax: fin.getline(buffer, SIZE)
It reads SIZE characters from the file represented by the object fin or till the new line character is
encountered, whichever comes first into the buffer.
Example:
char book[SIZE];
ifstream fin;
fin.getline (book, SIZE);
write ( ):
The write ( ) member function belongs to the class ofstream and which is used to write binary data
to a file.
Syntax: ofstream_object.write((char *) & variable, sizeof(variable));
These functions take 2 arguments. The first is the address of the variable and second the size of the
variable in bytes. The address of the variable must be type casted to pointer to character.
Example: student s;
ofstream fout(“std.dat”, ios::binary);
fout.write((char *) &s, sizeof(s));
read ( ):
The read ( ) member function belongs to the class ifstream and which is used to read binary data
from a file.
Syntax: ifstream_object.read((char *) & variable, sizeof(variable));
These functions take 2 arguments. The first is the address of the variable and second the size of the
variable in bytes. The address of the variable must be type casted to pointer to character.
Example: student s;
ifstream fin(“std.dat”, ios::binary)
fin.write((char *) &s, sizeof(s));
When we open a file in read only mode, the input pointer is automatically set at the beginning so
that we read the file from the beginning.
When we open a file in write only mode, the existing contents are deleted and output pointer is set
at the beginning
If we want to open an existing file to add more data, the file is opened in append mode. This
moves the file pointer to the end of the file.
seekg( ):
Move the get pointer to a specified location from the beginning of a file.
There are two types:
o seekg(long);
o seekg(offset, seekdir);
The seekg(long) moves the get pointer to a specified location from the beginning of a file.
8|Page Keerthi Kumar H M
Chapter 12- Data File Handling II PUC, MDRPUC, Hassan
Example: inf.seekg(20);
Constant Meaning
ios::beg seek from beginning of file
ios::cur seek from current location
ios::end seek from end of file
seekp ( ):
Move the put pointer to a specified location from the beginning of a file.
There are two types:
o seekp(long);
o seekp(offset, seekdir);
The seekp(long) moves the put pointer to a specified location from the beginning of a file.
Example: inf.seekp(20);
object.seekp(m, ios::beg) Move forward by m bytes from the beginning for writing
object.seekp(-m, ios::end) Go backward by m bytes from the end for writing
Important Questions
2 Marks Question:
1. Differentiate between ifstream and ofstream. [March 2015]
2. What is a stream? Mention any one stream used in C++. [June 2015]
3. Write any two member functions belonging to of stream class. [March 2016]
4. Write any two member functions belonging to if stream class. [June 2016]
5. Differentiate between read( ) and write( ). [March 2017]
6. Differentiate between put( ) and get( ) functions with reference to binary files. [June 2017]
10 | P a g e Keerthi Kumar H M
Chapter 12- Data File Handling II PUC, MDRPUC, Hassan
3 Marks Question:
1. Give the function of put( ), get( ) and getline( ) with respect to text files. [March 2015]
2. List the fifferent modes of opening a file with their meaning in C++. [June 2015]
3. Give the functions for the following: [March 2016]
a. get( ) b. getline( ) c. read( )
4. Mention the types of data files. Explain. [June 2016]
5. Explain any three modes of to open a file in C++. [March 2017]
6. Write the member function belong to ifstream. [June 2017]
****************
11 | P a g e Keerthi Kumar H M
Chapter 13- Database Concepts II PUC, MDRPUC, Hassan
Chapter-13
DATABASE CONCEPTS
One Mark Questions:
1. What is data?
Data is a collection of facts, numbers, letters or symbols that the computer process into
meaningful information.
2. What is Information?
Information is processed data, stored, or transmitted by a computer.
3. What is Database?
A Database is a collection of logically related data organized in a way that data can be easily
accessed, managed and updated.
4. What is a field?
Each column is identified by a distinct header called attribute or filed.
5. What is a record?
A single entry in a table is called a record or row. A record in a table represents set of related
data.
Records are also called the tuple.
6. What is an entity?
An Entity can be any object, place, person or class.
In E-R Diagram, an entity is represented using rectangles.
7. What is an instance?
The collection of information stored in the database at a particular moment is called an
instance of the database.
8. What is an attribute?
It is defined as a named column of a relation.
Ex: In STUDENT table, Regno, Name, Age, Class, Combination and Marks.
9. What is domain?
It is defined as a set of allowed values for one or more attributes.
10. What is a relation?
A relation is defined as a table with columns and rows. Data can be stored in the form of a two-
dimensional table.
System Analysts
o System analysts determine the requirement of end users; (especially naïve users), to create
a solution for their business need and focus on non-technical and technical aspects.
Application programmers
o These are the computer professionals who implement the specifications given by the
system analysts and develop the application programs.
Database Administrators (DBA)
o DBA is a person who has central control over both data and application.
o Some of the responsibilities of DBA are authorization access, schema definition and
modification, new software installation and security enforcement and administration.
5. What is the difference between serial and direct access file organization.
Serial File Organization:
Organization is continuous and simple.
Data processing, which requires the use of all records, is best suited to use this method.
Direct Access File Organization
Alternate Key
The alternate key of any table are those candidate keys which are not currently selected as the
primary key.
This is also known as secondary key.
Foreign key
A key used to link two tables together is called a foreign key.
This is sometimes called a referencing key.
Foreign key is a field that matches the primary key column of another table.
The above example describes that one student can enroll only for one course and a course
will also have only one Student. This is not what you will usually see in relationship.
2. One to Many:
It reflects business rule that one entity is associated with many number of same entity.
For example, Student enrolls for only one Course but a Course can have many Students.
The arrows in the diagram describes that one student can enroll for only one course.
3. Many to Many:
The above diagram represents that many students can enroll for more than one course.
Reg_No Combination
101 PCMB
140 PCMC
110 CEBA
121 PCMB
18. What is Data warehouse?
A data ware house is a repository of an organization's electronically stored data.
Data warehouse are designed to facilitate reporting and supporting data analysis.
The concept of data warehouses was introduced in late 1980's.
Data storage: Data and information should be stored in memory so that it can be accessed
later.
Output: The result obtained after
processing the data must be presented
to the user in user understandable
form. The output can be generated in
the form of report as hard copy or soft
copy.
Communication: Computers now-a-
days have communication ability
which increases their power. With
wired or wireless communication connections, data may be input from a far place, processed in
a remote area and stored in several different places and then transmitted by modem as an e-
mail or posted to the website where the online services are rendered.
Physical Level:
o It is the lowest level of abstraction that
describes how the data are actually stored.
o The physical level describes complex low-
level data structures in detail.
o It contains the definition of stored record and
method of representing the data fields and
access aid used.
Conceptual Level:
o It is the next higher level of abstraction that
describes what data are stored in the database and what relationships exist among those
data.
o It also contains the method of deriving the objects in the conceptual view from the objects
in the internal view.
View Level:
o It is the highest level of abstraction that describes only part of the entire database.
o It also contains the method of deriving the objects in the external view from the objects in
the conceptual view.
11 | P a g e Keerthi Kumar H M
Chapter 13- Database Concepts II PUC, MDRPUC, Hassan
12 | P a g e Keerthi Kumar H M
Chapter 13- Database Concepts II PUC, MDRPUC, Hassan
13 | P a g e Keerthi Kumar H M
Chapter 13- Database Concepts II PUC, MDRPUC, Hassan
Important Questions
One Marks Questions:
1. Define Primary key [March 2015]
2. What is a database? [June 2015, June 2016]
3. Define Data Mining. [March 2016]
4. Define an Entity. [March 2017, June 2017]
14 | P a g e Keerthi Kumar H M
Chapter 13- Database Concepts II PUC, MDRPUC, Hassan
Extra Questions:
7. What is normalization? Explain second normal form with an example.
8. What is database model? Explain Hierarchical model.
9. Define any 5 Codd’s rule.
10. Explain 3-level DBMS architecture.
****************
15 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Chapter-15
NETWORKING CONCEPTS
Introduction:
A computer network is a interconnection of two or more computers that are able to exchange
information’s.
Two computers are said to be inter connected if they are capable of exchanging information.
Need of Networking:
File sharing provides sharing and grouping of data files over the network.
Printing sharing of computer resources such as hard disk and printers etc.
E-mail tools for communication with the e-mail address.
Remote access able to access data and information around the globe.
Sharing the database to multiple users at the same time by ensuring the integrity.
Evolution of Networking:
In 1969 U.S. Department of Defense sponsored a project named ARPANET (Advanced
Research Projects Agency Network).
The goal of the project was to connect various universities and US Defense.
In mid 80’s National Science Foundation created a new high capacity network called NSFnet,
which was more powerful than ARPANET.
In 1990 the Internet came into picture.
Internet:
The internet is worldwide network of computer network evolved from the first network
ARPANET.
Internet is an interconnection of large and small networks around the globe.
The common use of internet standards allows users connected to one network to communicate
with users on another network.
Interspace:
Interspace is a client/server software program that allows multiple users to communicate
online with real-time audio, video and text chat in dynamic 3D environments.
Interspace provides the most advanced form of communication available on the Internet
today.
Dedicated Servers:
On bigger network installations, there is a computer reserved for server's job and its only job
is to help workstations access data, software and hardware resources.
It does not double-up as a workstation and such a server is known as dedicated server.
The networks using such a server are known as MASTER-SLAVE networks.
On a network, there may be several servers that allow workstations to share specific
resources. For example, file server, printer server and modem server.
4. MAC address:
The MAC address refers to the physical address assigned by NIC manufacturer.
TCP/IP Model:
The TCP/IP model uses four layers to perform the functions of the seven-layer OSI model.
1. Layer 1 – Network Access Layer:
The lowest layer of the TCP/IP protocol hierarchy.
It defines how to use the network to transmit an IP data.
It encompasses the functions of physical and data link layer of OSI reference model.
2. Layer 2 – Internet Layer:
Provides services that equivalent to OSI network layer.
The primary concern of the protocol at this layer is to manage the connections across
Network Protocol:
A protocol is a set of rules and procedures that determine how a computer system receives and
transmits data.
TCP/IP Protocol:
o Transmission Control Protocol / Internet Protocol.
o It is the basic communication language or protocol of the Internet.
o TCP/IP is a two-layer program, the higher layer Transmission Control Protocol (TCP)
manages the assembling of a message or file into smaller packets that are transmitted over the
internet.
o The lower layer Internet Protocol (IP) handles the address part of each packet so that it gets
to the right destination.
HTTP Protocol:
o Hypertext Transfer Protocol.
o It provides a standard for web browsers and servers to communicate.
o The HTTP is an application layer network protocol built on top of TCP.
o HTTP clients (web browsers) and servers communicate via HHTP request and response
messages.
FTP Protocol:
o File Transfer Protocol.
o It is a standard Internet Protocol for transmitting files between computers on the internet.
o FTP is an application protocol that uses the Internet’s TCP/IP protocols.
o It is also commonly used to download programs and other files to your computer from other
servers.
SMTP Protocol:
o Simple Mail Transfer Protocol.
o It is a TCP/IP protocol used in sending and receiving e-mail.
o It is limited in its ability to queue messages at the receiving end; it is usually used with one of
two other protocols such as POP3 or IMAP.
SLIP:
o Serial Line Internet Protocol was the first protocol for relaying the IP packets over dial-up
lines.
o It defines an encapsulation mechanism, but little else.
o There is no support for dynamic address assignment, link testing or multiplexing different
protocols over a single link.
PPP:
o Point to Point Protocol is the standard for transmission of IP packets over serial lines.
o The PPP is currently the best solution for dial-up internet connections, including ISDN.
o PPP is a layered protocol, starting with a link control protocol (LCP) for link establishment,
configuration and testing.
o PPP supports both synchronized and unsynchronized lines.
Types of network:
A computer network means a group of networked components, i.e., computers are linked by
means of a communication system.
There are three types of network.
o Local Area Network (LAN)
o Wide Area Network (WAN)
o Metropolitan Area Network (MAN)
Local Area Network:
Privately owned small networks that are confined to a localized area (e.g., an office, a building
or a factory) are known as Local Area Networks (LANs).
The key purpose of a LAN is to serve its users in resource sharing.
6|Page Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Network Topologies
Network Topology refers to the arrangement of computers and other devices in a network.
Need for Topologies are: Cost, Flexibility, and Reliability.
Network topologies can be classified as follows:
1. Bus Topology
2. Star Topology
3. Ring Topology
4. Mesh Topology
5. Hybrid Topology
Star Topology
In this type of topology, all the computers are connected to a single
hub or a switch through a cable. This hub is the central node and all
others nodes are connected to the central node.
Advantages of a Star Topology
o Easy to install and wire.
o No disruptions to the network when connecting or removing
devices.
8|Page Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Ring topology
In a ring topology, all computers are connected via cable that loops in a ring or circle.
A ring topology is a circle that has no start and no end.
Each node connected to two neighboring computers.
Data accepted from one node transmitted to another.
Data travels in one direction, from the node to node around the ring.
Signal amplified at each node before being passed.
Advantages of Ring Topology
o Short cable length
o No wiring closet space required
o Suitable for optical fibers.
o Each client has equal access to resources.
Disadvantages
o Node failure causes network failure
o Difficult to diagnose faults
o Network reconfiguration is difficult
Tree Topology:
A tree topology combines characteristics of linear bus and star topologies.
It consists of groups of star-configured workstations connected to a linear bus backbone cable.
The tree network topology uses two or more star networks
connected together.
The central computers of the star networks are connected to
a main bus. Thus, a tree network is a bus network of star
networks.
Best suited for applications having hierarchical flow of data
and control.
Advantages of a Tree Topology
o Point-to-Point wiring for individual segments.
9|Page Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Mesh Topology:
In this topology each node is connected to two or more than two
nodes.
It is a point-to-point connection to other nodes or devices.
Traffic is carried only between two devices or nodes to which it
is connected.
This topology is robust, provides security and privacy.
Overall cost of this network is too high.
Transmission Medium:
The first layer of computer networks is dedicated to the transmission media.
Due to variety of transmission media and network writing methods, selecting the most
appropriate media can be confusing.
The factors to be considered are:
o Transmission rate, Distance, cost, easy of installation and resistance to environmental
condition.
There are two type of transmission media:
a. Guided b. Unguided
Guided media are:
o Twisted Pair: Unshielded Twisted Pair (UTP), Shielded Twisted pair (STP)
o Co-axial cable: Thinnet, Thicknet
10 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
UTP is the copper media inherited from telephone, which is being used for increasingly higher
data rates.
A UPT cable contains 2 to 4200 twisted pair.
UTP is flexible, low cost media; it can be sued for voice or data communication.
It is available in the following five categories:
1. CAT1: Voice-Grade communications only; No data
transmission
2. CAT2: Data-grade transmission up to 4 Mbps
3. CAT3: Data-Grade transmission up to 10 Mbps
4. CAT4: Data-grade transmission up to 16 Mbps
5. CAT5: Data-grade transmission up to 1000 Mbps
The UTP cables can have a maximum segment length of 100 meters.
11 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
12 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Optical Fibers
Optical Fibers consist of thin strands of glass or glass like
material which are so constructed that they carry light from a
source at one end of the fiber to a detector at the other end.
The light sources used are either light emitting diodes (LEDs)
or LASER Diodes (LDs).
It transmits light rather than electronic signals eliminating the
problem of electrical interference.
OFC has ability to transmit signals over much longer distances than coaxial cable and twisted pair.
The bandwidth of the medium is potentially very high. For LEDs, this range is between 20-150
Mbps and higher rates are possible using LDs.
It also capacity to carry information at vastly greater speed.
Advantages Disadvantages
Transmit data over long distance with Difficult to install
high security. Expensive as compared to other guided
Data transmission is high. media
Provide better noise immunity. Difficult to repair.
Bandwidth is up to 100 Gbps
Radio Wave
The transmission making use of radio frequencies is termed as radio-wave transmission.
Any radio setup has two parts:
a. The transmitter b. The receiver
The transmitter takes some sort of message, encodes it onto a sine wave and transmits it with radio
wave.
The receiver receives the radio wave and decodes the message from the sine wave it receives.
13 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Both the transmitter and receiver use antennas to radiate and capture the radio signals.
Advantages Disadvantages
Provide mobility It is an insecure communication.
Inexpensive. Susceptible to weather effects like rains,
It proves cheaper than digging trenches for thunder storms etc
laying cables.
Free from land acquisition rights.
Microwave:
Microwave transmission is line of sight transmission.
The transmit station must be in visible contact with
the receive station.
This sets a limit on the distance between stations
depending on the local geography.
Microwave operates at high operating frequencies of 3 to 10 GHz.
This allows carrying large quantities of data due to their large bandwidth.
Advantages Disadvantages
Maintenance easy than cables. Repeaters are required for long distance
Suitable when cable cannot be used. communication.
Free from land acquisition rights. Less Bandwidth available.
Low cost land purchase ( Tower occupies Reflected from flat surfaces like water and
small area) metals.
Satellite communication:
A satellite consists of transponders (unit that receive on one frequency and retransmit on another)
that are set in geostationary orbits directly over the equator.
Satellite communication is special case of microwave relay system.
These geostationary orbits are 22,000 - 36,000
Km from the Earth’s surface.
The uplink is the transmitter of data to the
satellite.
The downlink is the receiver of data.
14 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Uplinks and downlinks are also called Earth stations because they are located on the Earth.
Advantages Disadvantages
The area coverage through satellite Very expensive
transmission is large. Installation is complex.
No line of sight restrictions. Signals sent to the stations can be tampered
Earth station which receives the signals by external interference.
Apart from microwaves, radio waves and satellites, two other unguided media are also very popular.
These are infrared and laser waves.
Infrared:
This type of transmission uses infrared light to send data.
You can see the use of this type of transmission in everyday life - TV remotes, automotive garage
doors, wireless speakers etc., all make use of infrared as transmission media.
The infrared light transmits data through the air and can propagate throughout a room (bouncing
off surfaces), but will not penetrate walls.
The infrared transmission has become common in PDAs (Personal digital assistants) e.g., hand
held devices like palm pilots etc.
The infrared transmission is considered to be a secure one.
Laser:
The laser transmission requires direct line-of-sight.
It is unidirectional like microwave, but has much higher speed than microwaves.
The laser transmission requires the use of a laser transmitter and a photo-sensitive receiver at each
end.
The laser transmission is point-to-point transmission, typically between buildings.
Disadvantage: It can be adversely affected by the weather.
Switching techniques:
Switching techniques are used for transmitting data across networks.
There are three types of switching:
o Circuit Switching
o Message Switching
o Packet Switching
15 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Circuit Switching:
In this technique, first the complete physical connection between two computers is established
and then data are transmitted from the source computer to the destination computer.
That is, when a computer places a telephone call, the switching equipment within the telephone
system seeks out a physical copper path all the way from sender telephone to the receiver's
telephone.
The important property of this switching technique is to setup an end-to-end path connection
between computers before any data can be sent.
Message Switching:
In this technique, the source computer sends data or the message to the switching office first,
which stores the data in its buffer.
It then looks for a free link to another switching office and then sends the data to this office.
This process is continued until the data are delivered to the destination computers.
It is also known as store and forward. i.e., store first in switching office, forward later, one
jump at a time.
Packet Switching:
Packet switching can be seen as an option that tries to combine the advantages of circuit and
message switching and to minimize the disadvantage of both.
In Packet switching, a message is broken into smaller parts called packets.
A fixed size of packet which can be transmitted across the network is specified.
Communication Modes:
The way in which data is transmitted from one place to another is called data transmission
mode.
It is also called the data communication mode.
It is indicates the direction of flow of information.
Sometimes, data transmission modes are also called directional modes.
Different types of data transmission modes are as follows:
1. Simplex mode
2. Half-duplex mode
3. Full-duplex mode
Simplex Mode
In simplex mode, data can flow in only one direction.
In this mode, a sender can only send data and cannot receive it.
16 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Similarly, a receiver can only receive data but cannot send it.
Data sent from computer to printer is an example of simplex mode.
In simplex mode, it is not possible to confirm successful transmission of data.
It is also not possible to request the sender to re-transmit information.
This mode is not widely used.
Half-Duplex Mode
In half-duplex mode, data can flow in both directions but only in one direction at a time.
In this mode, data is sent and received alternatively.
It is like a one-lane bridge where two-way traffic must give way in order to cross the other.
The Internet browsing is an example of half duplex mode.
The user sends a request to a Web server for a web page.
It means that information flows from user's computer to the web server.
Web server receives the request and sends data of the requested page.
The data flow the Web server to the user's computer.
At a time a user can a request or receive the data of web page.
Full-Duplex Mode
In full duplex-mode, data can flow in both directions at the same time.
It is the fastest directional mode of data communication.
The telephone communication system is an example of full-duplex communication mode.
Two persons can talk at the same time.
Network Devices:
Modem:
Modem means Modulation/ Demodulation.
17 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
A modem is a computer peripheral that allows you to connect and communicate with other
computers via telephone lines.
Modulation: A modem changes the digital data from your computer into analog data, a format that
can be carried by telephone lines.
Demodulation: The modem receiving the call then changes the analog signal back into digital
data that the computer can digest.
The modem modulates the signal at the sending end and demodulates at the receiving end.
Modems are of two types:
o Internal modems: The modems that are fixed
within the computer
o External modems: The modems that are
connected externally to a computer as other
peripherals are connected.
RJ-45:
RJ-45 is short for Registered Jack-45 is an eight-wire connector, which
is commonly used to connect computers on the local area networks i.e.,
LANs especially Ethernets.
The standard connector for unshielded twisted pair cabling is an RJ-45 connector.
Ethernet Card:
The computer that are part of Ethernet, have to install our
special card called Ethernet card.
It is LAN architecture developed by Xerox Corp association
with DEC and Intel.
It make use of Bus or Star topology and data transfer rates of 10 Mbps.
An Ethernet card contains connections for either coaxial or twisted pair cables (or both).
If it is designed for coaxial cable, the connection will be BNC.
If it is designed for twisted pair, it will have a RJ-45 connection.
Some Ethernet cards also contain an AUI connector. This can be used to
attach coaxial, twisted pair, or fiber optical cables to an Ethernet card.
Hub:
A hub is a hardware device used to connect several computers together.
18 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
A concentrator is device that provides a central connection point for cables from workstations,
servers, and peripherals.
In a star topology, twisted-pair wire is run from each workstation to a central concentrator.
Types of hub:
o Active hubs:
It electrically amplifies the signal as it moves from one connected device to another.
Active concentrators are used like repeaters to extend the length of a network.
o Passive hubs:
It allows the signal to pass from one computer to another without any change.
Switch:
The switch is a telecommunication device grouped as one of computer network components.
The switch is like Hub but built in with advanced features.
The switch connects the source and destination directly which increases the speed of the network.
Repeater:
A Repeater is network device that amplifies and restore signals for long-distance transmission.
It is used in long network lines, which exceed the maximum rated distance for a single run.
Bridge:
A Bridge is a network device that establishes an intelligent connection between two local networks
with the same standard but with different type’s cables.
Router:
A router works like a bridge but can handle different protocols.
A Router is a network device that is used to separate different segments in a network to improve
performance and reliability.
19 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Gateway:
The term gateway is applied to a device, system or software application which has internetwork
capability of joining dissimilar network.
It is node on network that provides entry to another network.
It performs data translation and protocol conversions which is suitable to other network.
Example: It needs to convert Ethernet traffic from the LAN to SNA (System Network
Architecture). It then routes SNA traffic to Mainframe. When Mainframe answers, the reverse
process occurs.
Gateway can be implemented on software, hardware or a combination of both.
Gateway is that only the data format is translated, not the data itself.
Wireless communication:
Wireless communication is simply data communication without the use of landlines.
This may involve cellular telephone, two way radio, fixed wireless, LASER or satellite
communication.
Mobile computing means that the computing device is not continuously connected to the base or
central network.
Mobile devices include PDAs, Laptop computers and smart phones.
GSM:
GSM is short for Global System for Mobile communications, which is one of the leading digital
cellular systems.
The GSM standard for digital cell phones was established in Europe in the mid 1908s.
GSM uses narrowband TDMA, which allows eight simultaneous calls on the same radio
frequency.
TDMA is short for Time Division Multiple Access, a technology for delivering digital wireless
service using time-division multiplexing (TDM).
TDMA:
Time Division Multiple Access.
20 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
TDMA works by dividing a radio frequency into time slots and then allocating slots to, multiple
calls. In this way, a single frequency can support multiple, simultaneous data channels.
SIM card:
The SIM - Subscriber Identity Module - is a chip card; the size of a first class postage stamp.
A SIM is a computer chip that gives a cellular device its unique phone number.
It has memory (16 to 64 KB), processor and the ability to interact with the user.
CDMA:
CDMA is short for Code-Division Multiple Access, a digital cellular technology that uses spread-
spectrum techniques.
CDMA is a form of spread spectrum, which simply means that data is sent in small pieces over a
number of the discrete frequencies available for use at any time in the specified range.
WLL
Wireless in Local Loop (WLL or WiLL),
It is meant to serve subscribers at homes or offices.
In WLL services, the telephone provided is expected to be as good as wired phone.
Its voice quality must be high - a subscriber carrying out long conversation must not be irritated
with quality; one must be able, to use speakerphones, cordless phones and parallel phones.
GPRS
GPRS stands for General Packet Radio Service.
GPRS is used for wireless communication using a mobile device.
With the service you can access the internet, send emails and large data, download games and
watch movies.
EDGE:
The new EDGE air interface has been developed specifically to meet the bandwidth needs of 3G.
Enhanced Data rates for Global Evolution (EDGE) is a radio based high-speed mobile data
standard.
It allows data transmission speeds of 384 Kbps.
EDGE was formerly called GSM384.This means a maximum bit rate of 48 kbps per time slot.
EDGE is considered an intermediate step in the evolution of 3G WCDMA.
The “G” in wireless networks refers to the “Generation” of the underlying wireless network
technology.
21 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Applications in Networking:
SMS:
Short Message Service (SMS) is the transmission of short text messages to and from a mobile
phone, fax machine and/or IP address.
Messages must be no longer than some fixed number of alpha-numeric characters and contain
no images or graphics.
E-mail:
Electronic mail (e-mail) is sending and receiving message by computer.
Advantages:
o Low cost: Electronic mail is an extremely cost-effective way to move information
around, especially when it must be moved quickly.
o Speed: Electronic mail can be delivered almost as fast as the wire can carry it.
Voice Mail:
The voice-mail refers to e-mail systems that support audio.
Users can leave spoken messages for one another and listen to the messages by executing the
appropriate command in the e-mail system.
Chat:
Chatting is the most fantastic thing on Internet.
22 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Wi-fi:
Wi-Fi is short for Wireless Fidelity, which lets you connect to the internet without a direct line
from your PC to the ISP.
For Wi-Fi to work, you need:
o A broadband internet connection.
o A wireless router, which relays your internet connection from the “wall” to the PC.
o A laptop or desktop with a wireless internet card or external wireless adapter.
Wi-Fi Hotspots:
A hotspot is a venue that offers Wi-Fi access.
The public can use a laptop, Wi-Fi phone or other suitable portable devices to access the
internet through a Wi-Fi hotspot.
Hotspots are public locations with free or fee-based wireless internet access.
WiMax:
WiMax is wireless digital communication system.
WiMax can provide Broadband Wireless Access (BWA) up to 30 miles for fixed stations and
3-10 miles for mobile stations.
WiMax requires a tower called WiMax Base Station, similar to cell phone tower, which is
connected to the internet using a standard wired high-speed connection.
VIRUS:
VIRUS – “Vital Information Resource Under Siege”.
A computer virus is a computer program that can replicate itself and spread from one computer
to another.
Depend on the nature of a virus, it may cause damage of your hard disk contents, and/or
interfere normal operation of your computer.
Characteristics of a computer virus:
23 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
It is able to replicate.
Reduced memory or disk space.
Modification of data.
Files overwritten or damaged.
Hard drive erased.
Types of Virus:
File Infectors:
o Infect executable files or attach themselves to a program file and create duplicate files.
Boot sector Virus:
o Install themselves on the beginning tracks of the hard drive or the Master Boot record.
Macro Virus:
o Infect data file like spread sheets or databases of several software packages.
Network Virus:
o E-mail or any data transfer files to spread themselves on the network.
Trojan Horse:
o A Trojan Horses is code hidden in a program such as a game as spreadsheet that looks
safe to run but has hidden side effects.
Worm:
o A worm is a program designed to replicate. The program may perform any variety of
additional tasks as well.
How Computer Viruses Spread?
It moves from computer to computer by attaching themselves to files or boot records of disks.
A virus travel from file to another on the same computer if the infected file executed, from
computer memory to a file on the disk, on a disk that is carried from one computer to another.
Damage:
Can destroy file allocation table (FAT)
Can create bad sectors on the disk
Can decrease the space on the hard disks by duplicating file.
Can format specific tracks on the disk.
Can destroy specific executable files
Can cause the system to hang.
Virus Protection:
The following guidelines to lead virus free computing life.
o Never use a CD without scanning it for viruses.
24 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Network Security:
Network security consists of the provisions and policies adopted by a network administer to
prevent and monitor unauthorized access, misuse, modification of a computer network and
network accessible resources.
The problem encountered under network security are:
1. Physical Security holes: When individuals gain unauthorized physical access to a computer
and tamper with files.
2. Software Security holes: When badly written programs or privileged software are
compromised into doing things that they shouldn’t be doing.
3. Inconsistent usage holes: When a system administrator assembles a combination of hardware
and software such that the system is seriously flawed from a security point of view.
Protection Methods:
1. Authorization - Authorization is performed by asking the user a legal login ID. If the user is
able to provide a legal login ID, He/she is considered an authorized user.
2. Authentication - Authentication also termed as password protection as the authorized user is
asked to provide a valid password and if he/she is able to do this, he/she considered to be an
authentic user.
3. Encryption Smart cards– conversion of the form of data from one form to another form. An
encrypted smart card is a hand held smart card that can generate a token that a computer
system can recognize. Every time a new and different token is generated, which even though
carked or hacked, cannot be used later.
4. Biometric System – It involves unique aspect of a person's body such as Finger-prints, retinal
patterns etc to establish his/her Identity.
5. Firewall - A system designed to prevent unauthorized access to or from a private network is
called firewall. It can be implemented in both hardware and software or combination or both.
25 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
Cookies :
Cookies are messages that a web server transmits to a web browser so that the web server can
keep track of the user’s activity on a specific web site. Cookies have few parameters name,
value, expiration date.
Cyber Law:
It is a generic term, which refers to all the legal and regulatory aspects of internet and the
World Wide Web.
India’s IT Act:
In India the cyber laws are contained in the IT Act 2000. Aims to provide legal infrastructure
for e-commerce in India by governing transactions through internet and other electronic
medium.
Important Questions
1 Marks Question:
1. Expand FTP. [March 2015, June 2017]
2. What is network topology? [March 2015, March 2016]
26 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan
11. Name the first computer network? 16. What are cookies?
12. What is client/workstation? 17. What hackers and crackers?
13. What is server? 18. Expand the terms: TCP/IP, GPRS,
14. What are the various types of network? GSM, EDGE, Wi-Fi.
15. What is Modem and Hub?
2 Marks Question:
1. Explain half duplex communication mode. [March 2015]
2. Mention any two antivirus software. [March 2016]
3. Write the difference between LAN and WAN. [June 2016]
4. What is communication (transmission) mode? Explain simplex mode. [March 2017]
5. Write the difference between half duplex and full duplex communication modes. [June 2017]
5 Marks Question:
1. Explain any five network devices. [March 2015]
2. Give the measures for prevention virus. [June 2015, June 2017]
3. Explain the network security in detail. [March 2016, June 2016]
4. What is networking? Explain the goals of networking. [June 2017]
****************
27 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
Chapter-14
SQL COMMANDS
What is SQL?
Structured Query Language and it helps to make practice on SQL commands which provides
immediate results.
SQL is Structured Query Language, which is a computer language for storing, manipulating and
retrieving data stored in relational database.
SQL is the standard language for Relation Database System.
All relational database management systems like MySQL, MS Access, and Oracle, Sybase,
Informix, and SQL Server use SQL as standard database language.
Why SQL?
Allows users to create and drop databases and tables.
Allows users to describe the data.
Allows users to define the data in database and manipulate that data.
Allows users to access data in relational database management systems.
Allows embedding within other languages using SQL modules, libraries & pre-compilers.
Allows users to set permissions on tables, procedures, and views
SQL Architecture:
When you are executing an SQL command for any RDBMS, the system determines the best way
to carry out your request and SQL engine figures out how to interpret the task.
There are various components included in the process.
These components are:
o Query Dispatcher
o Optimization Engines
o Classic Query Engine
o SQL Query Engine, etc.
Classic query engine handles all non-SQL queries
but SQL query engine won't handle logical files.
Simple diagram showing SQL Architecture:
SQL Commands:
The standard SQL commands to interact with relational databases are CREATE, SELECT,
INSERT, UPDATE, DELETE and DROP.
These commands can be classified into groups based on their nature:
1. NUMBER:
o Used to store a numeric value in a field column.
o It may be decimal, integer or real value.
o General syntax: NUMBER(n, d)
o Where n specifies the number of digits and d specifies the number of digits to right of the
decimal point.
o Example: marks NUMBER(3), average NUMBER(2, 3)
2. CHAR:
o Used to store a character type data in a column.
o General syntax: CHAR(size)
o Where size represents the maximum (255 Characters) number of characters in a column.
o Example: name CHAR(15)
3. VARCHAR/VARCHAR2:
o It is used to store variable length alphanumeric data.
o General syntax: VARCHAR(size) / VARCHAR2(size)
o Where size represents the maximum (2000 Characters) number of characters in a column.
o Example: address VARCHAR2(50)
4. DATE:
o It is used to store date in columns.
o SQL supports the various date formats other than the standard DD-MON-YY.
o Example: dob DATE
5. TIME:
o It is used to store time in columns.
o SQL supports the various time formats other than the standard hh-mm-ss.
o Every DATE and TIME can be added, subtracted or compared as it can be done with other
data types.
6. LONG:
1. It is used to store variable length strings of up to 2GB size.
2. Example: description LONG
IS NULL The NULL operator is used to compare a value with a NULL value.
The UNIQUE operator searches every row of a specified table for uniqueness (no
UNIQUE
duplicates).
CREATE TABLE
The SQL CREATE TABLE statement is used to create a new table.
Creating a basic table involves naming the table and defining its columns and each column's data
type.
Syntax: Basic syntax of CREATE TABLE statement is as follows:
CREATE TABLE Table_name
(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
o Here CREATE TABLE is the keyword followed by the Table_name, followed by an open
parenthesis, followed by the column names and data types for that column, and followed by a
closed parenthesis.
o For each column, a name and a data type must be specified and the column name must be a
unique within the table definition.
o Column definitions are separated by commas (,).
o Uppercase and lowercase letters makes no difference in column names.
o Each table must have at least one column.
o SQL commands should end with a semicolon (;).
Example: Create a table “STUDENT” that contains five columns: RegNo, Name, Combination,
DOB and Fees.
CREATE TABLE STUDENT
(
RegNo NUMBER (6),
Name VARCHAR2 (15),
Combination CHAR (4),
DOB DATE,
Fees NUMBER (9, 2),
PRIMARY KEY ( RegNo )
);
ALTER Statement:
The table can be modified or changed by using the ALTER command.
Syntax: Basic syntax of ALTER TABLE statement is as follows:
1. ALTER TABLE Table_name
ADD (column_name1 DataType, Cloumn_name2 DataType……);
2. ALTER TABLE Table_name
MODIFY (column_name1 DataType, Cloumn_name2 DataType……);
3. ALTER TABLE Table_name
DROP (column_name1 DataType, Cloumn_name2 DataType……);
Example:
Using the ALTER TABLE command the following tasks cannot be performed
o Changing a table name.
o Changing the column name.
o Decreasing the size of a column if table data exists.
o Changing a column‟s data type.
DROP TABLE:
The SQL DROP TABLE statement is used to remove a table definition and all data, indexes,
triggers, constraints, and permission specifications for that table.
Syntax: Basic syntax of DROP TABLE statement is as follows:
Example:
INSERT:
The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.
Syntax:
There are two basic syntaxes of INSERT INTO statement as follows:
Here, column1, column2,...columnN are the names of the columns in the table into which you
want to insert data.
You may not need to specify the column(s) name in the SQL query if you are adding values for all
the columns of the table. But make sure the order of the values is in the same order as the columns
in the table.
METHOD 1: The SQL INSERT INTO syntax would be as follows:
UPDATE:
SQL provides the ability to change data through UPDATE command.
The UPDATE command used to modify or update an already existing row or rows of a table.
The basic syntax of UPDATE command is given below.
UPDATE Table_name
SET column_name = value
[, column_name =value ……….]
[WHERE condition];
Example:
SQL> UPDATE STUDENT SET COMBINATION='CEBA' WHERE REGNO=1411;
1 row updated.
SQL> UPDATE STUDENT SET NAME='AKASH' WHERE REGNO=1412;
1 row updated.
DELETE command:
In SQL, an already existing row or rows are removed from tables through the use of DELETE
command.
The basic syntax of DELETE command is given below.
DELETE Table_name
[WHERE condition];
Example:
SQL> DELETE STUDENT WHERE REGNO=1412;
1 row deleted.
SELECT:
SQL SELECT statement is used to fetch the data from a database table which returns data in the
form of result table. These result tables are called result-sets.
Syntax: The basic syntax of SELECT statement is as follows:
SELECT column1, column2, columnN Compulsory
FROM Table_name; Part
[WHERE condition(s)]
[GROUPBY column-list] Optional
[HAVING condition(s)] Part
[ORDER BY column-name(s)];
Here, column1, column2...are the fields of a table whose values you want to fetch. If you want to
fetch all the fields available in the field, then you can use the following syntax:
Following is an example, which would fetch REGNO, NAME and COMBINATION fields of the
customers available in STUDENT table:
DISTINCT:
The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the
duplicate records and fetching only unique records.
10 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
There may be a situation when you have multiple duplicate records in a table. While fetching such
records, it makes more sense to fetch only unique records instead of fetching duplicate records.
Syntax: The basic syntax of DISTINCT keyword to eliminate duplicate records is as follows:
First, let us see how the following SELECT query returns duplicate combination records:
Now, let us use DISTINCT keyword with the above SELECT query and see the result:
This would produce the following result where we do not have any duplicate entry:
The WHERE clause is not only used in SELECT statement, but it is also used in UPDATE,
DELETE statement, etc., which we would examine in subsequent chapters.
Syntax: The basic syntax of SELECT statement with WHERE clause is as follows:
Following is an example, which would fetch REGNO, NAME and COMBINATION fields from
the STUDENT table for a COMBINATION is „PCMC‟.
Here, it is important to note that all the strings should be given inside single quotes ('') where as
numeric values should be given without any quote as in above example:
The SQL AND and OR operators are used to combine multiple conditions to narrow data in an
SQL statement. These two operators are called conjunctive operators.
These operators provide a means to make multiple comparisons with different operators in the
same SQL statement.
Syntax: The basic syntax of AND operator with WHERE clause is as follows:
12 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
You can combine N number of conditions using AND operator. For an action to be taken by the
SQL statement, whether it be a transaction or query, all conditions separated by the AND must be
TRUE.
Example: Consider the STUDENT table having the following records:
Following is an example, which would fetch REGNO, NAME and DOB fields from the
STUDENT table where fees is less than 1500 AND combination is „PCMC:
The OR Operator:
The OR operator is used to combine multiple conditions in an SQL statement's WHERE clause.
You can combine N number of conditions using OR operator. For an action to be taken by the
SQL statement, whether it be a transaction or query, only any ONE of the conditions separated by
the OR must be TRUE.
Following is an example, which would fetch REGNO, NAME and DOB fields from the
STUDENT table where fees is less than 1500 OR combination is „PCMC:
13 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
SELECT column-list
FROM Table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
You can use more than one column in the ORDER BY clause. Make sure whatever column you
are using to sort, that column should be in column-list.
Example: Consider the STUDENT table having the following records:
Following is an example, which would sort the result in ascending order by NAME:
Following is an example, which would sort the result in descending order by NAME:
14 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
SQL Functions:
The SQL functions serve the purpose of manipulating data items and returning a result.
There are many built in functions included in SQL and can be classified as Group Functions and
Scalar Functions.
Group Functions:
o Functions that act on set of values are called group functions.
o A group functions can takes entire column of data as its arguments and produces a single
data item that summarizes the column.
o Following are the SQL group functions.
Function Description
AVG Returns average value of „N‟, ignoring NULL values
COUNT(expr) Returns the number of rows where „expr‟ is not NULL
Returns the number of rows in the table including duplicates and those with
COUNT(*)
NULL values
MIN Returns minimum value of „expr‟
MAX Returns maximum value of „expr‟
SUM Returns sum of values „N‟
Scalar Functions:
o Functions that act on only one value at a time are called scalar functions.
o We can further classify the functions using the type of data with they are designed to work.
15 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
Function Description
Numeric Work with numbers.
Functions Examples: ABS, POWER, ROUND, SQRT
String Work with character based data.
Functions Examples: LOWER, INITCAP, UPPER, SUBSTR, LENGTH, LTRIM, RTRIM
Date Work with Date data types.
Functions Example: ADD_MONTHS, LAST_DAY, MONTHS_BETWEEN, NEXT_DAY
Conversion These functions are used to convert one type of data to another.
Functions Example: TO_NUMBER, TO_CHAR, TO_DATE
COUNT ( ) Function:
This function is used to count the number of values in a column.
COUNT (*) is used to count the number of rows in the table including duplicates and those with
NULL values.
Example 1:
o SELECT COUNT (*) FROM EXAMINATION;
o The above query returns 10.
Example 2:
o SELECT COUNT (RegNo) FROM EXAMINATION WHERE CC = „C3‟ ;
o The above query returns 4.
16 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
AVG ( ) Function:
This function is used to find the average of the values in a numeric column.
Example 1:
o SELECT AVG (Cs) FROM EXAMINATION;
o The above query returns 74.7
SUM ( ) Function:
This function is used to find the sum of the values in a numeric column.
Example:
o SELECT SUM (Phy) FROM EXAMINATION;
o The above query returns 729
MAX ( ) Function:
This function is used to find the maximum values in a column.
Example:
o SELECT MAX (Phy) FROM EXAMINATION;
o The above query returns 100
MIN ( ) Function:
This function is used to find the minimum values in a column.
Example:
o SELECT MIN (Phy) FROM EXAMINATION;
o The above query returns 33
17 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
SQL CONSTRAINTS:
Constraints are the rules enforced on data columns on table.
These are limiting the type of data that can go into a table.
This ensures the accuracy and reliability of the data into the database.
SQL allows two types of constraints.
o Column level constraints: These constraints are defined along with the column definition
when creating or altering a table structure. These constraints apply only to individual
columns.
o Table level constraints: These constraints are defined after all the table columns when
creating or altering a table structure. These constraints apply to groups of one or more
columns.
Following are the commonly used constraints available in SQL.
Constraints Description
NOT NULL Ensures that a column cannot have NULL value
UNIQUE Ensures that all values in column are different
PRIMARY KEY Uniquely identified eac row in a database table.
FOREIGN KEY Uniquely identified each rown in any other database table
DEFAULT Provides a default value for a column when none is specified
CHECK Ensures that all values in a column satisfy certain condition.
18 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
Example: Consider the following CREATE TABLE command creates a new table called
PRODUCT and add six columns, two which PID and Description specify not to accept NULLs.
CREATE TABLE PRODUCT
(
PID CHAR (4) NOT NULL,
Description VARCHAR2 (25), NOT NULL
CompanyId CHAR (10),
DOM DATE,
Type CHAR (10),
Price NUMBER (10,2)
);
UNIQUE Constraints:
This constraint ensures that no rows have the same value in the specified column(s). A table must
have many unique keys.
Example: UNIQUE constraint applied on PID of PRODUCT table ensures that no rows have the
same PID value, as shown below
CREATE TABLE PRODUCT
(
PID CHAR (4) NOT NULL UNIQUE,
Description VARCHAR2 (25), NOT NULL
CompanyId CHAR (10),
DOM DATE,
Type CHAR (10),
Price NUMBER (10,2)
);
PRIMARY KEY Constraints:
A primary key is a field which uniquely identifies each row in a database table. A primary key in a
table has special attributes:
By default this column is NOT NULL. It defines the column as a mandatory column i.e. the
column cannot be left blank.
The data held in this column must be unique.
Example:
CREATE TABLE PRODUCT
(
PID CHAR (4) PRIMARY KEY,
Description VARCHAR2 (25), NOT NULL
CompanyId CHAR (10),
DOM DATE,
Type CHAR (10),
Price NUMBER (10,2)
);
19 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
20 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
(
PID CHAR (4) CHECK (PID LIKE ‘P%’),
Description VARCHAR2 (25),
CompanyId CHAR (10),
DOM DATE,
Type CHAR (10),
Price NUMBER (10, 2) CHECK (Price>0)
);
TABLE Constraints:
When a constraint is applied to a group of columns of the table, it is called a table constraint.
Column constraint is defined along with the end of the column.
Table constraints are defined at the end of the table.
Example:
CREATE TABLE PRODUCT
(
PID CHAR (4) NOT NULL,
Description VARCHAR2 (25) NOT NULL,
CompanyId CHAR (10),
DOM DATE,
Type CHAR (10),
Price NUMBER (10, 2),
PRIMARY KEY (PID, Description)
);
Joins
The SQL Joins clause are used to fetch/retrieve data from two or more tables based on the join
condition which is specified in the WHERE condition.
Basically data tables are related to each other with keys. We can used these keys relationship in
SQL joins.
21 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
o CARTESIAN JOIN: returns the Cartesian product of the sets of records from the two or
more joined tables.
Creating VIEWs:
Database Views are created using the CREATE VIEW statement.
Views can be created from a single table, multiple tables or another view.
To create a view, a user must have the appropriate system privilege according to the specific
implementation.
Syntax: The basic CREATE VIEW syntax is as follows:
Important Questions
Two Marks Questions:
1. Give the syntax and example for DELETE command in SQL. [March 2015]
2. List the data types supported in SQL. [June 2015]
3. Write the syntax for DELETE and INSERT commands in SQL. [March 2016]
4. Mention the logical operators used in SQL. [June 2016]
5. Give the syntax and example of UPDATE command in SQL. [March 2017]
22 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan
6. What is the difference between ORDER BY and GROUP BY clause used in SQL? Give example
for each. [June 2017]
7. List the relational operators supported by SQL.
8. Why the DROP command used? Write its syntax.
9. What are the difference between DROP and DELETE command?
10. Give the syntax and example for CREATE VIEW command in SQL.
11. Classify the built-in functions in SQL.
1. Explain various group functions in SQL. [March 2015, March 2017, June 2017]
2. What is data definition language? Explain SELECT and UPDATE command. [June 2015]
3. Describe any five logical operators available in SQL. [March 2016]
4. What is SQL? Explain the different SQL commands.
5. What is the purpose of CREATE command? Write the syntax and example of CREATE command.
6. Explain SELECT statement with syntax and with minimum 3 examples.
7. Explain 5 variations of SELECT command.
8. What are SQL constraints? Explain any two constraints.
****************
23 | P a g e Keerthi Kumar H M
Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan
Chapter-16
INTERNET AND OPEN SOURCE CONCEPTS
Introduction:
Internetwork: An internetwork is a collection of individual networks, connected by intermediate
networking devices, that functions as a single large network.
Classification of Internetworks:
o Internet: The globe public network.
o Intranets: The wholly owned/private internetworks.
o Extranets: The hybrid internetworks: private networks/ internetworks connected through
the internet
The term “open source” software is used to refer to those categories of software/ programs
whose licenses do not impose much condition.
OSS:
OSS refers to open source software, which refers to software whose source code is available to
customers and it can be modified and redistributed without any limitation.
FLOSS:
FLOSS refers to Free Libre and open Source Software or to Free Livre and Open Source
Software.
The term FLOSS is used to refer to software which is both free software as well as open source
software.
Here the words Libre (a Spanish word) and Livre (a Portuguese’s word) mean freedom.
GNU:
GNU is a Unix-like computer operating system developed by the GNU project.
It is composed wholly of free software.
It refers to GNU’s Not Unix .GNU Project emphasizes on freedom and thus its logo type show
a GNU, an animal living in freedom
FSF:
FSF is Free Software Foundation. FSF is a non-profit organization created for the purpose of
supporting free software movement.
Richard Stallman founded FSF in 1985 to support GNU project and GNU licenses.
OSI:
OSI is Open Source Initiative. It is an organization dedicated to cause of promoting open
source software.
Bruce Perens and Erics Raymond were the founders of OSI that was founded in February
1998.
W3C:
W3C is acronym for World Wide Web Consortium.
W3C is responsible for producing the software standards for World Wide Web.
The W3C was created by Tim Berners-Lee in 1994.
Proprietary Software:
Proprietary software or closed source software is the software that is neither open nor freely
available.
Its use is regulated and further distribution and modifications is either forbidden or requires
special permission by the supplier or vendor.
Source of proprietary software is normally not available.
Freeware:
The term freeware has no clear definition, but is generally used for software, which is available
free of cost and which allows copying and further distribution, but not modification and whose
source code is not available.
Freeware is distributed in Binary Form (ready to run) without any licensing fees.
Shareware:
Shareware is software, offered as trial version (for limited period of time) with certain features
only available after the license is purchased.
Its source code is not available and modifications to the software are not allowed.
WWW (World Wide Web).
The World Wide Web (WWW) is a set of protocols that allows you to access any documents
on the Net through a naming system based on URLs.
WWW also specifies a way -- the Hypertext Transfer Protocol (HTTP) - to request and send a
document over the internet.
Attributes of WWW
o User friendly - www resources can be easily used with the help of browser.
o Multimedia documents - A web page may have graphic, audio, video, and animation
etc at a time.
o Hypertext and hyperlinks - The dynamic links which can move towards another web
page is hyperlink.
o Interactive - www with its pages support and enable interactivity between users and
servers.
o Frame - display of more than one section on single web page.
Advantages of WWW:
o Availability of mainly free information.
o Low cost of initial connection.
o It is accessible from anywhere.
o Facilities rapid interactive communication.
o Facilities the exchange of huge information.
o Facilitates the establishment of professional contact.
o Facilitates access to different sources of information.
Disadvantages of WWW:
o Danger of overload and excess information
o It requires an efficient information search strategy
E-Commerce:
E-Commerce is the trade of goods and services with the help of telecommunications and
computers.
E-Commerce involves the automation of a variety of business to consumer transaction through
reliable and secure connections.
E-Commerce Process:
A consumer uses a Web browser to connect to the home page of a merchant's Web site on the
Internet.
5|Page Keerthi Kumar H.M
Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan
The consumer browses the catalog of products featured on the site and selects items to
purchase. The selected items are placed in the electronic equivalent of a shopping cart.
When the consumer is ready to complete the purchase of selected items, it provides a bill to
and ship to address for purchase and delivery
When the credit card number is validated and the order is completed at the Commerce Server
site, the merchant's site displays a receipt confirming the customer's purchase.
The Commerce Server site then forwards the order to a Processing Network for payment
processing and fulfillment.
Business-to-Business (B2B):
The exchange of services, information and/or products from one business to another business
partners.
Examples: Intel selling microprocessor to Dell
Business-to-Consumer (B2C):
The exchange of services, information and/or product from business to a consumer.
Example: Dell selling me a laptop. Websites: Flipkart, Amazon, Snapdeal.
Consumer-to-Business (C2B):
Customer directly contact with business vendors by posting their project work with set budget
online so that needy companies review it and contact the customer directly with bid.
Example: guru.com, freelancer.com
Consumer-to-Consumer (C2C)
E-commerce is simply commerce between private individuals or consumers.
Example: Ram buying smartphone from Sham using OLX
Advantages of e-commerce
Buying & selling can be done online at any time (24 hours) money.
It provides faster payments through Electronic Fund Transfer.
Online payment reduces work of carrying money to the shop and also saves money.
Customer can search for competitive prices quickly before purchasing the items.
Wider choice for item selection.
Without going to the shops customers can view the products through websites thus saves time.
Disadvantages of e-commerce
Initial cost is high.
E-Commerce websites needs to be protected from virus attacks, hackers.
Needs more security.
Some company may charge more for shipping or other transport.
There is the possibility of credit card number theft.
Mechanical failures can cause unpredictable effects on the total processes.
IPR Issues:
IPR stands for Intellectual Property Rights.
Intellectual Property Rights (IPR) means copyrights, patents, and trademarks, designs etc held
by a person or company who have invented or designed a product.
Copyright, trademarks, industrial designs, patents, integrated circuits are the different forms of
Intellectual property.
The main benefits of IPR are wealth creation, legitimate ownership, talent attraction, image of
a trustworthy organization.
WIPO – World Intellectual Property Organization.
IPR-related issues in India like patents, trademarks, copyrights, designs are governed by the
Patents Act 1970 and patents Rules 2003, Trademarks Act 1999, Trademarks Rules 2002,
Copyright Act 1957, Design Act 2000 and Rules 2001.
Important Questions
1 Marks Question:
1. What is Open source software?
2. What are Freeware? [March 2015]
3. Define E-Commerce. [March 2016]
4. What is telnet? [June 2016]
5. Expand OSS and FLOSS.
3 Marks Question:
1. Explain Free software.
2. What is meant by shareware? Write its limitations [March 2016]
3. What is Web browser? Mention any two web browser. [March 2015, June 2015]
4. Give the advantages of WWW.
5. Define the terms webpage, website, web server. [June 2016]
6. Explain URLs.
7. What is E-Commerce? Explain types of E-commerce. [June 2015, March 2017]
8. What are the advantages and disadvantages of E-commerce?
9. Explain IPR.
****************
Chapter-17
WEB DESIGNING
Introduction to HTML:
HTML stands for Hypertext Markup Language, and it is the most widely used Language to
write Web Pages.
Hypertext refers to the way in which Web pages (HTML documents) are linked together.
Thus the link available on a webpage is called Hypertext.
HTML documents are also called web pages.
Now, HTML is being widely used to format web pages with the help of different tags available in
HTML.
<HTML>
<HEAD>
DOCUMENT HEADER RELATED
TAGS
</HEAD>
<BODY>
DOCUMENT BODY RELATED TAGS
</BODY>
</HTML>
HTML Tags:
HTML markup tags are usually called HTML tags.
These tags are keywords (tag name) surrounded by angle braces like <Tag Name>.
The first pair of tags is the start tag and the second tag is the end tag.
End tag contains a forward slash before the tag name.
Start tag and end tag are also called opening tags and closing tags.
Except few tags, most of the tags have their corresponding closing tags.
For example <html> has its closing tag </html> and <body> tag has its closing tag </body> tag.
Tags Description
This tag encloses the complete HTML document and mainly comprises
<HTML> of document header which is represented by <HEAD>...</HEAD> and
document body which is represented by <BODY>...</BODY> tags.
This tag represents the document's header which can keep other HTML
<HEAD>
tags like <TITLE>, <LINK> etc.
The <TITLE> tag is used inside the <head> tag to mention the
<TITLE>
document title.
This tag represents the document's body which keeps other HTML tags
<BODY>
like <H1>, <BR>, <P> etc.
HTML Images:
Images are very important to beautify as well as to depict many complex concepts in simple way
on your web page.
This will take you through simple steps to use images in your web pages.
Insert Image:
You can insert any image in your web page by using <img> tag.
Following is the simple syntax to use this tag.
<img src="Image URL" ... attributes-list/>
Anchor element allows you to link various WebPages or different sections on the same page. The
syntax of Anchor element is given below:
<A>………</A>
The various attributes of the Anchor element are HREF, NAME, TITLE, TARGET and ALT
o Href: The href (hyperlink reference) attribute specifies the location of the file or resource
that you want to provide a link to.
o Name: The name attribute specifies a location within the current or the existing document.
o Title: The title attribute specifies a title for the file which you are providing a link.
o Target: The target attribute specifies a position in the webpage where the browser displays
a file.
o Alt: The alt attribute specifies the alternative text which is displayed when an image used
as a hyperlink is not displayed.
HTML Lists:
HTML offers web authors three ways for specifying lists of information.
All lists must contain one or more list elements.
Lists may contain:
1. <UL> - An unordered list. This will list items using plain bullets.
2. <OL> - An ordered list. This will use different schemes of numbers to list your items.
3. <DL> - A definition list. This arranges your items in the same way as they are arranged in a
dictionary.
HTML Tables:
The HTML tables allow web authors to arrange data like text, images, links, other tables, etc.
into rows and columns of cells.
Basic TABLE tags:
<TABLE> …….. </TABLE>
o This tag defines a table in HTML. If the BORDER attribute is present, your browser
displays the table with a border.
<CAPTION>……..</CAPTION>
o This tag defines the caption for the title of the table.
<TR>………. </TR>
o This tag specifies a table row within a table.
<TH>………. </TH>
o This tag specifies a table header cell. By default the text in this cell is bold and centerd.
<TD>………. </TD>
o This tag specifies a table data cell. By default the text in this cell is aligned left and
centered vertically.
Example:
<HTML>
<HEAD>
<TITLE> TABLE ELEMENTS </TITLE>
</HEAD>
<BODY>
<TABLE BORDER="1">
<CAPTION> THIS IS THE TABLE CAPTION </CAPTION>
<TR>
<TH>REGNO</TH>
<TH>NAME</TH>
<TH>MARKS</TH>
</TR>
<TR>
<TD>101</TD>
<TD>AKASH</TD>
<TD>535</TD>
</TR>
<TR>
<TD>102</TD>
<TD>KARTHIK</TD>
<TD>578</TD>
</TR>
</TABLE>
</BODY>
</HTML>
FORMS:
A form is a web page which allows the user to enter information; it also allows the user to interact
with the contents of the form.
To insert a form we use the <FORM> </FORM> tags.
The rest of the form elements such as text boxes, check boxes, and pull down menus and so on must
be inserted between the form tags.
The form container works as follows:
<FORM METHOD=”how to send” ACTION=”URL of script”>
…..form data…..
</FORM>
The <FORM> tag takes two attribute:
o METHOD: This attribute accepts GET or POST as its value. POST is by far the more popular,
as it allows for a greater amount of data to be sent. GET is a little easier for web programmer to
deal with, and is best with single response, like a single textbox.
o ACTION: It simply accepts the URL for the script that will process the data from your form.
etc. The GET method appends data along with the URL. It is less secure than POST method.
<FORM> Elements:
Form elements have properties such as Text boxes, Password boxes, Check boxes, Radio buttons,
Submit, Reset etc.
The properties are specified in the TYPE attribute of the HTML element <INPUT> </INPUT>
<INPUT> Element’s Properties
Element Description
This value indicates the type of INPUT entry filed which can include
TYPE =
text, password and so on.
NAME = It represents a variable name passed to CGI application.
The data associated with the variable name to be passed to the CGI
VALUE =
application.
CHECKED = This value indicates the Button/box is checked by default.
SIZE = This value indicates the number of characters in the text field.
This value indicates the maximum number of characters that can be
MAXLENGTH =
accepted.
INPUT TYPES:
1. TEXT BOXES:
o These boxes are used to provide input fields for text, phone, numbers, and dates and so on.
o Example: <INPUT TYPE=”TEXT” NAME = “ studentname” SIZE=”30”>
2. PASSWORD:
o These boxes are used to allow the entry of passwords.
o Example: <INPUT TYPE=”PASSWORD” NAME=”Secret”>
3. CHECKBOX:
o These boxes are used to allow the user to select more than one option.
o Example: <INPUT TYPE=”CHECKBOX”>
4. RADIO Button:
o The Radio button allows user to select only one option among a list of options.
o Example: <INPUT TYPE=”RADIO”>
5. File Upload:
o You can use a file upload to allow users to upload files to your web server.
o Example: <INPUT TYPE=”FILE” NAME=”fileupload>
6. SUBMIT:
o This is the element that causes the browser to send the names and values of the other
elements to the CGI application specified by the CATION attribute of the FORM element.
o Example: <INPUT TYPE=” SUBMIT” VALUE=”Submit the Form”>
7. RESET:
o It allows the user to clear all the input in the form.
o Example: <INPUT TYPE=” RESET” VALUE=”Reset the Form”>
FRAMES:
HTML Frames are used to divide your browser window into multiple sections where each section
can load a separate HTML document.
A collection of frames in the browser window is known as Frameset.
Creating Frames:
To use frames on a page we use <FRAMESET> tag instead of <BODY> tag.
The <FRAMESET> tag defines how to divide the window into frames.
The row attribute of <FRAMESET> tag defines horizontal frames.
The cols attribute of <FRAMESET> tag defines vertical frames.
Each Frame is indicated by <FRAME> tag.
Example:
<HTML>
<HEAD>
<TITLE> HTML FRAMES </TITLE>
</HEAD>
<FRAMESET ROWS= “10%, 80%, 10%”>
<FRAME name= “top” src=”/html top_frame.htm” />
Advantages of HTML:
HTML document browser interfaces are easy to build.
It is easy to learn.
There are some specialized structures in HTML.
Disadvantages of HTML:
It is a weak presentation tool.
Weak markup tool.
It is very instable.
XML:
XML stands for eXtensible Markup Language.
XML is a markup language for documents containing structured information.
Structured information contains both content (words, pictures etc.) and some indication of what
role content plays.
XML is a text-based markup language that is fast becoming the standard for data interchange
on the web.
Difference between HTML and XML:
HTML XML
Hypertext Markup Language eXtensible Markup Language
HTML is used to display data and to XML is used to describe data and focus
focus on formatting of data. on what data is.
XML tags are not predefined (Create our
HTML tags are predefined
own tag)
HTML tags are not case sensitive XML tags are case sensitive
HTML is not extensible XML is extensible
DHTML:
Web Hosting:
Web Hosting means of hosting web-server application on a computer system through which
electronic content on internet is readily available to any web-browser client.
Various types of web hosting services are:
o Free Hosting
o Virtual or shared Hosting
o Dedicated Hosting
o Co-location Hosting
Free Hosting:
This type of hosting is available with many prominent sited that offer to host some web pages
for no cost.
Virtual or shared Hosting:
This type of hosting is where one’s own web site domain (ex: www.yourname.com) is hosted on
the web server of hosting company along with the other web sites.
Dedicated Hosting:
In this type of hosting, the company wishing to go online rents an entire web server from
hosting company. This is suitable for large, high traffic sites.
Co-location Hosting:
In this type of hosting, the company owing the site instead of web hosting company. Suitable
for those who need the ability to make changes?
Web Scripting :
The process of creating and embedding scripts in a web page is known as web-scripting.
Script:
o A Script is a list of commands embedded in a web page.
o Scripts are interpreted and executed by a certain program or scripting –engine.
Types of Scripts:
1. Client Side Script:
o Client side scripting enables interaction within a web page.
o The client-side scripts are downloaded at the client-end and then interpreted and
executed by the browser.
o Some popular client-side scripting languages are VBScript, JavaScript, ActionScript.
2. Server-Side Scripts:
o Server-side scripting enables the completion or carrying out a task at the server-end and
then sending the result to the client –end.
o Some popular server-side Scripting Languages are PHP, Perl, ASP(Active Server
Pages), JSP(Java Server Pages) etc.
Important Questions
1 Marks Question:
1. Expand the following:
a. HTML b. XML c. DHTML [June 2016]
2. What are HTML, XML, and DHTML?
3. Mention the use of HTML. [March 2015]
4. Write any one HTML tag. [June 2015]
5. What is DHTML? [March 2016]
6. What will be the extension of HTML language file?
7. What is the use of web page?
8. What is Script?
3 Marks Question:
1. Explain any three text formatting tags in HTML. [March 2015, March 2017]
2. Explain Anchor tag with syntax and example.
3. Explain different INPUT in HTML.
4. What is web hosting? Mention different types of web hosting. [June 2015, March 2016]
5. What is web scripting? Explain the different types of web scripting.
6. Write the difference between client side scripting and server side scripting.
**************