Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 56

Vi Institute of Technology

96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108


Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

COURSE FILE – THEORY – TITLE PAGE

COURSE FILE - THEORY

DEPARTMENT : COMPUTER SCIENCE AND ENGINEERING

ACADEMIC YEAR : 2010 - 2011

SEMESTER : SECOND SEMESTER

SECTION : ECE

SUBJECT CODE : EC2202

SUBJECT TITLE : DATA STRUCTURES AND OOP IN C++

NAME OF THE STAFF : SATHIYAPRIYA.K

DESIGNATION : ASST.PROF

1|Page
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

COURSE FILE – INDEX - THEORY

S. No CONTENTS Page No
1 Title Page 3
2 Syllabus 4
3 Lesson Plan & Coverage 5-11
4 Students Nominal Roll 12
5 Subject Handlers of Yester Years 13
6 Assignment Plan 14
7 Self Study Topics 15
8 Internal I - Question Paper & Key 16-27
9 Internal I - Marks Statement 28
10 Internal I - Result Analysis & Corrective Action 29
11 Internal II - Question Paper & Key 30-40
12 Internal II - Marks Statement 41
13 Internal II - Result Analysis & Corrective Action 42
14 Model Exam - Question Paper & Key 43-52
15 Model Exam - Mark Statement 53
16 Model Exam – Result Analysis & Corrective Action 54
17 Final University Internal Mark Statement 55
18 University Question Paper
19 University Exam - Mark Statement
20 University Exam – Result Analysis
21 Notes of Lesson Unit I to V
Sample of 3 Answer Booklets & Assignment Papers –
22 i) Best ii) Medium iii) Poor Assignment

2|Page
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

EC 2202 DATA STRUCTURES


AND OBJECT ORIENTED
PROGRAMMING IN
C++

3|Page
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
SYLLABUS
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
EC 2202 DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++

UNIT – I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 9


Introduction- Tokens-Expressions-contour Structures –Functions in C++, classes and
objects, constructors and destructors ,operators overloading and type conversions .

UNIT – II ADVANCED OBJECT ORIENTED PROGRAMMING 9


Inheritance, Extending classes, Pointers, Virtual functions and polymorphism, File
Handling Templates ,Exception handling, Manipulating strings.

UNIT – III DATA STRUCTURES & ALGORITHMS 9


Algorithm, Analysis, Lists, Stacks and queues, Priority queues-Binary Heap-Application,
Heaps–hashing-hash tables without linked lists

UNIT – IV NONLINEAR DATA STRUCTURES 9


Trees-Binary trees, search tree ADT, AVL trees, Graph Algorithms-Topological sort,
shortest path algorithm network flow problems-minimum spanning tree - Introduction to
NP - completeness.

UNIT – V SORTING AND SEARCHING 9


Sorting – Insertion sort, Shell sort, Heap sort, Merge sort, Quick sort, Indirect sorting,
Bucket sort, Introduction to Algorithm Design Techniques –Greedy algorithm (Minimum
Spanning Tree), Divide and Conquer (Merge Sort), Dynamic Programming (All pairs
Shortest Path Problem).
Total hours = 45
TEXT BOOKS:
1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in C”, 3rd ed, Pearson
Education Asia, 2007.
2. E. Balagurusamy, “ Object Oriented Programming with C++”, McGraw Hill Company
Ltd., 2007.
REFERENCES:
1. Michael T. Goodrich, “Data Structures and Algorithm Analysis in C++”, Wiley student
edition, 2007.
2. Sahni, “Data Structures Using C++”, The McGraw-Hill, 2006.
3. Seymour, “Data Structures”, The McGraw-Hill, 2007.
4. Jean – Paul Tremblay & Paul G.Sorenson, An Introduction to data structures with
applications, Tata McGraw Hill edition, II Edition, 2002.
5. John R.Hubbard, Schaum’s outline of theory and problem of data structure with C++,
McGraw-Hill, New Delhi, 2000.
6. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley, 2000

4|Page
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696,
Vi INSTITUTE FAX: 91-44– 2740 1696
OF TECHOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

LESSON PLAN

Academic Year : NOV-DEC 2010

Branch : ECE

Semester : III

Subject Name : DATA STRUCTURE & OOPS IN C++

Subject Code : EC2202

Name of the Faculty : SATHIYAPRIYA.K

Designation & Dept : ASST.PROF & CSE

Subject Time Table:

Class Type Total no. of


Sl. No Day Period No
(L/T) Periods in
a week
1.
MONDAY 7 T
2.
TUESDAY 1 T
3.
WEDNESDAY 2 T
4. 4+3=7
THRUSDAY - -
5. 3,4 T
FRIDAY
5,6,7 L

6. SATURDAY - -

UNIT – I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 9

5|Page
SYLLABUS:
Introduction- Tokens-Expressions-contour Structures –
Functions in C++, classes and objects, constructors and
destructors, operator overloading and type conversions.
Objective: To learn to program in C++ and basic OOPS concepts.

Session Topics to be covered Time Ref Teaching


No.
Method
1. Basic introduction to c++- header files, 50m 2,8,9 BB
input, output statements, formatted
output

2. Tokens, native data types and derived types 50m 2,8,9 BB

3. Types of expressions and operators 50m 2,8,9 BB


involved, types of statements

4. Functions- inbuilt and user defined, oops – 50m 2,8,9 BB


basics, difference in POP and OOPS

5. Class and objects-simple examples, inline 50m 2,8,9 BB


functions

6. Constructors, types -default, parameterized, 50m 2,8,9 BB


copy constructors, destructors
7. Operator overloading-overloading of 50m 2,8,9
arithmetic operators, comparison
operators BB

8. Operator overloading-overloading of equality 50m 2,8,9


operators, assignment operators
BB

9. Overloading of shift operators, type 50m 2,8,9 BB


conversions-automatic, explicit,templates-
basics

10. TEST-I 60 m - -

Total Number of Periods Allotted No of


L11 + T3 =
L9 +T3 = 12 Total L9 +T3 = 12
to Cover the Unit - I Periods Periods 14
Planne
d

UNIT – II ADVANCED OBJECT ORIENTED PROGRAMMING 9

SYLLABUS:

6|Page
Inheritance, Extending classes, Pointers, Virtual functions and
polymorphism, File Handling Templates ,Exception handling,
Manipulating strings.

Objective: To learn advanced features of OOPS.

Session Topics to be covered Time Ref Teaching


No. Meth
od
11. Inheritance – types 50m 2,8,9 BB

12. Nested classes 50m 2,8,9 BB

13. pointers 50m 2,8,9 BB

14. Friend functions, Abstract classes 50m 2,8,9 BB

15. Virtual functions, virtual base class, pointer 50m 2,8,9 BB


to objects

16. Polymorphism – function overloading 50m 2,8,9 BB

17. File Handling , templates 50m 2,8,9 BB

18. Exceptions, unspecified exceptions, 50m 2,8,9 BB


rethrowing exceptions

19. String manipulations 50m 2,8,9 BB

20. TEST-II 60m - -

Total Number of Periods Allotted No of


L11 + T3 =
L9 +T3 = 12 Total L9 +T3 = 12
to Cover the Unit - II Periods Periods 14
Planne
d

UNIT – III DATA STRUCTURES & ALGORITHMS 9

SYLLABUS:

