Ex No: 1(A) Date: Class & Objects Aim: To write a C++ program to implement the basic concepts of Class and Object’s. Algorithm: 1) Start the program. 2) Define a class stud with the needed data members. 3) Define the function input () o read the value such as rno, name, and 3marks. 4) Define the function print () to calculate the total marks, and average. 5) Display the calculated values with the rno and name. 6) In main (), create an object for the class stud. 7) Call the function input () with the object. 8) Call the function print () with the object. 9) Stop the program.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Ex No: 1(A)Date:
Class & Objects
Aim:
To write a C++ program to implement the basic concepts of Class and Object’s.
Algorithm:
1) Start the program.
2) Define a class stud with the needed data members.
3) Define the function input () o read the value such as rno, name, and 3marks.
4) Define the function print () to calculate the total marks, and average.
5) Display the calculated values with the rno and name.
6) In main (), create an object for the class stud.
7) Call the function input () with the object.
8) Call the function print () with the object.
9) Stop the program.
// PROGRAM FOR CLASS AND OBJECTS
#include<iostream.h>
#include<conio.h>
class stud
{
private:
int m1,m2,m3,rno,tot;
char name[20];
float avg;
public:
void input()
{
cout<<"\n\n\t\t\t CLASS AND OBJECTS \n ";
cout<<"\n ENTER YOUR NAME : ";
cin>>name;
cout<<"\n ENTER A REGISTER NUMBER : ";
cin>>rno;
cout<<"\n ENTER THREE SUBJECT MARKS : ";
cin>>m1>>m2>>m3;
}
void print()
{
cout<<"\n NAME : "<<name<<endl;
cout<<"\n REGISTER NUMBER : "<<rno<<endl;
cout<<"\n THREE SUBJECT MARKS : "<<m1<<"\t"<<m2<<"\t"<<m3<<endl;
cout<<"\n RESULT = ";
if((m1>=50)&&(m2>=50)&&(m3>=50))
{
cout<<" PASS "<<endl;
tot=m1+m2+m3;
avg=tot/3;
cout<<"\n TOTAL = "<<tot<<endl;
cout<<"\n AVERAGE = "<<avg<<endl;
}
else
{
cout<<" FAIL "<<endl;
}
}
};
void main()
{
clrscr();
stud s;
s.input();
s.print();
getch();
}
SAMPLE INPUT AND OUTPUT:
CLASS AND OBJECTS
ENTER YOUR NAME: RAJA.A
ENTER A REGISTER NUMBER: 12345
ENTER THREE SUBJECT MARKS: 90
98
78
NAME: RAJA.A
REGISTER NUMBER: 12345
THREE SUBJECT MARKS: 90 98 78
RESULT = PASS
TOTAL = 266
AVERAGE = 88
CLASS AND OBJECTS
ENTER YOUR NAME: RAVI.S
ENTER A REGISTER NUMBER: 4321
ENTER THREE SUBJECT MARKS: 10
60
90
NAME: RAVI.S
REGISTER NUMBER: 4321
THREE SUBJECT MARKS: 10 60 90
RESULT = FAIL
Result:
Thus the C++ program for implementing the concept of Classes and Objects has
been executed successfully and the output was verified.
Ex No: 1(B)Date:
Constructor & Destructor
Aim:
To write a C++ program to implement the basic concepts of Constructor and
Destructor.
Algorithm:
1) Start the program.
2) Define a class prime.
3) Define the Constructor under public section, in that read the input.
4) Depend on the input check the given input is prime or not.
5) Define the Destructor to de-allocate the memory for the data members.
6) In main (), create an object for the class prime.
7) Once the object is created, the constructor invoked automatically.
8) Destructor gets invoked at the termination of the program.
9) Stop the program.
// PROGRAM FOR CONSTRUCTOR AND DESTRUCTOR
#include<iostream.h>
#include<conio.h>
#include<process.h>
class prime
{
private:
int a,i,n;
public:
prime()
{
cout<<"\n\n\t\t CONSTRUCTOR AND DESTRUCTOR \n";
cout<<"\n ENTER A NUMBER: ";
cin>>n;
for(i=2;i<=n/2;i++)
{
if(n%2==0)
{
cout<<"\n THE GIVEN NUMBER IS NOT PRIME. "<<endl;
getch();
exit(0);
}
}
cout<<"\n THE GIVEN NUMBER IS PRIME. "<<endl;
}
~prime()
{
cout<<"\n ALL CONTENTS ARE DELETED........"<<endl;
getch();
}
};
void main()
{
clrscr();
prime p;
getch();
}
SAMPLE INPUT AND OUTPUT:
CONSTRUCTOR AND DESTRUCTOR
ENTER A NUMBER: 8
THE GIVEN NUMBER IS NOT PRIME.
CONSTRUCTOR AND DESTRUCTOR
ENTER A NUMBER: 5
THE GIVEN NUMBER IS PRIME.
ALL CONTENTS ARE DELETED........
Result:
Thus the C++ program for implementing the concepts of Constructor and
Destructor has been executed successfully and the output was verified.
Ex No: 2Date:
Array Implementation
Aim:
To write a C++ program to implement the basic concepts of an Array.
Algorithm:
1) Start the program.
2) Define a class array and declare the needed variables.
3) Define the function arrayin (), read the value for n and read the elements for the
array.
4) Define the function print (), to display the array elements.
5) Define the function insert (), insert the element in the array at the given location.
6) Define the function del (), to delete the element in the given location.
7) In main (), create an object for the class.
8) Call the function arrayin () with the object.
9) Display the menus such as insert, delete and display option inside the switch case.
10) Read the choice, depend on the choice, the case gets execute and
the respective function is invoked.
11) Stop the program.
// PROGRAM FOR ARRAY IMPLEMENTATION
#include<iostream.h>
#include<conio.h>
#include<process.h>
class array
{
private:
int a[20],i,n,p,d,i1,d1;
public:
void arrayin()
{
cout<<"\n\n\t\t ARRAY IMPLEMENTATION \n\n";
cout<<"\n ENTER THE ARRAY SIZE : ";
cin>>n;
cout<<"\n ENTER THE ARRAY ELEMENTS ONE BY ONE : "<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
void print()
{
cout<<"\n ARRAY ELEMENT "<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}
void insert()
{
cout<<"\n ENTER THE POSITION TO INSERT : "<<endl;
cin>>p;
for(i=n+1;i>=p;i--)
{
a[i]=a[i-1];
}
cout<<"\n ENTER THE ELEMENT TO INSERT : "<<endl;
cin>>i1;
a[i]=i1;
cout<<"\n THE NEW ARRAY ELEMENTS AFTER INSERTION : "<<endl;
for(i=0;i<n+1;i++)
{
cout<<a[i]<<endl;
}
}
void del()
{
cout<<"\n ENTER THE POSITION TO DELETE : ";
cin>>d;
for(i=d-1;i<n+1;i++)
{
a[i]=a[i+1];
}
cout<<"\n THE NEW ARRAY ELEMENTS AFTER DELETION : ";
for(i=0;i<n-1;i++)
{
cout<<a[i]<<endl;
}
}
};
void main()
{
array k;
int ch;
clrscr();
k.arrayin();
cout<<"\n\n\t\t INDEX \n"<<endl;
cout<<"\n 1.ARRAY ELEMENT INSERTION \n"<<endl;
cout<<"\n 2.ARRAY ELEMENT DELETION \n"<<endl;
cout<<"\n 3.exit \n"<<endl;
cout<<"\n ENTER YOUR CHOICE : ";
cin>>ch;
switch (ch)
{
case 1:
k.insert();
break;
case 2:
k.del();
break;
case 3:
exit(0);
default: cout<<"\n INVALID CHOICE "<<endl;
}
getch();
}
SAMPLE INPUT AND OUTPUT:
ARRAY IMPLEMENTATION
ENTER THE ARRAY SIZE: 5
ENTER THE ARRAY ELEMENTS ONE BY ONE:
10
20
30
40
50
INDEX
1. ARRAY ELEMENT INSERTION
2. ARRAY ELEMENT DELETION
3. EXIT
ENTER YOUR CHOICE: 1
ENTER THE POSITION TO INSERT: 2
ENTER THE ELEMENT TO INSERT: 25
THE NEW ARRAY ELEMENTS AFTER INSERTION:
10
25
20
30
40
50
ARRAY IMPLEMENTATION
ENTER THE ARRAY SIZE: 5
ENTER THE ARRAY ELEMENTS ONE BY ONE:
10
20
30
40
50
INDEX
1. ARRAY ELEMENT INSERTION
2. ARRAY ELEMENT DELETION
3. EXIT
ENTER YOUR CHOICE: 2
ENTER THE POSITION TO DELETE: 2
THE NEW ARRAY ELEMENTS AFTER DELETION: 10
30
40
50
Result:
Thus the C++ program for implementing the concept of Array has been executed
successfully and the output was verified.
Ex No: 3Date:
Linked List Operations
Aim:
To write a C++ program to implement all the operations of Linked List.
Algorithm:
1) Start the program.
2) Define the list using structure.
3) In main (), display the menus such as Insert, delete, and display.
4) Read the choice, depend on the choice, the case gets execute and it invokes the
respective function.
5) To insert an element, we can have the following:
6) Define the function insempty (), to insert an element in the empty list.
7) Define the function insbegin (), to insert an element at the beginning of the list.
8) Define the function insmiddle (), to insert an element at the middle of the list.
9) Define function insend (), to insert an element at the end of the list.
10) To delete an element, we can have the following:
11) Define the function delsingle (), to delete the single node element.
12) Define the function delbegin (), to delete the element at the
beginning of the list.
13) Define the function delmiddle (), to delete the element at the
middle of the list.
14) Define the function delend (), to delete the element at the end of
the list.
15) Define the function display (), to display the elements in the list.
16) Stop the program.
// PROGRAM FOR LINKED LIST OPERATIONS
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct list
{
int data;
struct list*next;
}*start;
void insempty();
void insbegin();
void insmiddle();
void insend();
void delsingle();
void delbegin();
void delmiddle();
void delend();
void display();
void main()
{
int ch,ch1;
clrscr();
do
{
cout<<"\n\n\t\t SINGLY LINKED LIST \n\n";
cout<<"\n\n\t\t LIST OPERATIONS \n\n";
cout<<"\n 1.INSERT AN ELEMENT \n";
cout<<"\n 2.DELETE AN ELEMENT \n";
cout<<"\n 3.DISPLAY AN ELEMENT \n";
cout<<"\n 4.EXIT \n";
cout<<"\n\n\n ENTER YOUR CHOICE : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\n\t\t INSERT OPERATIONS \n\n";
cout<<"\n 1.INSERT AT EMPTY \n";
cout<<"\n 2.INSERT AT BEGIN \n";
cout<<"\n 3.INSERT AT MIDDLE \n";
cout<<"\n 4.INSERT AT END \n";
cout<<"\n\n\n ENTER YOUR CHOICE : ";
cin>>ch1;
switch(ch1)
{
case 1:
insempty();
break;
case 2:
insbegin();
break;
case 3:
insmiddle();
break;
case 4:
insend();
break;
}
break;
case 2:
cout<<"\n\n\t\t DELETE OPERATIONS \n\n";
cout<<"\n 1.SINGLE NODE DELETION \n";
cout<<"\n 2.DELETE AT BEGIN \n";
cout<<"\n 3.DELETE AT MIDDLE \n";
cout<<"\n 4.DELETE AT END \n";
cout<<"\n\n\n ENTER YOUR CHOICE : ";
cin>>ch1;
switch(ch1)
{
case 1:
delsingle();
break;
case 2:
delbegin();
break;
case 3:
delmiddle();
break;
case 4:
delend();
break;
}
break;
case 3:
display();
break;
case 4:
exit(0);
}
}
while(ch<=3);
getch();
}
void insempty()
{
if(start!=NULL)
cout<<"\n LIST IS NOT EMPTY ";
else
{
struct list*node;
node=new list;
cout<<"\n ENTER THE VALUE : ";
cin>>node->data;
node->next=NULL;
start=node;
}
}
void insbegin()
{
if(start==NULL)
cout<<"\n LIST IS EMPTY SO PLEASE INSERT AT EMPTY ";
else
{
struct list*node;
node=new list;
cout<<"\n ENTER THE VALUE : ";
cin>>node->data;
node->next=start;
start=node;
}
}
void insmiddle()
{
int item;
if(start->next==NULL)
cout<<"\n IT IS NOT POSSIBLE TO INSERT AN ELEMENT AT MIDDLE ";
else
{
struct list *node,*pre,*ptr,*temp;
node=new list;
cout<<"\n ENTER THE VALUE : ";
cin>>node->data;
cout<<"\n ENTER THE ELEMENT BEFORE INSERTION : ";
cin>>item;
pre=start;
while(pre->data!=item)
{
temp=pre;
pre=pre->next;
}
temp->next=node;
node->next=pre;
}
}
void insend()
{
if (start==NULL)
cout<<"\n LIST IS EMPTY ";
else
{
struct list *node,*pre,*ptr;
node=new list;
cout<<"\n ENTER THE VALUE : ";
cin>>node->data;
ptr=start;
while(ptr!=NULL)
{
pre=ptr;
ptr=ptr->next;
}
pre->next=node;
node->next=NULL;
}
}
void delsingle()
{
if(start->next!=NULL)
cout<<"\n LIST HAVING MORE THAN ONE NODE ";
else
{
cout<<"\n DELETED NODE IS : "<<start->data;
start=NULL;
}
}
void delbegin()
{
if(start->next==NULL)
cout<<"\n LIST HAVING ONLY ONE NODE ";
else
{
cout<<"\n DELETED ELEMENT IS : "<<start->data;
start=start->next;
}
}
void delmiddle()
{
int item;
struct list*ptr,*pre;
ptr=start->next;
if(ptr->next==NULL)
cout<<"\n THERE IS NO MIDDLE NODE ";
else
{
cout<<"\n ENTER THE ELEMENT TO DELETE : ";
cin>>item;
pre=start;
for(ptr=start;(ptr);ptr->next)
{
if(ptr->data==item)
{
pre->next=ptr->next;
break;
}
pre=ptr;
}
}
}
void delend()
{
if(start->next==NULL)
cout<<"\n IT IS NOT POSSIBLE TO DELETE AT END ";
else
{
struct list*ptr,*pre,*loc;
pre=loc= start;
for(ptr=start;(ptr);ptr->next)
{
loc=pre;
pre=ptr;
}
cout<<"\n DELETED ELEMENT IS : "<<pre->data;
loc->next=NULL;
}
}
void display()
{
struct list*ptr;
if(start==NULL)
cout<<"\n LIST IS EMPTY ";
else
{
cout<<"\n NOW, LIST HAVING THE FOLLOWING ELEMENTS : ";
for(ptr=start;(ptr);ptr=ptr->next)
cout<<ptr->data<<"\n";
}
}
SAMPLE INPUT AND OUTPUT:
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 1
INSERT OPERATIONS1. INSERT AT EMPTY2. INSERT AT BEGIN3. INSERT AT MIDDLE4. INSERT AT END
ENTER YOUR CHOICE: 1ENTER THE VALUE: 10
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 1
INSERT OPERATIONS1. INSERT AT EMPTY2. INSERT AT BEGIN3. INSERT AT MIDDLE4. INSERT AT END
ENTER YOUR CHOICE: 2ENTER THE VALUE: 20
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 3LIST HAVING THE FOLLOWING ELEMENTS: 20 10
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 1
INSERT OPERATIONS
1. INSERT AT EMPTY2. INSERT AT BEGIN3. INSERT AT MIDDLE4. INSERT AT END
ENTER YOUR CHOICE: 3ENTER THE VALUE: 30ENTER ELEMENT BEFORE INSERTION: 10
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT
4. EXIT
ENTER YOUR CHOICE: 3LIST HAVING THE FOLLOWING ELEMENTS: 20 30 10
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 1
INSERT OPERATIONS
1. INSERT AT EMPTY2. INSERT AT BEGIN3. INSERT AT MIDDLE4. INSERT AT END
ENTER YOUR CHOICE: 4ENTER THE VALUE: 40
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 3NOW, LIST HAVING THE FOLLOWING ELEMENTS: 20 30 10
40
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2
DELETE OPERATIONS
1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 1LIST HAVING MORE THAN ONE NODE
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2
DELETE OPERATIONS
1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 2DELETED ELEMENT IS: 20
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 3NOW, LIST HAVING THE FOLLOWING ELEMENTS: 30
10 40
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2
DELETE OPERATIONS
1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 3ENTER THE ELEMENT TO DELETE: 10
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 3NOW, LIST HAVING THE FOLLOWING ELEMENTS: 30 40
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2
DELETE OPERATIONS
1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 4DELETED ELEMENT IS: 30
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 3NOW, LIST HAVING THE FOLLOWING ELEMENTS: 40
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2
DELETE OPERATIONS
1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 4IT IS NOT POSSIBLE TO DELETE AT END
SINGLY LINKED LIST
LIST OPERATIONS1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2
DELETE OPERATIONS1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 1DELETED NODE IS: 40
SINGLY LINKED LIST
LIST OPERATIONS
1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 3LIST IS EMPTY
SINGLY LINKED LIST
LIST OPERATIONS1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 2 DELETE OPERATIONS1. SINGLE NODE DELETION2. DELETE AT BEGIN3. DELETE AT MIDDLE4. DELETE AT END
ENTER YOUR CHOICE: 1LIST IS EMPTY
LIST OPERATIONS1. INSERT AN ELEMENT2. DELETE AN ELEMENT3. DISPLAY AN ELEMENT4. EXIT
ENTER YOUR CHOICE: 4
Result:
Thus the C++ program for implementing the Linked List Operations has been
executed successfully and the output was verified.
Ex No: 4Date:
Cursor Implementation of List ADT
Aim:
To write a C++ program to implement the Cursor concepts for LIST ADT.
Algorithm:
1) Start the program.
2) Display the option such as Insert, Delete, Display, Search and Exit.
3) Depend on the choice, case gets execute and the respective function is called.
4) CASE 1: read the total number of elements and read the elements
In the array.
5) CASE 2: insert an element at the desired location.
6) CASE 3: delete an element from the specified location.
7) CASE 4: display the elements present in the array.
8) Stop the program.
// PROGRAM FOR CURSOR IMPLEMENTATION OF LIST ADT
#include<iostream.h>
#include<conio.h>
int main()
{
int a[20],i,j,ch,n,x;
while(1)
{
clrscr();
cout<<"\n\n\t\t CURSOR IMPLEMENTATION OF LIST ADT \n";
cout<<"\n\n\t LIST OPERATIONS \n\n";
cout<<"\n 1.CREATION \n";
cout<<"\n 2.INSERTION \n";
cout<<"\n 3.DELETION \n";
cout<<"\n 4.DISPLAY \n";
cout<<"\n 5.SEARCH \n";
cout<<"\n 6.EXIT \n";
cout<<"\n ENTER YOUR CHOICE : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n ENTER THE TOTAL NO OF VALUE : ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\n ENTER THE "<<i+1<<" VALUE : ";
cin>>a[i];
}
break;
case 2:
cout<<"\n ENTER THE INSERT POSITION : ";
cin>>i;
for(j=n;j>i-1;j--)
a[j]=a[j-1];
cout<<"\n ENTER THE INSERT VALUE : ";
cin>>a[i];
n++;
break;
case 3:
if(n<0)
cout<<"\n THE LIST IS EMPTY ";
else
{
cout<<"\n ENTER THE DELETING POSITION : ";
cin>>j;
cout<<"\n THE DELETED ELEMENT IS : "<<a[j];
for(i=j-1;i<n;i++)
a[i]=a[i+1];
n--;
}
getch();
break;
case 4:
for(i=1;i<n;i++)
cout<<a[i]<<"\t";
getch();
break;
case 5:
if(n<0)
cout<<"\n THE LIST IS EMPTY ";
else
{
cout<<"\n ENTER THE SEARCHING ELEMENT : ";
cin>>x;
for(i=0;i<n;i++)
if(a[i]==x)
{
cout<<"\n THE GIVEN ELEMENT FOUND IN THE POSITION "<<i;
goto aa;
}
cout<<"\n THE GIVEN ELEMENT NOT FOUND IN THIS LIST ";
aa:getch();
break;
case 6:
return(0);
}
getch();
}
}
}
SAMPLE INPUT AND OUTPUT:
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 1
ENTER THE TOTAL NO OF VALUE: 5
ENTER THE 1 VALUE: 10
ENTER THE 2 VALUE: 20
ENTER THE 3 VALUE: 30
ENTER THE 4 VALUE: 40
ENTER THE 5 VALUE: 50
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 4
10 20 30 40 50
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 2
ENTER THE INSERT POSITION: 0
ENTER THE INSERT VALUE: 5
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 4
5 10 20 30 40 50
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 3
ENTER THE DELETING POSITION: 0
THE DELETED ELEMENT IS: 5
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 4
10 20 30 40 50
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 5
ENTER THE SEARCHING ELEMENT: 10
THE GIVEN ELEMENT FOUND IN THE POSITION 0
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 5
ENTER THE SEARCHING ELEMENT: 20
THE GIVEN ELEMENT FOUND IN THE POSITION 1
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 5
ENTER THE SEARCHING ELEMENT: 90
THE GIVEN ELEMENT NOT FOUND IN THIS LIST
CURSOR IMPLEMENTATION OF LIST ADT
LIST OPERATIONS
1. CREATION
2. INSERTION
3. DELETION
4. DISPLAY
5. SEARCH
6. EXIT
ENTER YOUR CHOICE: 6
Result:
Thus the C++ program for implementing the Cursor concepts for LIST ADT Operations
has been executed successfully and the output was verified.
Ex No: 5Date:
STACK ADT using Array Implementations
Aim: To write a C++ program to implement the STACK ADT using array implementations.
Algorithm:
1) Start the program.
2) In main (), display the options such as Push, Pop, and Display.
3) Read the choice, depend on the choice the case gets execute and the respective
function gets invoked.
4) Define the function push (), to insert a new element into the stack.
5) Define the function pop (), to delete an element from the stack.
6) Define the function display (), to display the elements in the stack.
7) Stop the program.
// PROGRAM FOR STACK ADT USING ARRAY IMPLEMENTATION
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 3
void push();
void pop();
void display();
int s[size],top=-1;
void main()
{
int ch;
clrscr();
do
{
cout<<"\n\n\t\t STACK ADT USING ARRAY IMPLEMENTATION \n";