0% found this document useful (0 votes)
33 views79 pages

IIPU ComputerScience StudyMaterial

Uploaded by

122testy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views79 pages

IIPU ComputerScience StudyMaterial

Uploaded by

122testy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

II PU COMPUTER SCIENCE

STUDY MATERIAL
Chapter 1
CONFIGURING A COMPUTER

MOTHERBOARD :
The main circuit board containing almost all the components of computers.
Characteristics of motherboard :
1) Form factor. 2) Chip set 3) Processor socket
Form factor: Refers to the motherboards geometry, dimensions, arrangement and electrical requirements.
Chip set : It controls and co-ordinates data transfer between various components of the computer.
Processor socket : It may be a rectangular or square shaped connector into which the processor mounted
vertically.
Types of motherboard :
1. XT 2. AT 3. ATX
1. XT : Extended Technology : IBM 1983, Old model processors, RAM slot DIMM, industrial standard
architecture.
Eg: Pentium 1, Pentium MMX, Pentium 2.
2. AT : Advanced Technology : IBM 1984, PGA (pin grid array)Socket, SDRAM Slot, PCI slot.
Eg: Pentium 3 processor.
3. ATX : Advanced Extended Technology :INTEL 1986, latest motherboard MPGA Processor, DDRRAM slot,
PCI, AGP slots.
Eg: Pentium 4, dual core, core2duo, i3,i5,i7…

Motherboard chipset:
1> North Bridge. 2> south Bridge.
North Bridge (Host bridge) :- The north bridge connects directly to the processor through the front side bus. A
memory controller is located in north bridge which gives CPU fast access to memory. AGP, PCI, ……
South bridge: The south bridge is slower than the north bridge USB, IDE, Net card, Sound card, hard disk
connections.
Components of motherboard :
1. Processor slot or CPU socket. 2. BIOS 3. CMOS Battery 4. Disk controller. 5. I/O ports. 6.Expansion slots.
7. Bus.
1. Processor slot or CPU socket : The socket where processor can be connected.
Processor : The clock speed of CPU is defined as the frequency with which a processor executes the
processed data.
Microprocessor :An integrated circuit on a single chip that makes up computer CPU.
2. BIOS : Basic Input Output System : A set of computer instructions which control input and output
operations.
3. CMOS : Complementary Metal Oxide Semiconductor: This battery supply the board small amount of power
to store set up parameters like date, time, password,
4. Disk controller : It is the circuit which enables the CPU to communicate with a hard disk, floppy disk or other
kind of disk drives
a. FDD. b. HDD.
5. I/O Ports and interfaces : It is a socket used to connect external devices to the computer.
a. Serial port b. Parallel port c. SCSI
d. Game port e. USB f. PS2
e. Ethernet h. MIDI
Serial port : This port transfers data serially 1 bit at a time, it is also called as RS 232 C port. Eg. Mouse,
Modem.
Parallel port : This port carries 8bit of data on a parallel path at a time. It is also called as LPT1 port or
printer port.
SCSI : Small Computer System Interface : It is used to transfer data very fast, generally high performance
hard disks uses this interface.
Game port : It is used to connect gaming devices like joystick.
USB : Universal Serial Bus : It is a plug n play interface between a computer and add on devices such as
audio players, joystick etc.
USB supports 12mbps data speed and 127 devices can be connected.
PS2 : Developed by IBM to interface, Keyboard, Mouse, Track ball, Touch pads.
Ethernet : This port connects to a network and high speed internet. Data travels at 10 MBPS to 1000
MBPS.
MIDI: Musical Instrument Digital Interface : Transmits information between electronic musical
instruments.
DVI :Digital Video Interface
6) Expansion slots :
1) ISA 2) PCI 3) AGP
1) ISA : Industrial standard architecture: It is 16 bit bus was introduced by IBM. It is a non plug n play port.
2) PCI : Peripheral Component Inter Connect: It is plug n play port with 32 bit bus. That is also available in 64 bit
bus.
3) AGP : Accelerated Graphics Port: It is an advanced port to enhance the video clarity.
7) Bus : It is a collection of wires which carries electronics signal from one component to another.
1) System bus (Internal bus) 2) Local bus (external bus)
1) System bus or Internal bus:
1) Address bus 2) Data bus 3) Control bus
Address bus : It connects CPU and RAM with set of lines of wires.
Data bus : It provides a path to transfer a data between CPU and memory.
Control bus : It is used by the processor to control access of data and address lines.
Local bus : ISA, PCI, AGP (Expansion slots)
Memory : Information storage device: a)Primary memory b) Secondary memory
I Primary memory : It is a main memory or temporary memory or Internal memory.
1) RAM 2) ROM
1) Random Access Memory : It is a read and write memory, stores information until power supply is on. It is a
volatile memory.
a) Static RAM
b) Dynamic RAM
a) SDRAM : Synchronous Dynamic RAM
b) DDRRAM : Dual data rate RAM
ROM : Read Only Memory: It is non volatile memory used to set environment for a system to perform its operations.
a) PROM b) EPROM c) EEPROM
Disk controllers : It is the circuit that enables the CPU to communicate with Hard disk , Floppy disk…
Registers : High speed temporary storage area.
Cache Memory:
Memory

Registers L1 L2 Disk
cac ca
he
It is a small very fast memory used tochstore most recently performed data.
1) L1 cache 2) Le2 cache 3) L3 cache
L1 is located in CPU
L2 is located in memory
L3cache : Located on the mother board. It is used to improve the performance of L1 and L2 .
It is capacity up to 6 MB.
SMPS : Switch Mode Power Supply : It transfer power from source (mains) to the computer. Computer system
requires around 300 w to 500 watts of power supply.

UPS : Uninterrupted Power Supply: It supply the power at following circumstances.


a) Power line disturbance b)Power outage
c) Over voltage d) Under voltagee) Lighting
Types of UPS : 1) Online UPS 2) Offline UPS
1) Online UPS : The inverter is directly connected to the device and it always on to give the required current to
the device.
2) Offline or standby UPS : The input current is directly connected to the device, if there is voltage drop or
mains failure, it switches on the inverter to give AC power to the device.

******
Chapter-2

BOOLEAN ALGEBRA

Introduction:
 An algebra that deals with binary number system is called “BooleanAlgebra”.
 It is very power in designing logic circuits used by the processor of computersystem.
 The logic gates are the building blocks of all the circuit in acomputer.
 Boolean algebra derives its name from the mathematician George Boole (1815-1864) who is
considered the “Father of symboliclogic”.
 Boolean algebra deals with truth table TRUE andFALSE.
 It is also called as “SwitchingAlgebra”.

Binary Valued Quantities – Variable andConstants:


 A variable used in Boolean algebra or Boolean equation can have only one of two variables. The two
values are FALSE (0) and TRUE(1)
 ASentencewhichcanbedeterminedtobeTRUEorFALSEarecalledlogicalstatementsor
truth functionsand the results TRUE or FALSE is called Truth values.

 The variables which can store the truth values are called logical variables or binary valued variables.
These can store one of the two values 1 or0.
 The decision which results into either YES (TRUE or 1) or NO (FALSE or 0) is called Binary decision.
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 possiblescenarios.
 Example: Consider the logicalexpression
Y = AAND B(Logical Variables: Y, A, B, Logical OperatorAND)

A B Y=A.B

0 0 0

0 1 0

1 0 0

1 1 1

 If result of any logical statement or expression is always TRUE or 1, it is called Tautologyand if the
result is always FALSE or 0, it is called Fallacy.

Logical Operators:
 There are three logical operator, NOT, OR andAND.
 These operators are now used in computer construction known as switchingcircuits.

NOTOperator:
 The Not operator is a unary operator. This operator operates on singlevariable.
 The operation performed by NOT operator is calledcomplementation/negation.
 The symbol we use for it isbar.
 𝐗means complementation ofX
 IfX=1,X=0 If X=0,X=1
 The Truth table for the NOT operatoris:
X ̅
X
1 0

0 1
OROperator:
 The OR operator is a binary operator. This operator operates on twovariables.
 The operation performed by OR operator is called logicaladdition.
 The symbol we use for it is‘+’.
 Example: X + Y can be read as X ORY
 The Truth table and the Venn diagram for the OR operatoris:

X Y X+Y
0 0 0
0 1 1
1 0 1
1 1 1
ANDOperator:
 The AND operator is a binary operator. This operator operates on twovariables.
 The operation performed by AND operator is called logicalmultiplication.
 The symbol we use for it is‘.’.
 Example: X.Y can be read as X ANDY
 The Truth table for the AND operatoris:

X Y X .Y
0 0 0
0 1 0
1 0 0
1 1 1

BooleanPostulates:
 The fundamental laws of Boolean algebra are called as the postulates of Booleanalgebra.
 These postulates for Boolean algebra originate from the three basic logic functions AND, OR andNOT.
 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
b. 0 + 1 =1
c. 1 + 0 =1
d. 1 + 1 =1
III. AND relation ( LogicalMultiplication)
a) 0 . 0 =0
b) 0 . 1 = 0
c) 1 . 0 =0
d) 1 . 1 =1
IV. ComplementRules

a) 0̅ = 1 b) 1̅ = 0
Principle of DualityTheorem:
 This is very important principle used in Booleanalgebra.
 Principle of Duality statesthat;
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 by0.
 Example: Find the duals for the following BooleanExpression

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

BooleanTheorems:

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 ̅= 1
X +X 18 XY + XY = X
8 ̅= 0
X .X 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
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 perfectinduction.

Theorem 1: 0 + X = X

Proof: If X = 0 Proof: If X = 1 Using Truth table


then LHS then LHS
=0+X =0+X 0 X 0+X
=0+0 =0+1
0 0 0
=0 =1
= RHS = RHS 0 1 1
Theorem2: 1+X=1

Proof: If X = 0 Proof: If X = 1 Using Truth Table


then LHS then LHS
=1+X =1+X 1 X 1+X
=1+0 =1+1
1 0 1
=1 =1
= RHS = RHS 1 1 1

Theorem3: 0.X=0

Proof: If X = 0 Proof: If X = 1 Using Truth Table


then LHS then LHS
=0.X =0.X 0 X 0 .X
=0.0 =0.1
0 0 0
=0 =0
= RHS = RHS 0 1 0

Theorem4: 1.X=X

Proof: If X = 0 Proof: If X = 1 Using Truth Table


then LHS then LHS
=1.X =1.X 1 X 1 .X
=1.0 =1.1
1 0 0
=0 =1
= RHS = RHS 0 1 1

Indempotence Law: “This law states that when a variable is combines with itself using OR or AND operator, the
output is the samevariable”.

Theorem5: X + X =X

Proof: If X = 0 Proof: If X = 1 Using Truth Table


then LHS then LHS X X X+X
=X+X =X+X
0 0 0
=0+0 =1+1
=0 =1 1 1 1
= RHS = RHS
Theorem 6: X . X =X

Proof: If X = 0 Proof: If X = 1 Using Truth Table


then LHS then LHS
=X.X =X.X X X X .X X
=0+0 =1.1 .
0 0 0
=0 =1 X
= RHS = RHS 1 1 0 0
1
Complementary Law: “This law states that when a variable is Anded with its complement is equal to 0 and a
variable is OR ed with its complement is equal to1”.
Theorem 7: ̅= 1
X+𝐗

Proof: If X = 0 Proof: If X = 1 Using Truth Table


then LHS then LHS
= X +X = X +X X ̅
X ̅
X +X
=0+1 =1+0
0 1 1
=1 =1
= RHS = RHS 1 1 1

Theorem 8: ̅=0
X .X
Proof: If X = 0 Proof: If X = 1 Using Truth Table
then LHS then LHS
X ̅
X ̅
X .X
̅
= X.X ̅
= X .X
0 1 0
=0.1 =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 given variable value itself.

Theorem9: ̿
X= X
Proof: If X = 0, thenX =1 Using Truth Table
Take complement again, thenX = 0 i.e. X If X = 1, thenX =0
Take complement again, thenX = 1 i.e. X
X ̅
X ̿
X

0 1 0

1 0 1
Commutative Law: “This law states that the order in which two variable are Ored or AND ed make
nodifference”.

Theorem 10: X + Y = Y +X
Proof: If Y = 0 Proof: If Y = 1 Using Truth Table
thenLHS = X +Y thenLHS = X +Y
X Y X+Y Y+X
=X+0 =X+1
=X =1 0 0 0 0
RHS = Y +X RHS = Y +X
=0+X =1+X 0 1 1 1
=X =1 1 0 1 1
Therefore LHS = RHS Therefore LHS = RHS
1 1 1 1

Theorem 11: X . Y = Y .X

Proof: If Y = 0 Proof: If Y = 1 Using Truth Table


thenLHS = X .Y thenLHS = X .Y
=X.0 =X.1 X Y X.Y Y.X
=0 =X
0 0 0 0
RHS = Y .X RHS = Y .X
0 1 0 0
=0.X =1.X
=0 =X 1 0 0 0
Therefore LHS = RHS Therefore LHS = RHS 1 1 1 1
Associative Law: “This law allows the removal of brackets from an expression and regrouping of thevariables”.

Theorem 12: X.(Y.Z) = (X.Y).Z


Proof: If Y = 0 LHS Proof: If Y = 1 LHS
=X.(Y.Z) =X.(Y.Z) Using Truth Table
=X.(0.Z) =X.(1.Z)
= X.0 = X.Z X Y Z XY YZ X.(Y.Z) (X.Y).Z
=0 = XZ RHS 0 0 0 0 0 0 0
RHS = (X.Y).Z =(X.Y).Z
0 0 1 0 0 0 0
= (X.0).Z =(X.1).Z
= 0.Z = X.Z 0 1 0 0 0 0 0
=0 = XZ 0 1 1 0 1 0 0
Therefore LHS =RHS Therefore LHS =RHS 1 0 0 0 0 0 0
1 0 1 0 0 0 0
1 1 0 1 0 0 0
1 1 1 1 1 1 1

Theorem 13: X+(Y+Z) = (X+Y)+Z