7|Page
Algorithm, Analysis, Lists, Stacks and queues, Priority queues-Binary Heap-
Application, Heaps–hashing-hash tables without linked lists
Objective: To learn how various data structures can be implemented and also
to analyze the efficiency of algorithms.

Session Topics to be covered Time Ref Teaching


No.
Method
21. Framing algorithms, Asymptotic notations, 50m 1,3,4,6,7 BB
Analysis of algorithms-run time efficiency

22. List ,linked list 50m 1,3,4,6,7 BB

23. Linked list – DLL ,CLL 50m 1,3,4,6,7 BB

24. Stacks – array and pointer implementation 50m 1,3,4,6,7 BB

25. Queues – array and pointer implementation 50m 1,3,4,6,7 BB

26. Priority Queues- operations 50m 1,3,4,6,7 BB

27. Heaps- operations 50m 1,3,4,6,7 BB

28. Hashing ,types of hashing 50m 1,3,4,6,7 BB

29. Types of hashing, hash table without 50m 1,3,4,6,7 BB


linked list

30. TEST-III 60m - -

Total Number of Periods Allotted No of


L12 + T3 =
Perio L9 +T3 = 12 Period Total L9 +T3 = 12
to Cover the Unit - III 15
ds s
Planne

UNIT – IV NONLINEAR DATA STRUCTURES 9

SYLLABUS:

8|Page
Trees-Binary trees, search tree ADT, AVL trees, Graph
Algorithms-Topological sort, shortest path algorithm
network flow problems-minimum spanning tree -
Introduction to NP - completeness.

Objective: To implement various types of trees and also to learn about graphs and
their applications.

Session Topics to be covered Time Ref Teaching


No.
Method
30. Trees – array and pointer representation, 50m 1,3,4,6,7 BB
binary trees, types of traversals

31. BST-operations. 50m 1,3,4,6,7 BB

32. AVL trees-types of rotations 50m 1,3,4,6,7 BB

33. Graphs –terminologies and representations 50m 1,3,4,6,7 BB

34. Topological sort 50m 1,3,4,6,7 BB

35. DFS,BFS 50m 1,3,4,6,7 BB

36. Shortest path algorithm-dijkstra’s 50m 1,3,4,6,7 BB


algorithm,
37. Minimum spanning tree – prim’s algorithm 50m 1,3,4,6,7 BB
and kruskal’s algorithm

38. Network flow problems, NP complete 50m 1,3,4,6,7 BB


problems

39. TESTIV 60m - -

Total Number of Periods Allotted No of


L11 + T3 =
L9 +T3 = 12 Total L9 +T3 = 12
to Cover the Unit - IV Periods Periods 14
Planne
d

UNIT – V SORTING AND SEARCHING 9

SYLLABUS:
9|Page
Sorting – Insertion sort, Shell sort, Heap sort, Merge sort, Quick sort,
Indirect sorting, Bucket sort, Introduction to Algorithm Design
Techniques –Greedy algorithm (Minimum Spanning Tree), Divide
and Conquer (Merge Sort), Dynamic Programming (All pairs
Shortest Path Problem).

Objective: To implement various types of sorting algorithms and to learn about


techniques to design various algorithms

Session Topics to be covered Time Ref Teaching


No. Method
40. Sorting methods – insertion sort , shell 50m 1,3,4,6,7 BB
sort

41. Heap sort - problems 50m 1,3,4,6,7 BB

42. Merge sort - problems 50m 1,3,4,6,7 BB

43. Quick sort - problems 50m 1,3,4,6,7 BB

44. Indirect sort, bucket sort 50m 1,3,4,6,7 BB

45. Bucket sort- problems, 50m 1,3,4,6,7 BB

external sorting methods

46. Greedy algorithm -examples 50m 3,6,7 BB

47. Divide and Conquer -examples 50m 3,6,7 BB

48. Dynamic Programming -examples 50m 3,6,7 BB

49. TEST-V 60m - -

Total Number of Periods Allotted No of


L11 + T3 =
Perio L9 +T3 = 12 Period Total L9 +T3 = 12
to Cover the Unit - V 14
ds s
Planne

TEXT BOOK

1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in C”, 3 rd

ed, Pearson Education Asia, 2007.

10 | P a g e
Vi Institute of Technology
2. E. Balagurusamy, “ Object Oriented Programming with C++”, McGraw

96,Ltd.,
Hill Company Sirunkundram
2007.   Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

REFERENCES

3. Michael T. Goodrich, “Data Structures and Algorithm Analysis in C++”,

Wiley student edition, 2007.

4. Sahni, “Data Structures Using C++”, The McGraw-Hill, 2006.

5. Seymour, “Data Structures”, The McGraw-Hill, 2007.

6. Jean – Paul Tremblay & Paul G.Sorenson, An Introduction to data

structures with applications, Tata McGraw Hill edition, II Edition, 2002.

7. John R.Hubbard, Schaum’s outline of theory and problem of data

structure with C++, McGraw-Hill, New Delhi, 2000.

8. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley,

2000

9. Robert Lafore, Object oriented programming in C++, Galgotia

Publication

Lecture Tutorial Total


Subject Coverage Details Remarks
Periods Periods Periods

Number of Periods Allotted by 45 15 60


University
No of Periods Planned by Faculty 56 15 71
Number of Periods Conducted by
Faculty
Deviations ( If Any)

Signature of the Faculty Head of the Department

11 | P a g e
STUDENTS NOMINAL ROLL
Vi Institute of Technology
96, Sirunkundram
Year & Branch with Section: II &ECE Village, Chengalpattu
Semester: III Tk,Academic
PincodeYear:
- 6032010-2011
108
S. No Reg. No Ph:Name
+91-44-2740 1695 / 1696,S.FAX:
of the Student No 91-44– 2740 1696
Reg. No Name of the Student
1 47609106001 CHITRAKUMAR.D 31 LE1 JOHNSIRANI.S

2 47609106002 DHINESHKUMAR.M 32
3 47609106003 DHINESH.V 33
4 47609106004 DIVYA.V 34
5 47609106005 JENNIFER JANE.J 35
6 47609106006 KARTHIK..M 36
7 47609106007 MANOHARAN.E 37
8 47609106008 NALANKILLI.E 38
9 47609106009 PARTHIBAN.P 39
10 47609106010 RAJA.G 40
11 47609106011 RAMANUJAM.P 41
12 47609106012 RAVIKUMAR.E 42
13 47609106014 SARASCHANDRA.M 43
14 47609106015 SATHISHKUMAR.C 44
15 47609106016 SELVAM.S 45
16 47609106017 SIVAPRALASH.A 46
17 47609106018 SRIRAM.T 47
18 47609106019 VEERASWAMY.P.M 48
19 47609106020 KAMESHKANNAN.S 49
20 LE1 VINAYAGAM 50
LE1 KUMARESAN
21 51
LE1 AUGESTINE
22 52
LE1 SATHISHKUMAR.R
23 53
LE1 SARAVANAN
24 54
LE1 ALLABAKSH
25 55
LE1 SATHISHKUMAR.T
26 56
LE1 JANAKIRAMAN
27 57
LE1 DILEEP SESARAJ
28 58
LE1 RAJARAJESWARAN
29 59
LE1 AMANULLA
30 60

SUBJECT HANDLERS OF PREVIOUS YEARS


12 | P a g e
Vi Institute of Technology
nd
Academic Year &
96,Branch: 2010 Village,
Sirunkundram – 2011 /Chengalpattu
ECE Tk,Semester
Pincode&- Section:
603 108 3 SEM / ECE

