Sei sulla pagina 1di 11

GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING AND TECHNOLOGY

B.Tech (IT) II Year- I Semester

DATA STRUCTURES THROUGH C++ LAB

SYLLABUS

Task-1
Write C++ program to implement the following
a) Constructors and destructors
b) Overloading constructors
Task2
Write C++ program to implement the following variations of
Friend Concepts
a) External Function declared as Friend
b) Member Function declared as Friend
c) One Class declared as Friend of another class.
Task-3
Write C++ program to implement the following
a) Function and Operator Overloading
b) Function and Operator Overloading using FRIEND concept
Task-4
Write C++ program to implement Function and Class Templates
Task-5
Write a C++ program to implement
a) Single Inheritance
b) Multiple Inheritance
c) Multilevel Inheritance
d) Hybrid Inheritance
Task-6
Write C++ program to implement Runtime Polymorphism.
Task-7
Write C++ program to implement the
a) Merge sort
b) Heap sort
Task-8
Write a C++ program to implement Open addressing collision
resolution strategies of Hashing
a) Linear probing
b) Quadratic probing
c) Double Hashing
Task-9
Write a C++ program to perform the following operations:
a) Insert an element into a binary search tree.
b) Delete an element from a binary search tree.
c) Search for a key element in a binary search tree.
Task-10
Write C++ programs to implement Non-Recursive Tree Traversal
techniques
a) Preorder
b) Inorder
c) Postorder.
Task-11
Write C++ program to perform the following operations on
AVLtree
a) Insert an element
b) Delete an element from AVLtree
c) Search for a key element in an AVLtree
Task-12
Write C++ programs to Implement Graph Traversal Techniques
a) BFS
b) DFS.
DS THROUGH C++ LAB PROGRAMS
Task-1
1. TO IMPLEMENT DEFAULT CONSTRUCTORS WITH (OR) WITHOUT ARGUMENTS
#include<iostream>

using namespace std;

class area

int l,b,h;

public:

area()

cout<<"default constructor";

l=0;b=0;h=0;

area(int i, int j)

cout<<"\n constructor with two arguments";

l=i;b=j;

area(int x, int y, int z)

cout<<"constructor with three arguments";

l=x;b=y;h=z;

void display()
{

cout<<"\n\t l="<<l<<"b="<<b<<"h="<<h;

};

int main()

area a=area();

a.display();

area b=area(10,20);

b.display();

area c=area(10,20,30);

c.display();

}
OUTPUT:
default constructor:
l=0 b=0 h=0
constructor with two arguments:
l=10 b=20
constructor with three arguments:
l=10 b=20 c=30

2. TO IMPLEMENT COPY CONSTRUCTORS

#include<iostream>

using namespace std;

class area

int a;

public:

area(int b)

{
a=b;

area(area&a1) //copy constructor

a=a1.a;

void display()

cout<<a;

};

int main()

area a1(10);

area a2(a1);

cout<<"value of a in object a1";

a1.display();

cout<<"value of a in a2";

a2.display();

}
OUTPUT:
value of a in a1:10
value of a in a2:10

3. TO IMPLEMENT CONSTRUCTOR OVERLOADING


#include<iostream>

using namespace std;

class area
{

/*function to calculate area of a circle*/

public:

area(float radius);

area(int length, int breadth);

area(int length, int breadth, int height);

};

area::area(float radius)

cout<<"\n area of circle is:"<<(3.141*radius*radius);

/*function to calculate area of rectangle*/

area::area(int length, int breadth)

cout<<"\n area of rectangle is:"<<(length*breadth);

/*function to calculate area of cube*/

area::area(int length, int breadth, int height)

cout<<"\n the area of cube is:"<<(length*breadth*height);

int main()

area circle(2.1);
area rectangle(2,3);

area cube(2,3,4);

OUTPUT:
area if circle is:13.851809
area of rectangle is:6
area of cube is:24

4. TO IMPLEMENT DESTRUCTORS

#include<iostream>

using namespace std;

int a=0;

class area

public:area()

a++;

cout<<"object"<<a<<" created";

public:~area()

cout<<"object"<<a<< "destroyed";

a--;

};

int main()

{
area a1,a2;

}
OUTPUT:
object 1 created
object 2 created
object 2 destroyed
object 1 destroyed

Task-2

a) External Function declared as Friend


#include<iostream>

using namespace std;

class shape

int age;

char name[10];

public:

void set_val()

cout<<"\nEnter Values\n";

cout<<"\nEnter name\n";

cin>>name;

cout<<"\nEnter age\n";

cin>>age;

friend void display(shape);

};

void display(shape s)

cout<<"\nName="<<s.name;
cout<<"\nAge="<<s.age;

int main()

shape sh;

sh.set_val();

display(sh);

Output:
Enter the name:Sandeep
Enter age:24
Name=Sandeep
Age=24

TASK-2
a) External Function declared as Friend
b) Member Function declared as Friend
c) One Class declared as Friend of another class.
Task-3
Write C++ program to implement the following
a) Function and Operator Overloading
b) Function and Operator Overloading using FRIEND concept
Task-4
Write C++ program to implement Function and Class Templates
Task-5
Write a C++ program to implement
a) Single Inheritance
b) Multiple Inheritance
c) Multilevel Inheritance
d) Hybrid Inheritance
Task-6
Write C++ program to implement Runtime Polymorphism.
Task-7
Write C++ program to implement the
a) Merge sort
b) Heap sort
Task-8
Write a C++ program to implement Open addressing collision
resolution strategies of Hashing
a) Linear probing
b) Quadratic probing
c) Double Hashing
Task-9
Write a C++ program to perform the following operations:
a) Insert an element into a binary search tree.
b) Delete an element from a binary search tree.
c) Search for a key element in a binary search tree.
Task-10
Write C++ programs to implement Non-Recursive Tree Traversal
techniques
a) Preorder
b) Inorder
c) Postorder.
Task-11
Write C++ program to perform the following operations on
AVLtree
a) Insert an element
b) Delete an element from AVLtree
c) Search for a key element in an AVLtree
Task-12
Write C++ programs to Implement Graph Traversal Techniques
a) BFS
b) DFS.

Potrebbero piacerti anche