Proof: If Y = 1 Using Truth Table
Proof: If Y = 0 LHS = X+(Y+Z) X Y Z X+Y Y+Z X+(Y+Z) (X+Y)+Z
LHS = X+(Y+Z) = X+(1+Z) 0 0 0 0 0 0 0
= X+(0+Z) = X+1
0 0 1 0 1 1 1
= X+Z =1
RHS = (X+Y)+Z RHS = (X+Y)+Z 0 1 0 1 1 1 1
= (X+0)+Z = (X+1).Z 0 1 1 1 1 1 1
= X+Z = 1+Z 1 0 0 1 0 1 1
Therefore LHS =RHS =1 1 0 1 1 1 1 1
Therefore LHS = RHS
1 1 0 1 1 1 1
1 1 1 1 1 1 1

Distributive Law:
1) X.(Y+Z) = XY + XZ
Proof: If X = 0 LHS Proof: If X = 1
=X.(Y+Z) LHS =X.(Y+Z)
=0.(Y+Z) =1.(Y+Z)
=0 = Y+Z RHS
RHS = XY + XZ = XY +XZ
= 0.Y+0.Z =1.Y+1.Z
=0 = Y+Z
Therefore LHS =RHS Therefore LHS =RHS

Absorption Law:

1) X+XY = X 2) X (X+Y) = X
LHS = X +XY LHS = X(X+Y)
= X (1 + Y) = XX + XY
=X = X + XY
= RHS = X (1+Y)
=X
Other Boolean laws:

(X+Y)(X+𝐗)= X ̅Y=X+Y
X +𝐗 ̅ + Y)=XY
X.(𝐗 XY + X𝐗
=X
LHS LHS = X +XY LHS =X (X+Y) LHS =XY+ XY
=(X+Y)(X+ = (X +X ) = X.X + X.Y = X(Y+Y)
Y) (X+Y) = 0 + XY = X.1
= XX + XY + XY +YY = 1. (X+Y) = XY =X
= X + XY + XY + 0 =X+Y = RHS = RHS
= X (1 +Y + Y) =RHS
= X. 1
=X

DeMorgan’s Theorem:

I Theorem:
Statement: Complement of the sum is the product of their complements.

̅̅̅̅̅̅̅
X+Y=X ̅.Y
̅
Proof : De Morgan’s I theorem by using Truth Table:

X Y 𝐗 𝐗 X+Y ̅̅̅̅̅̅̅
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

̅̅̅̅̅̅̅
ColumnX ̅.Y
+ Yand X ̅are same. Hence the De Morgan’s first theorem isproved.

IITheorem:Statement: Complement of the product is the sum of their complements.


̅̅̅̅̅
X. Y = X̅ + Y̅

Proof: De Morgan’s Second theorem by using Truth Table:

X Y ̅
X ̅
Y X.Y ̅̅̅̅̅
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

̅̅̅̅̅
Column X. Yand X̅ + Y̅are same. Hence theDeMorgan’s Second theorem isproved.

Application of De Morgan’sTheorem:
- It is used in simplification of Boolean expression.
- De Morgan’s law commonly apply to text searching using Boolean operators AND, OR and
NOT.
- It is useful in the implementation of the basic gates operations with alternativegates.
Simplification of BooleanExpression:
 Boolean expressions can be simplified by two methods:
o Algebraic method
o KarnaughMap

 Algebraic Method:

Example : Example:
Prove algebraically X (X + Y) = X X + XY = X (Absorption law)
LHS = X (X + Y) X + XY = X
= XX+XY X(1 + Y) =X
= X+XY  X.X = X X(1)=X (1 + Y = 1) properties of 1 X =X
= X ( 1+Y)
= X ( 1) = X = RHS  1+Y=1
Karnaugh Map method (K-MAP)
To Simplify the Boolean expression in Karnaugh Map method it is essential to knoe min and max terms.
Minterm:
 Minterm is a product of all the literal (with or without bar) within the logicsystem.
 (OR) A single variable or the logical product of several variables. The variables may or may not
becomplemented.
 Avariable mayappear eitherin its normal form (X)or in its complement form (X )
 If a variable value is 0 then its complementedotherwise it is in its normalform.
 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 standardproduct.

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 mi where i denotes the decimal
equivalent of the binary number of the Mintermdesignated.
 For example, the Minterm𝐗 𝐗 Z̅whose combination is 1 1 0 can be written as m6as decimal equivalent of
1 1 0 is6.
 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 thoseterms (This is known as SOP – Sum of Products).
 Sum of Product (SOP): A Sum of all product term or several product terms logicallyadded.

Maxterm:
 Maxterm is a sum of all the literal (with or without complement) within the logicsystem.
 Avariable mayappear eitherin its normal form (X)or in its complement form( ̅ X)
 If a variable value is 1 then its complementedotherwise it is in its normalform.
 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 Booleanexpressions
terms and is called a Minterm or a standard product.
X Y Minterm Designation
0 0 X+Y M0
0 1 X+̅
Y M1
1 0 ̅+Y
X M2
1 1 ̅+Y
X ̅ M3
- A symbol for each Maxterm is also shown in the table and is of the form M i where i denotes the decimal
equivalent of the binary number of the Maxtermdesignated.
- For example, the Maxterm𝐗 + 𝐗 + Z̅whose combination is 0 0 1 can be written as M1as decimal
equivalent of 0 0 1 is1.
- A Boolean expression may be represented from a given truth table by forming a Maxterm for each
combination of the variables which produces as 0 in the function, and then taking the AND (Logical
Multiplication) of all thoseterms.
- Assume the truthtable

X Y Z Output Minterm Designation


0 0 0 0 X+Y+Z M0
0 0 1 0 𝐗 + 𝐘 + Z̅ M1
0 1 0 1 ̅+Z
X +Y M2
0 1 1 1 ̅ + Z̅
X +Y M3
1 0 0 0 ̅+ Y + Z
X M4
1 0 1 0 ̅ + 𝐘 +𝐙̅
X M5
1 1 0 1 ̅ +Y
X ̅+ Z M6
1 1 1 0 ̅
X+̅
Y + Z̅ 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).
- 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 7thMaxterm.
- Product of Sum (POS): A sum term or several sum terms logicallymultiplied.
Canonical Form:

- Boolean expression expressed as sum of Minterms or product of Maxterms are called


canonicalforms.
- For example, the following expressions are the Minterm canonical form and Maxterm canonical form
of two variables X and Y.
̅Y
Minterm Canonical = f(X, Y) = X ̅+ X
̅Y +X Y
̅+ XY
̅).(X
Maxterm Canonical = f(X, Y) = (X +Y).(X +Y ̅+Y
̅)
Karnaugh Map:
- A graphical display of the fundamental products in a truthtable. Fundamental Product: The
logical product of variables and complements that produces a high output for a given
inputcondition.
- The map method provides simple procedure for minimizing the Booleanfunction.
- The map method was first proposed by E.W. Veitch in 1952 known as “VeitchDiagram”.
- In 1953, Maurice Karnaugh proposed “Karnaugh Map” also known as“K-Map”.
Construction ofK-Map:
- The K-Map is a pictorial representation of a truth table made up ofsquares.
- Each square represents a Minterm orMaxterm.
- A K-Map for n variables is made up of 2nsquares.

Single Variable K-Map:


- There are two Minterms (A andA̅ ) for onevariable.
- Hence the map consists of 2 squares (i.e. 2n square, 21 = 2square)

̅
A A
0 1

 In one variableK-map:
- One square represents oneMinterm.
- Two adjacent squares represents a function which is always true i.e. f (A) =1.

Two VariableK-Map:
̅B
- There are fourMinterms(A ̅ B, A B
̅, A ̅ and AB fortwovariable).
- Hence the map consists of 4 squares (i.e. 2n square, 22 = 4square)

̅
B B
̅
𝐀 00 01

A 10 11

Three VariableK-Map:
- 3-variable K-map consists of 8 squares (i.e. 2n square, 23 = 8square)

̅C̅
B ̅C
B BC B C̅
̅
A 000 001 011 010

A 100 101 111 110

Four VariableK-Map:
 The four variable Boolean expressions are of the form f (A, B, C,D).
 There are sixteen Minterms for fourvariables.
 Hence the map consists of 8 squares (i.e. 2n square, 24 = 16square).
 The rows and columns are numbered in a reflected codesystem.

C̅D
̅ C̅ D CD ̅
CD

̅B
A ̅ 0000 0001 0011 0010
̅B
A 0100 0101 0111 0110
AB 1100 1101 1111 1110
̅
AB 1000 1001 1011 1010
Entries in the K-Map:
Each square represents a min-term or a max-term. Enter 1’s for the min terms in the expression (0’s for the max-
terms).
Pair – two adjacent 1’s form a pair
Quadrant - four adjacent 1’s form a quadrant
Octet - fight adjacent 1’s form an octet (Try from Octet to pair order)
Examples:

1. Given the Boolean function F(a,b,c,d) = ∑(0,1,2,3,4,6,8,10,12,14). Reduce it by using Karnaugh map.

2. Draw K-map and write the reduced expression for F(A,B,C,D) = ∑ (0,1,2,3,8,9,10,11,13)
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 outputsignal.
 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 Booleanalgebra.
 Gates are classified into twotypes: Basic Gates – AND, OR, NOT Derived Gates – NOR, NAND, XOR, XNOR

BasicGates:
NOT Gate:

 A NOT gate has only one input and oneoutput.


 The output state is always the opposite of the inputstate.
 A NOT Gate is also called as Inverter gate, because the output is not same as theinput.
 The output is sometimes called the complement (opposite) of theinput.
 The logical symbol andthetruth table for NOT gate are givenbelow.

X
X ̅
X
0 1
1 0

OR Gate:
 A OR gate has two or more input signal but only one outputsignal.
 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 givenbelow.

X Y X+Y
X X+Y 0 0 0
0 1 1
1 0 1
Y 1 1 1

AND Gate:
 A AND gate has two or more input signal but only one outputsignal.
 When all the input signals are 1 (high), the output is 1 (high), otherwise the output is0.
 The logical symbol for two-input AND gate and the truth table is givenbelow.

X X Y 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 outputsignal.
 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 a1.
 NOR is short form ofNOT-OR.
 The logical symbol for two-input NOR gate and thetruthtable
̅̅̅̅̅̅̅
X+Y
X X+Y

X Y ̅̅̅̅̅̅̅
X+Y
0 0 1
0 1 0
1 0 0
1 1 0
NAND Gate:
 A NAND gate has two or more input signal but only one outputsignal.
 The NAND gate is a complemented of ANDgate.
 The output of NAND gate will be 0 only when all inputs are 1 and output will be 0 if any input represents
a0.
 NAND is short form ofNOT-AND.
. TRUTH Table
X X.Y
X Y X.Y
Y
0 0 1
0 1 1
1 0 1
1 1 0

XOR (Exclusive-OR)Gate:
 An exclusive-OR has two or more input signal but only one outputsignal.
 Exclusive-OR gate is different form of ORgate.
 Exclusive-OR gate produces output 1 for only those input combinations that have odd number of1’s.
 The output is 0 if there are even number of 1’s in theinput.
 The output is 1 if there are odd number of 1’s in theinput.
 In Boolean algebra ⊕ sign stands for XOR operation. Thus X XOR Y can be written asX⊕Y
 If the output is givenby:
F=X⊕Y
 The following truth table illustrates XOR operation for 2 and 3inputs.

Number Input Output


Of 1’s X Y F=X⊕Y
EVEN 0 0 0
ODD 0 1 1
ODD 1 0 1
EVEN 1 1 0
XNOR (Exclusive-NOR)Gate:
 The XNOR gate is complement of XORgate.
 The output of XNOR is 1 only when the logic values of both X and Y is same i.e. either both are equal to 1 or
both are0.
 Its output is 0 when its inputs aredifferent.
 In Boolean algebra, ʘ sign stands for XNOR operation. Thus X XNOR Y can be written as X ʘY

Number Input Output


Of 1’s X Y ̅̅̅̅̅̅̅̅
𝑋⊕Y
EVEN 0 0 1
ODD 0 1 0
ODD 1 0 0
EVEN 1 1 1
Universal Gate (NAND &NOR):

 Universal gate is a gate using which all the basic gates can bedesigned.
 NAND and NOR gate re called as Universal Gates, because all the Boolean functions can also be
implemented using these twogates.(All basic gates can be designed using NAND and NOR universal gates.

NAND as AND NAND as OR


NAND as NOT

̅̅̅̅̅ ̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿ ̅̅̅̅̅


X. X= ̅
X
̿̿̿̿̿
X. Y = X.Y ̅̅̅̅̅̅
(X. X) ̅̅̅̅̅̅̅̅̅
. ( Y. Y) = ̅̅̅̅̅
X. Y = X+Y

NOR as AND NOR as OR NAND as NOT

̅̅̅̅̅
X. X= ̅
X
̅̅̅̅̅̅̅
a + b = ̅̅̅̅̅̅̅
̿̿̿̿̿̿̿ a̅ + b̅ = a.b
̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿
̅̅̅̅̅̅̅̅ +( b + b) = ̅̅̅̅̅̅̅
(a + a) ̅̅̅̅̅̅̅̅̅̅̅̅ a̅ + b̅ = a.b
Chapter 4
DATA STRUCUTRE
Data Structure : It is a specialized format for organizing and storing of data.
Primitive data structure : The data structures which are directly operated on machine level instructions.
Ex :int, float, pointers etc…

Non-primitive data structure : The data structures which are derived from primitive data structures are called non-
primitive operating system.
Ex : arrays, lists, files etc…
Operations performed on primitive data structures
1) create (2) destroy (3) select (4) update
(1) create : This operation is used to create new data structure.
(2) destroy : This operation is used to remove unwanted data structures.
(3)select : This operation is used to extract required data from data structure
(4) update : This operation is used to modify the contents of a data strucutre

Linear data structure : The collection of homogeneous elements arranged in a linear order
Eg : stacks, queues, linked list etc…
Operations performed on linear data structure
1) traversing : This operation is used to visit or access each element of the list at least once
2) inserting : This operation is used to add a new element into the list.
3) deleting : This operation is used to remove an unwanted element from the list
4) searching : This operation is used to find the location of the element in the list
5) sorting : This operation is used to arrange the elements in ascending or descending order

