0% found this document useful (0 votes)
19 views69 pages

Chapter-4-Data-structure (1) (9 Files Merged)

Chapter 4 discusses data structures, defining them as ways to organize and store data efficiently for processing. It distinguishes between primitive and non-primitive data structures, detailing operations such as creation, updating, deletion, and searching. Additionally, it covers specific types of data structures like arrays, their operations, and algorithms for searching elements within them.

Uploaded by

cscdhvr
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)
19 views69 pages

Chapter-4-Data-structure (1) (9 Files Merged)

Chapter 4 discusses data structures, defining them as ways to organize and store data efficiently for processing. It distinguishes between primitive and non-primitive data structures, detailing operations such as creation, updating, deletion, and searching. Additionally, it covers specific types of data structures like arrays, their operations, and algorithms for searching elements within them.

Uploaded by

cscdhvr
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/ 69

Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

Chapter-4 Example: int n=15; // memory spaced to be created for n.


• Select: This operation is used programmers to access the data within the data structure. This
DATA STRUCTURES operation updates or alters data.
Example: cin>>x;
 Introduction:
• Update: This operation is used to change data of data structures. An assignment operation is a
• Data Structure is the way of collecting and organizing the data in such a way that we can
good example.
perform operation on these data in an effective way.
Example: int n = 5; //modifies the value of n to store the new value 5 in it.
• For Example: We have the data student€s Name “Akash” and age “16”. Here “Akash” is a string
• Destroy: This operation is used to destroy or remove the data structure from the memory space. In
type data type and 16 are of integer. We can now organize this data as a record like a Student
C++ one can destroy data structure by using the function called delete.
Record. We can collect and store other Student€s Record in a file or a database as a data structure.

 Non-Primitive Data structures:


 Data Representation:
• The Data structures that are derived from the primitive data structures are called Non-primitive
• Computer memory is used to store the data which is required for processing. This process is
data structure.
known as data representation.
• These data structures are used to store group of values.
• Data may be of same type or different type.
• Non-Primitive data structures are classified as arrays, lists and files.
• Data Structure provides efficient way of combining these data types and process data.
• Data Structures under lists are classified as linear and non-linear data structure.
Data Structure i. Linear Data structures:
 Linear Data structures are kind of data structure that has homogeneous elements.
Primitive Data Structure Non-Primitive Data Structure  The data structure in which elements are in a sequence and form a liner series.
 Linear data structures are very easy to implement, since the memory of the computer is also
INTEGER ARRAYS LISTS organized in a linear fashion.

CHARACTER Single Dimension  Some commonly used linear data structures are Stack, Queue and Linked Lists.
Linear Non-Linear
ii. Non-Linear Data structures:
FLOAT Two Dimension
Stack Trees  A Non-Linear Data structures is a data structure in which data item is connected to
POINTERS Multi Dimension several other data items.
Queue Graphs
 Non-Linear data structure may exhibit either a hierarchical relationship or parent child
Linked List relationship.
 Primitive Data structures:
 The data elements are not arranged in a sequential structure.
• Data structures that are directly operated upon the machine-level instructions are known as
 The different non-linear data structures are trees and graphs.
primitive data structures.
• The integers, float, character data, pointers are primitive data structures.  Operations on Non-Primitive Data structures:
1. Traversing: The processing of accessing each element exactly once to perform some operation is
 Operations on Primitive Data structures:
called traversing.
• Create: Create operation is used to create a new data structure. This operation reserves memory
2. Insertion: The process of adding a new element into the given collection of data elements is called
space for the program elements. It may be carried out at compile time and run time.
insertion.
1|Page 2|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

3. Deletion: The process of removing an existing data element from the given collection of data 1002 C A[2]
elements is called deletion. 1003 D A[3]
4. Searching: The process of finding the location of a data element in the given collection of data 1004 E A[4] Upper Bound(UB)
elements is called as searching.
5. Sorting: The process of arrangement of data elements in ascending or descending order is called • Calculating the length of the array:

sorting. o A[n], the number of n is called the size or length of the array.
6. Merging: The process of combining the elements of two structures to form a single structure is o The length of the array can be calculated by:
called merging. L = UB – LB + 1
o Here, UB is the largest Index and LB is the smallest index
 Arrays:
o Example: If an array A has values 10, 20, 30, 40, 50, stored in location 0,1, 2, 3, 4 the UB
• An array is an ordered collection of elements of same data type that share common name.
= 4 and LB=0
• The elements are arranged one after the other in adjacent memory location.
o Size of the array L = 4 – 0 + 1 = 5
• These elements are accessed by numbers called subscripts or indices.
• The elements are accessed using subscripts; arrays are also called as subscripted variables.  Basic operations on One-dimensional array: Important
• There are three types of arrays
1. Traversing : Processing each element in the array.
i. One-dimensional Array
2. Insertion : Inserting a new element into the array.
ii. Two-dimensional Array
3. Deletion : Removing an element from the array.
iii. Multi-dimensional Array
4. Searching : Finding the location of an element in the array.
 One dimensional array: 5. Sorting : Arranging the elements of the array in some order.

• An array with only one row or column is called one-dimensional array. 6. Merging : Combining one or more array to form a single array.

• It is finite collection of n number of elements of same type such that:


 Traversing an array:
o Elements are stored in continuous locations.
o Elements can be referred by indexing. • Traversing is the process of visiting each subscript at least once from the beginning element to
• The syntax to define one-dimensional array is: last element.
Syntax: Datatype Array_Name [Size]; • For example, to find the maximum element of the array we need to access each element of the
• Where, array.
o Datatype : Type of value it can store (Example: int, char, float)
ALGORITHM: Traversal (A, LB, UB) A is an array with Lower Bound LB and
o Array_Name: To identify the array.
Upper Bound UB.
o Size : The maximum number of elements that the array can hold.
Step 1: for LOC = LB to UB do
• Example: int a[5];
Step 2: PROCESS A [LOC]

Address Content Location [End of for loop]

1000 A A[0] Lower Bound(LB) Step 3: Exit

1001 B A[1]

3|Page 4|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

 Inserting an element into an array: • For example: Let A[4] be an array with items 10, 20, 30, 40, 50 stored at consecutive locations.

• Insertion refers to inserting an element into the array. Suppose item 30 has to be deleted at position 2. The following procedure is applied.

• Based on the requirement, new element can be added at the beginning, end or any given position o Copy 30 to ITEM, i.e. Item = 30.

of array. o Move Number 40 to the position 2.

• When an element is to be inserted into a particular position, all the elements from the asked o Move Number 50 to the position 3.

position to the last element should be shifted into higher order position. A[0] 10 A[0] 10 A[0] 10 A[0] 10
• For example: Let A[5] be an array with items 10, 20, 40, 50, 60 stored at consecutive locations. A[1] 20 A[1] 20 A[1] 20 A[1] 20
Suppose item 30 has to be inserted at position 2. The following procedure is applied. A[2] 30 A[2] A[2] 40 A[2] 40
o Move Number 60 to the position 5. A[3] 40 A[3] 40 A[3] A[3] 50
o Move Number 50 to the position 4. A[4] 50 A[4] 50 A[4] 50 A[4]
o Move Number 40 to the position 3.
o Position 2 is blank. Insert 30 into the position 2 i.e. A[2]=30. ALGORITHM: Delete (A, N, ITEM, Pos) A is an array with N elements. ITEM is the
element to be deleted in the position Pos and it is stored into variable Item.
A[0] 10 A[0] 10 A[0] 10 A[0] 10 A[0] 10
Step 1: ITEM = A [Pos]
A[1] 20 A[1] 20 A[1] 20 A[1] 20 A[1] 20
Step 2: for I = Pos down to N-1
A[2] 40 A[2] 40 A[2] 40 A[2] 40 A[2] 30
A[ I ] = A[I+1]
A[3] 50 A[3] 50 A[3] 50 A[3] A[3] 40
[End of for loop]
A[4] 60 A[4] 60 A[4] A[4] 50 A[4] 50
Step 3: N = N-1
A[5] A[5] A[5] 60 A[5] 60 A[5] 60
Step 4: Exit

ALGORITHM: Insert (A, N, ITEM, Pos) A is an array with N elements. ITEM is the
 Searching an element in an array:
element to be inserted in the position Pos.
Step 1: for I = N-1 down to Pos • Searching refers to finding the location of the element in a linear array.

A[ I + 1] = A[I] • There are different algorithms, but the most common methods are linear search and binary search.

[End of for loop]


 Linear Search:
Step 2: A [Pos] = ITEM
• This is the simplest method in which the element to be searched is compared with each element of
Step 3: N = N+1
the array by one from the beginning to end of the array.
Step 4: Exit
• Searching is one after the other, it is also called as sequential search.

 Deleting an element into an array: ALGORITHM: Linear_Search (A, N, Element) A is an array with N elements.
• Deletion refers to deleting an element from the array. Element is the being searched in the array.
• Based on the requirement, element can be deleted at the beginning, end or any given position of Step 1: LOC = -1 [Assume the element does not exist]
array. Step 2: for I = 0 to N-1 do
• When an element is to be deleted from a particular position, all the subsequent shifted into lower if ( Element = A [ I ] ) then
order position.
5|Page 6|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

LOC = I MID = (BEG+END)/2


Goto Step 3 if ( ELE = A [ MID ] ) then
[End if] LOC = MID Important
[End of for loop] Goto Step 3
Step 3: if ( LOC >= 0 ) then else
Print Element, “Found in Location”, LOC if( ELE < A[MID])
else END=MID-1;
Print Element, “Not Found” else
Step 4: Exit BEG=MID+1;
[End if]
• Example: Consider the following elements stored in an array and we are searching for the element
[End if]
17. The trace of the algorithm is given below.
[End of While loop]
Index (I) Compare 17 Location
Step 3: if ( LOC >= 0 ) then
17 = 12
I=0 LOC = -1 Print Element, “Found in Location”, LOC
(Does not match)
A[0] A[1] A[2] A[3] A[4] 17 = 23 else
I=1 LOC = -1
(Does not match) Print Element, “Search is Unsuccessful”
12 23 9 17 7
17 = 9 Step 4: Exit
I=2 LOC = -1
(Does not match)
17 = 17 • Example: Consider the following elements stored in an array and we are searching for the element
I=3 LOC = 3
(Matches)
47. The trace of the algorithm is given below.
 Binary Search: MID =
BEG & END Compare Location
(BEG+END)/2
• When the elements of the array are in sorted order, the best method of searching is binary search.
• This method compares the element to be searched with the middle element of the array. A[0] A[1] A[2] A[3] A[4]
47>39
12 23 39 47 57 BEG = 0 MID = (0+4)/2
• If the comparison is searched either at the right half of the array or at the left half of the array. (Does not LOC = -1
END = 4 MID = 2
BEG MID END match)
• Let the position of first (BEG) and last (END) elements of the array. The middle element A[MID]
can be obtained by find the middle location MID by MID= (BEG+END)/2.
The search element i.e. 47 is greater than the element in the middle position i.e. 39 then
• If A[MID]= ELE, then search is successful. Otherwise a new segment is found as follows: continues the search to the right portion of the middle element.
o If ELE<A[MID], searching is continued at left half of the array. Reset END=MID-1.
A[0] A[1] A[2] A[3] A[4]
o If ELE>A[MID], searching is continued at right half of the array. Reset BEG=MID+1.
12 23 39 47 57 BEG = 3 MID = (3+4)/2
o If ELE not found then we get a condition BEG>END. This results in unsuccessful search. 47 = 47 LOC = 3
END = 4 MID = 3
BEGMID END
ALGORITHM: Binary_Search (BEG, END, MID ELE) A is an array with N
elements. Let BEG, END, MID denote Beginning, end and middle location of the array Since the element in the middle position is the same as the search element LOC gets the value 3.
Step 1: Set BEG=LB, END=UB LOC = -1 Since the value of LOC is greater than 0, we get the output as 47 Found in location 3
Step 2: While(BEG <= END)
7|Page 8|Page
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

• Example: Consider the following elements stored in an array and we are searching for the element  Sorting the elements in an array:
67. The trace of the algorithm is given below. • Sorting is the arrangement of elements of the array in some order.
MID = • There are different sorting methods like Bubble Sort, Selection Sort, Shell Sort, Quick sort, Heap
BEG & END Compare Location
(BEG+END)/2
Sort, Insertion Sort etc.
A[0] A[1] A[2] A[3] A[4]
67>39
12 23 39 47 57 BEG = 0 MID = (0+4)/2  Insertion Sort:
(Does not LOC = -1
END = 4 MID = 2
BEG MID END match) • In Insertion sort, the first element of the array is assumed to be in the correct position next element

The search element i.e. 67 is greater than the element in the middle position i.e. 39 then is considered as the key element and compared with the elements before the key element and is
continues the search to the right portion of the middle element. inserted in its correct position.
A[0] A[1] A[2] A[3] A[4] • Example: Consider the following array contains 8 elements as follows:
67>47
12 23 39 47 57 BEG = 3 MID = (3+4)/2 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7]
(Does not LOC = -1
END = 4 MID = 3
BEGMID END match) 45 26 23 56 29 36 12 4

The search element i.e. 67 is greater than the element in the middle position i.e. 47 then
continues the search to the right portion of the middle element.
A[0] A[1] A[2] A[3] A[4]
12 23 39 47 57 67>57
BEG = 4 MID = (4+4)/2
(Does not LOC = -1
BEGMID END = 4 MID = 4
match)
END
The search element i.e. 67 is greater than the element in the middle position i.e. 57 then
continues the search to the right portion of the middle element.

A[0] A[1] A[2] A[3] A[4] ALGORITHM: Insertion_Sort (A, N) A is an array with N unsorted elements.
12 23 39 47 57 BEG = 5 Since the condition (BEG <= END) is
Step 1: for I=1 to N-1
END = 4 false the comparison ends
ENDBEG Step 2: J=I

We get the output as 67 Not Found While(J >= 1)


if ( A[J] < A[J-1] ) then
 Difference between Linear Search and Binary Search Temp = A[J];
Linear Search Binary Search A[J] = A[J-1];
This can be used in sorted and unsorted A[J-1] = Temp;
1 This can be used only in sorted array
array
[End if]
One must have direct access to the middle
2 Array elements are accessed sequentially J = J-1
element in the sub list.
3 Access is very slow Access is faster. [End of While loop]
This can be used in single and multi
4 Used only in single dimensional array. [End of For loop]
dimensional array
This technique is easy and simple in Step 3: Exit
5 Complex in operation
implementing

9|Page 10 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC,, M
MDRPUC, Hassan

 Two dimensional array:  Advantages of Array:


• A two dimensional array is a collection of elements and each element is identified by a pair of • It is used to represent multiple
ple da
data items of same type by using single name
me.
subscripts. ( A[5] [5] ) • It can be used to implement othe
other data structures like linked lists, stacks,
ks, que
queues, tree, graphs etc.
• The elements are stored in continuous memory locations. • Two-dimensional arrays are use
used to represent matrices.
• The elements of two-dimensional array as rows and columns. • Many databases include one-di
-dimensional arrays whose elements are records.
ords.
• The number of rows and columns in a matrix is called as the order of the matrix and denoted as
 Disadvantages of Array:
y:
mxn.
• We must know in advance the
he how many elements are to be stored in array.
y.
• The number of elements can be obtained by multiplying number of rows and number of columns.
• Array is static structure. It me
means that array is of fixed size. The memory
ory which is allocated to
[0] [1] [2]
array cannot be increased or de
decreased.
A[0] 1 2 3
• Array is fixed size; if we alloc
locate more memory than requirement then the memory space will be
A[1] 7 8 9
wasted.
A[2] 4 5 6
• The elements of array are stor
stored in consecutive memory locations. So inse
insertion and deletion are
 Representation of Two Dimensional Array: very difficult and time consumi
nsuming.
• A is the array of order m x n. To store m*n number of elements, we need m*n memory locations.
 STACKS:
The elements should be in contiguous memory locations.
• A stack is an ordered collection
tion of items in which an element may be inse
nserted or deleted only at
• There are two methods:
same end.
o Row-major method
• This end is called as the top of tthe stack.
o Column-major method
• known as the base.
The end opposite to top iss know
• Row-Major Method: All the first-row elements are stored in sequential memory locations and
• Stacks are sometimes knownn as LIFO (Last In First Out).
then all the second-row elements are stored and so on.
1001 1 A[0][0]
1001 1 A[0][0]  Representation of Stacks
cks using Array:
1002 2 A[1][0]
1002 7 A[0][1] • Stack can be represented using
ng a one-dimensional array.
1003 3 A[2][0]
1003 4 A[0][2] • The items into the stack aree st location of the memory
stored in a sequential order from the first loc
1004 7 A[0][1]
1004 2 A[1][0] block.
1005 8 A[1][1]
1005 8 A[1][1] • A pointer TOP contains the loc
location of the top element of the stack.
1006 9 A[2][1]
1006 5 A[1][2] • A variable MAXSTK contains
ns tthe maximum number of element that cann be stored in the stack.
1007 3 A[0][2]
1007 4 A[2][0]
• If we attempt to add new elem ncounter a stack overflow
ement beyond the maximum size, we will encount
1008 9 A[1][2]
1008 5 A[2][1] condition. Similarly, you cannot remove elements
1009 6 A[2][2]
1009 6 A[2][2] beyond the base of the stack.
k. If such is the case, we
Row-Major Method Column Major Method will reach a stack underflow con
condition.

• Column-Major Method: All the first column elements are stored in sequential memory locations • The condition TOP = MAXS
XSTX indicates that the

and then all the second-column elements are stored and so on. stack is full and TOP = NULL
LL indicates that stack is
empty.
11 | P a g e 12 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

 Operation on Stacks:  Application of Stacks:


• Stack( ): It creates a new stack that is empty. It needs no parameter and returns an empty stack. • It is used to reverse a word. You push a given word to stack – letter by letter and then pop letter
• push(item): It adds a new item to the top of the stack. from the stack.
• pop( ): It removes the top item from the stack. • “Undo” mechanism in text editor.
• peek( ): It returns the top item from the stack but does not remove it. • Backtracking: This is a process when you need to access the most recent data element in a series of
• isEmpty( ): It tests whether the stack is empty. elements. Once you reach a dead end, you must backtrack.
• size( ): It returns the number of items on the stack. Important • Language Processing: Compiler€ syntax check for matching braces in implemented by using stack.
• Conversion of decimal number to binary.
 PUSH Operation: • Conversion of infix expression into prefix and postfix.
• The process of adding one element or item to the stack is represented by an operation called as • Quick sort
the PUSH operation. • Runtime memory management.
• The new element is added at the topmost position of the stack.
ALGORITHM: PUSH (STACK, TOP, ITEM) STACK is the array with N elements. TOP is the  Arithmetic Expression:
pointer to the top of the element of the array. ITEM to be inserted. • An expression is a combination of operands and operators that after evaluation results in a single
Step 1: if TOP = N-1 then [Check Overflow] value.
PRINT “ STACK is Full or Overflow” • Operand consists of constants and variables.
Exit • Operators consists of {, +, -, *, /, ), ] etc.
[End if] • Expression can be
Step 2: TOP = TOP + 1 [Increment the TOP] o Infix Expression
Step 3: STACK[TOP] = ITEM [Insert the ITEM] o Postfix Expression
Step 4: Return o Prefix Expression
• Infix Expression: If an operator is in between two operands, it is called infix expression.
 POP Operation:
Example: a + b, where a and b are operands and + is an operator.
• The process of deleting one element or item from the stack is represented by an operation called
• Postfix Expression: If an operator follows the two operands, it is called postfix expression.
as the POP operation.
Example: ab +
ALGORITHM: POP (STACK, TOP, ITEM) STACK is the array with N elements. TOP is the
• Prefix Expression: an operator precedes the two operands, it is called prefix expression.
pointer to the top of the element of the array. ITEM to be inserted.
Example: +ab
Step 1: if TOP = NULL then [Check Underflow]
 Algorithm for Infix to Postfix:
PRINT “ STACK is Empty or Underflow”
1. Examine the next element in the input.
Exit
2. If it is operand, output it.
[End if]
3. If it is opening parenthesis, push it on stack.
Step 2: ITEM = STACK[TOP] [copy the TOP Element]
4. If it is an operator, then
Step 3: TOP = TOP - 1 [Decrement the TOP]
o If stack is empty, push operator on stack.
Step 4: Return
13 | P a g e 14 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

o If the top of the stack is opening parenthesis, push operator on stack. • Consider the following examples of converting from infix to prefix.
o If it has higher priority than the top of stack, push operator on stack.
Infix Prefix
Sl No
o Else pop the operator from the stack and output it, repeat step 4.
1 (A+B)*C = [+AB] * C *+ABC
5. If it is a closing parenthesis, pop operators from the stack and output them until an opening
2 A+B+C = [+AB]+C ++ABC
parenthesis is encountered. Pop and discard the opening parenthesis.
6. If there is more input go to step 1. 3 (A+B)/(X–Y) = [+AB]/[-XY] /+AB-XY