Subject Name: Data Ph: +91-44-2740


Structures & OOP1695 / 1696, FAX: 91-44–Subject
IN C++ 2740 1696
Code : EC2202

Name of the Faculty: SATHIYAPRIYA.K Designation & Dept: AP / CSE

Sl. Academic Semester % of Result


Name of the Faculty Designation Department
No. Year No. Produced
1

Faculty In charge. Head Of the Department

13 | P a g e
ASSIGNMENT PLAN

Academic Year & Branch: 2010 – 2011 / ECE Semester & Section: 3nd Sem / ECE

Subject Name: Data Structures & OOP IN C++ Subject Code : EC2202

Name of the Faculty: SATHIYAPRIYA.K.A Designation & Dept: AP / CSE

Date of
Unit Roll Nos. / Books / Journal to be Announce Date of
No Assignment Topics Batch Referred ment Submission
E. Balagurusamy, “
Object Oriented
Programming with
1. Functions in C++ All C++” 8/7/2010 13/7/2010
E. Balagurusamy, “
Object Oriented
Virtual functions and Programming with
2 polymorphism All C++” 1/10/2010 6/10/2010
Mark Allen Weiss,
“Data Structures and
28/7/2010 2/8/2010
Algorithm Analysis
3 Binary Heap All in C”

6/9/2010 11/9/2010
4 Graph Algorithms All Browse and find
Data structures and
algorithms by Mark
5 Greedy algorithm All Allien Weiss 21/9/2010 27/9/2010

Faculty In charge. Head Of the Department

14 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

SELF STUDY TOPICS

Academic Year & Branch: 2010 – 2011 / ECE Semester & Section: 3nd Sem / ECE

Subject Name: Data Structures & OOP IN C++ Subject Code : EC2202

Name of the Faculty: SATHIYAPRIYA.K.A Designation & Dept: AP / CSE

Unit
No Self Study Topics Roll Nos. / Batch Books / Journal to be Referred
E. Balagurusamy, “
Object Oriented
1. Control Structures All Programming with C++”
Mark Allen Weiss, “Data
Structures and Algorithm
2. Trees All Analysis in C”
Mark Allen Weiss, “Data
Structures and Algorithm
3. Dynamic Programming All Analysis in C”

Faculty In-Charge Head Of the Department

15 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

CYCLE TEST I -QUESTION PAPER

YEAR/SEM : II Year/ III SEM


EC2202-Data Structures & OOPS in C++
Date: Session: FN

PART A (5*2=10)

1. What is mean by Algorithm?


2. What is mean by enqueue and dequeue?
3. What is a heap and mention its types?
4. What is the use of sentinel value in binary heap?
5. Define Priority queue

PART B (8*1=8)
6. Give array representation and implementation of Circular queue
(Or)
Give array representation and implementation of Stack

Part C (16*2=32)

7. Explain with suitable examples of basic heap operations and write algorithms
(Or)
How would you implement a stack of queues? Write routines for creation and
inserting of elements into it.

8. Explain how a stack can be used to convert an infix expression to a postfix


expression?
(Or)
Explain Binary Heap Sort with suitable example

16 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696

CYCLE TEST I –ANSWER KEY


YEAR/SEM : II Year/ III SEM
EC2202-Data Structures & OOPS in C++
PART A (5*2=10)

1. Define Algorithm :-
Definition: A set of instructions for solving a problem

2. Enqueue and Dequeue


Queue is a linear data structure in which all insertions can take place at one end
called the rear and all deletions take place at the other end called the front. The
two operations that are possible in a queue are Insertion and Deletion.
Enqueue:Inserting an element in the queue
Dequeue: Deleting an element in the queue

3. Heap and its types


A heap is a specialized tree-based data structure that satisfies the heap property

Binary heap Binomial heap D-ary heap Fibonacci heap Leftist heap

4. Sentinel value in binary heap :-


A sentinel value is an extra entry put into a data structure so that boundary
conditions need not be treated as special case