Arrays
It is a collection of homogeneous elements all are of same type same name.
Advantages or applications of Arrays
1. The number of similar type of elements can be stored under single name.
2. 2 dimensional array is used to implement matrix applications
3. Arrays are used to implement other data structures like stacks and queues.
Disadvantages of Arrays
1. The array size must be pre-known
2. Only similar type of elements can be stored.
3. These may be a chance of shortage and wastage of memory.
Types of Arrays
1) One dimensional array
2) Two dimensional array
3) Multi dimensional array
1) One dimensional array :
Declaration :
data type array name[size];
ex :int a[10];
initialization : memory representation
data type array name[size] = { elements};
int a[5] = { 10, 20, 30, 40, FIFTY};
int a[0] = 10
int a[1] = 20
int a[2] = 30
int a[3] = 40
int a[4] = 50
Algorithm for Traversing an array
Step -1 : for ( I = 0 to n-1)
Step-2 : input a[i]
End for
Step-3 : stop
Algorithm for inserting an element
Step-1 : for (i=n-1 down to p)
Step-2: a[i+1] = a[i]
End for
Step-3: a[p] = ele
Step-4: n=n+1
Step-5: stop
Write an algorithm for deleting an element
Step 1 :ele=a[P];
Step 2 : for (I = P to n-1)
Step 3 : a[i] = a[i+1]
End for
Step 4 : n = n-1
Step 5 : stop
Searching : Finding the location of an element
(1) linear search
(2) binary search
Linear search : In this method searching can be done sequentially one after the other.
Write a algorithm to search an element using linear search method.
Step 1 - loc=-1
Step 2 – for (i = 0 to n-1)
Step 3 – if (ele == a[i])
Step 4 – loc = i
Go to step 5
end if
end for
step 5 – if (loc>= 0)
step 6 – print “Element found at “ loc+1
else
step 7 - print “element not found”
end if
step 8 – stop
Binary search : In this method searching can be done by dividing it into 2 groups.

write an algorithm for binary search method


step 1 – loc=-1, l=0, n=n-1
step 2 – while (1 <= h)
step 3 – m = (l+h)/2
step 4 – if (a[m] == ele)
step 5 – loc = m
step 6 – goto step 10
else
step 7 – if (ele> a[m])
step 8 – l = m + 1
else
step 9 – h = m – 1
end if
end if
end while
step 10 – if (loc>= 0)
print “element found at “ loc + 1
else
step 12 – print “ element not found”,
step 13 – stop

Sorting : arranging an element in ascending or descending order

Write an algorithm to sort the elements using insertion sort method [ ascending]
Step1 : for (I = 0 to n-1)
Step 2 : j = i
Step 3 : while (j >= 1)
Step 4 : if (a[i] < a[j-1])
Step 5 : temp = a[j]
Step 6 : a[j] = a[j-1];
Step 7 : a[j-1] = temp;
End if of step 4
Step 5 : j = j-1
End while
end for
2) Two dimensional array
Declaration:
Data type array name [row size][column size]
Ex :int a [3][3];
Initialization / memory representation
Data type array name [ row size][column size] = {elements};
Inta[[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

1 2 3
[4 5 6]
7 8 9

Row major matrix(Row major ordering)


int a[0][0] = 1
int a[0][1] = 2
int a[0][2] = 3
int a[1][0]= 4
int a[1][1] = 5
int a[1][2] = 6
int a[2][0] = 7
int a[2][1] = 8
int a[2][2] = 9
Column major matrix (Column major ordering)
int a[0][0] = 1
int a[1][0] = 4
int a[2][0] = 7
int a[0][1]= 2
int a[1][1] = 5
int a[2][1] = 8
int a[0][2] = 3
int a[1][2] = 6
int a[2][2] = 9
Stacks : It is an ordered collection of data item where insertion and deletion takes place at same end.
Insertion and deletion can be done from top position of the stack, opposite to the top is called base.
Stacks follows ‘LIFO’ rule [Lost In First Out].

Operations performed on Stacks


1) stack () (2) push (item) (3) pop() (4)isempty()
5)size() (6)peek()
1) stack () : This operation is used to create new empty stack ( no parameters are required returns nothing)
(2) push (item) : This operation is used 10 add a new data item to the top of stack [ parameters are required but
returns nothing].
(3) pop() : This operation is used to remove the top item from the stack [no parameters are required but returns
data item]
(4)isempty() : This operation is used to check whether the stack is empty or not [returns the Boolean value].
(5)size(): This operation returns number of data items in the stack [ returns integer value]
(6)peek() : This operation returns top item from thestack but it is not modified.

Write an algorithm for push operation:


Step 1: if (top == n-1)
Step 2 : print “stack is full” [over flow]
Step 3 : exist ()
End if
Step 4 : top = top+1
Step 5 : stack (top) = item
Step 6 : stop
Write an algorithm for pop operation
Step 1: if (top = -1)
Step 2 : print “stack is empty” [under flow]
Step 3 : exist ()
End if
Step 4 : item = stack [top]
Step 5 : top = top-1
Step 6 : stop
Applications of stacks
1. Reversing a string
2. Undo mechanism
3. Back tracking
4. Expression evaluation
5. Tower of honai
6. Quick sort
Queues : It is an ordered collection of data item where insertion and deletion takes place at different ends
Deletion  insertion
Front 0 1 2 3 4 Rear
It follows “FIFO” rule [First In First Out]
Types of Queues:
1. Simple Queue
2. Circular Queue
3. Priority Queue
4. Double ended Queue
1) Simple Queue : In this type of Queue insertion can be done at reare end and deletion can be done at front end
Front  Rear

A B C
0 1 2
2) Circular Queue : In this type of Queue it follows circular path. The last node follows the first node.

A B C D
0 1 2 3

3) Priority Queue : In this type of Queue insertion and deletion can be done from any position based on the pre-
set priority.


4) Double ended Queue : In this type of Queue insertion and deletion can be done from both the ends

A B C

Operations performed on Queues:
1) Queue () (2) Enqueue () (3) dequeue() (4)size() (5)isempty()
1) Queue () : This operation is used to create a new empty Queue [ no parameters returns nothing]
(2) Enqueue () : This operation is used to (insert) add a new item to the rear end of queue [ parameters are
required returns nothing]
(3) dequeue() : This operation is used to remove data item from front end of queue [no parameters are required
but returns data item]
(4)size():This operation returns number of data items in the queue [from the queue] [returns integer value]
(5)isempty() : This operation is used to check wheather the queue is empty or not [returns Boolean value]

(1) Write an algorithm to insert an element into the queue [ enqueue]


Step 1 : if (Rear = N)
Step 2 : print “Queue is full”
Step 3 : exit()
End if
Step 4 : if (Front = NULL)
Step 5 : Front = 0
Step 6 : Rear = 0
Else
Step 7 : Rear = Rear + 1
End if
Step 8 : Queue [Rear] = item
Step 9 : stop
(2) Write an algorithm to delete an element from the queue [ dequeue]
Step 1 : if (Front = NULL)
Step 2 : print “Queue is empty”
Step 3 : exit()
End if
Step 4 : item = Queue[Front]
Step 5 : if (Front = Rear)
Step 6 : Front = 0
Step 7 : Rear = 0
Else
Step 8 : Front = Front + 1
End if
Step 9 : stop
Application of Queue
1. Printer server rooting
2. Multi-programming
3. CPU – scheduling
4. Round-robin system
5. Some process of operating system
6. Simulation etc…
Linked list : It is a linear collection of data items called nodes and each node reffered by means of pointers
Linked list used dynamic memory allocation [ dynamic : as and when required we can increase or decrease the
memory allocation]
Types of linked list
1) Singly linked list
2) Circular linked list
3) Doubly linked list
1) Singly linked list: In this type each node has 2 parts one is data field and the another is link field of next node.
[Last node link field must be null]
2) Circular linked list : In this type all the nodes are connected in a circular path the last node follows the first
node.

start
 10 P2 20 P3 30 P1

P1 P2 P3
3) Doubly linked list : In this type each node contains three parts : (1) backward reference(2) data field
(3) forward reference
First node backward reference will be null and the last node forward reference will be null
  P 30 \
\ 10 P2 P1 20 P3 2
 
P1 P2 P3
New and delete operations
New : This operator allocates the memory space dynamically
Ex : int *p ; int *p;
P = new int p; p = new int;
P = new[10];
Delete: This operator deallocates the memory space dynamically
Ex :int *p;
P = delete[]
Operations performed on linked list
1. Creating a linked list
2. Inserting an element into the list
3. Deleting an element from the list
4. Searching an element from the list
5. Sorting elements of the list
Memory representation of stacks
Static representation
Insertion deletion
Top = top +1 item = stack [top]
Stack[top] = item top = top-1
= 5 -1 = 4
Top = 4
Memory representation of Queues
Front  Rear A B C

0 1 2
Insertion:
Rear = Rear + 1
=2+1=3
Queue[Rear] = item

A B C D
0 1 2 3

Deletion
Item = Queue[Front]
Front = Front + 1
0+1

B C

0 1 2 3
Non-linear data structure
The data structure in which each node is connected with several other nodes.
Ex : graph, tree
Graph : A graph is a collection of vertices and edges which are connected.
Tree : A tree is a collection of root node and its sub nodes.
Root node : A node at the top of a tree which do not have any parent node.
Leaf node or chain node : A node at bottom of a tree which do not have any sub nodes.
Internal node : A node which have both parent and leaf node.
Height : The number of nodes traversed from root
Depth : height + 1
Chapter 5

Review of C++

It is a an Object Oriented Programming(OOP) language. OOP emphasizes on data.

Characteristics of C++

 Object-oriented programming.
 Portability.
 Brevity.
 Modular Programming.
 C Compatibility.
 Speed.
 Machine independent.
 Flexibility.
 Wide range of library functions.
 System Software development.

Procedural programming versus Object Oriented Programming

Procedural programming Object Oriented Programming

Larger programs are developed in terms of Programs are developed in terms of objects.
functions.

Data is not hidden Data is hidden

Follows top-down approach Follows bottom-up approach

Data communicate between the functions Objects communicate with each other according
through arguments/returning value to the respective access specifiers defined in the
associated classes.

Emphasis is on procedure rather than data Emphasis is on data rather than procedure

Advantages of OOP

 Modularity: The programs are modularized based on the principle of classes and objects.
 Data Security: The data is encapsulated along with methods(Functions). Therefore data is hidden or under
controlled access.
 Reusability: The code(program) can be reused through the concept of inheritance.
 Communication: Effective communication is possible between the Objects through the message passing.
 Polymorphism: Operators and functions works in different forms also known as overloading.
Chapter 6

Object oriented programming(OOP)

OOP is the principle of design and development of programs using modular approach.

Object is the basic unit of OOP. An object is a collection of set of data known as member data and the functions that
operate on these data known as member functions or methods.
Objects are created according to the specifications of the entity defined.
To design OOP model, first a set of classes are defined. A class is a template from which objects are created. The
template of a class specifies the data, member functions and their attributes.
Some of the OOP languages are C++, Java, C # and so on.

Major characteristics of OOP

Objects, Classes, Data abstraction, Data encapsulation, Inheritance, Overloading, Polymorphism, Dynamic binding,
Message passing.

Object: An object may represent a person, place or data concerned to real world task. Every object must be a
member of particular class. Objects interacts with each other by sending messages to one another.

Ex: two_wheeler, four_wheeler are the objects of a class vehicles.

Class: A class is a way of grouping objects having similar characteristics. Once the class is defined, any number of
objects of that class are created.

Ex: planets, sun, moon, are members of classsolar_system.

Abstraction: Abstraction refers to the process of representing essential operational features without including
background details or explanations.

Data encapsulation: Data encapsulation provides controlled access to data.


Inheritance: The process of forming a new class from an existing class is known as Inheritance.
Overloading: There are two types of overloading;
1. Operator overloading.
2. Function overloading.
The ability of an operator and function to operate in different forms depending upon problem/programming
context.

Polymorphism:

The ability of an operator and function to take different forms is also known as polymorphism.

Dynamic binding: Dynamic binding is the process of connecting one program to another at the time of program
execution.
Message passing: Communication between objects takes place using message passing. It involves specifying the
object name, the name of the function (message) and information to be send.
Advantages of OOP
1. Programs are modularized based on the principle of classes and objects.
2. Data is encapsulated along with the functions. This provides controlled data access and thereby secures
data.
3. Linking code and object allows related objects to share common code. Hence provides reusability.
4. Complexity can be minimized through inheritance.
5. reduces software develop time .

Limitations of OOP

1. OOP software is not having set standards.


2. The classes are overly generalized.
3. It is difficult to convert real world problem into object oriented model.
4. The adoptability of flow diagrams and OOP using classes and objects is a complex process.
Applications of OOP:

The common application areas of OOP are:

1. Computer graphic applications.


2. CAD/CAM software.
3. Object oriented database.
4. User interface design such as windows.
5. Real-time systems.
6. Simulation and modelling.
7. Artificial intelligence and expert systems.
Chapter 7
Classes and objects
Definition of classes and declaration of objects;
A class definition is a process of naming a class and data variables, and interface operations of the class.
An object declaration specifies the representation of objects of the class and the set of operations that can be
applied to such objects.
The general syntax for defining a class:
classuser_defined_name
{
private:
member_data;
member_functions;
protected:
member_data;
member_functions;
public:
member_data;
member_functions;
};

Ex:
classaccount
{
private:
intaccno;
char name[20];
public:
voidget_data();
voiddisplaydata();
};

Access specifiers
Every member of a class is specified by three types of access protection for hiding data and function. The access
specifiers define the scope of data and functions. Three types of access specifiers are:
1. Private.
2. Protected.
3. Public.
Private: Private access means a member data can only be accessed by the member function.
Protected: These member data can be accessed only by the member functions, friend functions and also by the
member functions derived from the respective class.
Public: These member data can be accessed by any function outside the class also.
Note: If no access specifier is mentioned, then by default, members are private.
Members of the class: The members of a class can be data or functions.
Definition of a member function inside the class definition:
Syntax:
classclass_name
{
Member_data;
Return_typemember_function_name()
{
Member_function_body;
}
};
Ex:
class rectangle
{
intlen, bre;
public:
voidget_data()
{
cin>>len;
cin>>bre;
};
void display()
{
cout<<len;
cout<<bre;
}
};

The syntax for accessing class member is:


Class_object.member_data ;
Class_object.member_function(argument);
Ex:
class rectangle
{
int l;
int b;
public:
voidget_data();
void compute();
void display();
};

Member functions
Member functions defined inside the class definition(inline functions)
Member functions defined outside the class definition

Member functions defined inside the class definition(inline functions)