7. If there is no more input, pop the remaining operators to output. = [^AB] *C-D
4 A^B*C–D -*^ABCD
= [*^ABC]-D
• Example: Suppose we want to convert 2*3/(2-1)+5*3 into postfix form. = ([+AB]*C-[-DE])^[+XY]
Expression Stack Output 5 ((A + B)*C–(D–E))^(X+Y) =([*+ABC]-[-DE])^[+XY] ^-*+ABC-DE^+XY
2 Empty 2 = (-*+ABC-DE)^[+XY]
* * 2
3 * 23  QUEUES:
/ / 23* • A queue is an ordered collection of items where an item is inserted at one end called the “rear”
( /( 23* and an existing item is removed at the other end, called the “front”.
2 /( 23*2 • Queue is also called as FIFO list i.e. First-In First-Out.
- /(- 23*2 • In the queue only two operations are allowed enqueue and dequeue.
1 /(- 23*21 • Enqueue means to insert an item into back of the queue.
) / 23*21- • Dequeue means removing the front item.
+ + 23*21-/ REAR FRONT

5 + 23*21-/5
Dequeue
* +* 23*21-/5
Enqueue
3 +* 23*21-/53  Types of Queues:
Empty 23*21-/53*+ • Queue can be of four types:
• Consider the following examples of converting from infix to postfix o Simple Queue
Sl No Infix Postfix o Circular Queue
1 (A+B)*C = [AB+] * C AB+C* o Priority Queue
2 A+B+C = [AB+]+C AB+C+ o Dequeue ( Double Ended Queue)
3 (A+B)/(X–Y) = [AB+]/[XY-] AB+XY-/ • Simple Queue: In simple queue insertion occurs at the rear end of the list and deletion occurs at
= [AB^] *C-D the front end of the list.
4 A^B*C–D AB^C*D-
= AB^C*-D Front Rear
= ([AB+]*C-[DE-])^[XY+]
A B C D Front = 1
5 ((A + B)*C–(D–E))^(X+Y) =([AB+C*]-[DE-])^[XY+] AB+C*DE--XY+^
Rear = 4
= (AB+C*DE--)^[XY+] 0 1 2 3 4 5

15 | P a g e 16 | P a g e
Chapter 4- Data Structures II PUC,, M
MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

• Ci
Circular Queue: A circular queue is a queue
ue in which all nodes are ITEM = QUEUE [FRONT], FRONT = FRONT + 1
treatedd as circular such that the last node follows the fi
first node. Front Rear

• Pr
Priority Queue: A priority queue is a
B C D E Front = 2
queue tha
that contains items that have some Rear = 5
0 1 2 3 4 5
present pr
priority. An element can be inserted
 Queue Insertion Operation (ENQUEUE):
or removed from any position
on de
depending upon some priority.
• Consider a queue Q with 5 elements.
• Dequeue: It is a queue in which
hich iinsertion and deletion takes place
Q[0] Q[1] Q[2] Q[3] Q[4] Initially Queue is Empty FRONT = -1, REAR= -1
at the both ends.

• If we want to add one element i.e. 8 in the queue, then FRONT and REAR Indicator are set to 0
and the element 8 would be stored at the position pointed by the REAR.
REAR = 0, FRONT = 0, Q[REAR]=Q[0]=8 Q[0] Q[1] Q[2] Q[3] Q[4]
 Operation on Queues: 8
• Queue( ): It creates a new queue that is empty.
• If we want to add one more element i.e. 12 in the queue, then REAR Indicator would be
• enqueue(item): It adds a new
w iitem to the rear of the queue.
incremented by 1 and the element 12 would be stored at the position pointed by the REAR.
• dequeue( ): It removes the front
ront item from the queue.
REAR = 1, FRONT = 0, Q[REAR]=Q[1]=12 Q[0] Q[1] Q[2] Q[3] Q[4]
• isEmpty( ): It tests to see whethe
hether the queue is empty.
8 12
• size( ): It returns the number of items in the queue.
• Repeat this procedure three more times to insert 4, 18 and 34 elements.
 Memory Representation
n of a queue using array: REAR = 4, FRONT = 0, Queue is full. Q[0] Q[1] Q[2] Q[3] Q[4]
• Queue is represented in memor
ory using linear array. 8 12 4 18 34
• Let QUEUE is a array, twoo point
pointer variables called FRONT and REAR are re m
maintained.
 Algorithm for Insertion:
• The pointer variable FRONT cont moved or deleted.
contains the location of the element to be remove
ALGORITHM: ENQUEUE (QUEUE, REAR, FRONT, ITEM) QUEUE is the array with N
• The pointer variable REAR cont
contains location of the last element inserted.
• The condition FRONT = NULL LL indicates that queue is empty. elements. FRONT is the pointer that contains the location of the element to be deleted and REAR
• The condition REAR = N-11 indi
indicates that queue is full. contains the location of the inserted element. ITEM is the element to be inserted.
Front Rear
Step 1: if REAR = N-1 then [Check Overflow]
PRINT “QUEUE is Full or Overflow”
A B C D Front = 1 Exit
Rear = 4
0 1 2 3 4 5 [End if]
REAR
EAR = R
REAR + 1, QUEUE [REAR] = ‚E€ Step 2: if FRONT = NULL then [Check Whether Queue is empty]
FRONT = 0
Front Rear REAR = 0
else
A B C D E Front = 1 REAR = REAR + 1 [Increment REAR Pointer]
Rear = 5 Step 3: QUEUE[REAR] = ITEM [Copy ITEM to REAR position]
0 1 2 3 4 5
Step 4: Return
17 | P a g e 18 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

 Queue Deletion Operation (DEQUEUE):  Application of Queue:


• Consider a queue Q with 3 elements. • Simulation
Q[0] Q[1] Q[2] Q[3] Q[4] FRONT = 0, REAR = 2, Delete 8 • Various features of Operating system
8 12 4 • Multi-programming platform systems.
• Different types of scheduling algorithms
• If we want to delete an element i.e. 8 from the queue, then the value of FRONT will be
• Round robin technique algorithms
incremented by 1. Deletions are done from this end of the queue.
• Printer server routines
REAR = 2, FRONT = 1, Q[0] Q[1] Q[2] Q[3] Q[4]
• Various application software€s is also based on queue data structure.
12 4

 LINKED LIST:
• If we want to delete an element i.e. 12 from the queue, then the value of FRONT will be
incremented by 1 i.e. 2. • A linked list is a linear collection of data elements called nodes.

REAR = 2, FRONT = 2 Q[0] Q[1] Q[2] Q[3] Q[4] • Each nodes is divided into two parts:

4 o The first part contains the information of the element.


o The second part contains the memory address of the next node in the list. Also called Link
• Observe that queue has only one element. When FRONT = REAR condition is true, then the queue part.
Q has only one element. If we want to this element also, then the queue Q becomes empty and set
the FRONT and REAR pointers to -1.
REAR = -1, FRONT = -1, Queue is Empty. Q[0] Q[1] Q[2] Q[3] Q[4]

 Algorithm for Deletion:

ALGORITHM: DEQUEUE (QUEUE, REAR, FRONT, ITEM) QUEUE is the array with N
• In the above figure shows an representation if Linked List with three nodes, each node contains
elements. FRONT is the pointer that contains the location of the element to be deleted and REAR
two parts.
contains the location of the inserted element. ITEM is the element to be deleted.
• The left part of the node represents Information part of the node.
Step 1: if FRONT = NULL then [Check Whether Queue is empty] • The right part represents the next pointer field. That contains the address of the next node.
PRINT “QUEUE is Empty or Underflow” • A pointer START or HEAD gives the location of the first node.
Exit • The link field of the last node contains NULL.
[End if]
 Types of Linked List: Important
Step 2: ITEM = QUEUE[FRONT]
Step 3: if FRONT = REAR then [if QUEUE has only one element] • There are three types of linked lists:
FRONT = NULL o Singly Linked List
REAR = NULL o Doubly Linked List
else o Circular Linked List
FRONT = FRONT + 1 [Increment FRONT pointer]
 Singly Linked List:
Step 4: Return
• A singly linked list contains two fields in each node - an information field and the linked field.
19 | P a g e 20 | P a g e
Chapter 4- Data Structures II PUC,, M
MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

• The information field contains


ins tthe data of that node.  Creating a linked list:
• The link field contains the mem
emory address of the next node. • The nodes of a linked list can be created by the following structure declaration.
• nked list.
There is only one link field inn eeach node, the linked list is called singly linke struct Node
{
int info;
struct Node *link;
}*node1, node2;
• Here info is the information field and link is the link field.
 Circular Linked List
• The link field contains a pointer variable that refers the same node structure. Such a reference is
• The link field of the last node node, such a linked list is
ode ccontains the memory address of the first node
called as Self addressing pointer.
called circular linked list.
• In a circular linked list every node is accessible from a given node.  Operator new and delete:
• Operators new allocate memory space.
• Operators new [] allocates memory space for array.
• Operators delete deallocate memory space.
• Operators delete [] deallocate memory space for array.
 Doubly Linked List
 Traversing a linked list:
• It is a linked list in which eac
each node is points both to the next node an
and also to the previous
node. • Traversing is the process of accessing each node of the linked list exactly once to perform some
operation.
ALGORITHM: TRAVERS (START, P) START contains the address of the first node. Another
pointer p is temporarily used to visit all the nodes from the beginning to the end of the linked list.
• In doubly linked list each node ccontains three parts:
Step 1: P = START
o FORW : It is a pointerr ffield that contains the address of the next node
Step 2: while P != NULL
o BACK: It is a pointerr fi ous node
field that contains the address of the previous node.
Step 3: PROCESS data (P) [Fetch the data]
o INFO: It contains the ac
actual data.
Step 4: P = link(P) [Advance P to next node]
• In the first node, if BACK cont
ontains NULL, it indicated that it is the first node in the list.
Step 5: End of while
• The node in which FORW cont
ontains, NULL indicates that the node is the last node.
Step 6: Return
 Operation on Linked List
List:
 AVAIL List
• The operation that are performe
med on linked lists are:
• The operating system of the computer maintains a special list called AVAIL list that contains only
o Creating a linked list
o Traversing a linked list
ist the unused deleted nodes.
o Inserting an item intoo a llinked list. • Whenever node is deleted from the linked list, its memory is added to the AVAIL list.
o Deleting an item from th the linked list.
• AVAIL list is also called as the free-storage list or free-pool.
o Searching an item inn the linked list
o Merging two or more lin linked lists.
21 | P a g e 22 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

 Inserting a node into the linked list: P2  link(P2)

o Inserting a node at the beginning of the linked list While end

o Inserting a node at the given position. Step 4: PRINT data(p2)

o Inserting a node at the end of the linked list. Step 5: link(P1)  NULL
Free(P2)
• Inserting a node at the beginning of the linked list
Step 6: STOP
1. Create a node.
2. Fill data into the data field of the new node.  Non-Linear Data structures:
3. Mark its pointer field as NULL • A Non-Linear Data structures is a data structure in which data item is connected to several
4. Attach this newly created node to START other data items.
5. Make the new node as the STARTing node. • The data items in non-linear data structure represent hierarchical relationship.
• Each data item is called node.
ALGORITHM: INS_BEG (START, P) START contains the address of the first node.
• The different non-linear data structures are trees and graphs.
Step 1: P  new Node;
Step 2: data(P)  num;  Trees:
Step 3: link(P)  START
• A tree is a data structure consisting of nodes organized as a hierarchy.
Step 4: START  P
Step 5: Return

 Garbage Collection:
• The operating system of the computer periodically collects all the deleted space into the free-
storage list. This technique of collecting deleted space into free-storage list is called as garbage
collection.

 Deleting an item from the linked list:


o Deletion of the first node
 Terminology of a tree:
o Deletion of the last node
o Deletion of the node at the give position • Node: A node is a fundamental part of tree. Each element of a tree is called a node of the tree.
• Root: The topmost node of the tree.
• Deletion of the last node
• Edge: It connects two nodes to show that tree is a relationship between them.
ALGORITHM: DEL_END (P1, P2, START) This used two pointers P1 and P2. Pointer P2 is used to • Parent: It is an immediate predecessor a node. ( A is parent of B, C, D)
traverse the linked list and pointer P1 keeps the location of the previous node of P2. • Child: A successor of parent node is called the child node. (E, F is a child of B)
Step 1: START
• Siblings: Nodes that are children of the same parent are called siblings. (B,C,D) (M,N)
Step 2: P2  START;
• Leaf or terminal node: Nodes that do not have any children are called leaf node. (J, K, L)
Step 3: while ( link(P2) ! = NULL)
• Internal Node: A node has one or more children is called an internal node. ( B, C, D, H )
P1  P2
23 | P a g e 24 | P a g e
Chapter 4- Data Structures II PUC, MDRPUC, Hassan Chapter 4- Data Structures II PUC, MDRPUC, Hassan

• Path: A path is an ordered list of nodes that are connected by edges. In figure path A to O is A, D, CHAPTER – DATA STRUCTURES BLUE PRINT
I, M, O. VSA (1 Marks) LA (3 Marks) Essay (5 Marks) Total
• Height: the height or depth of a tree is defined to be the maximum number of nodes in a branch of 01 Question 01 Question 02 Question 04 Questions
tree. ( The height of tree is 5)
Question No 3 Question No 23 Question No 28 & 29 14 Marks
• Ancestor: A node reachable by repeated proceeding from child to parent. (Ancestor of M is I, D,
and A)
Important Questions
• Descendant: A node reachable by repeated proceedings from parent to child. (Descendent of I are
1 Mark Questions:
(M,O) and N)
• Subtree: A Subtree is a set of nodes and edges comprised of parent and all the descendants of that 1. Definition of Data Structure, Linear Data Structures, Array, Stack, Queue, Linked List,
parent. In figure T1, T2 and T3 are subtrees. Non Linear Data Structures.
2. Definition on Tree, Tree Terminologies, Binary Tree, Complete Binary Tree, Graph.
 Binary tree:
3 Marks Questions:
• A binary tree is an ordered tree in which each internal node can have maximum of two child
nodes connected to it. 1. Types of Data Structure, Array, Queue, Linked list.
• A binary tree consists of: 2. Memory Representation of Array, Stack.
o A node ( called the root node) 3. Algorithms – Traverse, Insertion, Deletion, Linear Search, PUSH, POP
o Left and right sub trees. 4. Conversions: Infix to Postfix & Prefix.
5. Advantages/Applications of arrays, stacks, queues

5 Marks Questions:

• Operations on Non-Primitive Data Structure, Array, Stack, Queue, Linked list.


• Algorithms: Binary Search, Insertion Sort, Enqueue, Dequeue.
• Tracing Algorithm: Binary Search, Insertion Sort.
• A Complete binary tree is a binary tree in which each leaf is at the same
distance from the root i.e. all the nodes have maximum two subtrees.

 GRAPH

• A graph is a set of vertices and edges which connect them.


• A graph is a collection of nodes called vertices and the
connection between them called edges.
• Directed graph: When the edges in a graph have a direction, the
graph is called directed graph or digraph, and the edges are
called directed edges or arcs.

25 | P a g e 26 | P a g e
Chapter 6- Basic Concept of OOP III P
PUC, MDRPUC, Hassan Chapter 6- Basic Concept of OOP III P
PUC, MDRPUC, Hassan

Chapter-6 member data and the functions


ons tthat operate on these data known as member
ber ffunction.
• OOP follows bottom-up design
sign ttechnique.

BAS
BASIC CONCEPT OF OOP • Class is the major concept tha
that plays important role in this approach.
h. C
Class is a template that
represents a group of objectss w
which share common properties and relationshi
onships.
 Introduction:
 Difference between P
Procedural Programming & Object Oriented
• Object oriented programming
ng is the principle of design and developme
ment of programs using
programming:
modular approach.
• Object oriented programming
ng approach provides advantages in creation
ion and development of Procedural Progra
ogramming Object Oriented Progr
rogramming
software for real life application.
tion.
Large programs are divided
ed iinto smaller
Programs are divided intoo obj
objects
• The basic element of object orie
oriented programming is the data. programs known as functions
tions
• The programs are built by combi
ombining data and functions that operate on the
he da
data. Data is not hidden and can
an be accessed by Data is hidden and cannott be accessed by
• Some of the OOP€s languages
guages aare C++, Java, C #, Smalltalk, Perl, and Python
thon. external functions external functions
Follow top down approach
ch iin the program Follows bottom-up approac
oach in the
 Procedural programming
ing: design program design

• ing focuses on processing of


The procedural programming Data may communicate wit
with each other Objects may communicate
te w
with each other
through functions through functions.
instructions in order to per
perform a desired computation.
Emphasize is on procedure
re rrather than Emphasize is on data rather
her than
Therefore it emphasizes moree on doi
doing things like algorithms.
data procedure
• This programming is lengthy
thy, increases the complexity of
program, difficult to understand
and aand modify the program.  Basic Concepts of OOP€s
OP€s:
• This technique is used in a conve
onventional programming language such as C aand Pascal. The following are the major
or cha
characteristics of OOP€s: IImportant
• Objects • Overloading
 Structured programming
ing:
• Class • Polymorphism
• An organized approach to prog
programming involving
• Data abstraction • Dynamic Binding
nding
the use of three basic control structures – Sequence,
ol st
• Data encapsulation • Message Passing
ng
Conditional and loop.
• Inheritance
• The top-down concepts to decompose main
functions into lower level compone
omponents for modular coding purpose.
• The major drawback is that itt is ve
very difficult to model the real world scenar
nario using this model.

 Object oriented program


amming:
• Object oriented programming
ng (OOP) is a concept
that combines both the data aand the functions that
operate on that data into a si
single unit called the
object.
• An object is a collection of se
set of data known as
1|Page 2|Page
Chapter 6- Basic Concept of OOP III P
PUC, MDRPUC, Hassan Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan

 Objects • Data hiding is a method used in object oriented programming to hide information within computer

• Objects are basic building blocks


ocks ffor designing programs. code.

• An object is a collection of data m


members and associated member function
ions.
 Inheritance:
• An object may represent a person, pl
place or a table of data.
• Inheritance is the process by which one object can
• Each object is identified by a uni
unique name. Each object must be a memberr of a particular class.
acquire and use the properties of another object.
• Example: Apple, orange, mang
ngo are the objects of class fruit.
• The existing class is known as base class or super
• Objects take up space in memor
ory and have address associated with them.
class.
• At the time of execution of a pr
program, the objects interact by sending the me
messages to one another.
• The new class is known as derived class or sub class.
• The objects can interact with
th one another without having to know detail
tails of data or functions
• The derived class shares some of the properties of the base class. Therefore a code from a base
within an object.
class can be reused by a derived class.

 Overloading:
• Overloading allows objects to have different meaning depending upon context.
• There are two types of overloading viz.
o Operator Overloading
o Function Overloading
• When an existing operator operates on new data type is called operator overloading.
 Classes: • Function overloading means two or more function have same, but differ in the number of
• The objects can be made userr de
defined data types with the help of a class. arguments or data type of arguments.
• A class is a collection of object
objects that have identical properties, common
 Polymorphism:
behavior and shared relationsh
onship.
• The ability of an operator and function to take
• Once class is defined, any num
number of objects of that class is created.
multiple forms is known as Polymorphism.
• Classes are user defined data types. A class can hold both data and
• The different types of polymorphism are operator
functions.
overloading and function overloading.
• For example: Planets, sun, moon
oon aare member of class solar system.
 Dynamic binding:
 Data Abstraction:
• Binding is the process of connecting one program to another.
• Data Abstraction refers too th
the process of representing essential featu
atures without including
• Dynamic binding is the process of linking the procedure call to a specific sequence of code or
background details or explanat
anations.
function at run time or during the execution of the program.
 Data Encapsulation:
 Message Passing:
• The wrapping of data and fun
functions into a single unit (class) is called
• In OOP€s, processing is done by sending message to objects.
data encapsulation.
• A message for an object is request for execution of procedure.
• Data encapsulation enabless data hiding and information hiding.

3|Page 4|Page
Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan Chapter 6- Basic Concept of OOP II PUC, MDRPUC, Hassan

• Message passing involves specifying the name of the object, the name of the function (message) CHAPTER 6 – Basic Concept of OOP€s BLUE PRINT
and the information to be sent. VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
Important - 01 Question - 01 Question 02 Question
 Advantage of OOP€s
- Question No 13 Question No 30 07 Marks
• The programs are modularized based on the principles of classes and objects.
• Linking code & object allows related objects to share common code. This reduces code
Important Questions
duplication and code reusability.
• Creation and implementation of OOP code is easy and reduces software development time. 2 Marks Question:
• The concept of data abstraction separates object specification and object implementation.
• Data encapsulated along with functions. Therefore external non-member function cannot access or 1. Explain: Classes, Objects, Data Abstraction, Data Encapsulation, Inheritance, and
modify data, thus proving data security. Polymorphism.
• Easier to develop complex software, because complexity can be minimized through inheritance. 2. What is Base class and derived class?
• OOP can communicate through message passing which makes interface description with
outside system very simple.
5 Marks Question:

 Disadvantage of OOP€s 1. Distinguish between procedural and object oriented programming.

• Larger program size: OOP€s typically involves more lines of code than procedural programs. 2. Explain the characteristics of OOP€s.
• Slower Programs: OOP€s typically slower than procedure based programs, as they typically 3. Briefly explain the basic concepts of OOP€s.
require more instructions to be executed. 4. Explain the advantages of OOP€s.
• Not suitable for all types of programs. 5. Mention disadvantages of OOP€s.
• To convert a real world problem into an object oriented model is difficult.
6. Write the applications of OOP€s.
• OOP€s software development, debugging and testing tools are not standardized.
• Polymorphism and dynamic binding also requires processing time, due to overload of function
calls during run time.

 Application of OOP€s
• Computer graphics applications.
• .CAD/CAM software
• Object-oriented database.
• User-Interface design such as windows
• Real-time systems.
• Simulation and Modeling
• Artificial intelligence and expert systems.
• Client-Server Systems.

5|Page 6|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

Chapter-7 int accno;


char name[20];
char acctype[4];
CLASSES AND OBJECTS int bal_amt;
public:
void get_data( );
 Classes: void display_data( );
};
• A class is a collection of objects that have identical properties, common behavior and shared
relationship.  Access Specifiers:
• A class binds the data and its related functions together. • Every data member of a class is specified by three levels of access protection for hiding data and
function members internal to the class.
 Definition and Declaration of Classes:
• They help in controlling the access of the data members.
• A class definition is a process of naming a class and data variables, and interface operation of the
• Different access specifiers such as private, public, and protected.
class.
• The variables declared inside a class are known as data members.  private:
• The functions declared inside a class are known as member functions. • private access means a member data can only be accessed by the class member function or friend
• A class declaration specifies the representation of objects of the class and set of operations that function.
can be applied to such objects. • The data members or member functions declared private cannot be accessed from outside the
• The general syntax of the class declaration is: class.
class User_Defined_Name Important • The objects of the class can access the private members only through the public member functions
{ 5 Marks of the class. This property is also called information hiding.
private :
Data Member; • By default data members in a class are private.
Member functions; • Example:
public :
private:
Data Member; int x;
Member functions; float y;
protected :
Data Member ;  protected:
Member functions;
}; • The members which are declared using protected can be accessed only by the member functions,
friend of the class and also the member functions derived from this class.
• Key word class is used to declare a class. User_Defined_Name is the name of the class.
• The members cannot be accessed from outside the class.
• Class body is enclosed in a pair of flower brackets. Class body contains the declaration of its
• The protected access specifier is similar to private access specifiers.
members (data and functions).
• There are generally three types of members namely private, public and protected.  public:
• Example: Let us declare a class for representation of bank account. • public access means that member can be accessed any function inside or outside the class.
class account • Some of the public functions of a class provide interface for accessing the private and protected
{
members of the class.
private:

1|Page 2|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

 Outside class definition:


• To define member function outside the class declaration, you must link the class name of the class
with the name of member function.
• We can do this by preceding the function name with the class name followed by two colons (::).
• The two colons (::) are called scope resolution operator.
• Scope resolution operator (::) is used to define the member function outside the class.
• The general form of a member function defined outside the class is:
return_type class_name : : member_function_name( arg1, arg2, ….argN)
{
 Member Function:
function body;
• Member functions are functions that are included within a class (Member functions are also called
}
Methods).
• Example:
• Member functions can be defined in two places. class operation
o Inside class definition
Important {
private:
o Outside class definition 5 Marks int a, b;
public:
 Inside class definition: int sum( );
int product( );
• To define member function inside a class the function declaration within the class is replaced by };
actual function definition inside the class. int operation : : sum( )
{
• A function defined in a class is treated as inline function. return (a+b);
• Only small functions are defined inside class definition. }
int operation : : product( )
• Example: {
class rectangle return (a * b);
{ }
int length, breadth, area;  Program: To use classes using member functions inside and outside class definition.
public:
#include<iostream.h>
void get_data( )
class item
{ {
cout<< ” Enter the values for Length and Breadth”; private:
cin>>length>>breadth; int numbers;
} float cost;
void compute( ) public:
{ void getdata(int a, float b);
area = length * breadth; void putdata( )
} {
void display( ) cout<<”Number: “<<number<<endl;
{ cout<<”Cost:”<<cost<<endl;
cout<<” The area of rectangle is”<<area;
}
}
}; };

3|Page 4|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

void item : : getdata(int a, float b) • Example 2:


{ class num
number = a; {
cost = b; private :
} int x, y;
int main( ) public :
{ OUTPUT: int sum(int p, int q)
int diff(int p, int q)
item x;
Number: 250 };
x. getdata( 250, 10.5); void main( )
x.putdata( ); Cost: 10.5 {
return 0; num s1, s2;
} s1.sum ( 200,300);
s2.diff (600, 500);
 Defining object of a class: }

• An object is a real world element which is identifiable entity with some characteristics (attributes)  Accessing member of the class:
and behavior (functions). • The member of the class can be data or functions.
• An object is an instance of a class. Objects are sometimes called as instance variables. • Private and protected members of the class can be accessed only through the member functions of
• An object is normally defined in the main ( ) function. the class.
• The syntax for defining objects of a class as follows: • No functions outside a class can include statements to access data directly.
class Class_Name • The public data members of objects of a class can be accessed using direct member access
{
operator (.).
private : //Members
public : //Members • The syntax of accessing member (data and functions) of a class is:
}; a) Syntax for accessing a data member of the class:
class Class_Name Object_name1, Object_name2,……;
Object_Name . data_member;
where class keyword is optional.
b) Syntax for accessing a member function of the class:
• Example 1: The following program segment shows how to declare and create objects.
Object_Name . member_function(arguments)
class Student
{
private:
int rollno;
char name[20];
char gender;
int age;
public:
void get_data( );
void display( );
};
Student S1, S2, S3; //creation of objects
• Here, creates object S1, S2, and S3 for the class Student.
• When an object is created space is set aside for it in memory.

5|Page 6|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

• Example: void readarray( );


class rectangle void displayarray( );
{ };
int length, breadth, area; void array : : readarray( )
public: {
void get_data( ) cout<<”Enter “<<m<<”Array elements”<<endl;
{ for(int i=0; i<m; i++)
cout<<”Enter the length and breadth”<<end; cin>> a[i];
cin>>length>>breadth; }
} void array : : displayarray( )
void compute( ) {
{ cout<<”Array elements are:”<<endl;
area = length * breadth; for(int i=0; i<m i++)
} cout<< a[i]<<”\t”;
void display( ) }
{ void main( )
cout<<”The area of rectangle is “<<area; {
} int n;
}; array a;
void main( ) clrscr( ); OUTPUT:
{ cout<<”Input number of elements:”<<endl; Input number of elements: 5
rectangle r1; cin>>n;
OUTPUT: Enter 5 Array elements
clrscr( ); a.setnoofelements(n);
r1.get_data( ); Enter the length and breadth a.readarray( ); 10 20 30 40 50
r1.compute( ); 30 10 a.dispalyarray( ); Array elements are:
r1.display( ); getch( );
The area of rectangle is 300 10 20 30 40 50
getch( ); }
}

 Array as member of classes:  Classes, Objects and Memory:


• Array can be used as a data member of classes. • The class declaration does not allocate memory to the class data member.

• An array can be used as private or public member of a class. • When a object is declared, memory is reserved for only data members and not for member

• This is illustrated in the following program. functions.

#include<iostream.h> • The following program illustrates as follows:


#include<conio.h> #include<iostream.h>
class array #include<conio.h>
{ class student
private: {
int a[100], m; private:
public: long regno; // 4 bytes of memory
void setnoofelements( int n); char name[20]; // 20 bytes of memory
{ char comb[4]; // 4 bytes of memory
m = n;
int marks; // 2 bytes of memory
}
7|Page 8|Page
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

char address[30]; // 30 bytes of memory int regno, maths, computer;


public: public:
void readdata( ); void readdata( );
void average( );
void display( );
void display( );
}; };
void main( ) void data : : readata( )
{ {
OUTPUT:
student s1, s2; cout<<”Enter Register No:”;
cout<<”Size of the object s1 is = “<<sizeof(s1)<<endl; Size of the object s1 is = 60 cin>>regno;
cout<<”Size of the object s2 is = “<<sizeof(s2)<<endl; Size of the object s2 is = 60 cout<<”Enter Maths marks:”;
cin>>maths;
cout<<”Size of the class is = “<<sizeof(student)<<endl; Size of the class is = 60
cout<<”Enter Computer marks:”;
} cin>>computer;
 Array of Objects: dipalay( );
}
• An array having class type elements is known as array of objects. void data : : average( );
{ OUTPUT:
• An array of objects is declared after definition and is defined in the same way as any other array.
int avg;
• Example: avg = (maths+computer)/2; Enter Register No: 20
class employee } Enter Maths marks: 56
{ void data : : display( ) Enter Computer marks: 78
private: Important { Average = 67
char name[10]; 5 Marks cout<<”Average = “<<average( )<<endl;
Enter Register No: 22
}
int age; Enter Maths marks: 56
void main( )
public: { Enter Computer marks: 77
void readdata( ); data stude[3]; Average = 66
void displaydata( ); clrscr( ); Enter Register No: 10
}; for(i=0; i<3; i++) Enter Maths marks: 44
employee supervisor[3]; stud[i]. readdata( ); Enter Computer marks: 89
employee sales_executive[5]; getch( );
Average = 66
}
employee team_leader[10];
• In the above example, the array supervisor contains 3 objects namely supervisor[0], supervisor[1],  Objects as function arguments:
supervisor[2]. • A function can receive an object as a function argument.
• The storage of data items in an object array is: • This is similar to any other data being sent as function argument.
Name Age • An object can be passed to a function in two ways:
supervisor[0] o Copy of entire object is passed to function ( Pass by value)
supervisor[1] o Only address of the object is transferred to the function (Pass by reference)
supervisor[2] • In pass by value, copy of object is passed to the function.
• The function creates its own copy of the object and uses it.
• Program to show the use of array of objects:
• Therefore changes made to the object inside the function do not affect the original object.
#include<iostream.h>
#include<conio.h> #include<iostream.h>
class data #include<conio.h>
{ class exam
private: {
9|Page 10 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

private: Structure cannot be inherit Class can be inherit


float phy, che, mat ; A class contain both data member and
public: A structure contains only data member
member functions
void readdata( )
Classes having data hiding features by
{
cout<<”Input Physics, Chemistry, Maths marks : ” ; There is no data hiding features using access specifiers(public, private,
cin>>phy>>che>>mat; protected)
}
void total(exam PU , exam CT)
{ CHAPTER 7 – Classes and Objects BLUE PRINT
phy = PU.phy + CT.phy;
VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
che = PU.che + CT.che;
mat = PU.mat + CT.mat; 01 Question - - 01 Question 06 Marks
}
void display( ) Question No 04 - - Question No 31 -
{
cout<< “Physics :” <<phy<<endl;
IMPORTANT QUESTIONS:
cout<< “Chemistry :” <<che<<endl;
cout<< “Maths :” <<mat<<endl;
} 1 Mark questions:
};
void main( ); OUTPUT: 1. What is a Class, Objects, Data Member, Member Functions, Scope Resolution Operator, and
{ Array of objects?
Enter PUC Marks
Exam PUC, CET, Puc_plus_Cet;
Input Physics, Chemistry, Maths marks : 2. Mention the access specifiers used with a class?
clrscr( );
67 89 80
cout<<”Enter PUC Marks”<<endl;
Enter CET Marks
PUC.readdata( );
Input Physics, Chemistry, Maths marks : 5 Mark questions:
cout<<”Enter CET Marks”<<endl;
60 76 91
CET.readdata( ); 1. Explain class definitions and class declaration with syntax and example.
Total marks of PUC and CET is:
Puc_plus_Cet.total(PUC, CET);
Physics: 127 2. Explain Member function.
cout<<”Total marks of PUC and CET is:” <<endl;
Chemistry: 165
Puc_plus_Cet.display( ); a. Inside class definition
} Maths: 171
b. Outside class definition
• In pass by reference, when an address of an object is passed to the function, the function directly
works on the original object used in function call.
3. Explain the array of objects. Important
• This means changes made to the object inside the function will reflect in the original object, 5 Marks
Exercise programs
because the function is making changes in the original object itself.
1. Write a C++ program to find the simple interest using class and objects.
• Pass by reference is more efficient, since it requires only passing the address of the object and not
#include<iostream.h>
the entire object. #include<conio.h>
class SI
 Difference between Structure and Classes: {
private:
Structure Classes
float p, t, r, si;
A structure is defined with the struct
A class is defined with the class keyword public:
keyword
void readdata( )
All the member of a structure are public All the members of a class are private by {
by default default cout<<”Enter the Principal Amount, Time & Rate”<<endl;

11 | P a g e 12 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

cin>>p>>t>>r; void display( )


} {
void compute( ) cout<<itemcode<<”\t”<<price<<”\t”<<quantity<<endl;
{ }
si = (p * t * r)/100; };
} void main( )
void display( ) {
{ int N=0;
cout<<”Simple Interest = “<<si; char ans;
} product list[100];
}; clrscr( );
void main( ) while(1)
{ {
SI s; cout<<”Item Code, Price and Quantity”<<endl;
clrscr( ); List[N].Addproduct( );
s.readdata( ); cout<<”Do you want to add next item (Y/N)?”<<endl;
s.compute( ); cin>>ans;
s.display( ); if(toupper(ans) == ‚Nƒ)
getch( ); break;
} N++;
2. Let product list be a linear array of size N where each element of the array contains }
following field Itemcode, Price and Quantity. Declare a class Product list with three data cout<<”Item Code \t Price \t Quantity”<<endl;
for(i=0; i<N; i++)
members and member functions to perform the following List[i].display( );
a. Add values to the product list getch( );
b. Printing that total stock values }
3. A class cock has following member hours and minutes. Create member function
#include<iostream.h>
#include<conio.h> a. To initialize the data members
#include<iomainp.h> b. Display the time
class product
c. To convert hours and minutes to minutes.
{
private: #include<iostream.h>
char itemcode[6]; #include<conio.h>
float price, quantity; class clock
public: {
void Addproduct( ) private:
{ int hh, mm;
cout<<”Enter the Item Code”<<endl; public:
cin>>itemcode; void initialize( int h, int m)
cout<<”Enter the Price”<<endl; {
cin>>price; hh = h;
cout<<”Enter the Quantity”<<endl; mm = m;
cin>>quantity; }
} void display( )
{
13 | P a g e 14 | P a g e
Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan Chapter 7- Classes and Objects II PUC, MDRPUC, Hassan

cout<<”Hours = “<<hh; {
cout<<”Minutes = “<<mm; float dist;
} dist = ( (Ahh * 60 + Amm) – (Dhh * 60 + Dmm) ) * speed/60;
void convert( ) dist = (dist * 1000 / (60 * 60);
{ cout<<”Distance Travelled = “<<dist<<”Meter/Second”;
mm = hh * 60 + mm; }
cout<<”Total Minutes = “<<mm; };
} void main( )
}; {
void main( ) Distance d;
{ clrscr( );
int h, m; d.inputtime( ):
clock c; d.computedistance( );
clrscr( ); getch( );
cout<<”Enter the Hour and Minutes”<<endl; }
cin>>h>>m;
c.intialize( ); **************
c.display( );
c.convert( )
getch( );
}
4. Write a C++ program that receives arrival time and departure time and speed of an
automobile in kilometers/hours as input to a class. Compute the distance travelled in
meters/second and display the result using member functions.
#include<iostream.h>
#include<conio.h>
class Distance
{
private:
int Ahh, Amm, Dhh, Dmm;
float speed;
public:
void inputtime( )
{
cout<<”Enter the Arrival Time:”<<endl;
cout<<”Enter the Hour and Minutes”<<endl;
cin>>Ahh>>Amm;
cout<<”Enter the Departure Time:”<<endl;
cout<<”Enter the Hour and Minutes”<<endl;
cin>>Dhh>>Dmm;
cout<”Enter the speed in Kmph”<<endl;
cin>>speed;
}
void computedistance( )
15 | P a g e 16 | P a g e
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan

Chapter-8  Calling Overloaded Functions:


• The following program shows how overloaded functions can be called.
FUNCTION OVERLOADING AND MEMBER FUNCTION Program: To compute area of rectangle, circle, triangle using overloaded functions.
#include<iostream.h>
 Introduction: #include<conio.h>
• User defined function is a function defined by the user to solve his/her problem. Such a function class funoverloaded
{
can be called from anywhere and any number of times in the program. public:
• C++ implements polymorphism through function overloading and operator overloading. int area ( int l, int b) // area of rectangle
• Function overloading allows the user to create new abstract data type. {
return (l * b);
}
 Function Overloading:
float area ( float r) // area of circle
• Function Overloading means two or more functions have same name, but differ in the number of {
arguments or data types of arguments. return (3.14 * r * r);
}
• Function overloading is the process of defining same function name to carry out similar types of
float area (float b, float h)
activities with various data items. {
return (0.5 * b * a); // area of triangle
 Definition and Declaration of overloaded functions: }
• The main factor in function overloading is a functions argument list. };
void main( )
• If there are two functions having same name and different types of arguments or different number {
of arguments, then function overloading is invoked automatically by the compiler. funoverloaded f;
clrscr( ); OUTPUT:
• Function Overloading is also known as Compile time polymorphism.
cout<<” Area of Rectangle:”<<f.area(4,6)<<endl;
• Example: Area of Rectangle: 24
cout<<”Area of Circle:”<<f.area(10)<<end;
int sum (int a, int b) cout<<”Area of Triangle:”<<f.area(3.0, 7.0)<<endl; Area of Circle: 314.2857

float sum ( float p, float q) getch(); Area of Triangle: 10.5


}
• The function sum( ) that takes two integer arguments is different from the function sum( ) that
takes two float arguments. This is function overloading.  Need for function overloading:
• To overload a function, each overloaded function must be declared and defined separately. • The advantage of function overloading are:

• Example: o Code is executed faster.


int product ( int p, int q, int r); o It is easier to understand the flow of information and debug.
float product ( float x, float y); Important o Code Maintenance is easy.
int product ( int p, int q, int r)
{ 5 Marks o Easier interface between programs and real world objects.
cout<<”Product = “<<p * q * r << endl;
}  Restrictions on Overloaded Functions:
float product ( float x, float y, float z);
{ • Each function in a set of overloaded functions must have different argument list.
cout<< “Product = “ << x * y <<endl; • If typedef is used for naming functions, then the function is not considered as different type.
}
1|Page 2|Page
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan

 Inline Function:  Disadvantage of inline function:

• An Inline function is a special type of function whose body is inserted at the place where it is • May increase the size of the executable file

called, instead of transferring the control to the function. • More memory is needed.

• The keyword inline is used to define inline function. • If used in header file, it will make your header file size large and may also make it unreadable.
Important
• Rules:
5 Marks  Note: The inline function may not work some times for one of the following reasons:
o Inline function definition starts with keyword inline.
• The inline function definition is too long or too complicated.
o The inline function should be defined before all function that call it.
• The inline function is recursive.
o The compiler replaces the function call statement with the function code itself (expansion)
• The inline function has looping constructs.
and then compiles the entire code.
• The inline function has a switch or goto.
• The general format for the inline function declaration is given below:
inline Returntype Fun_Name ( [Argument] )  Friend Function:
{
• A friend function is a non-member function of a class has the access permission to the private
……….. ;
return expression ; member of the class.
} • The friend function is declared within a class with the prefix friend.
• Program to find the cube of a number using inline function:
• But it should be defined outside the class like a normal function without the prefix friend.
#include<iostream.h>
• The general format for the friend function is given below:
#include<conio.h>
inline int cube ( int a ) class class_name
{
Important
{
return a * a * a;
public:
5 Marks
}
void main( ) friend return_type function_name ( [arguments] );
{ }
int n ;  The friend functions have the following properties:
clrscr( );
OUTPUT: • Friend function is not a member function of the class, has full access permission to private and
cout<<”Enter the input number”<<endl;
cin>>n; Enter the input number protected members of the class.
cout<<”Cube of “ <<n<<” = “<<cunbe(n); 4
• It can be declared either in public or private part of a class.
getch(); Cube of 4 = 64
} • A friend function cannot be called using the object of that class. It can be invoked like any normal
function.
 Advantage of inline function:
• The function is declared with keyword friend. But while defining friend function it does not use
• The size of the object code is considerably reduced.
either keyword friend or : : operator.
• The speed of execution of a program increases.
• They are normal external functions that are given special access privileges.
• Very efficient code can be generated.
• It cannot access the data member variables directly and has to use an object name.membername.
• There is no burden on the system for function calling.
• Use of friend function is rare, since it violates the rule of encapsulation and data hiding.
• It also saves the overhead of return call from a function.
• The readability of the program increases.

3|Page 4|Page
Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan Chapter 8- Function Overloading and Member Function II PUC, MDRPUC, Hassan

 Program to check a number is even or odd using a friend function. CHAPTER 8 – Function Overloading and Member Function BLUE PRINT
#include<iostream.h> VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
#include<conio.h>
class number - - - 01 Question 01 Question
{ - - Question No 32 05 Marks
private:
int a;
public: Important Questions
void readdata( )
{ 5 Marks Question:
cout<<”Enter the Number”<<endl;
cin>>a; 1. What is function overloading? Explain the need for function overloading.
}
2. Discuss overloaded functions with syntax and example.
friend int even(number);
}; 3. What is inline function? Write a simple program for it.
int even(number n)
{
4. Mention the advantage and disadvantage of inline function.
if(n.a % 2 = = 0) //friend function can access the private data a of the object n 5. Explain friend function and their characteristics.
return 1;
else
OUTPUT: 6. Program to check whether a number is prime or not using inline function:
return 0; Enter the Number #include<iostream.h>
} 10 #include<conio.h>
void main( ) Number is Even inline int prime ( int n )
{ Enter the Number {
number num1; 11 for(int i=2; i<n/2; i++)
clrscr( ); Number is Odd if ( n % i = = 0)
num1.readadata( ); return 0;
if( even(num1) ) //friend function call return 1;
cout<<”Number is Even”; }
else void main( )
cout<<ƒNumber is Odd”; {
getch(); int num ;
} clrscr( );
cout<<”Enter the input number”<<endl;
cin>>num; OUTPUT:
if ( prime(num)) //inline function call Enter the input number
cout<<”Number is Prime “ ;
5
else
cout<<”Number is not a Prime “ ; Number is Prime
getch();
}

5|Page 6|Page
Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

Chapter-11 and graphs.


 Pointer Declaration:
POINTERS  Pointers are also variables and hence, they must be defined in a program like any other variable.
 Introduction:  The general syntax of pointer declaration is given below.
 Pointers are a powerful concept in C++ and have the following advantages. Syntax: Data_Type *Ptr_Variablename;
i. It is possible to write efficient programs.  Where,
ii. Memory is utilized properly. o Data_Type is any valid data type supported by C++ or any user defined type.
iii. Dynamically allocate and de-allocate memory. o Ptr_Variablename is the name of the pointer variable. The presence of ‘*’ indicates that it
is a pointer variable.
 Memory Utilization of Pointer:
 Defining pointer variables:
 Memory is organized as an array of bytes. A byte is basic storage and accessible unit in memory.
o int *iptr; iptr is declared to be a pointer variable of int type.
 Each byte is identifiable by a unique number called address.
o float *fptr; fptr is declared to be a pointer variable of float type.
 We know that variables are declared before they are used in a program. Declaration of a variable
o char *cptr; cptr is declared to be a pointer variable of character type.
tells the compiler to perform the following.
o Allocate a location in memory. The number of location depends on data type.  Pointer Initialization:
o Establish relation between address of the location and the name of the variable.  Once we declare a pointer variable, we must make it to point to something.
 Consider the declaration, int num;  We can do this by assigning or initializing to the pointer the address of the variable you want to
 This declaration tells the compiler to reserve a location in memory. We know that size of int type point to as in: iptr = &num;
is two bytes. So the location would be two bytes wide.  The „&’ is the address operator and it represents address of the variable.
Address Num  Example: A program to display the content of num and the address of the variable num using a
100 pointer variable.
15
101 #include<iostream.h>
 In the figure, num is the variable that stores the value 15 and address of num is 100. The address void main( )
{
of a variable is also an unsigned integer number. It can be retrieved and stored in another variable.
int num; // normal integer variable
int *iptr; // Pointer declaration, pointing to integer data
 Pointer:
num = 574; // assign value to num
 A pointer is a variable that holds a memory address of another variable.
iptr = & num // assign address of num to int pointer
 The pointer has the following advantages.
cout<<” Value of num is :”<<num<<endl;
o Pointers save memory space.
Important cout<<” Address of num is :”<<iptr<<endl;
o Dynamically allocate and de-allocate memory. }
o Easy to deal with hardware components.
3 Marks  The address of operator (&):
o Establishes communication between program and data.  „&‟ is a unary operator that returns the memory address of its operand.
o Pointers are used for file handling.  For example, if var is an integer variable, then &var is its address.
o Pointers are used to create complex data structures such as linked list, stacks, queues trees  We should read „&‟ operator as “the address-of” which means &var will be read as “the address of

1|Page Keerthi Kumar H M 2|Page Keerthi Kumar H M


Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

var”. o Subtraction -
 Example:  Example:
int num = 25; int num, *iptr; iptr  1200 9
int *iptr; num = 9; 1201
iptr = &num; //The address of operator & iptr = &num; iptr++  1202
iptr++; 1203
 Pointer Operator or Indirection Operator (*):
cout<<iptr;
 The second operator is indirection operator „*‟, and it is the complement of „&‟.
 The following operation can be performed on pointers.
 It is a unary operator that returns the value of the variable located at the address specified by its
o We can add integer value to a pointer.
operand.
o We can subtract an integer value from a pointer.
 Example: o We can compare two pointers, if they point the elements of the same array.
int num = 25; o We can subtract one pointer from another pointer if both point to the same array.
int *iptr; //Pointer Operator (Indirection Operator *) o We can assign one pointer to another pointer provided both are of same type.
iptr = &num;
 The following operations cannot be performed on pointers.
 Example: A program executes the two operations. o Addition of two pointers.
#include<iostream.h> o Subtraction of one pointer from another pointer when they do not point to the same array.
#include<conio.h>
void main( ) o Multiplication of two pointers.
{ o Division of two pointers.
int num;  A program to illustrate the pointer expression and pointer arithmetic.
int *iptr;
#include<iostream.h>
int val;
#include<conio.h>
void main( )
num = 300;
{ OUTPUT:
iptr = & num;
int a, b, x, y; Address of a = 65524
val = *iptr; OUTPUT: int *ptr1, *ptr2; Address of b = 65522
Value of num is : 300 a = 30;
cout<<” Value of num is :”<<num<<endl; a = 30 b=6
Value of pointer : 0xbff64494 b = 6;
cout<<” Value of pointer :”<<iptr<<endl; ptr1 = &a x = 30 y=6
cout<<” Value of val :”<<val<<endl; Value of val : 300 ptr2 = &b; a = 100 b = 12
} x = *ptr1 + *ptr2 – 6;
y = 6 - *ptr1 / *ptr2 + 30;
 Pointer Arithmetic:
 We can perform arithmetic operations on a pointer just as you can a numeric value. cout<<”Address of a = “<<ptr1<<endl;
cout<<”Address of b = “<<ptr2<<endl;
 There are four arithmetic operators that can be used on pointers:
cout<<”a = “<<a<<”b = “<<b<<endl;
o Increment ++ cout<<”x = “<<x<<”y = “<<y<<endl;
o Decrement --
*ptr1 = *ptr1 + 70;
o Addition + *ptr2 = *ptr2 * 2;

3|Page Keerthi Kumar H M 4|Page Keerthi Kumar H M


Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

cout<<”a = “<<a<<”b = “<<b<<endl; int a[10], i, n;


} cout<<”Enter the input for array”;
cin>>n;
 Pointers and Arrays: cout<<”Enter array elements:”; OUTPUT:
 There is a close relationship between array and pointers in C++. for(i=0; i<n; i++)
Enter the input for array 5
cin>>*(a+i);
 Consider the following program which prints the elements of an array A.
cout<<The given array elements are :”; Enter array elements
#include<iostream.h> for(i=0; i<n; i++) 1 2 3 4 5
void main( ) cout<<”\t”<<*(a+i);
The given array elements are :
{ Important getch( );
1 2 3 4 5
int A[5] = { 15, 25, 67, 83, 12}; 3 Marks }
for (int i = 0; i<5; i++)  Array of Pointers:
cout<<A[i]<<”\t”;
 There is an array of integers; array of float, similarly there can be an array of pointers.
}
 Output of the above program is: 15 25 67 83 12  “An array of pointer means that it is a collection of address”.

 When we declare an array, its name is treated as a constant pointer to the first element of the  The general form of array of pointers declaration is:

array. int *pint[5];

 This is also known as the base address of the array.  The above statement declares an array of 5 pointers where each of the pointer to integer variable.

 In other words base address is the address of the first element in the array of the address of a[0].  Example: Program to illustrate the array of pointers of isolated variables.

 If we use constant pointer to print array elements. #include<iostream.h>


#include<conio.h>
#include<iostream.h> void main( )
void main( ) {
{ int *pint[5];
int A[5] = { 15, 25, 67, 83, 12}; OUTPUT:
int a = 10, b = 20, c = 30, d=40, e=50;
cout<< *(A) <<”\t”; pint[0] = &a; Value 10 stored at 17500
cout<< *(A+1) <<”\t”; pint[1] = &b; Value 20 stored at 17502
cout<< *(A+2) <<”\t”; pint[2] = &c;
cout<< *(A+3) <<”\t”; Value 30 stored at 17504
pint[3] = &d;
cout<< *(A+4) <<”\t”; pint[4] = &e;
Value 40 stored at 17506
} Value 50 stored at 17508
 Output of the above program is: 15 25 for( int i=0; i<=4; i++)
67 83 12 cout<<”Value “ << *pint[i]<< “stored at “<<pint[i]<<endl;
 Here the expression *(A+3) has exactly same effect as A[3] in the program. }

 The difference between constant pointer and the pointer variable is that the constant pointer
 Pointers and strings:
cannot be incremented or changed while the pointer to an array which carries the address of the
 String is sequence of characters ends with null („\0‟) character.
first element of the array may be incremented.
 C++ provides two methods of declaring and initializing a string.
 The following example shows the relationship between pointer and one dimensional array.
 Method 1:
#include<iostream.h>
char str1[ ] = “HELLO”;
void main( )
{  When a string is declared using an array, the compiler reserves one element longer than the

5|Page Keerthi Kumar H M 6|Page Keerthi Kumar H M


Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

number of characters in the string to accommodate NULL character.  For Example: int m = 23;
 The string str1[ ] is 6 bytes long to initialize its first 5 characters HELLO\0. int &n = m;
 Method 2: int *p;
char *str2 = “HELLO”; p = &m;
 C++ treats string constants like other array and interrupts a string constant as a pointer to the first  Then the value of m i.e. 23 is printed in the following ways :
character of the string. cout <<m; // using variable name
 This means that we can assign a string constant to a pointer that point to a char. cout << n; // using reference name
 Example: A program to illustrate the difference between strings as arrays and pointers. cout << *p; // using the pointer
#include<iostream.h>
 Invoking Function by Passing the References :
#include<conio.h>
void main( )  When parameters are passed to the functions by reference, then the formal parameters become
{ references (or aliases) to the actual parameters to the calling function.
char str1[ ] = “HELLO”; OUTPUT:  That means the called function does not create its own copy of original values, rather, it refers to
char *str2 = “HELLO”;
HELLO the original values by different names i.e. their references.
cout<<str1<<endl;
HELLO
cout<<str2<<endl;  For example the program of swapping two variables with reference method:
str2++; ELLO
#include<iostream.h>
cout<<str2<<endl;
void main()
}
{
 Pointers as Function Parameters: void swap(int &, int &);
 A pointer can be a parameter. It works like a reference parameter to allow change to argument int a = 5, b = 6;
from within the function. cout << “\n Value of a :” << a << “ and b :” << b;
swap(a, b);
void swap(int *m, int *n) cout << “\n After swapping value of a :” << a << “and b :” << b;
{ }
int temp; void swap(int &m, int &n)
temp = *m;
{
*m = *n; int temp; OUTPUT:
*n = temp; temp = m; Value of a : 5 and b : 6
} m = n;
void swap(&num1, & num2); After swapping value of a : 6 and b : 5
n = temp;
 Pointers and Functions: }

 A function may be invoked in one of two ways :  Invoking Function by Passing the Pointers:
o Call by value  When the pointers are passed to the function, the addresses of actual arguments in the calling
Important
o Call by reference function are copied into formal arguments of the called function.
3 Marks
 The second method call by reference can be used in two ways :  That means using the formal arguments (the addresses of original values) in the called function;
o By passing the references we can make changing the actual arguments of the calling function.
o By passing the pointers  For example the program of swapping two variables with Pointers :
 Reference is an alias name for a variable. #include<iostream.h>
7|Page Keerthi Kumar H M 8|Page Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

void main()  The following code demonstrates how to allocate memory for different variables.
{
 To allocate memory type integer
void swap(int *m, int *n);
int a = 5, b = 6; int *pnumber;
cout << “\n Value of a :” << a << “ and b :” << b; pnumber = new int;
swap(&a, &b);  The first line declares the pointer, pnumber. The second line then allocates memory for an integer
cout << “\n After swapping value of a :” << a << “and b :” << b;
} and then makes pnumber point to this new memory.
void swap(int *m, int *n)  To allocate memory for array, double *dptr = new double[25];
{  To allocates dynamic structure variables or objects, student sp = new student;
int temp; OUTPUT:
temp = *m; Value of a : 5 and b : 6  delete Operator:
*m = *n;
After swapping value of a : 6 and b : 5  The delete operator is used to destroy the variables space which has been created by using the
*n = temp;
} new operator dynamically.
 Memory Allocation of pointers:  Use delete operator to free dynamic memory as : delete iptr;
 Memory Allocation is done in two ways:  To free dynamic array memory: delete [] dptr;
Important
o Static Allocation of memory  To free dynamic structure, delete structure;
3 Marks
o Dynamic allocation of memory.
 Difference between Static Memory Allocation and Dynamic Memory Allocation:
 Static Allocation of Memory:
Sl no Static Memory Allocation Dynamic Memory Allocation
 Static memory allocation refers to the process of allocating memory during the compilation of the
Memory space is allocated before the Memory space is allocated during the
program i.e. before the program is executed. 1
execution of program. execution of program.
 Example:
2 Memory space allocated is fixed Memory space allocated is not fixed
int a; // Allocates 2 bytes of memory space during the compilation.
3 More memory space is required Less memory space is required.
 Dynamic Allocation of Memory: 4 Memory allocation from stack area Memory space form heap area.
 Dynamic memory allocation refers to the process of allocating memory during the execution of
 Free store (Heap memory):
the program or at run time.
 Free store is a pool of memory available to allocated and de-allocated storage for the objects
 Memory space allocated with this method is not fixed.
during the execution of the memory.
 C++ supports dynamic allocation and de-allocation of objects using new and delete operators.
 These operators allocate memory for objects from a pool called the free store.  Memory Leak:
 The new operator calls the special function operator new and delete operators call the special  If the objects, that are allocated memory dynamically, are not deleted using delete, the memory
function operator delete. block remains occupied even at the end of the program.

 new operator:  Such memory blocks are known as orphaned memory blocks.

 We can allocate storage for a variable while program is running by using new operator.  These orphaned memory blocks when increases in number, bring adverse effect on the system.
This situation is called memory leak.
 It is used to allocate memory without having to define variables and then make pointers point to
them.
9|Page Keerthi Kumar H M 10 | P a g e Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

cout<<”Employee Number:”<<empno;
cout<<”Employee Name:”<<name;
cout<<”Employee Salary:”<<salary;
 Pointers and Structures: }
 We can create pointers to structures variable. };
void main( )
struct student
{
{ employee e, * ep;
int roll_no; ep = &e;
clrscr( );
float fee;
ep  read( );
}; ep  display ( );
student s; getch( );
student * sp = &s; }
 Here, employee is an already defined class. When accessing members of the class an object
(*sp).roll_no = 14;
pointer, the arrow operator () is used instead of dot (.) operator.
 The above statement can be written using the operator as 
sproll_no = 14;  this pointers:
 Every object in C++ has access to its own address through an important pointer called this
 Pointers and Objects:
Important pointer.
 The Pointers pointing to objects are referred to as object pointers.
3 Marks  The “this pointer” is an implicit parameter to all member functions.
 Declaration of pointers to object
 Therefore, inside a member function, this may be used to refer to the invoking object.
class_name * object-pointer;
 Here class_name is the name of the class, object-pointer is the pointer to an object of this class
 Program 12: Create a class containing the following data members Register_No, Name and
type.
Fees. Also create a member function to read and display the data using the concept of pointers to
 Example: employee * eptr
objects.
#include<iostream.h>
#include<conio.h> #include<iostream.h>
class employee #include<conio.h>
class Student
{
{
private:
private:
int empno; long regno;
char name[20]; char name[20];
float salary; float fees;
public: public:
void read( ) void readdata( );
{ void display( );
cout<<”Enter the Employee Number, Name and Salaray”<<endl; };
cin>>empno>>name>>salary; void Student::readdata( )
} {
cout<<"Enter the Register Number:"<<endl;
void display( )
cin>>regno;
{
11 | P a g e Keerthi Kumar H M 12 | P a g e Keerthi Kumar H M
Chapter 11- Pointers II PUC, MDRPUC, Hassan Chapter 11- Pointers II PUC, MDRPUC, Hassan

cout<<"Enter the Student Name:"<<endl; 7. Which is the address operator?


cin>>name;
8. What is pointer operator?
cout<<"Enter the Fees:"<<endl;
cin>>fees; 9. What is static memory & dynamic memory?
} 10. What is free store?
void Student::display( )
{
cout<<"Register Number : "<<regno<<endl;
3 Marks Question:
cout<<"Student Name : "<<name<<endl; 1. What are the advantages of pointers? [June 2016]
cout<<"Fees : "<<fees<<endl;
2. What are the operations performed on pointers? [March 2015, June 2017]
}
void main( ) 3. What is array of pointer? Give example. [June 2015]
{
4. Explain the new and delete operator in pointers. [March 2016]
Student *S; // Create a pointer to point Student object
clrscr( ); 5. Define: [March 2017]
S->readdata( ); // Access Student data member using a pointer a. Pointer.
S->display( ); // Display data using a pointer
getch( ); b. Static memory allocation.
} c. Dynamic memory allocation
OUTPUT 1: OUTPUT 2: 6. What is the relationship between pointers and arrays?
7. Explain with example call by reference.
8. Distinguish between static and dynamic memory allocation.
9. What is the relationship between pointers and objects? Give an example
10. Explain the use of “this pointer”.

****************

CHAPTER 11 – POINTERS BLUE PRINT


VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
01 Question - 01 Question - 02 Question
Question No 5 - Question No 22 - 04 Marks

Important Questions
1 Marks Question:
1. Define pointer. [June 2016]
2. Write the declaration syntax for a pointer. [March 2015]
3. How do we initialize a pointer? [March 2016]
4. Write any one advantage of pointers. [June 2015, March 2017]
5. What is the purpose of new operator in C++? [June 2017]
6. What is a pointer variable?

13 | P a g e Keerthi Kumar H M 14 | P a g e Keerthi Kumar H M


Chapter 12- Data File Handling II PUC, MDRPUC, Hassan Chapter 12- Data File Handling II PUC, MDRPUC, Hassan

Chapter-12  fstream.h header file:


 The I / O system of C++ contains a set of classes that define the file handling methods.
DATA FILE HANDLING
 These include ifstream, ofstream and fstream.
 Introduction:  These classes are derived from fstream base and from the corresponding iostream.h.
 A file is a collection of related data stored in a particular area on the disk.  These classes, designed to manage the disk files, are declared in fstream.h and therefore we must
 Programs can be designed to perform the read and write operations on these files. include this file in any program that uses files.
 In general a file is a sequence of bits, bytes, lines or records whose meaning is defined by its user.
 C++ I/O occurs in streams, which are sequence of bytes.
 If bytes flows from device like a keyboard, a disk drive, etc to main memory, this is called input
operation.
 If bytes flow from main memory to devices like a display screen, a printer etc. this is called output
operation.
 In C++, file input/output facilities are implemented through a header file fstream.h.

 Stream in C++:
 A stream is sequence of bytes. In C++, a stream is a general name given to flow of data.
 Different streams are used to represent different kinds of data flow.
 The three streams in C++ are as follows.
 Classes for file stream operation:
o Input Stream: The stream that supplies data to the program is known as input stream.
o Output Stream: The stream that receives data from the program is known as output Class Meanings
stream. filebuf It sets the file buffer to read and write
o Error Stream: Error streams basically an output stream used by the programs to the file or It supports operations common to the file streams. It serves as a base class for the
on the monitor to report error messages. fstreambase derived classes ifstream,ofstream and fstream and contains open( ) and close( )
as member functions
It supports input operations. It contains open( ) with default input mode and
ifstream
inherits get( ), getline( ), read( ), seekg( ) and tellg( ) functions from istream.
It supports output operations. It contains open( ) with default output mode and
ofstream
inherits put( ), seekp( ), tellp( ) and write( ) functions from ostream
It supports simultaneous input and output operations. It contains open( ) with
fstream default input mode and inherits all the functions from istream and ostream
classes through iostream

 Types of data Files:


 Generally there are two types of files in C++:
1|Page Keerthi Kumar H M 2|Page Keerthi Kumar H M
Chapter 12- Data File Handling II PUC, MDRPUC, Hassan Chapter 12- Data File Handling II PUC, MDRPUC, Hassan

 Text Files:  The syntax of opening a file for output purpose only using an object ofstream class and open( )
o A text file is a file that stores the information in ASCII characters. member function is as follows:
o Each line of text is terminated by a special character, known as End of Line (EOL) or delimiter. oftream_object.open(“file name”);
 Binary Files:  Example: ofstream outfile;
o A binary file is a file that contains information in the same format as it is held in memory. outfile.open (“data”);
o In binary files, no delimiters are used for a line and no translations occur here. outfile.open (“text.dat”);
 The syntax of opening a file for input purpose only using an object ifstream class and open( )
 Opening and Closing of Files:
member function is as follows:
 A file must first be opened before data can be read from it or written to it.
iftream_object.open(“file name”);
 In C++ there are two ways to open a file with the file stream object.
 Example: ifstream ifile;
o Opening file using constructor.
ifile.open (“data”);
o Opening file using open ( ) member function.
 The first method is preferred when a single file is used with a stream. However for managing  To open a file for both input and output, we declare objects of fstream class. We know that the
multiple files with the same stream, the second method is preferred. class fstream is derived from both ifstream and ofstream,
 The syntax for opening a file an object of type fstream class and the constructor is as follows:
 Opening files using Constructors:
fstream fstream-object(“file name’, mode);
 In order to access a file, it has to be opened either in read, write or append mode.
 The syntax for opening a file an object of type fstream class and the open( ) member function is as
 In all the three file stream classes, a file can be opened by passing a filename as the first parameter follows:
in the constructor itself. fstream-object.open(“file name’, mode); Important
 The syntax for opening a file using constructor is 3 Marks
streamclass_name file_objectname (“filename”)  File Modes:
 The syntax of opening a file for output purpose only using an object ofstream class and the  While using constructors or open( ), the files were created or opened in the default mode.
constructor is as follows:  There was only one argument passed, i.e. the filename.
ofstream ofstream_object(“file name”);  C++ provides a mechanism of opening a file in different modes in which case the second
 Example: ofstream fout (“results.dat”); parameter must be explicitly passed.
 The syntax of opening a file for input purpose only using an object ifstream class and the  Syntax: stream_object.open(“filename”, mode);
constructor is as follows:  Example: fout.open(“data”, ios::app) // This opens the file data in the append mode.
ifstream ifstream_object(“file name”);  The lists of file modes are:
 Example: ifstream fin (“results.dat”);
Mode method Meaning Stream Type
 Opening files using open( ): ios::app append to end of the file at opening time ofstream

 open( ) can be used to open multiple files that use the same stream object. ios::in open file for reading ifstream

 The syntax for opening a file using open ( ) member function is as follows: ios::out open file for writing ofstream

file_stream_class stream_object; Open file for updating and move the file
ios::ate ifstream
stream_object.open (“file_name”); pointer to the end of file

3|Page Keerthi Kumar H M 4|Page Keerthi Kumar H M


Chapter 12- Data File Handling II PUC, MDRPUC, Hassan Chapter 12- Data File Handling II PUC, MDRPUC, Hassan

ios::trunc On opening, delete the contents of file ofstream  Syntax: ifstream_object.get (ch); // where ch is the character variable.
ios::nocreate Turn down opening if the file does not exists ofstream  Example: char ch;
ios::noreplace Turn down opening if the file already exists ofstream ifstream fin(“text.txt”);
ios::binary Opening a binary file. ifstream fin.get (ch);
 fin is the object of ifstream. Text is the name of the file. Reads a character into the variable ch.
Example:
fstreamfout (“text”, ios::out); // open text in output mode  getline( ):
fstream fin(“text”, ios::in); // open text in input mode  It is used to read a whole line of text. It belongs to the class ifstream.
fout.open(“data”, ios::app) // This opens the file data in the append mode  Syntax: fin.getline(buffer, SIZE)
fout.open(“data”, ios::app | ios::nocreate)  It reads SIZE characters from the file represented by the object fin or till the new line character is
// This opens the file in the append mode but fails to open if it does not exist encountered, whichever comes first into the buffer.
 Closing File:  Example:
 The member function close( ) on its execution removes the linkage between the file and the stream char book[SIZE];
object. ifstream fin;

 Syntax: stream_object.close( ); fin.getline (book, SIZE);

 Example: ofstream.close( );
 Input and output operation in binary files:
ifstream.close( );
 Binary files are very much use when we have to deal with database consisting of records.
 Input and output operation in text file:  The binary format is more accurate for storing the numbers as they are stored in the exact internal

 The data in text files are organized into lines with new line character as terminator. representation.

 Text file need following types of character input and output operations:  There is no conversion while saving the data and hence it is faster.

o put( ) function Important  Functions used to handle data in binary form are: Important
o get( ) function 3 Marks o write ( ) member function. 3 Marks
 put ( ): o read ( ) member function

 The put( ) member function belongs to the class ofstream and writes single character to the
 write ( ):
associated stream.
 The write ( ) member function belongs to the class ofstream and which is used to write binary data
 Syntax: ofstream_object.put(ch); // where ch is the character variable.
to a file.
 Example: char ch=’A’;
 Syntax: ofstream_object.write((char *) & variable, sizeof(variable));
ofstream fout(“text.txt”);
 These functions take 2 arguments. The first is the address of the variable and second the size of the
fout.put (ch);
variable in bytes. The address of the variable must be type casted to pointer to character.
 fout is the object of ofstream. Text is the name of the file. Value at ch is written to text.
 Example: student s;
 get( ): ofstream fout(“std.dat”, ios::binary);

 The get( ) member function belong to the class ifstream and reads a single character from the fout.write((char *) &s, sizeof(s));

associated stream.

5|Page Keerthi Kumar H M 6|Page Keerthi Kumar H M


Chapter 12- Data File Handling II PUC, MDRPUC, Hassan Chapter 12- Data File Handling II PUC, MDRPUC, Hassan

 read ( ): o Write only mode


 The read ( ) member function belongs to the class ifstream and which is used to read binary data o Append mode
from a file.
 Syntax: ifstream_object.read((char *) & variable, sizeof(variable));
 These functions take 2 arguments. The first is the address of the variable and second the size of the
variable in bytes. The address of the variable must be type casted to pointer to character.
 Example: student s;
ifstream fin(“std.dat”, ios::binary)
fin.write((char *) &s, sizeof(s));

 Detecting End of file:


 Detecting end of file is necessary for preventing any further attempt to read data from the file.  When we open a file in read only mode, the input pointer is automatically set at the beginning so
 eof( ) is a member function of ios class. that we read the file from the beginning.
 It returns a non-zero (true) value if the end of file condition is encountered while reading;  When we open a file in write only mode, the existing contents are deleted and output pointer is set
otherwise returns a zero (false). at the beginning
 Example:  If we want to open an existing file to add more data, the file is opened in append mode. This
ifstream fin; moves the file pointer to the end of the file.
if(fin.eof( ))
 Functions for manipulation of file pointers:
{
statements;  To move file pointers to any desired position inside a file, file stream classes support the following

} functions.

 This is used to execute set statements on reaching the end of the file by the object fin. o seekg() - Moves get file pointer to a specific location
o seekp() - Moves put file pointer to a specific location
Important
 File pointers and their manipulation: o tellg() - Returns the current position of the get pointer
3 Marks
 In C++, the file I/O operations are associated with the two file pointers: o tellp() - Returns the current position of the put pointer
o Input pointer (get pointer)  The seekp() and tellp() are member functions of ofstream
o Output pointer (put pointer)  The seekg() and tellg() are member functions of ifstream.
 We use these pointers to move through files while reading or writing.  All four functions are available in the class fstream.
 Each time an input or output operation takes place, appropriate pointer is automatically advanced.
 seekg( ):
o ifstream, like istream, has a pointer known as get pointer that points to the element to be read
 Move the get pointer to a specified location from the beginning of a file.
in the next input operation.
 There are two types:
o ofstream, like ostream, has a pointer known as put pointer that points to the location where the
o seekg(long);
next element has to be written.
o seekg(offset, seekdir);
 There are three modes under which we can open a file:
 The seekg(long) moves the get pointer to a specified location from the beginning of a file.
o Read only mode
7|Page Keerthi Kumar H M 8|Page Keerthi Kumar H M
Chapter 12- Data File Handling II PUC, MDRPUC, Hassan Chapter 12- Data File Handling II PUC, MDRPUC, Hassan

 Example: inf.seekg(20); object.seekp(m, ios::beg) Move forward by m bytes from the beginning for writing
object.seekp(-m, ios::end) Go backward by m bytes from the end for writing
 The seekg(offset, seekdir) has two arguments: offset and seekdir.
 The offset indicates the number of bytes the get pointer is to be moved from seekdir position.  tellg ( ) and tellp( ):
 seekdir takes one of the following three seek direction constants.  tellg( ) returns the current position of the get pointer.
 Syntax: position = ifstream_object.tellg( );
Constant Meaning
 Example: int position
ios::beg seek from beginning of file position= fin.tellg();
ios::cur seek from current location
 tellp( ) returns the current position of the put pointer.
ios::end seek from end of file
 Syntax: position = ifstream_object.tellp( );
 Syntax: stream_objectname.seekg(offset, origin_value);  Example: int position
 Example : Some of the pointer offset calls and their actions are shown in the following table position= fin.tellp();
seekg( ) function option Action performed
object.seekg(0, ios::beg) Take get pointer to the beginning of the file  Basic operation on binary file in C++:
object.seekg(0, ios::end) Go to end of the file  Basic operation on binary file is:

object.seekg(0, ios::cur) Stay get pointer at the current position. o Searching

object.seekg(m, ios::beg) Move forward by (m+1) bytes in the file o Appending data

object.seekg(-m, ios::end) Go backward by m bytes from the file end. o Inserting data in sorted files
o Deleting a record
 seekp ( ): o Modifying data
 Move the put pointer to a specified location from the beginning of a file.
 There are two types: CHAPTER 12 – DATA FILE HANDLING BLUE PRINT
o seekp(long); VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
o seekp(offset, seekdir); - 01 Question 01 Question - 02 Question
 The seekp(long) moves the put pointer to a specified location from the beginning of a file. - Question no 15 Question no 23 - 05 Marks
 Example: inf.seekp(20);
Important Questions
 The seekp(offset, seekdir) has two arguments: offset and seekdir.
2 Marks Question:
 The offset indicates the number of bytes the put pointer is to be moved from seekdir position.
1. Differentiate between ifstream and ofstream. [March 2015]
 Syntax: stream_objectname.seekp(offset, origin_value);
2. What is a stream? Mention any one stream used in C++. [June 2015]
seekp( ) function option Action performed 3. Write any two member functions belonging to of stream class. [March 2016]
object.seekp(0, ios::beg) Go to beginning of the file for writing 4. Write any two member functions belonging to if stream class. [June 2016]
object.seekp(0, ios::end) Go to end of the file for writing 5. Differentiate between read( ) and write( ). [March 2017]
object.seekp(0, ios::cur) Stay at the current position for writing 6. Differentiate between put( ) and get( ) functions with reference to binary files. [June 2017]

9|Page Keerthi Kumar H M 10 | P a g e Keerthi Kumar H M


Chapter 12- Data File Handling II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

3 Marks Question: Chapter-14


1. Give the function of put( ), get( ) and getline( ) with respect to text files. [March 2015]
2. List the fifferent modes of opening a file with their meaning in C++. [June 2015] SQL COMMANDS
3. Give the functions for the following: [March 2016]  What is SQL?
a. get( ) b. getline( ) c. read( )  Structured Query Language and it helps to make practice on SQL commands which provides
4. Mention the types of data files. Explain. [June 2016] immediate results.
5. Explain any three modes of to open a file in C++. [March 2017]  SQL is Structured Query Language, which is a computer language for storing, manipulating and
6. Write the member function belong to ifstream. [June 2017] retrieving data stored in relational database.

****************  SQL is the standard language for Relation Database System.


 All relational database management systems like MySQL, MS Access, and Oracle, Sybase,
Informix, and SQL Server use SQL as standard database language.

 Why SQL?
 Allows users to create and drop databases and tables.
 Allows users to describe the data.
 Allows users to define the data in database and manipulate that data.
 Allows users to access data in relational database management systems.
 Allows embedding within other languages using SQL modules, libraries & pre-compilers.
 Allows users to set permissions on tables, procedures, and views

 SQL Architecture:
 When you are executing an SQL command for any RDBMS, the system determines the best way
to carry out your request and SQL engine figures out how to interpret the task.
 There are various components included in the process.
 These components are:
o Query Dispatcher
o Optimization Engines
o Classic Query Engine
o SQL Query Engine, etc.
 Classic query engine handles all non-SQL queries
but SQL query engine won't handle logical files.
 Simple diagram showing SQL Architecture:

11 | P a g e Keerthi Kumar H M
1|Page Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

 SQL Commands:  DCL - Data Control Language:


 The standard SQL commands to interact with relational databases are CREATE, SELECT,  These SQL commands are used for providing security to database objects.
INSERT, UPDATE, DELETE and DROP.  The different DCL commands are:
 These commands can be classified into groups based on their nature: Command Description
GRANT Gives a privilege to user
 DDL - Data Definition Language:
REVOKE Takes back privileges granted from user
 DDL defines the conceptual schema providing a link between the logical and the physical
structure of the database.  TCL – Transaction Control Language:
 The functions of the Data Definition Language (DDL) are:  It includes commands to control the transactions in a database system.
1. DDL defines the physical characteristics of each record, filed in the record, field‟s data type,  The commonly used commands are:
field‟s length, field‟s logical name and also specify relationship among those records. Command Description
2. DDL describes the schema and subschema. Make all the changes made by the statements issued
COMMIT
3. DDL indicate the keys of records. permanent.
4. DDL provides data security measures. ROLLBACK Undoes all changes since the beginning of transaction or
since a save point.
5. DDL provides for the logical and physical data independence.
 Few of the basic commands for DDL are:  Data Types in SQL:
Command Description  The following are the most common data types of SQL:
CREATE Creates a new table, a view of a table, or other object in database SL
DATA TYPE DESCRIPTION
ALTER Modifies an existing database object, such as a table. No
A variable-length column. Allowed values are zero,
DROP Deletes an entire table, a view of a table or other object in the database. 1 NUMBER
positive and negative numbers

 DML - Data Manipulation Language: 2 CHAR A variable length field up to 255 character in length

 DML provides the data manipulation techniques like selection, insertion, deletion, updation, 3 VARCHAR/VARCHAR2 A variable length field up to 2000 character in length
modification, replacement, retrieval, sorting and display of data or records. A fixed length field. The time is stored as a part of the
4 DATE/TIME
 DML facilitates use of relationship between the records. date. The default format is DD/MON/YY
 DML provides for independence of programming languages by supporting several high-level 5 LONG A variable length filed up to 2 GB in length
programming languages like COBOL, PL/1 and C++. A variable length filed used for binary data up to 2000
6 RAW
 Few of the basic commands for DML are: in length
A variable length filed used for binary data up to 2GB
Command Description 7 LONG RAW
in length
SELECT Retrieves certain records from one or more tables
1. NUMBER:
INSERT Creates a record
o Used to store a numeric value in a field column.
UPDATE Modifies records
o It may be decimal, integer or real value.
DELETE Deletes records
o General syntax: NUMBER(n, d)

2|Page Keerthi Kumar H M 3|Page Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

o Where n specifies the number of digits and d specifies the number of digits to right of the  SELECT, FROM and WHERE are keywords.
decimal point.  The clauses are “FROM student” and “WHERE RegNo=109”.
o Example: marks NUMBER(3), average NUMBER(2, 3)  Here SELECT and FROM are mandatory, but WHERE is optional.
2. CHAR:  Name, Student, RegNo, are identifier that refers to objects in the database.
o Used to store a character type data in a column.  Name and RegNo are column names, while Student is a table name.
o General syntax: CHAR(size)  The equal sign is an operator and 109 is a numeric constant.
o Where size represents the maximum (255 Characters) number of characters in a column.
o Example: name CHAR(15)  What is an Operator in SQL?
3. VARCHAR/VARCHAR2:  An operator is a reserved word or a character used primarily in an SQL statement's WHERE
o It is used to store variable length alphanumeric data. clause to perform operation(s), such as comparisons and arithmetic operations.
o General syntax: VARCHAR(size) / VARCHAR2(size)  Operators are used to specify conditions in an SQL statement and to serve as conjunctions for
o Where size represents the maximum (2000 Characters) number of characters in a column. multiple conditions in a statement.
o Example: address VARCHAR2(50) o Arithmetic operators (+, -, *, / %)
4. DATE: o Comparison operators (>, <, >=, <=, =, !=, <>, !<, !>)
o It is used to store date in columns. o Logical operators (AND, OR, NOT, IN, BETWEEN, EXISTS, ALL, ANY, LIKE, UNIQUE)
o SQL supports the various date formats other than the standard DD-MON-YY.
 SQL Logical Operators:
o Example: dob DATE
5. TIME:  Here is a list of all the logical operators available in SQL.

o It is used to store time in columns. Operator Description

o SQL supports the various time formats other than the standard hh-mm-ss. ALL The ALL operator is used to compare a value to all values in another value set.

o Every DATE and TIME can be added, subtracted or compared as it can be done with other The AND operator allows the existence of multiple conditions in an SQL statement's
AND
WHERE clause.
data types.
The ANY operator is used to compare a value to any applicable value in the list according
6. LONG: ANY
to the condition.
1. It is used to store variable length strings of up to 2GB size.
The BETWEEN operator is used to search for values that are within a set of values, given
2. Example: description LONG BETWEEN
the minimum value and the maximum value.
 Structure of SQL command: The EXISTS operator is used to search for the presence of a row in a specified table that
EXISTS
 Any SQL command is a combination of keywords, identifiers and clauses. meets certain criteria.

 Every SQL command begins with a keyword (CREATE, SELECT, DELETE and so on) which as The IN operator is used to compare a value to a list of literal values that have been
IN
specified.
a specific meaning to the language.
LIKE The LIKE operator is used to compare a value to similar values using wildcard operators.
The NOT operator reverses the meaning of the logical operator with which it is used. Eg:
NOT
NOT EXISTS, NOT BETWEEN, NOT IN, etc. This is a negate operator.
The OR operator is used to combine multiple conditions in an SQL statement's WHERE
OR
clause.

4|Page Keerthi Kumar H M 5|Page Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

IS NULL The NULL operator is used to compare a value with a NULL value.  It creates an empty STUDENT table which looks like this:
The UNIQUE operator searches every row of a specified table for uniqueness (no RegNo Name Combination DOB Fees
UNIQUE
duplicates).  Viewing the table information:
o The DESCRIBE or DESC command displays name of the columns, their data type and size
 Implementation of SQL Commands
along with the constraints.

 CREATE TABLE
 The SQL CREATE TABLE statement is used to create a new table.
 Creating a basic table involves naming the table and defining its columns and each column's data
type.
 Syntax: Basic syntax of CREATE TABLE statement is as follows:
 ALTER Statement:
CREATE TABLE Table_name
(  The table can be modified or changed by using the ALTER command.
column1 datatype,
column2 datatype,  Syntax: Basic syntax of ALTER TABLE statement is as follows:
column3 datatype, 1. ALTER TABLE Table_name
.....
ADD (column_name1 DataType, Cloumn_name2 DataType……);
columnN datatype,
PRIMARY KEY( one or more columns ) 2. ALTER TABLE Table_name
); MODIFY (column_name1 DataType, Cloumn_name2 DataType……);
o Here CREATE TABLE is the keyword followed by the Table_name, followed by an open
3. ALTER TABLE Table_name
parenthesis, followed by the column names and data types for that column, and followed by a
DROP (column_name1 DataType, Cloumn_name2 DataType……);
closed parenthesis.
 Example:
o For each column, a name and a data type must be specified and the column name must be a
unique within the table definition.
o Column definitions are separated by commas (,).
o Uppercase and lowercase letters makes no difference in column names.
o Each table must have at least one column.
o SQL commands should end with a semicolon (;).
 Using the ALTER TABLE command the following tasks cannot be performed
 Example: Create a table “STUDENT” that contains five columns: RegNo, Name, Combination,
o Changing a table name.
DOB and Fees.
o Changing the column name.
CREATE TABLE STUDENT
( o Decreasing the size of a column if table data exists.
RegNo NUMBER (6), o Changing a column‟s data type.
Name VARCHAR2 (15),
Combination CHAR (4),  DROP TABLE:
DOB DATE,
Fees NUMBER (9, 2),  The SQL DROP TABLE statement is used to remove a table definition and all data, indexes,
PRIMARY KEY ( RegNo ) triggers, constraints, and permission specifications for that table.
);  Syntax: Basic syntax of DROP TABLE statement is as follows:

6|Page Keerthi Kumar H M 7|Page Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

DROP TABLE Table_name; SQL> INSERT INTO STUDENT (REGNO, COMBINATION,FEES) VALUES(1412,
'PCMB',21000);
 Example: 1 row created.
 All the above statements would produce the following records in STUDENT table:

 INSERT:
 The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.
 Syntax:
 There are two basic syntaxes of INSERT INTO statement as follows:

INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]


VALUES (value1, value2, value3,...valueN);
 UPDATE:
 Here, column1, column2,...columnN are the names of the columns in the table into which you
 SQL provides the ability to change data through UPDATE command.
want to insert data.
 The UPDATE command used to modify or update an already existing row or rows of a table.
 You may not need to specify the column(s) name in the SQL query if you are adding values for all
 The basic syntax of UPDATE command is given below.
the columns of the table. But make sure the order of the values is in the same order as the columns
in the table. UPDATE Table_name
 METHOD 1: The SQL INSERT INTO syntax would be as follows: SET column_name = value
[, column_name =value ……….]
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
[WHERE condition];
 Example: Following statements would create six records in STUDENT table:
Example:
SQL> INSERT INTO STUDENT VALUES(1401,'RAMESH','PCMC','07-AUG-99',14000);
SQL> UPDATE STUDENT SET COMBINATION='CEBA' WHERE REGNO=1411;
1 row created.
1 row updated.
SQL> INSERT INTO STUDENT VALUES(1402,'JOHN','PCMB','15-SEP-99',13500); SQL> UPDATE STUDENT SET NAME='AKASH' WHERE REGNO=1412;
1 row created. 1 row updated.
SQL> INSERT INTO STUDENT VALUES(1403,'GANESH','PCME','19-AUG-99',16000);
 DELETE command:
1 row created.
 In SQL, an already existing row or rows are removed from tables through the use of DELETE
SQL> INSERT INTO STUDENT VALUES(1404,'MAHESH','PCMC','14-JAN-98',17650);
command.
1 row created.
 The basic syntax of DELETE command is given below.
SQL> INSERT INTO STUDENT VALUES(1405,'SURESH','PCMB','03-MAR-98',11500);
1 row created. DELETE Table_name

SQL> INSERT INTO STUDENT VALUES(1410,'ARUN','PCMC','01-APR-04',13000); [WHERE condition];

Example:
 METHOD 2: The SQL INSERT INTO syntax would be as follows: SQL> DELETE STUDENT WHERE REGNO=1412;
SQL> INSERT INTO STUDENT (REGNO, NAME, FEES) VALUES (1411, 'SHREYA',24000); 1 row deleted.
1 row created.
8|Page Keerthi Kumar H M 9|Page Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

 SELECT:  There may be a situation when you have multiple duplicate records in a table. While fetching such

 SQL SELECT statement is used to fetch the data from a database table which returns data in the records, it makes more sense to fetch only unique records instead of fetching duplicate records.

form of result table. These result tables are called result-sets.  Syntax: The basic syntax of DISTINCT keyword to eliminate duplicate records is as follows:

 Syntax: The basic syntax of SELECT statement is as follows: SELECT DISTINCT column1, column2,.....columnN
SELECT column1, column2, columnN Compulsory FROM Table_name
FROM Table_name; Part WHERE [condition]
[WHERE condition(s)]
 Example: Consider the STUDENT table having the following records:
[GROUPBY column-list] Optional
[HAVING condition(s)] Part
[ORDER BY column-name(s)];
 Here, column1, column2...are the fields of a table whose values you want to fetch. If you want to
fetch all the fields available in the field, then you can use the following syntax:

SELECT * FROM table_name;


 First, let us see how the following SELECT query returns duplicate combination records:
 Example: Consider the STUDENT table having the following records:

 Now, let us use DISTINCT keyword with the above SELECT query and see the result:

SQL> SELECT DISTINCT COMBINATION FROM STUDENT


 Following is an example, which would fetch REGNO, NAME and COMBINATION fields of the
ORDER BY COMBINATION;
customers available in STUDENT table:
 This would produce the following result where we do not have any duplicate entry:

 WHERE clause – (Extracting specific rows)


 DISTINCT:
 The SQL WHERE clause is used to specify a condition while fetching the data from single table
 The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the or joining with multiple tables.
duplicate records and fetching only unique records.  If the given condition is satisfied then only it returns specific value from the table. You would use
WHERE clause to filter the records and fetching only necessary records.
10 | P a g e Keerthi Kumar H M 11 | P a g e Keerthi Kumar H M
Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

 The WHERE clause is not only used in SELECT statement, but it is also used in UPDATE,  You can combine N number of conditions using AND operator. For an action to be taken by the
DELETE statement, etc., which we would examine in subsequent chapters. SQL statement, whether it be a transaction or query, all conditions separated by the AND must be
 Syntax: The basic syntax of SELECT statement with WHERE clause is as follows: TRUE.

SELECT column1, column2, columnN  Example: Consider the STUDENT table having the following records:
FROM Table_name
WHERE [condition]
 You can specify a condition using comparison or logical operators like >, <, =, LIKE, NOT, etc.
 Following is an example which would fetch REGNO, NAME and FEES fields from the
STUDENT table where FEES is greater than 15000:

 Following is an example, which would fetch REGNO, NAME and DOB fields from the
STUDENT table where fees is less than 1500 AND combination is „PCMC:

 Following is an example, which would fetch REGNO, NAME and COMBINATION fields from
the STUDENT table for a COMBINATION is „PCMC‟.
 Here, it is important to note that all the strings should be given inside single quotes ('') where as
numeric values should be given without any quote as in above example:  The OR Operator:
 The OR operator is used to combine multiple conditions in an SQL statement's WHERE clause.

 Syntax: The basic syntax of OR operator with WHERE clause is as follows:

SELECT column1, column2, columnN


FROM Table_name
 The SQL AND and OR operators are used to combine multiple conditions to narrow data in an WHERE [condition1] OR [condition2]...OR [conditionN];
SQL statement. These two operators are called conjunctive operators.
 You can combine N number of conditions using OR operator. For an action to be taken by the
 These operators provide a means to make multiple comparisons with different operators in the
SQL statement, whether it be a transaction or query, only any ONE of the conditions separated by
same SQL statement.
the OR must be TRUE.

 The AND Operator:  Following is an example, which would fetch REGNO, NAME and DOB fields from the
STUDENT table where fees is less than 1500 OR combination is „PCMC:
 The AND operator allows the existence of multiple conditions in an SQL statement's WHERE
clause.

 Syntax: The basic syntax of AND operator with WHERE clause is as follows:

SELECT column1, column2, columnN


FROM Table_name
WHERE [condition1] AND [condition2]...AND [conditionN];

12 | P a g e Keerthi Kumar H M 13 | P a g e Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

 ORDER BY – (Sorting the data)  Working out simple calculations.


 The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on  Whenever we want to perform simple calculations such as 10 / 5, we can perform using SELECT
one or more columns. Some database sorts query results in ascending order by default. statement which causes an output on monitor.
 Syntax: The basic syntax of ORDER BY clause is as follows:  But SELECT requires table name to operate.
 One can make use of the dummy table provided by SQL called DUAL which is a single row and
SELECT column-list
single column table.
FROM Table_name
[WHERE condition]  It is used when data from table is not required.

[ORDER BY column1, column2, .. columnN] [ASC | DESC];  For example, when a calculation is to be performed such as 10*3, 10/2 etc. and to display the
current system date, we could use the following queries.
 You can use more than one column in the ORDER BY clause. Make sure whatever column you
are using to sort, that column should be in column-list.
 Example: Consider the STUDENT table having the following records:

 SQL Functions:
 The SQL functions serve the purpose of manipulating data items and returning a result.
 There are many built in functions included in SQL and can be classified as Group Functions and
Scalar Functions.
 Group Functions:
 Following is an example, which would sort the result in ascending order by NAME: o Functions that act on set of values are called group functions.
o A group functions can takes entire column of data as its arguments and produces a single
data item that summarizes the column.
o Following are the SQL group functions.
Function Description
AVG Returns average value of „N‟, ignoring NULL values
COUNT(expr) Returns the number of rows where „expr‟ is not NULL
Returns the number of rows in the table including duplicates and those with
COUNT(*)
 Following is an example, which would sort the result in descending order by NAME: NULL values
MIN Returns minimum value of „expr‟
MAX Returns maximum value of „expr‟
SUM Returns sum of values „N‟

 Scalar Functions:
o Functions that act on only one value at a time are called scalar functions.
o We can further classify the functions using the type of data with they are designed to work.

14 | P a g e Keerthi Kumar H M 15 | P a g e Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

Function Description  AVG ( ) Function:


Numeric Work with numbers.  This function is used to find the average of the values in a numeric column.
Functions Examples: ABS, POWER, ROUND, SQRT  Example 1:
String Work with character based data. o SELECT AVG (Cs) FROM EXAMINATION;
Functions Examples: LOWER, INITCAP, UPPER, SUBSTR, LENGTH, LTRIM, RTRIM o The above query returns 74.7
Date Work with Date data types.  SUM ( ) Function:
Functions Example: ADD_MONTHS, LAST_DAY, MONTHS_BETWEEN, NEXT_DAY
 This function is used to find the sum of the values in a numeric column.
Conversion These functions are used to convert one type of data to another.
 Example:
Functions Example: TO_NUMBER, TO_CHAR, TO_DATE
o SELECT SUM (Phy) FROM EXAMINATION;

Consider the EXAMINATION table: o The above query returns 729


 MAX ( ) Function:
RegNo Name CC Phy Che Mat Cs Total City
 This function is used to find the maximum values in a column.
101 Ajay C1 98 100 97 99 394 Hassan
 Example:
102 Banu C2 38 50 37 49 174 Belur
o SELECT MAX (Phy) FROM EXAMINATION;
103 Chandan C2 100 100 97 99 396 Mysuru
o The above query returns 100
104 John C3 78 80 67 79 304 Alur
 MIN ( ) Function:
105 Kaleem C1 88 80 91 79 338 Hassan
 This function is used to find the minimum values in a column.
106 Raheem C2 100 98 97 79 374 Hassan
 Example:
107 Sanjay C3 47 60 56 78 241 Alur
o SELECT MIN (Phy) FROM EXAMINATION;
108 Tarun C3 33 34 77 28 172 Arasikere
o The above query returns 33
109 Uday C2 100 98 97 79 374 Hassan
110 Venki C3 47 60 56 78 241 Belur  GROUP BY (Grouping Result)
 The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange
 COUNT ( ) Function:
identical data into groups.
 This function is used to count the number of values in a column.
 The GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the
 COUNT (*) is used to count the number of rows in the table including duplicates and those with
ORDER BY clause.
NULL values.
 Syntax: The basic syntax of GROUP BY clause is given below.
 Example 1:
o SELECT COUNT (*) FROM EXAMINATION; SELECT column1, column2

o The above query returns 10. FROM Table_name

 Example 2: WHERE [ conditions ]

o SELECT COUNT (RegNo) FROM EXAMINATION WHERE CC = „C3‟ ; GROUP BY column1, column2

o The above query returns 4. ORDER BY column1, column2

16 | P a g e Keerthi Kumar H M 17 | P a g e Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

 Example 1: To find the number of students in each college.  Example: Consider the following CREATE TABLE command creates a new table called
SELECT CC, COUNT (CC) PRODUCT and add six columns, two which PID and Description specify not to accept NULLs.
FROM EXAMINATION CREATE TABLE PRODUCT
GROUP BY CC; (
 Example 2: To find the number of students, sum, average, maximum, minimum marks in PID CHAR (4) NOT NULL,
computer science from each city. Description VARCHAR2 (25), NOT NULL
SELECT City, COUNT (City), SUM (Cs), AVG (Cs), MAX (Cs), MIN (Cs) CompanyId CHAR (10),
FROM EXAMINATION DOM DATE,
GROUP BY City; Type CHAR (10),
Price NUMBER (10,2)
 SQL CONSTRAINTS: );

 Constraints are the rules enforced on data columns on table.


 UNIQUE Constraints:

 These are limiting the type of data that can go into a table.  This constraint ensures that no rows have the same value in the specified column(s). A table must
have many unique keys.
 This ensures the accuracy and reliability of the data into the database.
 Example: UNIQUE constraint applied on PID of PRODUCT table ensures that no rows have the
 SQL allows two types of constraints.
same PID value, as shown below
o Column level constraints: These constraints are defined along with the column definition
CREATE TABLE PRODUCT
when creating or altering a table structure. These constraints apply only to individual
(
columns. PID CHAR (4) NOT NULL UNIQUE,
o Table level constraints: These constraints are defined after all the table columns when Description VARCHAR2 (25), NOT NULL
creating or altering a table structure. These constraints apply to groups of one or more CompanyId CHAR (10),
DOM DATE,
columns. Type CHAR (10),
 Following are the commonly used constraints available in SQL. Price NUMBER (10,2)
Constraints Description );
 PRIMARY KEY Constraints:
NOT NULL Ensures that a column cannot have NULL value
 A primary key is a field which uniquely identifies each row in a database table. A primary key in a
UNIQUE Ensures that all values in column are different
table has special attributes:
PRIMARY KEY Uniquely identified eac row in a database table.
 By default this column is NOT NULL. It defines the column as a mandatory column i.e. the
FOREIGN KEY Uniquely identified each rown in any other database table
column cannot be left blank.
DEFAULT Provides a default value for a column when none is specified
 The data held in this column must be unique.
CHECK Ensures that all values in a column satisfy certain condition.
 Example:
 NOT NULL Constraint: CREATE TABLE PRODUCT
(
 By default column can hold NULL values. PID CHAR (4) PRIMARY KEY,
 When a column is defined as NOT NULL then the column becomes a mandatory column. Description VARCHAR2 (25), NOT NULL
CompanyId CHAR (10),
 It implies that a value must be entered into the column if the row is to be inserted for storage in the DOM DATE,
table. Type CHAR (10),
Price NUMBER (10,2)
);

18 | P a g e Keerthi Kumar H M 19 | P a g e Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

 FOREIGN KEY Constraint: (


PID CHAR (4) CHECK (PID LIKE ‘P%’),
 A FOREIGN KEY is used to link two tables together.
Description VARCHAR2 (25),
 A foreign key is a column whose values are derived from the PRIMARY KEY of some other table. CompanyId CHAR (10),
 Example: DOM DATE,
Type CHAR (10),
CREATE TABLE PRODUCT
Price NUMBER (10, 2) CHECK (Price>0)
(
);
PID CHAR (4) PRIMARY KEY,
 TABLE Constraints:
Description VARCHAR2 (25), NOT NULL
 When a constraint is applied to a group of columns of the table, it is called a table constraint.
CompanyId CHAR (10) REFERENCES COMPANY (CID)
DOM DATE,  Column constraint is defined along with the end of the column.
Type CHAR (10),  Table constraints are defined at the end of the table.
Price NUMBER (10,2)
);  Example:
CREATE TABLE COMPANY CREATE TABLE PRODUCT
( (
CID CHAR (10) PRIMARY KEY, PID CHAR (4) NOT NULL,
CProfile VARCHAR2 (200), Description VARCHAR2 (25) NOT NULL,
Noofproducts NUMBER (20), CompanyId CHAR (10),
DOE DATE DOM DATE,
); Type CHAR (10),
 DEFAULT Constraints: Price NUMBER (10, 2),
PRIMARY KEY (PID, Description)
 A default value can be specified for a column using the DEFAULT clause.
);
 The DEFAULT constraint provides a default value to a column when the INSERT INTO  Joins
command does not provide a specific value.  The SQL Joins clause are used to fetch/retrieve data from two or more tables based on the join
 Example: condition which is specified in the WHERE condition.
CREATE TABLE PRODUCT  Basically data tables are related to each other with keys. We can used these keys relationship in
(
PID CHAR (4) PRIMARY KEY, SQL joins.
Description VARCHAR2 (25), NOT NULL
CompanyId CHAR (10),  SQL Join Types:
DOM DATE,  There are different types of joins available in SQL:
Type CHAR (10), o INNER JOIN: returns rows when there is a match in both tables.
Price NUMBER (10, 2) DEFALUT 1000.00
); o LEFT JOIN: returns all rows from the left table, even if there are no matches in the right
 CHECK Constraints: table.
 The CHECK Constraint is used to establish a TRUE/FALSE condition that is applied to the data o RIGHT JOIN: returns all rows from the right table, even if there are no matches in the left
placed in a column. table.
 If a value does not meet the condition, it cannot be placed in the column. o FULL JOIN: returns rows when there is a match in one of the tables.
 Example: o SELF JOIN: is used to join a table to itself as if the table were two tables, temporarily
CREATE TABLE PRODUCT renaming at least one table in the SQL statement.

20 | P a g e Keerthi Kumar H M 21 | P a g e Keerthi Kumar H M


Chapter 14- SQL Commands II PUC, MDRPUC, Hassan Chapter 14- SQL Commands II PUC, MDRPUC, Hassan

o CARTESIAN JOIN: returns the Cartesian product of the sets of records from the two or 6. What is the difference between ORDER BY and GROUP BY clause used in SQL? Give example
more joined tables. for each. [June 2017]
7. List the relational operators supported by SQL.
 Creating VIEWs: 8. Why the DROP command used? Write its syntax.
 Database Views are created using the CREATE VIEW statement. 9. What are the difference between DROP and DELETE command?
 Views can be created from a single table, multiple tables or another view. 10. Give the syntax and example for CREATE VIEW command in SQL.
 To create a view, a user must have the appropriate system privilege according to the specific 11. Classify the built-in functions in SQL.
implementation.
 Syntax: The basic CREATE VIEW syntax is as follows:
Five Marks Question:

SQL> CREATE VIEW view_name AS 1. Explain various group functions in SQL. [March 2015, March 2017, June 2017]
SELECT column1, column2….. 2. What is data definition language? Explain SELECT and UPDATE command. [June 2015]
FROM table_name 3. Describe any five logical operators available in SQL. [March 2016]
WHERE [ condition ]; 4. What is SQL? Explain the different SQL commands.
5. What is the purpose of CREATE command? Write the syntax and example of CREATE command.
 Privileges and Roles: 6. Explain SELECT statement with syntax and with minimum 3 examples.
 Privileges: Privileges defines the access rights provided to a user on a database object. 7. Explain 5 variations of SELECT command.
 There are two types of privileges: 8. What are SQL constraints? Explain any two constraints.
o System Privileges: This allows the user to CREATE, ALTER, or DROP database objects.
****************
o Object privileges: This allows the user to EXECUTE, SELECT, INSERT, UPDATE or
DELETE data from database objects to which privileges apply.

CHAPTER 14 – STRUCTURED QUERY LANGUAGE BLUE PRINT


VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
- 01 Question - 01 Question 02 Question
- Question no 17 - Question no 36 06 Marks

Important Questions
Two Marks Questions:

1. Give the syntax and example for DELETE command in SQL. [March 2015]
2. List the data types supported in SQL. [June 2015]
3. Write the syntax for DELETE and INSERT commands in SQL. [March 2016]
4. Mention the logical operators used in SQL. [June 2016]
5. Give the syntax and example of UPDATE command in SQL. [March 2017]

22 | P a g e Keerthi Kumar H M 23 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

Chapter-15  Evolution of Networking:


 In 1969 U.S. Department of Defense sponsored a project named ARPANET (Advanced
NETWORKING CONCEPTS Research Projects Agency Network).
 Introduction:  The goal of the project was to connect various universities and US Defense.
 A computer network is a interconnection of two or more computers that are able to exchange  In mid 80’s National Science Foundation created a new high capacity network called NSFnet,
information’s. which was more powerful than ARPANET.
 Two computers are said to be inter connected if they are capable of exchanging information.  In 1990 the Internet came into picture.

 Network Goals/Advantages of Networking:  Internet:


 Resource Sharing:  The internet is worldwide network of computer network evolved from the first network
o The aim is to make all programs, data and peripherals available to anyone on the ARPANET.
network irrespective of the physical location of the resources and the user.  Internet is an interconnection of large and small networks around the globe.
 Reliability:  The common use of internet standards allows users connected to one network to communicate
o A file can have copies on two or three different machines, so if one of them is unavailable with users on another network.
(hardware crash), the other copies could be used.
o For military, banking, air reservation and many other applications it is of great
 Interspace:
importance.  Interspace is a client/server software program that allows multiple users to communicate

 Cost Factor: online with real-time audio, video and text chat in dynamic 3D environments.

o Personal computers have better price/performance ratio than micro computers.  Interspace provides the most advanced form of communication available on the Internet

o So it is better to have PC's, one per user, with data stored on one shared file server today.

machine.
 Elementary Terminology of Networks:
 Communication Medium.
1. Nodes (Workstations):
o Using a network, it is possible for managers, working far apart, to prepare financial report
 The term nodes refer to the computers that are attached to a network and are seeking to
of the company.
share the resources of the network.
o The changes at one end can be immediately noticed at another and hence it speeds up co-
 Of course, if there were no nodes (also called workstations), there would be no network at
operation among them.
all.
 Need of Networking: 2. Server:

 File sharing provides sharing and grouping of data files over the network.  A Server is also a computer that facilitates the sharing of data, software, and hardware

 Printing sharing of computer resources such as hard disk and printers etc. resources like printers, modems etc on the network.

 E-mail tools for communication with the e-mail address.  Servers can be of two types:

 Remote access able to access data and information around the globe. i. Non-dedicated servers ii. Dedicated servers

 Sharing the database to multiple users at the same time by ensuring the integrity.  Non-dedicated Servers:
 On small networks, a workstation that can double up as a server is known as non-
dedicated server since it is not completely dedicated to the cause of serving.
1|Page Keerthi Kumar H M 2|Page Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 Such servers can facilitate the resource-sharing among workstations on a proportionately 3. Layer 3 – Network Layer:
smaller scale.  The network layer is concerned
 Since one computer works as a workstation as well as server, it is slower and requires more with controlling the operation of
memory. the subnet.
 The (small) networks using such a server are known as PEER-TO-PEER networks.  The main function is
determining how packets are
 Dedicated Servers:
routed from source to
 On bigger network installations, there is a computer reserved for server's job and its only job
destination.
is to help workstations access data, software and hardware resources.
4. Layer 4 – Transport Layer:
 It does not double-up as a workstation and such a server is known as dedicated server.
 The basic function of the
 The networks using such a server are known as MASTER-SLAVE networks.
transport layer is to accept data
 On a network, there may be several servers that allow workstations to share specific
from the above (session) layer,
resources. For example, file server, printer server and modem server. split it up into smaller units if

3. Network Interface Unit (NIU) : needed, pass these to the

 A Network Interface Unit is an interpreter that helps establish communication between the network layer, and ensure that the pieces all arrive correctly at the other end.

server and workstations. 5. Layer 5 – Session Layer:

 The NIU is also called Terminal Access Point (TAP).  The session layer allows users on different machines to establish sessions between them.
 It includes dialog control, token management and synchronization.
4. MAC address:
6. Layer 6 – Presentation Layer:
 The MAC address refers to the physical address assigned by NIC manufacturer.
 The presentation layer is concerned with the syntax and semantics of the information

 OSI Reference Model: transmitted concerned with moving bits around the layer.
7. Layer 7 – Application Layer:
 The Open Systems Interconnection (OSI) model is a reference tool for understanding data
 The application layer contains a variety of protocols that are commonly needed by the user.
communications between any two networked systems.
 For example HTTP which is the bases for the World Wide Web to access web pages.
 It divides the communications process into seven layers.
 The three lowest layers focus on passing traffic through the network to end system.
 TCP/IP Model:
 The top four layers come into play in the end system to complete the process.
 The TCP/IP model uses four layers to perform the functions of the seven-layer OSI model.

1. Layer 1 – Physical Layer: 1. Layer 1 – Network Access Layer:

 The physical layer is concerned with transmitting raw bits over a communication channel.  The lowest layer of the TCP/IP protocol hierarchy.

 It also deals with mechanical, electrical and timing interfaces.  It defines how to use the network to transmit an IP data.

2. Layer 2 - Data Link Layer:  It encompasses the functions of physical and data link layer of OSI reference model.

 The main function of the data link layer is to take a raw transmission facility and transform it 2. Layer 2 – Internet Layer:

into a line that appears free of transmission errors in the network layer.  Provides services that equivalent to OSI network layer.
 The primary concern of the protocol at this layer is to manage the connections across

3|Page Keerthi Kumar H M 4|Page Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

network as information is passed from source to destination.  FTP Protocol:


 The internet Protocol (IP) is the primary protocol at this layer. o File Transfer Protocol.
3. Layer 3 – Transport Layer: o It is a standard Internet Protocol for transmitting files between computers on the internet.
 It is designed to allow peer entities on o FTP is an application protocol that uses the Internet’s TCP/IP protocols.
the source and destination hosts to carry o It is also commonly used to download programs and other files to your computer from other
on a conversation. servers.
 Two end-to-end transport protocols have  SMTP Protocol:
defined here TCP and UDP. o Simple Mail Transfer Protocol.
4. Layer 4 – Application Layer: o It is a TCP/IP protocol used in sending and receiving e-mail.

 It includes the OSI session, presentation o It is limited in its ability to queue messages at the receiving end; it is usually used with one of

and application layers. two other protocols such as POP3 or IMAP.

 An application is any process that occurs  SLIP:

above the transport layer. o Serial Line Internet Protocol was the first protocol for relaying the IP packets over dial-up

 This includes all of the processes that involve user interaction. lines.

 The application determines the presentation of the data and controls the session. o It defines an encapsulation mechanism, but little else.
o There is no support for dynamic address assignment, link testing or multiplexing different
 Network Protocol: protocols over a single link.
 A protocol is a set of rules and procedures that determine how a computer system receives and  PPP:
transmits data. o Point to Point Protocol is the standard for transmission of IP packets over serial lines.
o The PPP is currently the best solution for dial-up internet connections, including ISDN.
 TCP/IP Protocol:
o PPP is a layered protocol, starting with a link control protocol (LCP) for link establishment,
o Transmission Control Protocol / Internet Protocol.
configuration and testing.
o It is the basic communication language or protocol of the Internet.
o PPP supports both synchronized and unsynchronized lines.
o TCP/IP is a two-layer program, the higher layer Transmission Control Protocol (TCP)
manages the assembling of a message or file into smaller packets that are transmitted over the  Types of network:
internet.  A computer network means a group of networked components, i.e., computers are linked by
o The lower layer Internet Protocol (IP) handles the address part of each packet so that it gets means of a communication system.
to the right destination.  There are three types of network.
 HTTP Protocol: o Local Area Network (LAN)
o Hypertext Transfer Protocol. o Wide Area Network (WAN)
o It provides a standard for web browsers and servers to communicate. o Metropolitan Area Network (MAN)
o The HTTP is an application layer network protocol built on top of TCP.  Local Area Network:
o HTTP clients (web browsers) and servers communicate via HHTP request and response  Privately owned small networks that are confined to a localized area (e.g., an office, a building
messages. or a factory) are known as Local Area Networks (LANs).
 The key purpose of a LAN is to serve its users in resource sharing.
5|Page Keerthi Kumar H M 6|Page Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 The hardware as well as software resources are shared through LANs.  Network Topologies
 LAN users can share data, information, programs, printers, hard disk, modems, etc.  Network Topology refers to the arrangement of computers and other devices in a network.
 It is fast with speed from 10 MBPS to 10 GBPS.  Need for Topologies are: Cost, Flexibility, and Reliability.
 LAN Configuration consists of:  Network topologies can be classified as follows:
o A File Server: Stores all of the software that controls the network, as well as the software 1. Bus Topology
that can be shared by the computers attached to the network. 2. Star Topology
o A Workstation: Computers connected to the file server. These are less powerful than the 3. Ring Topology
file server. 4. Mesh Topology
o Cables: Used to connect the network interface cards on each computer. 5. Hybrid Topology

 Metropolitan Area Network (MAN)  Linear or bus Topology:


 Metropolitan Area Network is the networks spread over a city.  A linear bus topology consists of a main run of cable with a terminator at each end.
 MAN typically covers an area of between 5 and 50 KM.  All nodes (file server, workstations, and peripherals) are connected to the linear cable.
 The purpose of a MAN is also the sharing of hardware and software resources among its users.  In the bus network topology, every workstation is connected to a main cable called the bus.
 For example, cable TV networks that are spread over a city can be termed as metropolitan area  Therefore, in effect, each workstation is directly connected to every other workstation in the
networks. network.
 Advantages of a Linear Bus Topology
 Wide Area Network (WAN)
o Easy to connect a computer or
 The networks spreads across countries are known as WANs.
peripheral to a linear bus.
 A wide Area Network (WAN) is a group of computers that are separated by large distances and
o Requires less cable length than a star
tied together.
topology.
 The largest WAN in existence is the internet.
 Disadvantages of a Linear Bus Topology
 It can even be a group of LAN that are spread across several locations and connected and
o Entire network shuts down if there is a break in the main cable.
together to look like one big LAN.
o Terminators are required at both ends of the backbone cable.
 The WANs link computers to facilitate fast and efficient exchange of information at lesser
o Difficult to identify the problem if the entire network shuts down.
costs and higher speeds.
o Not meant to be used as a stand-alone solution in a large building.
 Difference between LAN and WAN
 Star Topology
Sl No LAN WAN
 In this type of topology, all the computers are connected to a single
1 Local Area Network Wide Area Network
hub or a switch through a cable. This hub is the central node and all
2 Diameter of not more than a few kilometre Span entire country
others nodes are connected to the central node.
3 A total data rate of at least several mbps Data rate is less compared to LAN
 Advantages of a Star Topology
4 Complete ownership by a single organization Owned by multiple organization
o Easy to install and wire.
5 Very low error rates Comparatively high error rates. o No disruptions to the network when connecting or removing
devices.
7|Page Keerthi Kumar H M 8|Page Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

o Easy to detect faults. o Supported by several hardware and software venders.


 Disadvantages of a Star Topology o Network can be easily extended.
o Requires more cable length than a linear topology.  Disadvantages of a Tree Topology
o If the hub, switch, or concentrator fails, nodes attached are disabled. o Use large cable length.
o More expensive than linear bus topologies because of the cost of the hubs, etc. o If the backbone line breaks, the entire segment goes down.
o More difficult to configure and wire than other topologies.
 Ring topology
 In a ring topology, all computers are connected via cable that loops in a ring or circle.  Mesh Topology:
 A ring topology is a circle that has no start and no end.  In this topology each node is connected to two or more than two
 Each node connected to two neighboring computers. nodes.
 Data accepted from one node transmitted to another.  It is a point-to-point connection to other nodes or devices.
 Data travels in one direction, from the node to node around the ring.  Traffic is carried only between two devices or nodes to which it
 Signal amplified at each node before being passed. is connected.

 Advantages of Ring Topology  This topology is robust, provides security and privacy.
o Short cable length  Overall cost of this network is too high.
o No wiring closet space required
 Data Communication Terminologies:
o Suitable for optical fibers.
 Data channel: The information / data carry from one end to another in the network by channel.
o Each client has equal access to resources.
 Baud & bits per second (bps): It’s used to measurement for the information carry of a
 Disadvantages
communication channel.
o Node failure causes network failure
o Difficult to diagnose faults
 Bandwidth: It is amount of information transmitted or receives per unit time. It is measuring in
Kbps/Mbps etc unit.
o Network reconfiguration is difficult

 Tree Topology:  Transmission Medium:


 A tree topology combines characteristics of linear bus and star topologies.  The first layer of computer networks is dedicated to the transmission media.

 It consists of groups of star-configured workstations connected to a linear bus backbone cable.  Due to variety of transmission media and network writing methods, selecting the most

 The tree network topology uses two or more star networks appropriate media can be confusing.

connected together.  The factors to be considered are:

 The central computers of the star networks are connected to o Transmission rate, Distance, cost, easy of installation and resistance to environmental

a main bus. Thus, a tree network is a bus network of star condition.

networks.  There are two type of transmission media:

 Best suited for applications having hierarchical flow of data a. Guided b. Unguided

and control.  Guided media are:

 Advantages of a Tree Topology o Twisted Pair: Unshielded Twisted Pair (UTP), Shielded Twisted pair (STP)

o Point-to-Point wiring for individual segments. o Co-axial cable: Thinnet, Thicknet

9|Page Keerthi Kumar H M 10 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

o Optical Fiber cable 2. Shielded Twisted Pair (STP) Cable:


 Unguided media are:  This type of cables comes with shielding of individual pairs of
o Radio wave Transmission wires, which further protects it from external interference.
o Microwave Transmission  But these also, like UTP, can have a maximum segment length of
o Satellite Communication 100 meters.
o Infrared  The advantage of STP over UTP is that it offers greater protection
o Laser from interference and crosstalk due to shielding.
 Twisted Pair Cable  But it is definitely heavier and costlier than UTP and requires proper grounding at both ends.
 One of the oldest and still most common transmission media is twisted pair. Advantages Disadvantages
 A twisted pair consists of two insulated copper wires.  Easy to install  Data transmission rate are very low
 The wires are twisted together in helical form.  Flexible  It is incapable to carry a signal over long
 Twisting is done because two parallel wires constitute a fine antenna.  It is very inexpensive distance without the use of repeaters
 The most common application of the twisted pair is the telephone system (RJ-11).  Low bandwidth
 Twisted pair can run several kilometers without amplification, but for longer distance the  Coaxial Cable
signal becomes too week and repeaters are needed.  This type of cable consists of a solid wire core surrounded by one or
 Due to low cost, twisted pairs are widely used. more foil or wire shields, each separated by some kind of plastic
 Twisted pairs are used in LAN (RJ-45) insulator.
 The inner core carries the signal, and the shield provides the ground.
 Types of Twisted Pair Cable:
 The coaxial cable has high electrical properties and is suitable for high
 There are two types of twisted pair cables available. These are:
speed communication.
1. Unshielded Twisted Pair (UTP) Cable:  While it is less popular than twisted pair, it is widely used for television signals.

 UTP is the copper media inherited from telephone, which is being used for increasingly higher  Types of Coaxial Cables:
data rates.  The two most commonly used types of coaxial cables are Thicknet and Thinnet.
 A UPT cable contains 2 to 4200 twisted pair. 1. Thicknet: This form of coaxial cable is thicker than Thinnet. The Thicknet coaxial cable
 UTP is flexible, low cost media; it can be sued for voice or data communication. segments (while joining nodes of a network) can be up to 500 meters long.
 It is available in the following five categories: 2. Thinnet: This form of coaxial cable is thinner and it can have maximum segment length of
1. CAT1: Voice-Grade communications only; No data 185 meters i.e. using these cables, nodes having maximum distance of 185 meters can be
transmission joined.
2. CAT2: Data-grade transmission up to 4 Mbps Advantages Disadvantages
3. CAT3: Data-Grade transmission up to 10 Mbps  Data transmission rate is better compared  Difficult to install, manage and
4. CAT4: Data-grade transmission up to 16 Mbps to Twisted pair reconfigure.
5. CAT5: Data-grade transmission up to 1000 Mbps  Used for broadband connection.  Expensive than twisted pair
 The UTP cables can have a maximum segment length of 100 meters.  Higher bandwidth up to 400 Mbps

11 | P a g e Keerthi Kumar H M 12 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 Optical Fibers  Both the transmitter and receiver use antennas to radiate and capture the radio signals.

 Optical Fibers consist of thin strands of glass or glass like Advantages Disadvantages
material which are so constructed that they carry light from a  Provide mobility  It is an insecure communication.
source at one end of the fiber to a detector at the other end.  Inexpensive.  Susceptible to weather effects like rains,
 The light sources used are either light emitting diodes (LEDs)  It proves cheaper than digging trenches for thunder storms etc
or LASER Diodes (LDs). laying cables.
 It transmits light rather than electronic signals eliminating the  Free from land acquisition rights.
problem of electrical interference.
 Microwave:
 OFC has ability to transmit signals over much longer distances than coaxial cable and twisted pair.
 Microwave transmission is line of sight transmission.
 The bandwidth of the medium is potentially very high. For LEDs, this range is between 20-150
Mbps and higher rates are possible using LDs.  The transmit station must be in visible contact with
the receive station.
 It also capacity to carry information at vastly greater speed.
 This sets a limit on the distance between stations
Advantages Disadvantages
depending on the local geography.
 Transmit data over long distance with  Difficult to install
 Microwave operates at high operating frequencies of 3 to 10 GHz.
high security.  Expensive as compared to other guided
 This allows carrying large quantities of data due to their large bandwidth.
 Data transmission is high. media
Advantages Disadvantages
 Provide better noise immunity.  Difficult to repair.
 Maintenance easy than cables.  Repeaters are required for long distance
 Bandwidth is up to 100 Gbps
 Suitable when cable cannot be used. communication.
 Free from land acquisition rights.  Less Bandwidth available.
 Comparison table of Guided Transmission media:
 Low cost land purchase ( Tower occupies  Reflected from flat surfaces like water and
Cable Parameter Twisted Pair Cable Co-axial Cable Optical Fibre Cable
small area) metals.
Data Transfer Rate 10 Mbps – 10 Gbps 100 Mbps More than 100 Gbps
 Carry high quantities of information due to
Data Transfer Range 100 Meters 185 Mts – 500 Mts Large distance
their high operating frequencies.
Interference More Less than T.P Nil
Cost of cable Lest cost More than T.P Very expensive  Satellite communication:
 A satellite consists of transponders (unit that receive on one frequency and retransmit on another)
 Radio Wave
that are set in geostationary orbits directly over the equator.
 The transmission making use of radio frequencies is termed as radio-wave transmission.
 Satellite communication is special case of microwave relay system.
 Any radio setup has two parts:
 These geostationary orbits are 22,000 - 36,000
a. The transmitter b. The receiver
Km from the Earth’s surface.
 The transmitter takes some sort of message, encodes it onto a sine wave and transmits it with radio
 The uplink is the transmitter of data to the
wave.
satellite.
 The receiver receives the radio wave and decodes the message from the sine wave it receives.
 The downlink is the receiver of data.

13 | P a g e Keerthi Kumar H M 14 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 Uplinks and downlinks are also called Earth stations because they are located on the Earth.  Circuit Switching:
Advantages Disadvantages  In this technique, first the complete physical connection between two computers is established
 The area coverage through satellite  Very expensive and then data are transmitted from the source computer to the destination computer.
transmission is large.  Installation is complex.  That is, when a computer places a telephone call, the switching equipment within the telephone
 No line of sight restrictions.  Signals sent to the stations can be tampered system seeks out a physical copper path all the way from sender telephone to the receiver's
 Earth station which receives the signals by external interference. telephone.
can be fixed position or relatively mobile.  The important property of this switching technique is to setup an end-to-end path connection
between computers before any data can be sent.
Apart from microwaves, radio waves and satellites, two other unguided media are also very popular.  Message Switching:
These are infrared and laser waves.  In this technique, the source computer sends data or the message to the switching office first,
which stores the data in its buffer.
 Infrared:
 It then looks for a free link to another switching office and then sends the data to this office.
 This type of transmission uses infrared light to send data.
 This process is continued until the data are delivered to the destination computers.
 You can see the use of this type of transmission in everyday life - TV remotes, automotive garage
 It is also known as store and forward. i.e., store first in switching office, forward later, one
doors, wireless speakers etc., all make use of infrared as transmission media.
jump at a time.
 The infrared light transmits data through the air and can propagate throughout a room (bouncing
 Packet Switching:
off surfaces), but will not penetrate walls.
 Packet switching can be seen as an option that tries to combine the advantages of circuit and
 The infrared transmission has become common in PDAs (Personal digital assistants) e.g., hand
message switching and to minimize the disadvantage of both.
held devices like palm pilots etc.
 In Packet switching, a message is broken into smaller parts called packets.
 The infrared transmission is considered to be a secure one.
 A fixed size of packet which can be transmitted across the network is specified.

 Laser:  Communication Modes:


 The laser transmission requires direct line-of-sight.
 The way in which data is transmitted from one place to another is called data transmission
 It is unidirectional like microwave, but has much higher speed than microwaves.
mode.
 The laser transmission requires the use of a laser transmitter and a photo-sensitive receiver at each
 It is also called the data communication mode.
end.
 It is indicates the direction of flow of information.
 The laser transmission is point-to-point transmission, typically between buildings.
 Sometimes, data transmission modes are also called directional modes.
 Disadvantage: It can be adversely affected by the weather.
 Different types of data transmission modes are as follows:

 Switching techniques: 1. Simplex mode


2. Half-duplex mode
 Switching techniques are used for transmitting data across networks.
3. Full-duplex mode
 There are three types of switching:
 Simplex Mode
o Circuit Switching
 In simplex mode, data can flow in only one direction.
o Message Switching
 In this mode, a sender can only send data and cannot receive it.
o Packet Switching
15 | P a g e Keerthi Kumar H M 16 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 Similarly, a receiver can only receive data but cannot send it.  A modem is a computer peripheral that allows you to connect and communicate with other
 Data sent from computer to printer is an example of simplex mode. computers via telephone lines.
 In simplex mode, it is not possible to confirm successful transmission of data.  Modulation: A modem changes the digital data from your computer into analog data, a format that
 It is also not possible to request the sender to re-transmit information. can be carried by telephone lines.
 This mode is not widely used.  Demodulation: The modem receiving the call then changes the analog signal back into digital
data that the computer can digest.
 The modem modulates the signal at the sending end and demodulates at the receiving end.
 Modems are of two types:
o Internal modems: The modems that are fixed
 Half-Duplex Mode
within the computer
 In half-duplex mode, data can flow in both directions but only in one direction at a time.
o External modems: The modems that are
 In this mode, data is sent and received alternatively.
connected externally to a computer as other
 It is like a one-lane bridge where two-way traffic must give way in order to cross the other.
peripherals are connected.
 The Internet browsing is an example of half duplex mode.
 The user sends a request to a Web server for a web page.  RJ-45:
 It means that information flows from user's computer to the web server.  RJ-45 is short for Registered Jack-45 is an eight-wire connector, which

 Web server receives the request and sends data of the requested page. is commonly used to connect computers on the local area networks i.e.,

 The data flow the Web server to the user's computer. LANs especially Ethernets.

 At a time a user can a request or receive the data of web page.  The standard connector for unshielded twisted pair cabling is an RJ-45 connector.

 Ethernet Card:
 The computer that are part of Ethernet, have to install our
special card called Ethernet card.
 Full-Duplex Mode
 It is LAN architecture developed by Xerox Corp association
 In full duplex-mode, data can flow in both directions at the same time.
with DEC and Intel.
 It is the fastest directional mode of data communication.
 It make use of Bus or Star topology and data transfer rates of 10 Mbps.
 The telephone communication system is an example of full-duplex communication mode.
 An Ethernet card contains connections for either coaxial or twisted pair cables (or both).
 Two persons can talk at the same time.
 If it is designed for coaxial cable, the connection will be BNC.
 If it is designed for twisted pair, it will have a RJ-45 connection.
 Some Ethernet cards also contain an AUI connector. This can be used to

 Network Devices: attach coaxial, twisted pair, or fiber optical cables to an Ethernet card.

 Modem:  Hub:
 Modem means Modulation/ Demodulation.  A hub is a hardware device used to connect several computers together.

17 | P a g e Keerthi Kumar H M 18 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 A concentrator is device that provides a central connection point for cables from workstations,  Gateway:
servers, and peripherals.  The term gateway is applied to a device, system or software application which has internetwork
 In a star topology, twisted-pair wire is run from each workstation to a central concentrator. capability of joining dissimilar network.
 Types of hub:  It is node on network that provides entry to another network.
o Active hubs:  It performs data translation and protocol conversions which is suitable to other network.
 It electrically amplifies the signal as it moves from one connected device to another.  Example: It needs to convert Ethernet traffic from the LAN to SNA (System Network
 Active concentrators are used like repeaters to extend the length of a network. Architecture). It then routes SNA traffic to Mainframe. When Mainframe answers, the reverse
o Passive hubs: process occurs.
 It allows the signal to pass from one computer to another without any change.  Gateway can be implemented on software, hardware or a combination of both.
 Gateway is that only the data format is translated, not the data itself.
 Switch:
 The switch is a telecommunication device grouped as one of computer network components.  Wireless and Mobile Computing:
 The switch is like Hub but built in with advanced features.  Wireless refers to the method of transferring information between a computing device, such as a
 The switch connects the source and destination directly which increases the speed of the network. personal data assistant (PDA), and a data source, such as an agency database server, without a
physical connection.
 Repeater:
 A Repeater is network device that amplifies and restore signals for long-distance transmission.  Wireless communication:
 It is used in long network lines, which exceed the maximum rated distance for a single run.  Wireless communication is simply data communication without the use of landlines.
 This may involve cellular telephone, two way radio, fixed wireless, LASER or satellite
 Bridge:
communication.
 A Bridge is a network device that establishes an intelligent connection between two local networks
 Mobile computing means that the computing device is not continuously connected to the base or
with the same standard but with different type’s cables.
central network.

 Router:  Mobile devices include PDAs, Laptop computers and smart phones.

 A router works like a bridge but can handle different protocols.  GSM:
 A Router is a network device that is used to separate different segments in a network to improve  GSM is short for Global System for Mobile communications, which is one of the leading digital
performance and reliability. cellular systems.
 The GSM standard for digital cell phones was established in Europe in the mid 1908s.
 GSM uses narrowband TDMA, which allows eight simultaneous calls on the same radio
frequency.
 TDMA is short for Time Division Multiple Access, a technology for delivering digital wireless
service using time-division multiplexing (TDM).

 TDMA:
 Time Division Multiple Access.

19 | P a g e Keerthi Kumar H M 20 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 TDMA works by dividing a radio frequency into time slots and then allocating slots to, multiple
calls. In this way, a single frequency can support multiple, simultaneous data channels.

 SIM card:
 The SIM - Subscriber Identity Module - is a chip card; the size of a first class postage stamp.
 A SIM is a computer chip that gives a cellular device its unique phone number.
 It has memory (16 to 64 KB), processor and the ability to interact with the user.

 CDMA:
 CDMA is short for Code-Division Multiple Access, a digital cellular technology that uses spread-
spectrum techniques.
 CDMA is a form of spread spectrum, which simply means that data is sent in small pieces over a
number of the discrete frequencies available for use at any time in the specified range.

 WLL
 Wireless in Local Loop (WLL or WiLL),
 It is meant to serve subscribers at homes or offices.
 Applications in Networking:
 In WLL services, the telephone provided is expected to be as good as wired phone.
 Its voice quality must be high - a subscriber carrying out long conversation must not be irritated  SMS:

with quality; one must be able, to use speakerphones, cordless phones and parallel phones.  Short Message Service (SMS) is the transmission of short text messages to and from a mobile
phone, fax machine and/or IP address.
 GPRS
 Messages must be no longer than some fixed number of alpha-numeric characters and contain
 GPRS stands for General Packet Radio Service.
no images or graphics.
 GPRS is used for wireless communication using a mobile device.
 E-mail:
 With the service you can access the internet, send emails and large data, download games and  Electronic mail (e-mail) is sending and receiving message by computer.
watch movies.
 Advantages:

 EDGE: o Low cost: Electronic mail is an extremely cost-effective way to move information
around, especially when it must be moved quickly.
 The new EDGE air interface has been developed specifically to meet the bandwidth needs of 3G.
o Speed: Electronic mail can be delivered almost as fast as the wire can carry it.
Enhanced Data rates for Global Evolution (EDGE) is a radio based high-speed mobile data
 Voice Mail:
standard.
 The voice-mail refers to e-mail systems that support audio.
 It allows data transmission speeds of 384 Kbps.
 Users can leave spoken messages for one another and listen to the messages by executing the
 EDGE was formerly called GSM384.This means a maximum bit rate of 48 kbps per time slot.
appropriate command in the e-mail system.
 EDGE is considered an intermediate step in the evolution of 3G WCDMA.
 Chat:
The “G” in wireless networks refers to the “Generation” of the underlying wireless network  Chatting is the most fantastic thing on Internet.
technology.
21 | P a g e Keerthi Kumar H M 22 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

 Chatting is like a text-phone.  It is able to replicate.


 In telephonic conversations, you say something, people hear it and respond, and you hear their  Reduced memory or disk space.
responses on the spot and can reply instantly.  Modification of data.
 Video Conferencing:  Files overwritten or damaged.
 A two-way videophone conversation among multiple participations is called Video  Hard drive erased.
Conferencing.  Types of Virus:
 File Infectors:
 Wi-fi:
o Infect executable files or attach themselves to a program file and create duplicate files.
 Wi-Fi is short for Wireless Fidelity, which lets you connect to the internet without a direct line
 Boot sector Virus:
from your PC to the ISP.
o Install themselves on the beginning tracks of the hard drive or the Master Boot record.
 For Wi-Fi to work, you need:
 Macro Virus:
o A broadband internet connection.
o Infect data file like spread sheets or databases of several software packages.
o A wireless router, which relays your internet connection from the “wall” to the PC.
 Network Virus:
o A laptop or desktop with a wireless internet card or external wireless adapter.
o E-mail or any data transfer files to spread themselves on the network.
 Wi-Fi Hotspots:  Trojan Horse:
 A hotspot is a venue that offers Wi-Fi access. o A Trojan Horses is code hidden in a program such as a game as spreadsheet that looks

 The public can use a laptop, Wi-Fi phone or other suitable portable devices to access the safe to run but has hidden side effects.

internet through a Wi-Fi hotspot.  Worm:

 Hotspots are public locations with free or fee-based wireless internet access. o A worm is a program designed to replicate. The program may perform any variety of
additional tasks as well.
 WiMax:  How Computer Viruses Spread?
 WiMax is wireless digital communication system.  It moves from computer to computer by attaching themselves to files or boot records of disks.
 WiMax can provide Broadband Wireless Access (BWA) up to 30 miles for fixed stations and  A virus travel from file to another on the same computer if the infected file executed, from
3-10 miles for mobile stations. computer memory to a file on the disk, on a disk that is carried from one computer to another.
 WiMax requires a tower called WiMax Base Station, similar to cell phone tower, which is  Damage:
connected to the internet using a standard wired high-speed connection.  Can destroy file allocation table (FAT)
 Can create bad sectors on the disk
 VIRUS:
 Can decrease the space on the hard disks by duplicating file.
 VIRUS – “Vital Information Resource Under Siege”.
 Can format specific tracks on the disk.
 A computer virus is a computer program that can replicate itself and spread from one computer
 Can destroy specific executable files
to another.
 Can cause the system to hang.
 Depend on the nature of a virus, it may cause damage of your hard disk contents, and/or
 Virus Protection:
interfere normal operation of your computer.
 The following guidelines to lead virus free computing life.
 Characteristics of a computer virus:
o Never use a CD without scanning it for viruses.
23 | P a g e Keerthi Kumar H M 24 | P a g e Keerthi Kumar H M
Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan

o Always scan files downloaded from the internet. o There are several types of firewall techniques-
o Never boot your PC from floppy. o Packet filter - accepts or rejects of packets based on user defined rules.
o Write protect your disks and make regular backup.. o Application gateway - security mechanism to specific application like FTP and Telnet
o Use licensed software. servers.
o Password protects your PC. o Circuit level gateway - applies security mechanism when a connection is established.
o Install and use antivirus software. o Proxy Server - Intercepts all messages entering and leaving the network.
o Keep antivirus software up to date.
 Cookies :
 Some of the antivirus are: Kaspersky, Quick Heal, K7, Norton 360, AVG, Avasta, McAFee.
 Cookies are messages that a web server transmits to a web browser so that the web server can
 Network Security: keep track of the user’s activity on a specific web site. Cookies have few parameters name,
 Network security consists of the provisions and policies adopted by a network administer to value, expiration date.
prevent and monitor unauthorized access, misuse, modification of a computer network and
 Hackers and crackers :
network accessible resources.
 Hackers are more interested in gaining knowledge about computer systems and possibly using
 The problem encountered under network security are:
this knowledge for playful pranks.
1. Physical Security holes: When individuals gain unauthorized physical access to a computer
 Crackers are the malicious programmers who break into secure systems.
and tamper with files.
2. Software Security holes: When badly written programs or privileged software are  Cyber Law:
compromised into doing things that they shouldn’t be doing.
 It is a generic term, which refers to all the legal and regulatory aspects of internet and the
3. Inconsistent usage holes: When a system administrator assembles a combination of hardware
World Wide Web.
and software such that the system is seriously flawed from a security point of view.
 India’s IT Act:
 Protection Methods:
 In India the cyber laws are contained in the IT Act 2000. Aims to provide legal infrastructure
1. Authorization - Authorization is performed by asking the user a legal login ID. If the user is
for e-commerce in India by governing transactions through internet and other electronic
able to provide a legal login ID, He/she is considered an authorized user.
medium.
2. Authentication - Authentication also termed as password protection as the authorized user is
CHAPTER 15 – NETWORKING CONCEPTS BLUE PRINT
asked to provide a valid password and if he/she is able to do this, he/she considered to be an
VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
authentic user.
3. Encryption Smart cards– conversion of the form of data from one form to another form. An 02 Question 01 Question - 01 Question 04 Question
Question no
encrypted smart card is a hand held smart card that can generate a token that a computer Question no 18 - Question no 37 09 Marks
07, 08
system can recognize. Every time a new and different token is generated, which even though
carked or hacked, cannot be used later. Important Questions
4. Biometric System – It involves unique aspect of a person's body such as Finger-prints, retinal
 1 Marks Question:
patterns etc to establish his/her Identity.
1. Expand FTP. [March 2015, June 2017]
5. Firewall - A system designed to prevent unauthorized access to or from a private network is
2. What is network topology? [March 2015, March 2016]
called firewall. It can be implemented in both hardware and software or combination or both.

25 | P a g e Keerthi Kumar H M 26 | P a g e Keerthi Kumar H M


Chapter 15- Networking Concepts II PUC, MDRPUC, Hassan Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan

3. Expand URL. [June 2015] Chapter-16


4. Define bus topology. [June 2015]
5. Define Local Area Networking. [March 2016] INTERNET AND OPEN SOURCE CONCEPTS
6. Define Networking. [June 2016]  Introduction:
7. Give an example for full duplex communication mode. [June 2016]  Internetwork: An internetwork is a collection of individual networks, connected by intermediate
8. What is Chatting? [March 2017] networking devices, that functions as a single large network.
9. What is a Server? [March 2017]  Classification of Internetworks:
10. Give the syntax of URL. [June 2017] o Internet: The globe public network.

Extra One Mark Questions o Intranets: The wholly owned/private internetworks.


o Extranets: The hybrid internetworks: private networks/ internetworks connected through
11. Name the first computer network? 16. What are cookies? the internet
12. What is client/workstation? 17. What hackers and crackers?
 The term “open source” software is used to refer to those categories of software/ programs
13. What is server? 18. Expand the terms: TCP/IP, GPRS,
whose licenses do not impose much condition.
14. What are the various types of network? GSM, EDGE, Wi-Fi.
15. What is Modem and Hub?  Terminology and Definitions:
 Free Software:
 2 Marks Question:
 Free software means the software is freely accessible and can be freely used, changed,
1. Explain half duplex communication mode. [March 2015] improved, copied and distributed by all who wish to do so.
2. Mention any two antivirus software. [March 2016]
 No payments are needed to be made for free software.
3. Write the difference between LAN and WAN. [June 2016]
 Open Source Software:
4. What is communication (transmission) mode? Explain simplex mode. [March 2017]
 Open Source Software, on the other hand, can be freely used but it does not have to be free of
5. Write the difference between half duplex and full duplex communication modes. [June 2017]
charge.

 5 Marks Question:  Open Source doesn’t just access to the source code. The distribution terms of Open Source

1. Explain any five network devices. [March 2015] Software must comply with the following criteria.

2. Give the measures for prevention virus. [June 2015, June 2017] 1. Free Redistribution

3. Explain the network security in detail. [March 2016, June 2016] 2. Source Code

4. What is networking? Explain the goals of networking. [June 2017] 3. Derived works
4. No Discrimination Against persons or groups
**************** 5. No Discrimination Against Fields or Groups
6. Distribution of License
7. License Must Not be Specific to a Product
8. The license must Not Restrict other Software
9. License Must Be technology Natural

27 | P a g e Keerthi Kumar H M 1|Page Keerthi Kumar H.M


Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan

 OSS:  Freeware:
 OSS refers to open source software, which refers to software whose source code is available to  The term freeware has no clear definition, but is generally used for software, which is available
customers and it can be modified and redistributed without any limitation. free of cost and which allows copying and further distribution, but not modification and whose
 FLOSS: source code is not available.
 FLOSS refers to Free Libre and open Source Software or to Free Livre and Open Source  Freeware is distributed in Binary Form (ready to run) without any licensing fees.
Software.  Shareware:
 The term FLOSS is used to refer to software which is both free software as well as open source  Shareware is software, offered as trial version (for limited period of time) with certain features
software. only available after the license is purchased.
 Here the words Libre (a Spanish word) and Livre (a Portuguese’s word) mean freedom.  Its source code is not available and modifications to the software are not allowed.
 GNU:  WWW (World Wide Web).
 GNU is a Unix-like computer operating system developed by the GNU project.  The World Wide Web (WWW) is a set of protocols that allows you to access any documents
 It is composed wholly of free software. on the Net through a naming system based on URLs.
 It refers to GNU’s Not Unix .GNU Project emphasizes on freedom and thus its logo type show  WWW also specifies a way -- the Hypertext Transfer Protocol (HTTP) - to request and send a
a GNU, an animal living in freedom document over the internet.
 FSF:  Attributes of WWW
 FSF is Free Software Foundation. FSF is a non-profit organization created for the purpose of o User friendly - www resources can be easily used with the help of browser.
supporting free software movement. o Multimedia documents - A web page may have graphic, audio, video, and animation
 Richard Stallman founded FSF in 1985 to support GNU project and GNU licenses. etc at a time.
 OSI: o Hypertext and hyperlinks - The dynamic links which can move towards another web
 OSI is Open Source Initiative. It is an organization dedicated to cause of promoting open page is hyperlink.
source software. o Interactive - www with its pages support and enable interactivity between users and

 Bruce Perens and Erics Raymond were the founders of OSI that was founded in February servers.

1998. o Frame - display of more than one section on single web page.

 W3C:  Advantages of WWW:


 W3C is acronym for World Wide Web Consortium. o Availability of mainly free information.

 W3C is responsible for producing the software standards for World Wide Web. o Low cost of initial connection.

 The W3C was created by Tim Berners-Lee in 1994. o It is accessible from anywhere.

 Proprietary Software: o Facilities rapid interactive communication.


o Facilities the exchange of huge information.
 Proprietary software or closed source software is the software that is neither open nor freely
o Facilitates the establishment of professional contact.
available.
o Facilitates access to different sources of information.
 Its use is regulated and further distribution and modifications is either forbidden or requires
special permission by the supplier or vendor.  Disadvantages of WWW:
o Danger of overload and excess information
 Source of proprietary software is normally not available.
o It requires an efficient information search strategy

2|Page Keerthi Kumar H.M 3|Page Keerthi Kumar H.M


Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan

o The search can be slow  HTTP uses Internet addresses in a special format called a URL.
o It is difficult to filter and prioritize information  A URL (Uniform Resources Locator) specifies the distinct address for each resource on the
o No guarantee of finding what one is looking for internet
o Net becomes overloaded because of large number of users  URLs look like this: type://address/path
o No quality control over available data  In URL,
 Telnet (Remote Login): o type specifies the type of server in which the file is located,
 Telnet (Teletype network) is an order Internet utility that lets you log on to remote computer o address is the address of the server,
systems. o path is the location within the file structure of the server, the path includes the list of
 Telnet program gives you a character-based terminal window on another system. folders( or directories) where the desired file is located.
 You get a login prompt on that system. If you’ve permitted access, you can work on that  Consider the URL
system, just as you would if you were sitting next to it. http://www.yahoo.com or http://www.facebook.com
 Web Browser:  Domain name:
 A Web Browser is software application that enables the user to view web pages, navigate web  An internet address which is a character based is called a Domain name.
sites and move from one website to another.  A domain name is away to identify and locate computer and resources connected to the
 Some of the web browsers are Google Chrome, Internet Explorer, Netscape Navigator, Mozilla internet.
Firefox, and Opera.  This type of domain name is also called hostname.
 Web Server:  Some most common domains are:
 An internet host computer that many store thousand of websites.
Domain ID Meaning Domain Cou Meaning
 A Web Server is a WWW server that responds made by web browsers.
.com Commercial .au Australia
 Example: Apache, IIS, PWS (Personal web server for Windows 98).
.gov Government .in India
 Web sites:
.mil Military .nz New Zealand
 A Web site is collection of web pages, images, videos and other digital assets and hosted on a
.ac Academic .ca Canada
particular domain on the WWW.
.org Organization .jp Japan
 Each web site has a unique address called URL.
.edu Education .uk United Kingdom
 Web page:
 A document that can be viewed in a web browser and residing on a website is a web page.
 E-Commerce:
 The web pages use HTTP.
o Home page - A web page that is the starting page and acts as an indexed page is home  E-Commerce is the trade of goods and services with the help of telecommunications and

page. computers.

o Web portal - That facilitates various type of the functionality as website.  E-Commerce involves the automation of a variety of business to consumer transaction through

o For example: www.pue.kar.nic.in , www.karnataka.gov.in. reliable and secure connections.

 URL and Domain :  E-Commerce Process:


 The internet structure of the www is built on a set of rules called Hypertext Transfer Protocol  A consumer uses a Web browser to connect to the home page of a merchant's Web site on the
(HTTP) and a page description language called Hypertext Markup Language (HTML). Internet.
4|Page Keerthi Kumar H.M 5|Page Keerthi Kumar H.M
Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan

 Consumer-to-Business (C2B):
 Customer directly contact with business vendors by posting their project work with set budget
online so that needy companies review it and contact the customer directly with bid.
 Example: guru.com, freelancer.com
 Consumer-to-Consumer (C2C)
 E-commerce is simply commerce between private individuals or consumers.
 Example: Ram buying smartphone from Sham using OLX

 Advantages of e-commerce
 Buying & selling can be done online at any time (24 hours) money.
 It provides faster payments through Electronic Fund Transfer.
 Online payment reduces work of carrying money to the shop and also saves money.

 The consumer browses the catalog of products featured on the site and selects items to  Customer can search for competitive prices quickly before purchasing the items.

purchase. The selected items are placed in the electronic equivalent of a shopping cart.  Wider choice for item selection.

 When the consumer is ready to complete the purchase of selected items, it provides a bill to  Without going to the shops customers can view the products through websites thus saves time.

and ship to address for purchase and delivery  Disadvantages of e-commerce


 When the credit card number is validated and the order is completed at the Commerce Server  Initial cost is high.
site, the merchant's site displays a receipt confirming the customer's purchase.  E-Commerce websites needs to be protected from virus attacks, hackers.

 The Commerce Server site then forwards the order to a Processing Network for payment  Needs more security.

processing and fulfillment.  Some company may charge more for shipping or other transport.
 There is the possibility of credit card number theft.
 Different types of E-Commerce  Mechanical failures can cause unpredictable effects on the total processes.
 Business-to-Business (B2B)
 Business-to-Consumer (B2C)  IPR Issues:
 Consumer-to-Business (C2B)  IPR stands for Intellectual Property Rights.

 Consumer-to-Consumer (C2C)  Intellectual Property Rights (IPR) means copyrights, patents, and trademarks, designs etc held

 Business-to-Business (B2B) by a person or company who have invented or designed a product.


 Copyright, trademarks, industrial designs, patents, integrated circuits are the different forms of
 Business-to-Business (B2B):
Intellectual property.
 The exchange of services, information and/or products from one business to another business
 The main benefits of IPR are wealth creation, legitimate ownership, talent attraction, image of
partners.
a trustworthy organization.
 Examples: Intel selling microprocessor to Dell
 WIPO – World Intellectual Property Organization.
 Business-to-Consumer (B2C):
 IPR-related issues in India like patents, trademarks, copyrights, designs are governed by the
 The exchange of services, information and/or product from business to a consumer.
Patents Act 1970 and patents Rules 2003, Trademarks Act 1999, Trademarks Rules 2002,
 Example: Dell selling me a laptop. Websites: Flipkart, Amazon, Snapdeal.
Copyright Act 1957, Design Act 2000 and Rules 2001.

6|Page Keerthi Kumar H.M 7|Page Keerthi Kumar H.M


Chapter 16- Internet and Open Source Concepts II PUC, MDRPUC, Hassan

CHAPTER 16 – INTERNET AND OPEN SOURCE CONCEPTS BLUE PRINT


VSA (1 marks) SA (2 marks) LA (3 Marks) Essay (5 Marks) Total
01 Question - 01 Question - 02 Question
Question no 9 - Question no 25 - 04 Marks

Important Questions
 1 Marks Question:
1. What is Open source software?
2. What are Freeware? [March 2015]
3. Define E-Commerce. [March 2016]
4. What is telnet? [June 2016]
5. Expand OSS and FLOSS.

 3 Marks Question:
1. Explain Free software.
2. What is meant by shareware? Write its limitations [March 2016]
3. What is Web browser? Mention any two web browser. [March 2015, June 2015]
4. Give the advantages of WWW.
5. Define the terms webpage, website, web server. [June 2016]
6. Explain URLs.
7. What is E-Commerce? Explain types of E-commerce. [June 2015, March 2017]
8. What are the advantages and disadvantages of E-commerce?
9. Explain IPR.

****************

8|Page Keerthi Kumar H.M

You might also like