5. Priority queue
An abstract data type to efficiently support finding the item with the highest
priority across a series of operations.
PART B (8*1=8)
17 | P a g e
6. Implementation of Circular queue :-
#include <stdio.h>
#include<ctype.h>
# define MAXSIZE 200
int cq[MAXSIZE];
int front,rear;
void main()
{
void add(int,int [],int,int,int);
int del(int [],int ,int ,int );
int will=1,i,num;
front = 1;
rear = 1;
clrscr();
printf("Program for Circular Queue demonstration through array");
while(will ==1)
{
printf("MAIN MENU: 1.Add element to Circular Queue
2.Delete element from the Circular Queue");
scanf("%d",&will);
switch(will)
{
case 1:
printf("Enter the data... ");
scanf("%d",&num);
add(num,cq,MAXSIZE,front,rear);
break;

case 2: i=del(cq,MAXSIZE,front,rear);
printf("Value returned from delete function is %d ",i);
break;
default:
printf("Invalid Choice . ");
}

18 | P a g e
printf(" Do you want to do more operations on Circular Queue ( 1 for
yes, any other key to exit) ");
scanf("%d" , &will);
} //end of outer while
} //end of main
void add(int item,int q[],int MAX,int front,int rear)
{
rear++;
rear= (rear%MAX);
if(front ==rear)
{
printf("CIRCULAR QUEUE FULL");
return;
}
else
{
cq[rear]=item;
printf("
Rear = %d Front = %d ",rear,front);
}}
int del(int q[],int MAX,int front,int rear)
{
int a;
if(front == rear)
{
printf("CIRCULAR STACK EMPTY");
return (0);
}else
{
front++;
front = front%MAX;
a=cq[front];
return(a);
printf("Rear = %d Front = %d ",rear,front);
}
(or)
19 | P a g e
Implementation of Stack

#include<stdio.h>
#include<conio.h>
#define MAX 5
Int top = -1;
int stack_arr[MAX];
main()
{
int choice;
while(1)
{
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 :
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice\n");
}}/*End of while*/
}/*End of main()*/
push()
20 | P a g e
{
int pushed_item;
if(top == (MAX-1))
printf("Stack Overflow\n");
else
{
printf("Enter the item to be pushed in stack : ");
scanf("%d",&pushed_item);
top=top+1;
stack_arr[top] = pushed_item;
}
}/*End of push()*/

pop()
{
if(top == -1)
printf("Stack Underflow\n");
else
{
printf("Popped element is : %d\n",stack_arr[top]);
top=top-1;
}
}/*End of pop()*/

display()
{
int i;
if(top == -1)
printf("Stack is empty\n");
else
{
printf("Stack elements :\n");
for(i = top; i >=0; i--)
printf("%d\n", stack_arr[i] );
}
}/*End of display()*/
21 | P a g e
Part C (16*2=32)
7. Basic heap operations and algorithms:-

Four basic procedures on heap are


1. Heapify, which runs in O(lg n) time.
2. Build-Heap, which runs in linear time.
3. Heap Sort, which runs in O(n lg n) time.
4. Extract-Max, which runs in O(lg n) time

Heap sort Algorithm:


                        void heapsort ( int x[], int n )
                        {
                           int i, elt, s, f, ivalue;
                        for ( i =1; i < n; i++)    {
                        elt = x[i];
                        /* pqinsert (x, I, elt ) */
                        s = i ;
                        f = (s-1) / 2;
                        while ( s > 0 && x[f] < elt )  {
                        x[s] = x[f];
                        s = f ;
                        f = (s-1) / 2;
                        } 
                        x[s] = elt;
                        }

            /* selection phase; repeatedly remove x[0] , insert it in its proper position*/
            /* and adjust the heap */

            for (i = n-1; i > 0; i--)     {


            /* pqmaxdelete (x, i+1) */
            ivalue = x[i];
            x[i] = x[0];
            f = 0;
            /* s = largeson (0, i-1) */
            if (i = = 1)
            s = -1;
            else
            s = 1;
            if ( i >2 && x[2] > x[1] )
            s = 2;
            while ( s >= 0 && ivalue < x[s] )    }
22 | P a g e
(Or)Implement a stack of queues:-

# include<stdio.h>
# include<conio.h>
# define MAX 5

int queue_arr[MAX];
int rear = -1;
int front = -1;

main()
{
int choice;
while(1)
{
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1 :
insert();
break;
case 2 :
del();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
23 | P a g e
printf("Wrong choice\n");
}/*End of switch*/
}/*End of while*/
}/*End of main()*/

insert()
{
int added_item;
if (rear==MAX-1)
printf("Queue Overflow\n");
else
{
if (front==-1) /*If queue is initially empty */
front=0;
printf("Input the element for adding in queue : ");
scanf("%d", &added_item);
rear=rear+1;
queue_arr[rear] = added_item ;
}
}/*End of insert()*/

del()
{
if (front == -1 || front > rear)
{
printf("Queue Underflow\n");
return ;
}
else
{
printf("Element deleted from queue is : %d\n", queue_arr[front]);
front=front+1;
}
}/*End of del() */

display()
24 | P a g e
{
int i;
if (front == -1)
printf("Queue is empty\n");
else
{
printf("Queue is :\n");
for(i=front;i<= rear;i++)
printf("%d ",queue_arr[i]);

printf("\n");}

8. Stack convert an infix expression to a postfix :-


Infix Expression :
Any expression in the standard form like "2*3-4/5" is an Infix(Inorder) expression.
Postfix Expression :
The Postfix(Postorder) form of the above expression is "23*45/-".
Infix to Postfix Conversion :

In normal algebra we use the infix notation like a+b*c. The corresponding postfix notation is
abc*+. The algorithm for the conversion is as follows :

 Scan the Infix string from left to right.


 Initialise an empty stack.
 If the scannned character is an operand, add it to the Postfix string. If the scanned
character is an operator and if the stack is empty Push the character to stack.
 If the scanned character is an Operand and the stack is not empty, compare the
precedence of the character with the element on top of the stack (topStack). If
topStack has higher precedence over the scanned character Pop the stack else
Push the scanned character to stack. Repeat this step as long as stack is not
empty and topStack has precedence over the character.

Repeat this step till all the characters are scanned.

 (After all characters are scanned, we have to add any character that the stack may have
to the Postfix string.) If stack is not empty add topStack to Postfix string and Pop
the stack. Repeat this step as long as stack is not empty.
 Return the Postfix string.

Example :
Let us see how the above algorithm will be imlemented using an example.
Infix String : a+b*c-d
Initially the Stack is empty and our Postfix string has no characters. Now, the first character
scanned is 'a'. 'a' is added to the Postfix string. The next character scanned is '+'. It being an
operator, it is pushed to the stack.

25 | P a g e
Postfix String

Stack

Next character scanned is 'b' which will be placed in the Postfix string. Next character is '*'
which is an operator. Now, the top element of the stack is '+' which has lower precedence
than '*', so '*' will be pushed to the stack.

Postfix String

Stack

The next character is 'c' which is placed in the Postfix string. Next character scanned is '-'. The
topmost character in the stack is '*' which has a higher precedence than '-'. Thus '*' will be
popped out from the stack and added to the Postfix string. Even now the stack is not empty.
Now the topmost element of the stack is '+' which has equal priority to '-'. So pop the '+' from
the stack and add it to the Postfix string. The '-' will be pushed to the stack.

Postfix String

Stack

Next character is 'd' which is added to Postfix string. Now all characters have been scanned so we
must pop the remaining elements from the stack and add it to the Postfix string. At this stage
we have only a '-' in the stack. It is popped out and added to the Postfix string. So, after all
characters are scanned, this is how the stack and Postfix string will be :

Postfix String

Stack

End result :

 Infix String : a+b*c-d


 Postfix String : abc*+d-

(OR) Binary Heap Sort with suitable example:-


26 | P a g e
Vi Institute of Technology
A binary heap is a heap data structure created using a binary tree. It can be seen as a
96, Sirunkundram
binary tree with two Village, Chengalpattu Tk, Pincode - 603 108
additional constraints:
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
 The shape property: the tree is a complete binary tree; that is, all levels of the
tree, except possibly the last one (deepest) are fully filled, and, if the last level of
the tree is not complete, the nodes of that level are filled from left to right.
 The heap property: each node is greater than or equal to each of its children
according to some comparison predicate which is fixed for the entire data
structure.

27 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
INTERNAL1695
Ph: +91-44-2740 MARK I STATEMETNT
/ 1696, FAX: 91-44– 2740 1696
Class - Section: II -ECE Semester: III Subject: Data Structures & OOP IN C++
S.
No Reg. No Name of the Student IT 1
1 47609106001 CHITRAKUMAR.D 30
2 47609106002 DHINESHKUMAR.M 02
3 47609106003 DHINESH.V 50
4 47609106004 DIVYA.V 80
5 47609106005 JENNIFER JANE.J 80
6 47609106006 KARTHIK..M 55
7 47609106007 MANOHARAN.E 36
8 47609106008 NALANKILLI.E 10
9 47609106009 PARTHIBAN.P 14
10 47609106010 RAJA.G 16
11 47609106011 RAMANUJAM.P 19
12 47609106012 RAVIKUMAR.E 50
13 47609106014 SARASCHANDRA.M 66
14 47609106015 SATHISHKUMAR.C 50
15 47609106016 SELVAM.S 11
16 47609106017 SIVAPRALASH.A 06
17 47609106018 SRIRAM.T 50
18 47609106019 VEERASWAMY.P.M 15
19 47609106020 KAMESHKANNAN.S 70
20 LE1 VINAYAGAM -
21 LE1 KUMARESAN -
22 LE1 AUGESTINE -
23 LE1 SATHISHKUMAR.R -
24 LE1 SARAVANAN -
25 LE1 ALLABAKSH -
26 LE1 SATHISHKUMAR.T -
27 LE1 JANAKIRAMAN -
28 LE1 DILEEP SESARAJ -
29 LE1 RAJARAJESWARAN -
30 LE1 AMANULLA -
31 LE1 JOHNSIRANI.S -

Faculty In charge. Head Of the Department

28 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
INTERNAL EXAM I RESULT ANALYSIS
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
Department : ECE Date of Exam :

Year : 2010 Sem. & Sec. : III & ECE

Subject Title : DATA STRUCTURES & OOPS IN C++ Subject Code : EC2202

Faculty Name : SATHIYAPRIYA.K Designation : AP/CSE

Name of Exam: IT 1

Total Strength : Appeared: Absent :

Passed : Failed : % of Pass :

Description Below 50 50 to 59 60 to 74 75 to 89 90 and Above


No. of Students
 Minimum Mark to Pass - 50
 Corrective Actions for the Failed & Poor Students:

Roll Number and Name of Failed and Poor Students


S. No Roll No. Name of Student S. No Roll No. Name of Student

Faculty In Charge Head Of the Department

29 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
CYCLE TEST II -QUESTION PAPER
YEAR/SEM : II Year/ III SEM
EC2202-Data Structures & OOPS in C++
Date: Session: FN

PART A (5*2=10)

1. What is mean by dynamic Programming?


2. What is the storage representation of graph?
3. When does a graph become tree?
4. What is mean by sorting? Mention its types.
5. Define Divide and Conquer

PART B (8*1=8)
6. Explain Merge Sort with example
(Or)
Explain Quick Sort with example

Part C (16*2=32)

7. Explain Prim’s & Kruskal’s algorithm for computing the MST weighted undirected
graph?
(Or)
Write a C++ program for Different methods of traversing a Binary Search Tree.

8. Write insertion algorithm for AVL tree .Write Suitable rotations algorithm.
(Or)
Show the result of inserting 2,1,4,5,9,3,6,7 into a empty AVL tree

30 | P a g e
CYCLE TEST II –ANSWER KEY
YEAR/SEM : II Year/ III SEM
EC2202-Data Structures & OOPS in C++
PART A (5*2=10)

1. Dynamic Programming:-
Dynamic programming is both a mathematical optimization method and a
computer programming method. In both contexts it refers to simplifying a
complicated problem by breaking it down into simpler subproblems in a
recursive manner

2. Storage representation of graph:-


Adj Matrix
Adj List

3. Graph become tree :-

It contains an unique node which has no incoming edge but have all the outgoing
edges.This node will become the root of the tree

Remaining nodes of the graph have at the most one incoming edges

4. Sorting & its types:-


Sorting is any process of arranging items in some sequence and/or in different
sets Merge Sort , Quick Sort , Heap Sort , Bubble Sort
Insertion Sort , Shell Sort
Bucket Sort

5. Divide and Conquer


Divide and conquer (D&C) is an important algorithm design paradigm based on
multi-branched recursion. A divide and conquer algorithm works by recursively
breaking down a problem into two or more sub-problems of the same (or
related) type, until these become simple enough to be solved directly
PART B (8*1=8)
6. Merge Sort With Example:-

31 | P a g e
Merge sort is an O(n log n) comparison-based sorting algorithm. In most
implementations it is stable, meaning that it preserves the input order of equal
elements in the sorted output
Algorithm mergeSort(S, C)
Input sequence S with n
elements, comparator C
Output sequence S sorted
according to C
if S.size() > 1
(S1, S2) ← partition(S, n/2)
mergeSort(S1, C)
mergeSort(S2, C)
S ← merge(S1, S2)

Algorithm merge(A, B)
Input sequences A and B with
n/2 elements each
Output sorted sequence of A ∪ B
S ← empty sequence
while ¬A.isEmpty() ∧ ¬B.isEmpty()
if A.first().element() < B.first().element()
S.insertLast(A.remove(A.first()))
else
S.insertLast(B.remove(B.first()))
while ¬A.isEmpty()
S.insertLast(A.remove(A.first()))
while ¬B.isEmpty()
S.insertLast(B.remove(B.first()))

(Or)
Quick Sort with Example:-

32 | P a g e
Quick-Sort
􀂊 Quick-sort is a randomized sorting algorithm based on the divide-and-conquer
paradigm:
􀂄 Divide: pick a random element x (called pivot) and partition S into
􀂊 L elements less than x
􀂊 E elements equal x
􀂊 G elements greater than x
􀂄 Recur: sort L and G
􀂄 Conquer: join L, E and G
Algorithm partition(S, p)
Input sequence S, position p of pivot
Output subsequences L, E, G of the
elements of S less than, equal to,
or greater than the pivot, resp.
L, E, G ← empty sequences
x ← S.remove(p)
while ¬S.isEmpty()
y ← S.remove(S.first())
if y < x
L.insertLast(y)
else if y = x
E.insertLast(y)
else { y > x }
G.insertLast(y)
An execution of quick-sort is depicted by a binary tree
􀂄 Each node represents a recursive call of quick-sort and stores
􀂊 Unsorted sequence before the execution and its pivot
􀂊 Sorted sequence at the end of the execution
􀂄 The root is the initial call
􀂄 The leaves are calls on subsequences of size 0 or 1

Part C (16*2=32)

7. Prim’s & Kruskal’s algorithm:-


33 | P a g e
Prim's Algorithm
Prim's algorithm is known to be a good algorithm to find a minimum spanning tree.

1. Set i=0, S0= {u0=s}, L(u0)=0, and L(v)=infinity for v <> u0. If |V| = 1 then stop,
otherwise go to step 2.
2. For each v in V\Si, replace L(v) by min{L(v), dvui}. If L(v) is replaced, put a label
(L(v), ui) on v.
3. Find a vertex v which minimizes {L(v): v in V\Si}, say ui+1.
4. Let Si+1 = Si cup {ui+1}.
5. Replace i by i+1. If i=|V|-1 then stop, otherwise go to step 2.

Kruskal's Algorithm

1. Set i=1 and let E0={}


2. Select an edge ei of minimum value not in Ei-1 such that Ti=<Ei-1 cup {ei} >is
acyclic and define Ei=Ei-1 cup {ei}. If no such edge exists, Let T=<Ei>and stop.
3. Replace i by i+1. Return to Step 2.

The time required by Kruskal's algorithm is O(|E|log|V|).

(Or) Traversal of Binary Search Tree:-

34 | P a g e
#include<stdio.h>                            // including headerfiles
#include<conio.h>
#include<stdlib.h>
struct tree                                  //creating structure
{
    int data;                                //data field of node
    struct tree *lchild,*rchild;             //left child & right child of node
};
struct tree *insert(struct tree *p,int n);    //function for insertion
void inorder(struct tree *p);                 //function for inorder traversal
void preorder(struct tree *p);                // function for preorder traversal
void postorder(struct tree *p);               // function for postorder traversal

void main()                                   //main function


{
    int x,y,i;                                   
    struct tree *root;
    clrscr();
    root=NULL;
    printf("Enter the no. of nodes in the tree\n");
    scanf("%d",&x);
    while(x-->0)
  {
        printf("Enter the data part of the node\n");
        scanf("%d",&y);
        root=insert(root,y);
  }
    clrscr();
    printf("\t\tEnter the traversal u want\n");
    printf("1.Inorder.\n2.Preorder.\n3.Postorder.\n");
    scanf("%d",&i);
    switch(i)
  {
    case 1:
    {
            printf("The inorder traversal is \n");
            inorder(root);                        //function calling
    }
        break;
    case 2:
    {
            printf("The preorder traversal is\n");
            preorder(root);                           //function calling

35 | P a g e
    }
        break;
    case 3:
    {
            printf("The postorder traversal is\n");
            postorder(root);                            // function calling
    }
        break;
  }
    getch();
}
//function definition for insertion
struct tree *insert(struct tree *p,int n)               
{
    static struct tree *temp1,*temp2;
    if(p==NULL)
  {
        p=(struct tree *)malloc(sizeof(struct tree));
        p->data=n;
        p->lchild=p->rchild=NULL;
  }
    else
  {
        temp1=p;
        while(temp1!=NULL)
    {
            temp2=temp1;
            if(n<temp1->data)
                temp1=temp1->lchild;
            else
                temp1=temp1->rchild;
    }
        if(temp2->data>n)
    {
            temp2->lchild=(struct tree *)malloc(sizeof(struct tree));
            temp2=temp2->lchild;
            temp2->data=n;
            temp2->lchild=temp2->rchild=NULL;
    }
        else
    {
            temp2->rchild=(struct tree *)malloc(sizeof(struct tree));
            temp2=temp2->rchild;

36 | P a g e
            temp2->data=n;
            temp2->lchild=temp2->rchild=NULL;
    }
  }
    return p;
}
//function definition for inorder traversal

void inorder(struct tree *p)


{
    if(p!=NULL)
  {
        inorder(p->lchild);
        printf("%d ",p->data);
        inorder(p->rchild);
  }
}

//function definition for preorder traversal


void preorder(struct tree *p)
{
    if(p!=NULL)
  {
        printf("%d ",p->data);
        preorder(p->lchild);
        preorder(p->rchild);
  }
}

//function definition for postorder traversal


void postorder(struct tree *p)
{
    if(p!=NULL)
  {
        postorder(p->lchild);
        postorder(p->rchild);
        printf("%d ",p->data);
  }
}

8. AVL tree with rotations algorithm:-

37 | P a g e
An AVL tree is a self-balancing binary search tree, and it was the first such
data structure to be invented.[1] In an AVL tree, the heights of the two child
subtrees of any node differ by at most one; therefore, it is also said to be height-
balanced
1. LL: new node is in the left subtree of the left subtree of A
2. LR: new node is in the right subtree of the left subtree of A
3. RR: new node is in the right subtree of the right subtree of A
4. RL: new node is in the left subtree of the right subtree of A

38 | P a g e
InsertAVL
TreeNode *InsertAVL(TreeNode *root, TreeNode *newnode, Boolean *taller)
{
if (!root) {
root = newnode;
root->left = root->right = NULL;
root->bf = EH;
*taller = TRUE;
} else if (EQ(newnode->entry.key, root->entry.key)) {
Error("Duplicate key is not allowed in AVL tree.");
} else if (LT(newnode->entry.key, root->entry.key)) {
root->left = InsertAVL(root->left, newnode, taller);
if (*taller) /* Left subtree is taller. */
switch(root->bf) {
case LH: /* Node was left high. */
root = LeftBalance(root, taller); break;
case EH:
root->bf = LH; break; /* Node is now left high. */
case RH:
root->bf = EH; /* Node now has balanced height.*/
*taller = FALSE; break;
}
} else {
root->right = InsertAVL(root->right, newnode, taller);
if (*taller) /* Right subtree is taller. */
switch(root->bf) {
case LH:
root->bf = EH; /* Node now has balanced height.*/
*taller = FALSE; break;
case EH:
root->bf = RH; break; /* Node is right high. */
case RH: /* Node was right high. */
root = RightBalance(root, taller); break;
}}
return root;}

39 | P a g e
(Or)
2, 1,4,5,9,3,6,7 into a empty AVL tree

40 | P a g e
ViInstitute
Vi InstituteofofTechnology
Technology
96,Sirunkundram
96, SirunkundramVillage,
Village,Chengalpattu
ChengalpattuTk,
Tk,Pincode
Pincode- 603
- 603108
108
Ph:+91-44-2740
Ph: +91-44-27401695
1695/ 1696,
/ 1696,FAX:
FAX:91-44–
91-44–2740
27401696
1696

INTERNAL MARK II STATEMETNT


Class - Section: II -ECE Semester: III Subject: Data Structures & OOP IN C++
S.
No Reg. No Name of the Student IT II
1 47609106001 CHITRAKUMAR.D
2 47609106002 DHINESHKUMAR.M
3 47609106003 DHINESH.V
4 47609106004 DIVYA.V
5 47609106005 JENNIFER JANE.J
6 47609106006 KARTHIK..M
7 47609106007 MANOHARAN.E
8 47609106008 NALANKILLI.E
9 47609106009 PARTHIBAN.P
10 47609106010 RAJA.G
11 47609106011 RAMANUJAM.P
12 47609106012 RAVIKUMAR.E
13 47609106014 SARASCHANDRA.M
14 47609106015 SATHISHKUMAR.C
15 47609106016 SELVAM.S
16 47609106017 SIVAPRALASH.A
17 47609106018 SRIRAM.T
18 47609106019 VEERASWAMY.P.M
19 47609106020 KAMESHKANNAN.S
20 LE1 VINAYAGAM
21 LE1 KUMARESAN
22 LE1 AUGESTINE
23 LE1 SATHISHKUMAR.R
24 LE1 SARAVANAN
25 LE1 ALLABAKSH
26 LE1 SATHISHKUMAR.T
27 LE1 JANAKIRAMAN
28 LE1 DILEEP SESARAJ
29 LE1 RAJARAJESWARAN
30 LE1 AMANULLA
31 LE1 JOHNSIRANI.S

Faculty In charge. Head Of the Department

41 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
INTERNAL EXAM II RESULT ANALYSIS

Department : ECE Date of Exam :

Year : 2010 Sem. & Sec. : III & ECE

Subject Title : DATA STRUCTURES & OOPS IN C++ Subject Code : EC2202

Faculty Name : SATHIYAPRIYA.K Designation : AP/CSE

Name of Exam: IT II

Total Strength : Appeared: Absent :

Passed : Failed : % of Pass :

Description Below 50 50 to 59 60 to 74 75 to 89 90 and Above


No. of Students
 Minimum Mark to Pass - 50
 Corrective Actions for the Failed & Poor Students:

Roll Number and Name of Failed and Poor Students


S. No Roll No. Name of Student S. No Roll No. Name of Student

Faculty In Charge Head Of the Department

42 | P a g e
CYCLE TEST III -QUESTION PAPER
YEAR/SEM : II Year/ III SEM
EC2202-Data Structures & OOPS in C++
Date: Session: FN

PART A (5*2=10)

1. When do we declare a member of a class static?


2. Why is it necessary to overload an operator?
3. What is an abstract class?
4. What does ‘this’ pointer point to?
5. Define Polymorphism

PART B (8*1=8)
6. What is a friend function? What are the merits and demerits of using friend
function?
(Or)
Define a class ‘string ‘Use overload ‘==’ operator to compare two strings

Part C (16*2=32)

7. Explain Operators overloading with syntax.


(Or)
Explain how pointers are used to implement linked list structure.

8. Discuss about Exception Handling and class Templates


(Or)
Explain inheritance with types.

43 | P a g e
Vi Institute of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
CYCLE TEST III – ANSWER KEY
YEAR/SEM : II Year/ III SEM
EC2202-Data Structures & OOPS in C++
PART A (5*2=10)

1. Declare a member of a class static :-


Static member functions have a class scope and they do not have access to
the 'this' pointer of the class. When a member is declared as static, a static
member of class, it has only one data for the entire class even though there
are many objects created for the class.

2. Necessary to overload an operator:-


Operator overloading is claimed to be useful because it allows to define
new meaning for an existing operator .It us to assign multiple meanings
to the operator.It provides the flexibility to the C++ programmer in
extending bulit in data type.
3. Abstract class :-
The abstract class is a base class in which at least one pure virtual function
is used,It can be used to specify an interface that must be implemented by
all subclasses abstract class Shape
{
       abstract void area();
       abstract void perimeter();
       void someMethod() // concrete method
       {
              ..
       } }
4. ‘this’ pointer point to
The this pointer is a pointer accessible only within the nonstatic member
functions of a class, struct, or union type. It points to the object for which the
member function is called. Static member functions do not have a this pointer
5. Polymorphism
In object-oriented programming, polymorphism (from the Greek meaning "having
multiple forms") is the characteristic of being able to assign a different meaning or
usage to something in different contexts - specifically, to allow an entity such as a
variable, a function, or an object to have more than one form. There are several different
kinds of polymorphism.
PART B (8*1=8)
44 | P a g e
6. Friend function merits and demerits:-

A friend function is used in object-oriented programming to allow access to


private or protected data in a class from outside the class. Normally a function
which is not a member of a class cannot access such information; neither can an
external class. Occasionally such access will be advantageous for the
programmer; under these circumstances, the function or external class can be
declared as a friend of the class using the friend keyword. The function or
external class will then have access to all information – public, private, or
protected – within the class.

#include
class exforsys
{
private:
int a,b;
public:
void test()
{
a=100;
b=200;
}
friend int compute(exforsys e1)

//Friend Function Declaration with keyword friend and with the object of class
exforsys to which it is friend passed to it
};

int compute(exforsys e1)


{
//Friend Function Definition which has access to private data
return int(e1.a+e2.b)-5;
}

main()
{
exforsys e;
e.test();
cout<<"The result is:"<<COMPUTE(E);
//Calling of Friend Function with object as argument.
}
(Or)
Class ‘string ‘Use overload ‘==’ operator to compare two strings
45 | P a g e
C++ strings can be compared and assigned with the standard comparison operators:
==, !=, <=, >=, <, >, and =. Performing a comparison or assigning one string to another
takes linear time.

Two strings are equal if:

1. Their size is the same, and


2. Each member in location i in one string is equal to the the member in location i in
the other string.

Comparisons among strings are done lexicographically.

In addition to the normal container operators, strings can also be concatenated with the
+ operator and fed to the C++ I/O stream classes with the << and >> operators.

For example, the following code concatenates two strings and displays the result:

string s1 = "Now is the time...";


string s2 = "for all good men...";
string s3 = s1 + s2;
cout << "s3 is " << s3 << endl;

Furthermore, strings can be assigned values that are other strings, character arrays, or
even single characters. The following code is perfectly valid:

char ch = 'N';
string s;
s = ch;

Individual characters of a string can be examined with the [] operator, which runs in
constant time

is.compare(s1); <0 if s<s1, 0 if s==s1, or >0 if s>s1



is.compare(start1, len1, Compares s[start1..start1+len1-1] to s1[start2..start2+len2-1].
= s1, Returns value as above.
start2, len2);

bs1 == s2 The comparison operators work as expected.


= also > < >= <= !=

Part C (16*2=32)

46 | P a g e
7. Operators overloading with syntax.
C++ also contains the type conversion operators const_cast, static_cast,
dynamic_cast, and reinterpret_cast which are not listed in the table for brevity.
The formatting of these operators means that their precedence level is
unimportant.
Operating overloading allows you to pass different variable types to the same
function and produce different results. In this article Ben gives us the low-down
on operator overloading in C++.Operator overloading is common-place among
many efficient C++ programmers. It allows you to use the same function name,
but as different functions.
If this sounds confusing, then just think about it like this: you can use the same
function name for as many functions as you like, but you *must* pass different
variable types to each function.
In this article I will show you exactly what function overloading is, and how you
can get it to work for you in C++. You should have an intermediate knowlede of
C++. Any compiler will do, as I will only use ISO-standard compliant syntax.
Sample Object
For my sample object, I'm going to implement a matrix. This won't be a full-scale
implementation of every imaginable matrix operation, but it should be enough to
cover the basics of operator overloading, and maybe whet your appetite to
complete the implementation for other operations (dot product, inverse,
determinant, etc.).
In order to completely encapsulate a matrix within a class, we actually need two
classes: Row and Matrix.
So let's start with Row:
template<class T>
class Row {
public:
Row(int cols=0):row(NULL) {SetRowSize(cols);}
~Row() {SetRowSize(0); }
Row(const Row &r):row(NULL) {
SetRowSize(r.numCols);
for (int i=0;i<numCols;i++)
row[i]=r.row[i];
}
void SetRowSize(int n) {
if(row) delete[] row;
if (n>0) {
47 | P a g e
row=new T[n];
memset(row,0,sizeof(T)*n/sizeof(char));
}
else row=NULL;
numCols=n;
}
int size() { return numCols;}
private:
int numCols;
T* row;
};
(Or)
Pointers are used to implement linked list structure.

Linked List Types: Node and Pointer


Before writing the code to build the above list, we need two data types...
• Node The type for the nodes which will make up the body of the list.
These are allocated in the heap. Each node contains a single client data
element and a pointer to the next node in the list.
Type:
struct node
struct node {
int data;
struct node* next;
};
• Node Pointer The type for pointers to nodes. This will be the type of the
head pointer and the .next fields inside each node. In C and C++, no
separate type declaration is required since the pointer type is just the node
type followed by a '*'. Type: struct node*

There are two common features of linked lists demonstrated in Length()...


1) Pass The List By Passing The Head Pointer
The linked list is passed in to Length() via a single head pointer. The pointer is copied
from the caller into the "head" variable local to Length(). Copying this pointer does not
duplicate the whole list. It only copies the pointer so that the caller and Length() both
have pointers to the same list structure. This is the classic "sharing" feature of pointer
code. Both the caller and length have copies of the head pointer, but they share the
pointee node structure.
2) Iterate Over The List With A Local Pointer
The code to iterate over all the elements is a very common idiom in linked list code....
struct node* current = head;
while (current != NULL) {
48 | P a g e
// do something with *current node
current = current->next;
}
The hallmarks of this code are...
1) The local pointer, current in this case, starts by pointing to the same
node as the head pointer with current = head;. When the function
exits, current is automatically deallocated since it is just an ordinary
local, but the nodes in the heap remain.
2) The while loop tests for the end of the list with (current != NULL).
This test smoothly catches the empty list case — current will be NULL
on the first iteration and the while loop will just exit before the first
iteration.
3) At the bottom of the while loop, current = current->next;
advances the local pointer to the next node in the list. When there are no
more links, this sets the pointer to NULL. If you have some linked list
code which goes into an infinite loop, often the problem is that step (3) has
been forgotten.