A function defined in a class is treated as inline function. Only small functions are defined inside class definition.
Member functions defined outside the class definition
A function declared as a member of a class must be defined separately outside the class.
Syntax for defining a member function outside of a class :
Return_typeclass_name::member_function_name(argument/s)
{
Function_body;
}
Ex:
class op
{
private :
int a, b;
public:
int sum();
};
int op::sum()
{
return (a+b);
};
Defining objects of a class:
Once the class is defined object/s are created from that class.
Syntax:
Class_name object_name_1, object_name_2, ...... .;

Ex:
classnum
{
private:
int x, y;
public:
int sum(int p, int q);
};
................
void main()
{
num s1;
s1.sum(50, 75);
};

Here object s1 is created, which belongs to the class ‘num’.


Array as a member of class:
It is possible to use arrays as a member data of class.
Ex:
class mark
{
int m[5];
................;
};

Array of objects
An array having class type elements is known as array of objects.
Ex:
classemp
{
char name[25]; int age;
public: void getdata(); void display();
};
emp team[10];
here ‘team’ is an array of objects.

Object/s as function argument/s :


A function can receive an object as a function argument. An object can be passed to a function in two ways:
1. Copy of entire object is passed to function(pass-by-value).
2. Address of the object is transferred to the function(pass-by-reference)

Ex: method 1
classrup
{
.............
voidmul(rup r1, rup r2)
{
.............
}
};
int main()
{
rup r1, r2, r3 ;
.................
r3.mul(r1, r2);
................
}
Here r1 and r2 are the objects used as arguments with the function ‘mul’

Difference between structure and class


structure class

Defined using the keyword struct Defining using the keyword class

Members are public by default Members are private by default and can be
public and protected with the use of respective
Not possible to use access specifiers access specifiers i.e., public and protect
Chapter 8
Function Overloading
It is a process of creating two or more functions with the same name, which differ in the number of
arguments or data type of arguments. Therefore it is said that function name is overloaded.

 It is also known as run time polymorphism.


 C++ supports two types of overloading i.e. Function overload & Operator Overload
 It supports the feature of polymorphism in OOP’s.
 It also allows the user to create new abstract data types.
 The compiler automatically decides about the appropriate function to be called depending on the arguments
passed
Example: int sum (int a, int b)
{
return (a + b);
}
float sum (float p, float q)
{
return (p + q);
}
In the above example we create 2 functions with the same name sum() but 1 st function accepts 2 integer
values and returns an integer result whereas 2nd function accepts 2 float arguments and returns the float result.
Advantages of function overloading or need for function overloading:

1. Reduces the complexity of the programme.


2. It is easier to understand and debug.
3. Helps in faster execution of programme.
4. Code maintenance is easy.
5. Eliminating the use of different function names for the same operation.
6. Through polymorphism it helps to represent real world objects.
7. Easier interface between programs and real world objects.
Restrictions on Function Overloading:
1) Each overloaded function must be declared and defined separately.
2) Each function must differ in number of arguments of type of arguments.
3) While typedef is used for declaring a function, then it cannot be overloaded.

Calling overloaded functions : The compiler automatically decides about the appropriate function to be called
depending on the arguments passed.

Programming example to compute the area of square/rectangle using function overload

#include<conio.h>
#include<process.h>
#include<iomanip.h>
class overload
{
public: float area(float a) //To compute area of square
{
return(a*a);
}
float area(float l, float b) // To compute area of rectangle
{
return(l*b);
}
};
void main()
{
overload f1;
cout<<”Area of square =”<<f1.area(5)<<endl;
cout<<”Area of rectangle =”<<f1.area(4,3)<<endl;
}

OUTPUT :
Area of square = 25
Area of rectangle = 12

OTHER FUNCTIONS IN A CLASS


Inline functions: The member function whose function call is replaced by the function code or body of the function
is called inline function.
A function defined inside a class is by default inline function.
Features of Inline function :

 The inline functions must be declared as member function of the class.


 It is defined outside the class with the keyword inline.
 Only small and simple functions are made inline.
 Inline function executed faster than normal functions.
 The memory usage is more since if a program calls an inline function many times, the code is replaced by
the call.
Advantages
 Inline functions are small in size and compact.
 Inline functions are executed faster than other functions.
 Efficient code can be generated.
 Readability of the program is increased.
Disadvantage

 The size of the executable file increases and requires more memory.

Inline functions may not work :

 If the function definition is long or complicated.


 If it contains looping construct,
 If it is recursive.
 It it contains switch or goto statements.
Example Programme :

Write a C++ program to find the cube of a number using inline functions.

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class assign
{
private : int n;
public : void getdata( );
void cube( );
};
void assign :: getdata()
{
cout<<”Enter the number”<<endl;
cin>>n;
}
inline void assign :: cube() // Inline definition
{
cout<<”The cube =”<<(n*n*n);
}
void main()
{
clrscr();
assign A;
A.getdata();
A.cube();
getch();
}
Friend functions
A non-member function which can access the private and protected members of the class is called Friend
function.
It is declared within a class with the keyword friend.
It should be defined outside the class like a normal function without the keyword friend. (And also without
class name and scope resolution operator)
Syntax: class class_name
{
public: friend return_type function1(class_name object);
};
When there is a situation where two classes must share a common function. C++ allows the common function to
be shared between the two classes by making the common function as a friend to both the classes, thereby
allowing the function to have access to the private data of both of these classes.
The properties of the friend function are :

1. The function is declared with keyword friend. But while defining friend function it defined as normal function i.e
without keyword friend or :: operator.
2. A class may have any number of friend functions and a function may be friend to any number of classes.
3. It can be declared or placed anywhere in the class i.e. private, public or protected.
4. A friend function cannot be called using the object of that class.
5. It can be invoked like a normal function.
6. The parameter of friend function must be an object of the class to which it is friend.
6. Unlike member function, it cannot access the class members directly, but it can access through the object of the
class to which it is a friend.
Example:
#include <iostream.h>
class sum
{
private:
int a,b;
public:
void getdata( );
friend int add(sum s1);
};
void sum::getdata( )
{
cout<<”Enter two numbers””<<endl;
cin>>a>>b;
}
//Definition of friend function like a normal function
int add(sum s1)
{
return (s1.a + s1.b);
}

void main()
{
sum s;
s.getdata( );
cout<<"Sum of two number is "<<add(s)<<endl;
}

*******
Chapter 9

Constructors and Destructors

Definition : “A constructor is a special member function that is used to initialize the objects or datamembers of a
class automatically”.

 constructor constructs the data members of an object. i.e., it defines a value to the data members.
 It is defined like other member functions of a class.
 It can be defined either inside the class or outside the class but without returntype.
The characteristics or rules for constructor function:
 The name of the constructor must be same as the class name.
 There is no return type for constructors (not even void)
 It should be declared in public section.
 A constructor is invoked automatically when objects are created.
 It can be with parameter or without parameter.
 It is not possible to refer to the address of the constructors.
 The constructors make implicit calls to the operators new and delete to allocate
and de-allocate the memory.
Creation of constructor :
Inside the class definition :
Syntax :class class_name
{
private :datatype variable;
public :class_name()
{
variable = value;
}
};
Example :
classnum
{
private :int x;
public :num( )
{
x=10;
}
};
Outside the class definition :
Example :
classnum
{
private :int x;
public :num( );
};
num :: num()
{
x=10;
}
Programme example to illustrate constructor (initialize and display 2 numbers):
#include<iostream.h>
#include<conio.h>
classnum
{
private :int x, y;
public :num ()
{
x=10;
y=20;
}
void display();
};

voidnum :: display ()
{
cout<<”x=”<<x<<”\t y=”<<y;
}
void main ()
{
clrscr();
num n1;
n1.display();
getch();
}
Practical problem 10. Write a program to find the sum of the series 1+x+x2+x3+…..+xn using constructors.
#include<iostream.h>
#include<math.h>
#include<conio.h>
class series
{
private:
int sum, n,i, x;
public: series() // constructor
{
sum=1; // initialize sum value
}
voidgetdata();
void compute();
void display();
};

void series :: getdata()


{
cout<<"Input base value and power value :"<<endl;
cin>>x>>n;
}
void series::compute()
{
for(i=1;i<=n;i++)
sum=sum+pow(x,i); //check you have included math.h for pow function
}
void series::display ()
{
cout<<"Sum="<<sum;
}
void main()
{
series S; // Create an object
S.getdata();
S.compute();
S.display(); // Display the sum value
}
Types of constructors:
There are three types of constructors, namely:
1. Default constructor
2. Parameterized constructor
3. Copy constructor
1) Default Constructor
Def.: A constructor without arguments or zero arguments is called default constructors.
Features of default constructor are:
1. It is declared and defined with no arguments.
2. It is automatically called for every object created of that class.
3. All the objects of the class are initialized to same set of values by the default constructor.
4. It is not possible to initialize different objects with different values using default constructor.
5. It simply allocates memory to data members of objects.

Note: Declaring a constructor with arguments hides default constructor.


Syntax: class_name::class_name( ) //constructor without arguments
{
data member = value;
}
Example: series::series( )
{
sum = 0;
}
Program to show initialization of an object using default constructor or constructor without argument.

#include<iostream.h>
#include<iomanip.h>
classnum
{
private:
int a, b;
public:
num()
{
a=10, b=20;
}
void display()
{
cout<<"a = "<<a<<" b = "<<b<<endl;
}
};

void main()
{
num E1;
E1.display();
}
Disadvantages of default constructor:

1. All objects of the class gets initialized to same set of values by default constructor.
2. The default constructor simply allocates memory to data members of objects.
3. Default constructor cannot be overloaded.
2) Parameterized Constructors: A constructor with arguments or that takes one or more arguments is called
parameterized constructor

Features of parameterized constructors:


1. It must be declare and defined with parameters
2. It is also invoked automatically when objects with arguments are created.
3. The parameterized constructors can be overloaded by creating multiple constructors with different
arguments.
4. The parameterized constructor can have default arguments and default values.
Invoking constructors
A default constructor is automatically invoked by C++ compiler when the object is created.
There are three methods of invoking parameterized constructor :
1. Explicit call
2. Implicit call
3. Initialization with assignment (‘=’) operator
1) Explicit call
In this method, the declaration of an object is followed by assignment operator,constructor name and
argument list enclosed in parenthesis.
Example: num n1=num(10,20);
num n2=num(40,50);
where in ‘num’ is the class name and n1 and n2 are objects
Program to illustrate constructor through explicit call:
#include<iostream.h>
classnum
{
private:
intm,n;
public:
num(int p, int q)
{
m = p;
n = q;
}
void display()
{
cout<<"m = "<<m<<" and n = "<<n<<endl;
}
};
void main()
{
num n1=num(10,20); // Explicit call
n1.display();
}

OUTPUT : m = 10 and n = 20
2) Implicit call
In this method the declaration of the object is followed by argument list enclosed in parentheses.
Example: numn1(10,20);
num n2(40,50);
where in ‘num’ is the class name an n1 and n2 are objects

Program to illustrate constructor through implicit call:


#include<iostream.h>
classnum
{
private:
intm,n;
public:
num(int p, int q)
{
m = p;
n = q;
}
void display()
{
cout<<"m = "<<n<<" and n = "<<n<<endl;
}
};
void main()
{
num n1(25,35); //Implicit call of object n1
n1.display();
}
OUTPUT : m = 25 and n=35
Note : The arguments are passed with only the object name and without assignment operator and constructor
name.

3) Initialization at the time of declaration with assignment (‘=’) operator


This method is used for the constructor with exactly one argument. The declaration of the object is followed by
assignment operator and the value to be initialize without constructor name.
Example: num n1=100;
num n2=400;
#include<iostream.h>
classnum
{
private:
int m;
public:
num(int p)
{
m = p;
}
void display()
{
cout<<"m = "<<m<<endl;
}
};
void main()
{
num n1=100;
n1.display();
}
Copy constructor

Copy constructor is a parameterized constructor using which one object can be copied to another object.
Syntax : Class_name Object1 (parameter);
Object2 = Object1;
Example: num a1 (10,20);
num a2 = a1; //copy constructor
Here the object a2 is initialized by using an existing object a1.
Copy constructors are used in the following situations.
 To initialize an object by another object of same class.
 When objects must be returned as function values.
 When we use objects as pass-by-value parameters of a function.
Invoking a Copy Constructor:
1. Copy constructor is not invoked explicitly.
2. Copy constructor is invoked automatically when a new object is created and equated to an already existing object.
Example: nums1(20, 30);
num s2 = s1; //copy constructor
3. When a new object is declared and existing object is passed as a parameter to it in the declaration, then also copy
constructor is invoked.
Example : num s1(100,200); //parameterized constructor
num s2(s1);
//copy constructor is invoked for object s2 with s1 as parameter
4. Copy constructor is invoked when an object returns a value.
Example programme to find the factorial of a number using copy constructor
#include<iostream.h>
class fact
{
private: int f, n i;
public:
fact(int m)
{
n = m;
}
void process();
void display ();
};
void fact :: process()
{
int f = 1;
for(int i = 1; i<= n; i++)
f = f * i;
}
void fact :: display()
{
cout<<”the factorial =”<<f;
}
void main()
{
fact f1(4);
fact f2=f1; //copy constructor
f1.process();
f1.display();
f2.process();
f2.display();
}
Constructor Overloading: A class can have two or more constructors with the same name but with different in their
number of arguments or data types of their arguments , or both.

Depending on the type and number of arguments passed, the compiler decides which version of the constructor to
invoke during object creation.

The following example has overloaded constructor that is used to specify the input values for the data members of
the class.

A program to find the area of a square, rectangle using constructor overloading.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class area
{
public: area();
area(int);
area(int,int);
};
area::area()
{
cout<<”Default constructor being called”<<endl;
}
area::area(int a)
{
cout<<”area of the square =”<<a*a<<endl;
}
area::area(int l, int b)
{
cout<<”area of the rectangle =”<<l*b<<endl;
}
void main()
{
area a1;
area a2(4);
area a3(4,5);
}

Destructors: A destructor is a special member function that is use to deallocate all the resources like memory when
the object of the class is destroyed.
It is automatically called when the object is destroyed or variables go out of scope.
The name of the destructor name must be same as the class name but preceded by
symbol tilde (~).

Syntax: class classname


{
private: data variables
public: classname(); //constructor
~classname(); //destructor
};
Example:
class sum
{
private :inta,b,s;
public : sum()
{
s=0;
}
~sum();
};

Features of or rules for creating destructor :


1. The destructor name is same as that of class and proceeded with symbol tilde (~).
2. It will not have return value.
3. They take no arguments. Therefore, destructors cannot be overloaded.
4. There can be only one destructor in each class
5. It should be declared in public section of class.
6. It is mainly used to de-allocate memory that was allocated for the object by the constructor.

*****************
CHAPTER 10
Inheritance
Definition :
Inheritance is the capability of one class to inherit properties from another class.
Advantages :
 Reusing existing code
 Faster development time
 Easy to maintain the code
 Easy to extend
 Memory utilization
Base class : The class from which the properties are inherited is called the base class or super class.
Derived class :The class that inherits the properties from the base class is called as derived class or subclass.
Defining derived classes
First the base class is defined and then derived class is defined by specifying its relationship with the base
class.
classderived_class_name : visibilitymodebase_class_name
{
//Members of the derived class
};
Here, colon derivation from the base class
visibility_mode Type of derivation. i.e., private, public or protected
 The body of the derived class contains its own data members and member functions.
 The class definition should be terminated by the semicolon.
 If no visibility_mode is specified, the default visibility mode is private.
 Note that all the members of the class except private can be inherited.
public derived class
class father //Base class
{
private:
char name[10];
int age;
public:
int boys;
int girls;
void getdata();
void display();
};
class son : public father //public derived class
{
private:
char company[10];
float salary;
public:
void inputdata();
void putdata();
};
Access specifiers or visibility mode
 The visibility mode defines whether the class is derived private or public or protected from the base class.
 The visibility mode basically controls the access specifier in the derived class.
public derivation:
 public members of the base class become the public members of the derived class.
 protected members of the base class remain protected members of the derived class. They are directly
accessible by the member functions.
 private members of the base class are not inheritable.
 The private members of the base class can be accessed indirectly using public or protected member
functions of the base class.
private derivation:
 This visibility mode is optional. i.e., when not used, the default visibility mode is private.
 public members of the base class become the private members of the derived class. Therefore, the public
members of the base class can be accessed only by the member functions of the derived class and not by the
objects of the derived class.
 protected members of the base class become private members of the derived class.
 private members are not inherited by the derived class.

protected derivation:
 When a member of a base class is declared protected, it is accessible by the member functions of its own
class and any class derived from it.
 public members of the base class become the protected members of the derived class.
 protected members of the base class remain protected members of the derived class.
 private members are not inherited by the derived class.

Levels of Inheritance
1. Single inheritance
2. Multilevel inheritance
3. Multiple inheritance
4. Hierarchical inheritance
5. Hybrid inheritance Base Father

Single Inheritance
If a class is derived from a single base
class, it is called as single inheritance. Derived class Son

Multilevel Inheritance Grand Father


Base
The classes can also be derived from the classes
that are already derived. This type of inheritance is called
multilevel inheritance. Derived class-1 Father

Derived class-3 Son

Derived class-n

Multiple inheritance
If a class is derived from more
than one base class, it is known as Base- Base-2 Base-n king queen
multiple inheritance. 1

prince
Hierarchical Inheritance Derived class
If a number of classes are derived
from a single base class, it is called as hierarchical inheritance.

Base Staff

Derived class Derived class Derived class Lecturers Office Staff Group-D
Hybrid Inheritance Base
Hybrid Inheritance is combination of Hierarchical and
Multilevel Inheritance.
Derived class-1 Derived class-2

Derived class
CHAPTER 11
POINTERS
Definition :A pointer is a variable that holds an address of another variable.
Advantage of pointers
i) It is possible to write efficient programs.
ii) Memory is utilized properly.
iii) Dynamically allocate and de-allocates memory.
iv) Easy to deal with hardware components.
v) Establishes communication between program and data.

Syntax and example


Syntax : datatype *variablename;
Example : int n=10, *ptr;
ptr=&n;

Address operator :& is used as address operator which is used to assign the address to a pointer.
Pointer operator: * is called as pointer operator. It is used to access the value of variable.

Pointer Arithmetic :
The following operations can be performed on pointers
i) Add an integer value to a pointer.
ii) Subtract an integer value from a pointer.
iii) Assign one pointer to another pointer provided both are of same type.
iv) We can increment a pointer variable.
v) We can decrement a pointer variable.
The following operations cannot be performed on pointers
i) Addition of two pointers.
ii) Multiplication of two pointers.
iii) Division of two pointers.
iv) Subtraction of one pointer from another pointer when they do not point to the same array
Array of pointers
An array of pointers means that it is a collection of addresses.
datatype *variablename[size];
int *iptr[5];
int a=10, b=20, c=30, d=40, e=50;
iptr[0]=&a; *iptr[0]=10;
iptr[1]=&b; *iptr[1]=20;
iptr[2]=&b; *iptr[2]=20;
iptr[3]=&b; *iptr[3]=20;
iptr[4]=&b; *iptr[4]=20;

Pointers and functions


After the function has performed its assignment, the changed values of the argument will be preserved and
given to the calling function. To pass pointer arguments, use the * when declaring the function and use the & when
calling the function. A function can be done by following two methods.
 By passing the references.
 By passing the pointers.

By passing the references :


A reference is an alias for a variable. The called function works with the original data and any change in the
values gets reflected to the data. The values of the original variable are to be changed using a function.

By passing the pointers


When the pointers are passed to the functions, the addresses of actual arguments in the calling function are
copied into formal arguments of the called function. This means that using formal arguments in the called function,
we can make changes into the actual arguments of the calling function.
Static allocation of memory Dynamic allocation of memory

1. Memory is allocated before the execution of the 1. Memory is allocated during the execution of the
program begins program

2. No memory allocation or de-allocation actions 2. Memory bindings are established and destroyed
are performed during execution during the execution.

3. Variables remain permanently allocated. 3. Allocated only when program unit is active.

4. Implemented using stacks and heaps 4. Implemented using data segments.

5. More memory space required. 5. Less memory space required.

New operator :New operator is used to allocate memory at run time.


Delete operator : Delete operator is used to free the allocated memory.
Free store : A program is provided with a pool of unallocated heap memory that it may utilize during the execution.
It is referred to as free store.

Free store is a pool where the memory is allocated dynamically to the objects.
 The allocated during execution.
 The allocated free memory is unnamed.
 The objects allocated on the free store are manipulated indirectly through pointers.
 The free memory is allocated and de-allocated using new and delete operator respectively.

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.

this pointer : Every object in C++ has access to its own address through an important pointer called this pointer.
CHAPTER 12
DATA FILE HANDLING
C++ I/O occurs in streams. If bytes flow from a device likes a keyboard, a disk drive etc., to main memory is called
input operations and if bytes flow from main memory to a display screen or disk is called output stream. A flow of
data from one device to another is called stream.
In C++, file input/output facilities available in header file fstream.h. The fstream library predefines a set of
operations for input and output.

fstream.h
The stream that supplies data to the program or Read any data from the file is known as input stream.
The stream that receives data from program or Write any data to the file is known as output stream
Stream classes
The following classes to perform output and input of characters to/from files
ofstream: This stream class helps to write data into a file. The function put(), write() and functions supporting
random access seekp and tellp from ofstream class defined inside iostream.h file.
ifstream: This stream class helps to read data from a file. The function get(), getline(), read() and functions
supporting random access seekg and tellg from istream class defined inside iostream.h file.
fstream :fstream class helps to both read and write from/to a file.

Types of data files : The files are used to store data or information permanently. The following types of data files are
i) text file ii) Binary file
Text file : That stores information in ASCII character. In text file can line of text is terminated with a special character
known as EOL character or delimeter.
Binary file : It is a file that contains information in the same format as it is held in memory no delimeters are used.

Opening and closing files


We need the stream like input, output and input/output.
To create an input stream you must declare the stream to be of class ifstream.
To create an output stream you must declare the stream to be of class ofstream.
The performing both input and output operations must be declared as class fstream.
Opening file using constructor
The syntax of opening a file for output purpose only using an object ofstream class
Syntax : ofstreamfout(“filename”);
ofstreamfout(“abc.dat”);
The syntax of opening a file for input purpose only using an object ifstream class.
Syntax : ifstream fin(“filename”);
ifstream fin(“abc.dat”);

Opening file using open():


The syntax of opening a file for output purpose only using an object ofstream class and open() member function
is as follows
ofstream_object.open(“filename”);
Example : ofstreamofile(“filename”);
ofile.open(“abc.dat”);

The syntax of opening a file for input purpose only using an object ifstream class and open() member function is as
follows
ifstream_object.open(“filename”);
example : ifstreamifile(“filename”);
ifile.open(“abc.dat”);
The syntax of opening a file an object of type fstream class and the open() member function is as follows
fstream_object.open(“filename”, mode);
Different modes of opening a file
File mode meaning
ios::app append to end of file
ios::in open file for reading only
ios::out open file for writing only
ios::ate open file for updation and move the file pointer to end of file
ios::binary opening a binary file
ios::trunk on opening, delete the contents of file

Closing file
The file should be saved on the secondary storage to use the member function close(). The function on its
execution removes the linkage between the file and the stream object.
Syntax : stream_object.close();
fout.close();

Input and output operations in text files


put() : The put function writes a single character to the text file.
Syntax : ofstream.put(ch);
Ex: char ch=’a’;
ofstreamfout(“abc.txt”);
fout.put(ch);
get() : The get function reads a single character from the text file.
Syntax : ifstream.get(ch);
Ex: char ch=’a’;
ifstream fin(“abc.txt”);
fin.get(ch);
getline() : The getline function reads an entire line of text from the text file.
Syntax : fin.getline(buffer, size);
Ex: char name[size];
fstream fin;
fin.getline(name, size);
Input and output operations in binary files
The following types of input and output operations are i) write() and read() function.
write() : The write() member function is used to write binary data to a file.
Syntax :fout.write(char *) &variable, sizeof(variable));
Example : student s;
ofstreamfout(“std.dat”, ios::binary);
fout.write((char *) &s, sizeof(s));

read() : The read() member function is used to read binary data from a file.
Syntax :fin.read(char *) &variable, sizeof(variable));
Example : student s;
ifstream fin(“std.dat”, ios::binary);
fin.read((char *) &s, sizeof(s));
Detecting end of file:
The end of file detected with the use of eof() member function, we can stop reading further.
while(!fin.eof())
{
statements;
}

Seekg() : Moves the get pointer to a specified location from the beginning of a file.
Example : inf.seekg(long);
inf.seekg(20);
seekg(offset, seekdir);
Constant Meaning
ios::beg offset specified from the beginning of the file.
ios::cur offset specified from the current position of the get pointer.
ios::end offset specified from the end of the file.

Seekp() : Moves the put pointer to a specified location from the beginning of a file.
Example : inf.seekp(long);
seekp(offset, seekdir);
inf.seekp(0, ios::beg);
tellg(): The ifstream class provides the member function name tellg(). The purpose of the function is to return
current position of the get pointer.
Syntax :int position
Position = fin.tellg();
tellp(): The ifstream class provides the member function name tellp(). The purpose of the function is to return
current position of the put pointer.
Syntax :int position
Position = fin.tellp();
Chapter 13

Database concepts

OBJECTIVES

 TO UNDERSTAND BASIC CONCEPTS OF DATABASE


 TERMINOLOGIES USED IN DATABASE
 DATA MODELS
 KEYS USED IN DATABASE
 DATA WAREHOUSE AND DATA MINING
Data is a collection of raw facts like a Person’s name, image, sound and so on. A data can be defined as a set of
isolated facts.

A database is a vast collection of logically related data in computer understandable format. The data in database can
be organized, accessed, managed and updated easily.

Information is processed and meaningful data. Information can be generated by processing and
manipulation of data.
The process of conversion of raw data into meaningful form is carried out using DBMS.
DBMS is therefore a Software that manages the data stored in database. DBMS is used to create and
manage the databases.
Applications of Database

 Banking- Maintenance of account holder details and transactions.


 Rail and airlines- Travel schedule and reservation information
 Telecommunication – Internet service details, Telephones and records of prepaid and postpaid
usage.
 Manufacturing –ERP used in supply chain management, inventories and so on.
 Educational institutions-maintenance of student data, attendance, test and examination marks,
library books and so on.
Data Vs Information
Data is a collection of raw facts. They occur as real life objects, such as numbers, text, sound, image etc.
Information is processed and meaningful data. Information may be in the form of summaries, reports and so
on.
The data is given to the computer. The program inside the computer processes the data and converts it into
meaningful and human understandable format. This is also known as data processing.
Manual Vs electronic data processing
Manual processing means doing data manipulation manually using paper and pen.
Electronic data processing means processing of data using computers and database.

Differences between manual and electronic data processing

Manual Data processing Electronic DP


1 Volume of data to processed is limited in 1 Large volume of data is processed in given
given time time
2 Large amount of paper needed 2 Usage of paper can be minimal
3 The speed and accuracy of processing has 3 Speed and accuracy are assured
limitations
4 High labour cost 4 Low labour cost
5 Storage material is paper 5 Storage is electronic median

Data processing cycle

The various steps involved in data processing are

a)Input b) Processing c) Storage d) Output e) Communication


Input:

The process of giving data to computer for further manipulation is known as input. The input data may be in the
form of text, graphics, sound, image and so on.The input is provided using input devices such as keyboard, OCR,
MICR, Scanner etc. If the input is directly given to the computer using devices like OCR, MICR etc.,,then it is known as
source data automation.

Processing:

The processing is a sequence of operations carried out on input data to generate output. Some of processing
activities are sorting, indexing, retrieval of selected data and computing the results through different operations.

Storage:

Data and information must be stored in computer for future use. Different storage devices like floppy disks,
Hard disks, Pen drives, CD’s can be used.

Output

The results of computation are made available to user in the form of reports (hard copy/soft copy) .Some of
the results may be in animation form with sound and video. The output generated may have the appropriate
headings, date of report generation, author name, validity data and so on.

Communication:

The computers can be used for data processing using communication devices (wired or wireless). .This
enables remote data to be processed and managed.

Files and File organisation

A file is a collection of inter related data. The arrangement of data in a file is known as file organization.
There are three types of file organization namely

1. Serial file organization


2. Sequential file organization
3. Indexed sequential organization
4. Random/direct file organization