8. Exception Handling and class Templates


Approaches for functions that implement identical tasks for different data
types
n Naïve Approach
n Function Overloading
n Function Template
Instantiating a Function Templates
void PrintInt( int n )
{
cout << "***Debug" << endl;
cout << "Value is " << n << endl;
}
void PrintChar( char ch )
{
cout << "***Debug" << endl;
cout << "Value is " << ch << endl;
}
void PrintFloat( float x )
{

}
49 | P a g e
void PrintDouble( double d )
{

}
A C++ language construct that allows the compiler to generate multiple
versions of a function by allowing parameterized data types.
• FunctionTemplate
Template < TemplateParamList >
FunctionDefinition
A C++ language construct that allows the compiler to generate
multiple versions of a class by allowing parameterized data types.
Class Template

Template < TemplateParamList >


ClassDefinition
• Class template arguments must be explicit.
• The compiler generates distinct class types called template classes or
generated classes.
• When instantiating a template, a compiler substitutes the template
argument for the template parameter throughout the class template.
template<class ItemType>
void GList<ItemType>::Insert( /* in */ ItemType item )
{
data[length] = item;
length++;
void GList<float>::Insert( /* in */ float item )
{
data[length] = item;
length++;
}

(Or) Inheritance with types.


50 | P a g e
Inheritance is the concept to inherit the properties of one class to another class. This has also
known as class structure again. For example, classes A contains two-member function ads
and subtracts and class b contain two another functions multiply and divide. We want to use
all these function with one object then we need to use inheritance where class B inherits all
the property of class, which is public, but class B cannot use the private properties of class A.
There are following types of inheritance:

1. Single class Inheritance:

When class a gas inherited in class has known as base class and B class is know as derived class. Here
only two classes have linked to each other.

2. Multilevel Inheritance:

In this type of inheritance, there are number of level and it has used in that cases where we want to use
all properties in number of levels according to the requirement. For example, class A inherited in class
b and class b has inherited in class c for class b so on. Where class A is base class c. In another way we
can say b is derived class a base class for c and a indirect base class for c is indirect base class for c and
c indirect derived class for class A.

3. Multiple Inheritances:

In this type of inheritance, number of classes has inherited in a single class. Where two or more classes
are, know as base class and one is derive class.

51 | P a g e
Vi Institute
4. Hierarchical Inheritance: of Technology
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
This type of inheritance helps us to create a baseless for number of classes and those numbers of
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
classes can have further their branches of number of class.

5. Hybrid Inheritance:

In this type of inheritance, we can have mixture of number of inheritances but this can generate an
error of using same name function from no of classes, which will bother the compiler to how to use the
functions. Therefore, it will generate errors in the program. This has known as ambiguity or duplicity.

MODEL MARK STATEMETNT


Class - Section: II -ECE Semester: III Subject: Data Structures & OOP IN C++
S.
No Reg. No Name of the Student IT III
52 | P a g e
1
Vi Institute
47609106001 of Technology
CHITRAKUMAR.D AB
47609106002 Village,
2 Sirunkundram
96, DHINESHKUMAR.M AB 108
Chengalpattu Tk, Pincode - 603
47609106003
3 Ph: DHINESH.V 47
+91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
4 47609106004 DIVYA.V 72
5 47609106005 JENNIFER JANE.J 30
6 47609106006 KARTHIK..M 45
7 47609106007 MANOHARAN.E 51
8 47609106008 NALANKILLI.E AB
9 47609106009 PARTHIBAN.P 45
10 47609106010 RAJA.G 18
11 47609106011 RAMANUJAM.P AB
12 47609106012 RAVIKUMAR.E 55
13 47609106014 SARASCHANDRA.M 58
14 47609106015 SATHISHKUMAR.C AB
15 47609106016 SELVAM.S 11
16 47609106017 SIVAPRALASH.A 07
17 47609106018 SRIRAM.T 58
18 47609106019 VEERASWAMY.P.M AB
47609106301
19 ALLABAKSH 45
47609106302
20 AMANULLA 45
47609106303
21 AUGESTINE 46
47609106304
22 DILEEP SESARAJ AB
47609106305
23 JANAKIRAMAN AB
47609106306
24 JOHNSIRANI.S 47
47609106307
25 KAMESHKANNAN.S 54
26 47609106308 KUMARESAN 59
27 47609106309 RAJARAJESWARAN 47
28 47609106310 SARAVANAN AB
29 47609106311 SATHISHKUMAR.T 49
47609106312
30 SATHISHKUMAR.R AB
47609106313 VINAYAGAM
31 55
Faculty In charge. Head Of the Department

INTERNAL EXAM III RESULT ANALYSIS

Department : ECE Date of Exam :

Year : 2010 Sem. & Sec. : III & ECE

53 | P a g e
Vi Institute
Subject Title : DATA STRUCTURES & OOPS INof Technology
C++ Subject Code : EC2202
96, Sirunkundram Village, Chengalpattu Tk, Pincode - 603 108
Faculty Name : SATHIYAPRIYA.K Designation : AP/CSE
Ph: +91-44-2740 1695 / 1696, FAX: 91-44– 2740 1696
Name of Exam: IT II

Total Strength : Appeared: Absent :

Passed : Failed : % of Pass :

Description Below 50 50 to 59 60 to 74 75 to 89 90 and Above


No. of Students
 Minimum Mark to Pass - 50
 Corrective Actions for the Failed & Poor Students:

Roll Number and Name of Failed and Poor Students


S. No Roll No. Name of Student S. No Roll No. Name of Student

Faculty In Charge Head Of the Department

UNIVERSITY INTERNAL MARK STATEMETNT


Class - Section: II -ECE Semester: III Subject: Data Structures & OOP IN C++
Convert Attend OMR
S. Total 15 5 Total 100
No Reg. No Name of the Student IT 1 IT2 MOD 300 Marks Marks 20
1 47609106001 CHITRAKUMAR.D 30 58 AB 88 4 2 6 32
2 47609106002 DHINESHKUMAR.M 02 00 AB 2 0 0 0 1
54 | P a g e
3 47609106003 DHINESH.V 50 78 47 175 9 3 12 60
4 47609106004 DIVYA.V 80 64 72 216 11 4 15 74
5 47609106005 JENNIFER JANE.J 80 30 30 140 7 3 10 50
6 47609106006 KARTHIK..M 55 34 45 134 7 2 9 44
7 47609106007 MANOHARAN.E 36 14 51 101 5 3 8 40
8 47609106008 NALANKILLI.E 10 22 AB 32 2 2 4 18
9 47609106009 PARTHIBAN.P 14 24 45 83 4 2 6 31
10 47609106010 RAJA.G 16 42 18 76 4 4 8 39
11 47609106011 RAMANUJAM.P 19 18 AB 37 2 4 6 29
12 47609106012 RAVIKUMAR.E 50 50 55 155 8 0 8 39
13 47609106014 SARASCHANDRA.M 66 76 58 200 10 4 14 70
14 47609106015 SATHISHKUMAR.C 50 AB AB 50 3 2 5 23
15 47609106016 SELVAM.S 11 50 11 72 4 4 8 38
16 47609106017 SIVAPRALASH.A 06 02 07 15 1 1 2 9
17 47609106018 SRIRAM.T 50 34 58 142 7 5 12 61
18 47609106019 VEERASWAMY.P.M 15 AB AB 15 1 1 2 9
19 47609106301 ALLABAKSH 26 45 71 4 2 6 28
20 47609106302 AMANULLA - 12 45 57 3 1 4 19
21 47609106303 AUGESTINE - 30 46 76 4 5 9 44
22 47609106304 DILEEP SESARAJ - 08 AB 8 0 4 4 22
23 47609106305 JANAKIRAMAN - 20 AB 20 1 5 6 30
24 47609106306 JOHNSIRANI.S - 18 47 65 3 3 6 31
25 47609106307 KAMESHKANNAN.S 70 74 54 198 10 5 15 75
26 47609106308 KUMARESAN - 28 59 87 4 1 5 27
27 47609106309 RAJARAJESWARAN - 50 47 97 5 1 6 29
28 47609106310 SARAVANAN - 14 AB 14 1 0 1 4
29 47609106311 SATHISHKUMAR.T - 38 49 87 4 3 7 37
30 47609106312 SATHISHKUMAR.R - 28 AB 28 1 2 3 17
47609106313 VINAYAGAM
31 - 38 55 93 5 3 8 38
Faculty In Charge Head Of the Department

55 | P a g e
56 | P a g e

You might also like