Serial file organization

In serial file organization, records are organized one after another in the order in which the records are inserted into
the file. This type of file organization is normally found on Transaction files where records are created for each
transaction carried out. The information is later used to update master files. The organization is very simple and no
overheads are needed.

Sequential file organization

 In a sequential file records are stored one after another in ascending or descending order according to
primary key.
 The sequential files may be stored on any type of storage device like magnetic tapes or magnetic disks.
 The records are read sequentially one after another in the order in which they are stored in the file.
 To locate a particular record one has to read through all previous records, until the desired record is found.
 This method of file organization is suitable for batch processing applications such as payroll processing,
result manipulation and so on.
Indexed sequential file organization

 Indexed sequential files are the files that are stored sequentially according to primary key, but the records
can be retrieved both sequentially as well as directly.
 The indexed files use a software called ISAM(indexed sequential access mode).The ISAM creates an index
for every record stored in the file.
 The index table contains the key value and address of the record.
 When a record is to be searched, the key value is given, the computer searches through the index, finds the
address and retrieves the record immediately. Therefore searching is done very quickly.
 The indexed files can be stored only on direct access storage devices like magnetic disks.
Advantages

1. The records can be accessed quickly.


2. Efficient method of processing data.
Disadvantages

1. Only direct access storage devices can be used such as magnetic disks.
2. Less efficient in terms of storage space utilization because of creation of index for every record.
Random/Direct file organization

 This method of file organization allows immediate access to the records on the file.
 The records are stored in storage where the record key is mapped on to the storage address.
 The direct file organization allows the records to be accessed both sequentially as well as randomly.
 The storage media used for direct files can be disks only.
 In order to create a mapping of record key to storage address, a hashing algorithm is used to generate
relative address of the record. Therefore records are stored in such a way that there is no relationship
between keys of adjacent records.
Advantages

1. The records can be accessed very quickly


2. Transactions need not be stored and placed in sequence before processing.
3. Best suitable for online transactions
Disadvantages

1. Address generation needs additional functions for hashing.


2. Less efficient in terms of storage utilization.
Database management Sytem

Data base is a collection of interrelated data in computer understandable format. DBMS is software that acts
upon the data stored in a database. The software allows creation and manipulation of data stored in database.

In addition to this DBMS provides security to data base and enables multiple users to use data. Different
Database packages are Mysql, , Oracle, Sybase, DBASE , MS Access& so on.

Features of DBMS

 Data in database is stored in central location and shared among multiple users.
 The DBMS provides centralized management of data.
 The data base is designed in such a way that the data are not duplicated in different files, there by reduces
redundancy.
 Data sharing – The data can be shared by a number of users and programs.
 It is also possible that new applications are developed using stored data.
 The data validation is done automatically by DBMS and this result in Integrity of data.
 Data in database can be protected against unauthorized access using security features such as login name and
password.
 DBMS has an automatic backup and recovery system that is responsible for recovery of the data from hardware
and software failures.
 DBMS also provides multiple interfaces between data and applications , such as query language, GUI, Menu
driven interface.
Terminologies used in DBMS

Relation- A table with number of columns and rows where data can be stored is called a relation.

Tuple- A row of data in a table is called a tuple.

Attribute- It is a named column in a relation.

Ex: In a relation called Student the regno,name,age are attributes

Domain- A set of values for an attribute.

Ex: In a relation the domain of regno may be 1000-2000

Degree- The degree of a relation is defined as the number of attributes in the relation

Types of Keys

A key is one of the attributes of a table to identify one or more tuples/records of the table.

Primary key-A primary key uniquely identifies a tuple /record in a table. A primary key cannot be duplicated for
different records in a table.

Ex: Student_id, Bank_accno are examples for primary key

Candidate key-There may be more than one unique field in a table that can be selected as primary key- All such
fields that are unique for every row of table are known as candidate keys.

Alternate keys- Those candidate keys that are not selected as primary keys are known as alternate keys.

Foreign key- A field in a table that can be chosen as primary key of another table is known as foreign key.

For ex: bank_accno in a student table that may have student_id as primary key and bank_accno as the foreign key.

Composite key-A key that consists of two or more attributes to identify a record in a table are known as composite
keys.

Database users

Application Programmers: Application programmers are people who write programs.

System analysts: They develop specifications based on requirement of end users who may not have computer
knowledge at all.

End Users- People who access data base for querying and updating and generating output.

Database administrator: Person who manages and controls both data and application programs. The DBA is
responsible for schema definition and modification. The DBA also manages new software installation and security
controls and other administration based activities.

Database designers: People who are responsible for identification and design of tables and establish relationships
between tables in the database.

Data Abstraction and architecture


Database architecture describes how the data in DB is viewed by different types of users at different
levels.This viewing of data in DB is known s data abstraction. Data abstraction provides a view of how data is
physically stored.

Database architecture provides description of data at 3 levels

 Internal level
 Conceptual level
 External level or view level
V1 V2 V3

Conceptual

Internal

DB

Internal level

This is also known as physical level. This architecture describes how data is physically stored and organized
on storage medium. This level also describes about data storage allocation techniques, Indexes, data compression
methods and encryption and data placement. This level considers optimal storage utilization

Conceptual Level:

The conceptual level describes logical relationship between data. This level of abstraction tells what data is
stored in the database, relationship among the data and complete view of users requirement without physical
storage structures. Therefore the complexity involved in physical storage structure is not shown at this level.

External Level

This is the highest level of abstraction. It deals with users view of database and therefore is known as view level. In
most of the cases the user needs only a part of data. The external level describes a part of database for particular
groups or users who can access data according to their needs so that same data can be seen by different users in
different ways at the same time. The external view provides a powerful and flexible security mechanism by hiding
parts of database from certain users.

Data independence:

Data independence is the ability to change the structure of a table (scheme definition) without affecting
other scheme definitions or application programs. There are two types of data independence .

 Logical data Independence


 Physical data Independence
Logical data independence:

Changing structure of tables in data base without modifying application program is known as logical data
independence.
Physical data independence:
Changing physical structure of a database like reorganizing files without changing application programs is
known as physical data independence.
Database architecture:

Design of DBMS depends on architecture. The DBMS architecture can be

 One tier architecture.


 Two tier client/server model
 Three tier client/server architecture
One tier architecture:

In this model user can directly interact with DBMS and process the data stored in DBMS. Any change done will
directly be done on the DBMS itself.

Two tier-client server model:

In this model the database is stored in a computer called server and the client which may be a user or an
application program is stored on another computer called client. The client generates a request that is conveyed to
the server. The server processes the query and returns an answer to the client. The client can establish connection
with the database using open database connectivity(ODBC driver).

Three tier architecture:

Large organizations use three tier architecture. In this model DB and query processing language reside on
the inner tier. The application server and programs to access DB sits on second tier. User tier- The end user or the
client sits on this tier. From this layer the user can retrieve the data through the application server.

Database Model

A Database model or data model that describes data and data relationships. A data model describes the structure of
data and the set of operations that can be performed on the data.

The relationships between different parts of the data is known as logical design. There are database models namely

 Hierarchical Model
 Network Model
 Relational model
Hierarchical Model

This model organizes data in tree structure. There is one parent node known as root node and a number of
child nodes (dependent nodes) for the root are represented in the form of a tree. The data are related in 1-1
relationship and one-many relationship. Any changes made to the physical structure will require the application
programs also to be changed. The data may be repeatedly present in multiple databases. This may lead to
inconsistency of data.

Student

Course Name ID

FN MN LN

The disadvantage of this model is the parent-child connection cannot be modified and therefore any
changes will result in redesigning.

Network Model

In a network model the data are linked in parent-child relationship. However the data are represented in the
form of graph. The data therefore can be accessed through several paths.
A parent node can have many child nodes and the child node also can have many parents. Therefore many-
many relationship is possible between data.

Any link or relationship broken between nodes may result in problems in DB and further database design
also becomes complex.

A B

E F
C D

Relational Model:

This was developed by EF CODD in 1970. In this model data is maintained in the form of tables (relations)
consisting of rows and columns. Each table is called a Relation, and is assigned a name such as student-table,
teacher-table and so on.

Each relation has a number of rows and each row is known as instance of a relation or tuple. Each column (field)
represents an attribute of a tuple. Every tuple has a unique value known as primary key.

St.Id St.Name Class Section Age


123 Amith II PUC B 17
124 Varun IIPUC F 18

Entity Relationship Diagram:

Database design is done by creating entity relationship (E-R) models. These models provide a high level view
of data requirement of an organization. These models are created using a set of diagrammatic tools known as ER
diagrams ER diagram consists of entities, relationship between entities and attributes that describe the entities and
relationships. ER diagrams has 3 components .

Entitiy
An entity is any object, person, place or transaction on which data has to be maintained by organization. Entities are
represented as rectangles.

Customers orders
Ex: customers, orders, products etc.,
Attributes

An attribute describes the properties of an entity. The attributes are facts about entity.
For ex: Customer entity contains attributes like name, address, phone and so on.
Among all attributes one should be unique valued and this constitutes primary key.
Attributes one represented using ellipse.
The two types of attributes are
Key attributes- They represent main characteristic of an entity.(primary key)
Composite attributes-Attributes having their own attributes further in the hierarchy are known as composite
attributes.

address

citycity pin code


state
Relationship- A relationship between describes relations between entities. Relationship is represented using
rhombous symbol.

entity relationshipp entity

There are three types of relationships that exist between entities

 Binary relationship
 Recursive relationship
Binary relationship-This represents relationship between two entities. This is further divided into

One to one- one entity is related to another one entity only

Student--------------course

One to many- one entity is associated with many entities


S1
Enroll course

S2

Many to many- many entities are related to many entities

Recursive relationship- Entity related to itself is known as recursive relationship

Genaralisation
Combining 2 low level entities to higher level entities (Bottom up approach)is known as generalization.
Specialization
one higher level entity is broken up into 2 lower level entities-(Top class)
Aggregation- relationship between 2 entities is treated as single entity.
Relational Algebra

Relational algebra is a procedural query language. The data manipulation capabilities for database can be described
through relational algebra. It consists of set of operations that take one or two relations as input and produce a
new relation as output. Relational Algebra provides:

 A formal /theoretical description of working/operations of relational database.


 An interface for sql instructions to be represented as a set of internal operations.
 Represents the operations of query language as a set of Mathematical relations.
 The operators used in Relational algebra are same as that of SQL.
The various operations carried out in relational algebra are

Unary operations-These operations are carried out on a single relation


 Select, project, rename
Binary operations- operations that operate on 2 relations

 Union, product, join


1) Select operation- The select operation retrieves all the tuples from a relation that satisfy a given condition.
2)Project operation-A Relation may have a number of attributes, all of which are not always required. Project
operation is used to select some of the attributes from a relation.

3)Rename operator

The rename operator returns an existing relation under a new name.


Binary operations are Set theory based operations- Union, Intersection, difference and Cartesian product

UNION

The operation of two relations R and S selects all the tuples that are in R, or in S or in both eliminating duplicating
tuples.

Intersection:

This operation finds common tuples in two relations. The operation is denoted by the symbol ∩

Difference

The difference of two tuples is the relation that contains all the tuples in the first table and not in the second table.

CARTESIAN PRODUCT

This operation is denoted by X. This is also known as cross productOr cross join. The Cartesian product of two
relations s1 and s2 is denoted by s1 X s2.This defines a new relation which is a combination of each tuple of relation
s1 with each tuple of relation s2.

JOIN Operation

Join is used to combine related tuples from two relations. In other words join operation is the cross product of two
relations.

Natural join- In this method the attributes in both the relations must have the same name. And two attributes in the
same relation cannot have same name. (symbolic notation-( ))

OUTER JOIN

During Join operation, it is possible that most of the useful data is lost during join. Therefore to retain the data,
different types of joins are possible.
Left outer join- This keeps the data from left hand table. (symbolic notation- )
Right outer join-keeps data from right hand table(symbolic notation- )
Full join-keeps data from both the tables.
Note: the symbolic operators are used similar to verbal operators.
Data Warehouse

Data warehouse is storage of electronic data of an organization. To analyse the data,(Data analysis helps in decision
making or performance evaluation and so on) the Datawarehousing is required. Earlier to data warehouse concept,
the organizations maintained separate databases for different operations. Data warehouse is capable of receiving
data from different types of computers such as mainframes, mini computers or personal computers. Also the data
can be received from different software media and can be integrated into a single format. In addition to this data
warehouse has user friendly reporting tools and any changes in the operational formats do not affect the data.

The various types of data warehouses are

1. Offline operational databases-The databases are copied from a working system to an offline server.
Processing of data on the server does not affect the operational system or working system.
2. Database warehouses are regularly updated at definite intervals such as daily,weekly or monthly from
operational systems. The data is further integrated with report-generation system.
3. Real time data warehouse- The data warehoused are updated on transaction basis. That is every time a
transaction takes place on the database, the data warehouse is updated.
4. Real time Data warehouse- The data ware houses are used to generate activity and the results are passed
on to the operational system as and when transaction takes place.
Components of Data warehouse

Data source: Data source is any information stored in electronic media. The data stored in data source can be used
for data management or analysis. The data may be stored in spread sheet, or in database of oracle, ms access sql
server and so on. The data is passed on from data source to data ware house after every transaction in case of
realtime data warehouses or in regular intervals for offline data ware houses.

Data Transformation: The data received from data source is cleaned and converted into a standard format and
loaded in to storage. This process is known as staging. Staging can be done either manually or can be done using a
software tool called “Extract transform and load(ETL)”.

Reporting: The data from data ware house is made available to the users in a user friendly format. These are known
as reports. The reports can be customized. Some of the reporting tools are Executive information systems, business
intelligence tools, online analytical processing tools(OLAP).
Metadata: “data about data” is meta data. The meta data is reporting status and information of the data stored in
data warehouse.
Operations: The operations on data warehouse means extracting data from data warehouse, loading data into data
warehouse and manipulating the data. The operations also include security management of data.
Optional components:The data warehouses also contain the following components
 Dependent data marts
 Logical data marts
 Operational data store
Advantages of Data warehouses
1. The end users can easily access reports and also analyse the information using computers.
2. The data consistency increases.
3. The computing cost is reduced and productivity increases.
4. The data from different sources can be combined in one place.
5. Data warehouse supports changes to data and changed data are stored in the system.
Disadvantages of Data warehouses
1. The process of extracting cleaning and loading data takes time.
2. The data warehouse gets outdated very quickly.
3. The end users must be trained to operate the data warehouse.
4. Security is an issue when data from data warehouse is available through WAN.
5. The compatibility of systems may cause problems.
Data Mining

Data mining is the process of analyzing data from different perspectives and selecting relevant information. The
data mining uses best methods to analyse and process large volumes of data. Initially a small set of data are analysed
and processed and time taken is analysed. If the analysis is correct, then the method is extended to larger set of
data.

Some of the data mining software are SPSS, SAS and so on.

The data mining is done to extract suitable knowledge from data warehouse. The various stages of data mining are

 Selection-The data is selected and segmented into small sets.


 Preprocessing-In this stage unwanted data is removed because having more unnecessary data may slow
down the querying process. The data thus preprocessed is reconfigured.
 Transformation- The data is converted to usable format. Suitable patterns are defined to relate the datain a
simple way.
 Interpretation and evaluation- The patterns identified in transformation are interpreted to knowledge that
are used to support human decision.
CHAPTER 14
SQL – COMMANDS
SQL-Structured Query Language: It is a database language for sorting, manipulating and retrieving data stored in
relational database.

The features of SQL:

1. It is very easy to learn and use.


2. Large volume of databases can be handled quite easily
3. It is non procedural language
4. Change system security settings.
5. Add user permissions on databases or tables.
6. It is used to create New databases, New tables.
7. One can insert, delete, and update records in a database.
8. Allows users to create and drop databases and tables.

At the time of executing a SQL command for any RDBMS, the system determines the best way to carry out user’s
request and SQL engine determines how to interpret the task.

There are various components included in the process. These components are Query Dispatcher, Optimization
Engines, Classic Query Engine and SQL Query Engine, etc. Classic query engine handles all non-SQL queries but SQL
query engine won't handle logical files.

SQL commands: Based on their nature SQL commands can be classified into 4 groups.

1. DDL – Data definition language


2. DML – Data manipulation language
3. DCL – Data Control language
4. TCL – Transaction Control language
1. DDL: Data definition languagedefine the physical characteristics of each record, field in the record, field’s data
type, field’s length, field’s logical name and also specify relationships among those records.
Basic commands for DDL are: create, alter and drop
2. DML: Data manipulation language provides the data manipulation techniques like selection, insertion, deletion,
update, modification, replacement, retrieval, sorting and display of data or records.
Basic commands for DML are: insert, update and delete.
3. DCL: Data Control language is used for providing security to database objects.
Basic commands for DCL are: grant and revoke
4. TCL: Transaction Control languageincludes commands to control the transactions in a database system.
Basic commands for DQL are: select
Data types in SQL:
1. Numeric data types: Ex: Number (3) Number with maximum 3 digits
2. Floating point numeric data Type: Ex: Number (5, 2) Number 5 digit with two digits after decimal point.
3. Date Data type: Ex: Date (‘ 23/12/2019’)
4. Time data type: Ex: Time ( 12:30p.m)
5. Character data type
a) Char (size) Ex: char (25)
b) varchar2 (Size) Ex: varchar2(25)

SQL operators: The SQL operators are


1. Arithmetic
2. Comparison
3. Logical
Arithmetic operators:

Operator Description Example (a=10, b=20)


+ Addition a + b = 30
- Subtraction a - b = -10
* Multiplication a * b = 200
/ Division a/b=0
% Modulus a % b = 10
Comparison Operators:

Operator Description
= Equal
!= Not equal
> Greater than
< Lesser than
>= Greater than or equal to
<= Lesser than or equal to
!< Not less than
!> Not greater than
Logical Operators:

ALL Compare a value to all values in another set


AND
Allows the existence of multiple condition in an SQL statement’s WHERE clause.
ANY
Used to compare a value to any applicable value in the list according to the condition

BETWEEN
Used to search for values that are within a set of values, given the max. and min. value.
EXISTS
Used to search for presence of a row in a specified table that meets certain criteria.

IN Used to compare a value to a list of literal values that have been specified.
LIKE Compare a value to similar values using wild card operators.
NOT Reverse the meaning of the logical operator with which it is used.
OR Combine multiple conditions in an SQL
IS NULL Used to compare a value with NULL value
UNIQUE Searches and very row of a specified table for uniqueness. (No duplicate)

SQL expressions or queries: SQL expressions are like formulas and are written in query language. They are different
types of SQL expressions
1. SQL-Boolean Expressions: fetches the data on the basis of matching single value.
Ex:
SQL>select * from employee where age=45;
2. Numeric Expressions: used to perform any mathematical operations in any query
Ex:
SQL>select (15+6) as addition;
SQL>select count (*) as “RECORDS” from employee;
3. Date Expressions: return current date and time value.
Ex: SQL> SELECT get_date();
SQL Constraints:
Constraints are the rules enforced on data columns on table. These are used to limit the type of data that
can go into a table. This ensures the accuracy and reliability of the data in the database.
Constraints could be column level or table level. Column level constraints are applied only to one column
where as table level constraints are applied to the whole table.
Commonly used constraints available in SQL
1.NOT NULL: Ensures that column cannot have NULL value.
2.UNIQUE: ensures that all values in a column are different.
3.PRIMARY KEY: uniquely identified each row/record in a database.
4.FOREIGN KEY: uniquely identified each row/record in another database.
5. CHECK: ensures that all values in a column satisfied certain condition.
[Note: constraints can be specified when a table is creating with create table command]
Implementation of SQL commands
DDL commands:

1. CREATE TABLE command: used to create a new table.


Syntax
CREATE TABLEtablename
( column1datatype, column2 datatype, ……….columnNdatatype);
Ex:
SQL>create table bill
(RRNO varchar2(10), NAME varchar2(10), BILLDATE date, UNITS number(3));
2. ALTER TABLE command: used to add a column or modify existing table or delete a column from the table.
Syntax
ALTER TABLEtablename
ADD( column1 datatype, column2 datatype, ……….);
Ex:
SQL>alter table bill add(AMOUNT number(6,2),DUEDATE date);
3. DROP TABLE command: used to delete an existing table from database.
Syntax
DELETE TABLEtablename
Ex:SQL>delete table bill;
DML commands:
1. INSERT command: used to add data to a table.
Syntax
INSERT INTO tablename
VALUES (column1_value, column2_value………column_ value);
Ex:
SQL>insert into bill values (‘A10002’,’sandeep’, ’29-jan-2015’, 90);
2. UPDATE command: used to change data or update and already existing row of a table.
Syntax
UPDATE tablename SET column = value WHERE condition;
Ex:
SQL>update bill set amount=50;
3. DELETE command: used to remove an existing rows from table.
Syntax
DELETE FROM tablename WHERE condition;
Ex:
SQL>delete from bill where RRNO=’A10002’;

4. SELECT command: used to fetch the data from a database table which returns data in the form of result table.
Syntax
SELECT column1,column2,……columnN FROM tablename
WHERE condition;
Ex:
a) Selecting all columns and all rows in a table
SQL>select * from bill;
b) Selecting set of column list in a table
SQL>select RRNO, UNITS from bill;
c) Selecting specific rows in a table
SQL>select * from bill where UNITS >100;
WHERE clause using AND operator
The AND operator allows the existence of multiple conditions in a SQL statement’s where clause.
Syntax
SELECT column1,column2,……columnN FROM tablename
WHERE condition1 AND condition2………AND conditionN ;
Ex:
SQL>select * from bill where name=’sandeep’ AND rrno=’A10002’;

WHERE clause using OR operator


The OR operator is used to combine multiple conditions in a SQL statement’s where clause.
Syntax
SELECT column1,column2,……columnN FROM tablename
WHERE condition1 OR condition2………OR conditionN ;
Ex:
SQL>select * from bill where amount>500 OR units>100;
Order by clause: It is used to sort the data in ascending or descending order based on one or more columns.
Syntax
SELECT column1,column2,……columnN FROM tablename
WHERE condition order by column1,column2…..[asc]/[desc];
Ex:
SQL>select * from bill order by rrno;
Group by clause: It is used in collaboration with the select statement to arrange identical data into groups.
Syntax
SELECT column1,column2,……columnN FROM tablename
WHERE condition group by column1,column2…..;
Ex:
SQL>select name, sum (salary) from employee group by dept;
Distinct command: It is used in conjunction with SELECT statement to eliminate all the duplicate records and
fetching only unique records.
Syntax
SELECT DISTINCT column1,column2,……columnN FROM tablename
WHERE condition;

Ex:.
SQL>select DISTINCT salary from employee;

JOIN clause: It is to combine records from two or more tables in database.


There are different types of joins:
 Inner Join: returns rows where there is b match in both tables.
 Left Join: returns all rows from the left table, even if there is no match in the right table.
 Right Join: returns all rows from the right table, even if there is no match in the left table.
 Full Join: returns rows when there is b match in one of the table.
 Self Join: used join a table to itself as if the table were two tables, temporarily remaining at least one table in
the SQL statement.
 Cartesian Join: returns the Cartesian product of the sets of records from the two or more joined tables.
NULL: The SQL NULL is the term used to represent a missing value. There is a special comparison operator IS NULL or
IS NOT NULL in order to check for b NULL value.
Ex:.SQL>select * from employee where salary IS NOT NULL;
CREATE VIEW command: database view is created using CREATE VIEW statement. Views can be created from a
single table, multiple tables or another view.

Syntax

CREATE VIEW view_name AS select column1, column2……from tablename

Where condition;
Ex:.

SQL>CREATE VIEW bill_view AS select name, rrno, units from bill;

COMMIT command: It is the transactional command used to save changes invoked by a transaction to the database.

Syntax

COMMIT;

DCL commands

GRANT command: It is used to provide access or privileges on the database objects to the users.

REVOKE command: It removes user access right or privileges to database objects.

SQL built functions: There are two types of functions in SQL

1. Scalar functions
2. Group function
Scalar functions: scalar functions return a value for every row that is processed in a Query. There are four types of
scalar functions

Numeric functions: They accept numeric input and return numeric values.

Example: abs(),round(),sqrt()

Character or text functions: Used to manipulate characters and strings

Example: LOWER(),UPPER(),TRIM()

Date functions: used to manipulate date data type

Example:sysdate(),next_date()

Group functions:

1.COUNT (): this function returns the number of rows in the table that satisfied the condition.

Example :select count (*) from employee where dept=’sales’;

2.MAX (): It is used to get the maximum value from a column

Example :select max (salary) from employee where dept=’sales’;

3.MIN (): It is used to get the minimum value from a column

Example:select min (salary) from employee where dept=’sales’;

4. AVG (): This function is used to get the average value of a numeric column.

Example:selectavg (salary) from employee where dept=’sales’;

5.SUM (): It is used to get the sum of a numeric column.

Example:select sum (salary) from employee where dept=’sales’;


Chapter 15
Networking concept
A network is interconnection of autonomous computer.
Network goals
• Resource sharing
Reliability
• Cost factor
• Communication medium

Need of networking

• File sharing
• Recourse sharing
• Communication
• Remote access
• Sharing of database to multiple user
TCP /IP (Transmission Control Protocol /Internet Protocol)

It is the basic communication language or protocol of the Internet.


TCP breaks the data into packets that the network can handle efficiently, verifies that all the packets arrive at their
destination and reassembles the data
Internet Protocol (IP) handles the address part of each packet so that it gets to the right destination.
Note: A datagram is a unit of data, the protocols deal with it
Packet is a physical thing appearing on the Ethernet

HTTP (Hypertext Transfer Protocol)

The Hypertext Transfer Protocol (HTTP) is an application-level protocol .


HTTP allows an open-ended set of methods to be used to indicate the purpose of a request.
The HTTP has various built-in request methods which allow users to read a web page

FTP (File Transfer Protocol)


It is a standard Internet Protocol for transmitting files between computers on the internet.
FTP is an application protocol that uses the Internet’s TCP/IP protocols.
It is also commonly used to download programs and other files to your computer from other servers.
THE INTERNET
It is an interconnection of large and small networks around the globe.

Elementary Terminology of Networks


(1) Nodes (Workstations)
The term nodes refer to the computer that are attached to a network and are seeking to share the
resources of the network.
(ii)Server
Server refer to the computer that are attached to a network and respond to the node.
Servers can be of two types: (1) non- dedicated servers and (2) dedicated servers
Non-dedicated Servers
Workstation that can double as a server is known as non-dedicated server
It is not completely dedicated to the cause of serving.

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 dos not double-up as a workstations and such a
server is known as dedicated server. The networks using such server are known as MASTER· SLAVE network.
TYPES OF NETWORKS
1.Local Area Networks (LANs)
2. Wide Area Networks (WANs)
3.Metropolitan Area Networks (MANs)
local Area Networks (LANs)
Small computer networks that are confined to a localized area
e.g., an office, a building or a factory
The key purpose of a LAN is to serve its uses in resource sharing.
Metropolitan Area Networks (MANs)
Metropolitan Area Networks (MANs) networks are the networks spread over a city.
For example, cable TV networks that are spread over a city
The purpose of a MAN is also the sharing of the hardware and the software resources among its users.
The several LAN connected with each other and form a MAN
Wide Area Networks (WANs)
The networks spread across the countries are known as WANs.
A WANs is a group of computers that are separated by large distances and tied together.
Computers connected to a Wide Area Networks are often connected through public networks, such as the
telephone system.
Sometimes they can be connected through leased lines or satellites. The largest WAN in existence is the
internet.
Difference between LAN and WAN
LAN WAN
1 Diameter is not more than few Span Entire country
Kilometer
2 Data rate is at least several MBPS Data rate is less than one mbps
3 Owned by single organization Owned by multiple organization
4 Very low error rate Comparatively high error rate

Network Topologies
The geographical arrangement of computer resources and communication facility is called as topology.
We can also say that the actual appearance or layout of inter connection of different computer is called topology.
The some of the most popularly used topologies are
Star Topology
This topology consists of a central node to which all other nodes are connected.
Bus or Linear Topology
A linear bus topology consists of a central cable with a terminator at each end
All nodes are connected to the linear cable

Ring or Circular topology


In this caseeach node is connects to neighboring nodes in circular manner.
The data travels in one direction only

The Tree Topology


. If we combine the tree and star topology it will gives the tree topology
.
Mesh Topology
In this topology, each node is connected to more than one node to provide an alternative root in the
case the host is either down or too busy.
SWITICHING TECHINIQUES

Different types of switching techniques are employed to provide communication

1) Circuit switching: In this technique there is direct connection between sender and receiver in a unbroken path.
In this technique ones a connection is established a dedicated path exist between both ends until the
connection is terminated. Ex telephone
2) Message switching: In this techniques there is no need of a dedicated path between 2 stations. When sending
the message it appends the destination address to the message and transmitted through the network node to
node, each node receives the entire message stores it and then is transmitted to the next node due to that this
type of network can also be called as store and forward. The device needs the sufficient storage capacity to
buffer the message.
3) Packet Switching: It combine the advantages of both message switching and the circuit switching. In this
technique the message is broken into smaller part is called packet and each packet contain the proper source
and destination address and transfer through the different path along with sequence number and at the
destination rearranging of the packet will takes place based on the sequence number.
Communication Modes

The way in which data is transferred from one place to other.


They are Simplex, Half Duplex and Full Duplex.

Simplex

In this mode data flow in only one direction


The full bandwidth is completely for signals traveling across transmitter to receiver or receivers.
On this channel transmitting interface cannot receive and receiving interface cannot transmit.
For example Radio, TV, etc uses simplex channels.

Half Duplex

On this channel each interface works as transmitter and receiver, but only one interface can transmit at a time. The
full bandwidth of a channel is available to thetransmitting interface which will not receive whit transmitting.
Generally it is used in Walkie -Talkies, Marin / Aviation, etc use Half Duplex channel.

Full Duplex

This channel has two ends each serving as transmitter and receiver. Each interface can transmit and receive at
the same time. The modem telephone systemuse Full Duplex channels. It is more expensive

NETWORK DEVICES
a) Modem (Modulator and Demodulator)
Device used to connect the system to internet

b) Ethernet Card

Device used to connect the networking cable


c) Hub

A hub is a hardware device used to connect several computers together.

Hubs can be either passive or active.

d) Switch

A switch is a device that is used to segment networks into different sub networks

e) Repeater

A repeater is a device that amplifies a signal being transmitted on the network.

f) Bridge

A bridge is a device that lets you link two networks together


g) Router

A device that works like a bridge but can handle different protocols is known as a router.

h) Gateway

A Gateway i a device that connects dissimilar networks.

GSM

GSM (Global System for Mobile communications) is one of the leading digital cellular systems. The GSM
standard for digital cell phones.
GSM operates in the 900 MHz and 1800 MHz bands.

GSM uses TDMA ( Time Division Multiple Access)

SIM card

The SIM - Subscriber Identity Module - is a chip card, the size of a postage stamp.
A SIM is a tiny computer chip that gives a cellular device its unique phone number.
It has memory, a processor and the ability to interact with the user.
CDMA

CDMA is Code Division Multiple Access


A digital cellular technology that uses spread spectrum techniques.
CDMA does not assign a specific frequency to each user. Instead, every channel uses the full available
spectrum.
GPRS

GPRS is the abbreviation for General Packet Radio Service.


GPRS is used for wireless communication using a mobile device.
With this service you can access the internet, send emails and large data

Applications in networking
SMS: Short Message Service (SMS) is the transmission of short text messages to and from a mobile phone.

Chat: It is the process of instantaneous communication.

Video Conferencing: Two way videophone conversation is called Video conferencing.

Wi-Fi: Wi-Fi refers to Wireless Fidelity, which lets you connect to the internet without a direct line from your
PC to the ISP.

Wi-Fi Hotspot. A hotspot is a venue that offers Wi-Fi access.

WiMax: WiMax is a wireless digital communications system.

Network Security.

While ensuring network security, the concerns are to make sure that only legal or authorized user and
programs gain access to information resources like databases.

The problems encountered under network security can be summarized as follows:

1. Physical security holes. When individuals gain unauthorized physical access to a computer and temper with
files.
2. Software security hole. When badly written programs are compromised into doing things

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: It determines whether the service provider has granted access to the web service to the
requestor.
Basically, authorization confirms the service requestor’s credentials.
Authorization is performed by asking the user a legal login ID.

2. Authentication: Authentication involves accepting credentials from the entity and validating them against
an authority.
Authentication also termed as password protection

3. Encrypted Smart Cards:

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 cracked or hacked, cannot
be used later.

4. Bio Metric Systems: They form the most secure level of authorization. The Biometric systems involve some
unique aspects 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. They can be implemented in both hardware and software or a combination of both.

Cookies: Cookies are messages that a web server transmits to a web browser so that a web
server can keep track of the user's activity on a specific web site.

Hackers and Crackers

The Crackers malicious programmers who break into secure systems, whereas Hackers are more
interested in gaining knowledge about computer systems and possibly using this knowledge for play full
pranks.

Cyber Law

Cyber Law is refers to all the legal and regulatory aspects of internet and the WWW.

Viruses: Computer Virus is a malicious program that requires a host and is designed to make a system sick,
just like a real virus. Viruses can spread from computer to computer and they replicate themselves.

Virus can be classified in to 4 different types according to its environment, and they are
a) File virus: This will effect for executable file or create a copy of the file.
b) Boot virus : They saves them selves in the boot sector and change the pointer of boot sector
c) Macro virus: It infect to document files.
d) Network virus: Use the protocols and the command of the computer network or the email to spread them
selves.
Symptoms of virus infection:

 Computer starts executing very slowly


 Reduce the memory size
 Playing of musical tune
 Unreadable message
 Disappearing of files from system
 Computer stops responding
 Applications are not work properly
 Disk drives are in accessible
 Files contain the double extension
 System shutdown
Most viruses are spread by email attachment and warn them to be suspicious of many file attached to
unsolicited messages.

Characteristics of virus:
1. It is able to replicate
2. It requires a host program as a carrier
3. It is activated by external action
4. Its replication ability is limited to the system.
Virus Prevention

All you need to be is extra careful and ensure following guideline.


1. Never use a foreign CD without scanning it for virus.
2. Always scan file downloaded from the internet or other soure .
3. Never boot your PC from floppy unlessit is virus free.
4. Write protect your disks
5. Use licensed software
6. Password protect your PC
7. Install and use antivirus software
8. Keep antivirus software up to date,
Anti virus software:

The anti virus software is used to detect the virus. It is better to prevent the virus than deal with it. The McAfee,
Symantec, Kaspersky, quick heal, K7, Norton 360

Cloud technology:Cloud computing relies on sharing of resources to achieve coherence and economies of scale,
similar to a utility (like the electricity grid) over a network
Chapter 16
Internet and open source

Free software
Free software means the software is freely accessible and can be freely used, changed, improved, copied
and distributed by all who wish to do so.
OSS and FLOSS
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 limitations. An OSS may come free of cost or with
a payment of nominal charges that its developers may charge in the name of development, support of software.
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

FSF
FSF is Free Software Foundation. It is a non-profit organization created for the purpose of supporting free
software movement.

OSI
OSI is Open Source Initiative. It is an organization dedicated to cause of promoting open source software

Proprietary Software
Proprietary Software is the software that is neither open nor freely available.

Freeware : Which is available free of cost and which allows copying and further distribution, but not modification
and whose source code is not available.

Shareware: Which is made available with the right to redistribute copies, but it is stipulated that if one intends to
use the software, often after a certain period of time, then a license fee should be paid.
(i). in shareware the source code is not available
(ii). Modification to the software are no allowed.

WWW (World Wide Web)


The WWW is a set protocols that allows you to access any document on the net through a naming system based
on URLs.

Telnet
Telnet is an older Internet Utility that lets you log on to remote computer systems.

Web Browser
A Web Browser is a WWW client that navigates through the World Wide Web and displays web pages. Internet
Explorer and Netscape Navigator, Google chrome, Opera Mozilla Firefox are most popular web browsers

Web Server
Web Server is a WWW server that responds to the requests made by web browsers.

Web Page
The documents residing on web sites are called Web Pages. The web pages use HTTP.
1. Home Page: It is the top-level web page of a web site. When a web-site is opened, its home page is displayed.
2. Web Portal: It is a web site, which hosts other web sites. In other words, a web portal has hyperlink to many other
web sites. By clicking upon these links, the corresponding web sites can be opened.
URL
HTTP uses internet addresses in a special format called uniform resource locator.
URL’s looks like type://address/path
Example: http://www.pue.kar.nic.in/results.asp

URL, is determined by the following:


1. The type of server or protocol
2. The name or address of the server on the Internet
3. The location of the file on the server
.
Some frequently using protocol:
File Transfer Protocol (FTP)
Transmission Control Protocol/Internet Protocol (TCP / IP)
Hyper Text Transfer Protocol (HTTP)
Post Office Protocol (POP)
Simple Mail Transfer Protocol (SMTP)
Network News Transfer Protocol (NNTP)
Domains
The domain is the name tat identifies a computer on the internet. We have different types of domain

In addition to it, a two letter abbreviation indicating the country name


may be used e.g.,http://www.pue.kar.nic.in. Here the last in suggests that it is
based in India (.in).

Electronic Commerce ( E-Commerce)


Definition: E-commerce is the trade of goods and services with the help of telecommunication and computers.
E-commerce involves the automation of a variety of business to consumer (B2B, B2C, C2B and C2C) transaction
through reliable and secure connections.
Some of the technologies and services used in e-commerce are

1. Electronic Data interchange (EDI): EDI is the electronic interchange of business information using a
standardized format.

2. e-mail

3. Electronic Funds transfer(EFT)


4. Electronic Benefits transfer(EBT),
5. Electronic forms(online admissions forms for college and other registrations)
6. Digital cash(DC)
7. Interoperable database access
8. Bulletin Boards(BBs)
9. Electronic Banking(EB)
Types of e-commerce applications:
1. Business-to-Business (B2B): The exchange of services, information and/or products from one business to another
Business partners. Ex Ebay.com
3. Business-to-Consumer (B2C): The exchange of services, information and/or productfrom a business to a
consumer.
3. Consumer-to Business (C2B): Customer directly contact with business vendors by posting their project work with
set budge online so that the needy companies review it and contact the customer directly with bid. Ex. guru.com,
freelancer.com.
4. Consumer-to-consumer(C2C): Electronic commerce is an internet facilitated form of business (commerce). The
buying and selling of old used goods will takes place

Advantages of electronic commerce application and implementation:


l. Easier entry into new markets,
2. Creates a new markets through the ability to easily and economical rate potential for customer.
3. Global participation
4. Optimization of resource.
5.Reduce time to complete business transaction,
6. Buyer makes a buying decision,
7. Improved market intelligence and strategic planning.
8. Faster service at door step.
9. 24X7 Service
Disadvantages of E commerce
1. Limited internet access in some countries
2. EDI standards have to be implemented
3. It is not possible to get real feeling of shopping
4. security issue
Chapter 17

Web designing

HTML, was invented in 1990 by a scientist is called Tim Berners-Lee.


HTML is an abbreviation of "Hyper Text Mark-up Language".
When you save an HTML file, you can use either the .htm or the .html extension.

Structure of HTML
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>
Text Layout Tags:
Tag Description
<p> Defines a paragraph
<center> Aligns text to center
<br> Brea k a line and starts new line

Text Formatting tags

Tag Description
<b> Defines bold text
<big> Defines big text
<i> Defines italic text
<small> Defines small text
superscripted
<sup> Defines text
<sub> Defines subscripted text
<tt> Defines teletype text
<u> Deprecated. Use styles instead

HTML Links (Anchor Tag)


HTML uses the <a> anchor tag to create a link to another document or web page.
<a href="http://www.austincc.edu/">Visit ACC!</a>

Marquee tag: This tag is used to scroll the text information with the following syntax
<marquee>san</marquee>
Table Tag
Table Tags Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines groups of table columns
<col> Defines the attribute values for one or
more columns in a table
FORMS

Using form user can interact with webpage

The FORM Tag

Forms are placed in your document using a <FORM> tag which must have a closing </FORM> tag. You can have more
than one form in a document as long as they don’t overlap. I.e. one form must finish before the next one begins. A
<FORM> tag specifies two main things.

The Elements of form

1. Select
The <select> element defines a drop-down list
2. text area

The <textarea> element defines a multi-line input field (a text area):

3. Input
The <input> element can be displayed in several ways, depending on the type attribute.

Web hosting

Web Hosting is a means of hosting web-server application on a computer system through which electronic
content on the Internet is readily available to any web-browser client

Various types of web hosting services are available.


1. Free Hosting
2. Virtual or Shared Hosting
3 Dedicated Hosting
4. Collocation Hosting

1. Free Hosting: This type of hosting is available with many prominent sites that offer to host some web
pages for no cost.
2. Virtual or Shared Hosting: This type of hosting is provided under one's own domain name,
3. Dedicated Hosting: In this type of hosting, the company wishing to go online rents an entire web
server from the hosting company.
4. Co-location Hosting: For those who do not fit the dedicated- server mold, hosting companies offer a
similar, but less restrictive hosting, known as co-location hosting.

XML
XML is aeXtended Markup Language
XML is a text-based markup language used for data interchange on the web.
XML document is always constrained to be well formed.
The most important is that every tag has a closing tag

DHTML (Dynamic Hyper Text Markup Language)


DHTML refers to web content that changes each time it is viewed.
It is used to generate dynamic font.
Using HTML we can change the tags and their properties.
Can be used to create animations and games
Web Scripting
The process of creating and embedding scripts in a web page is known as Web- Scripting. Scripts may be written
for a variety of purposes such as for automating processes on a local-computer
The programming languages in which scripts are written are called scripting languages. There are many scripting
languages available today. Most common ones are VBScript, JavaScript, ASP, PHP, PERL, JSP etc.
Types of Scripts
Scripts are broadly of following two types:
1. Client-Side Scripts
Client-Side scripting enables interaction within a web page.
The client-side scripts are downloaded at the client-end and then interpreted and executed by the browser.
The client side scripting is browser dependent.
Client-side scripting is used when the client-side interaction is used.
2. Server-side scripts
Server-side scripting enables the completion or carrying out a task at the server end and then sending the result to
the client end.
In server side script, the server does all the work, so it doesn't matter which browser is being used at client end.
Server side scripting is used when the information is sent to a server to be processed at the server end.
Some popular server side scripting languages are PHP (Hypertext Pre Processor)

-oOo-

You might also like