Professional Documents
Culture Documents
Date:
Aim:
Algorithm:
1
Coding:
#include"iostream.h"
#include"conio.h"
void main()
int a,b;
clrscr();
cout<<"\n\t\t\tADDITION OPERATION";
cout<<"\n\t\t\t~~~~~~~~ ~~~~~~~~~\n";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>a;
cin>>b;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
for(int i=1;i<=b;i++)
2
{
a++;
getch();
ADDITION OPERATION
~~~~~~~~ ~~~~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
A Value =32
B Value =12
3
Ex:No
Date:
Aim:
Algorithm:
4
CODING:
#include"iostream.h"
#include"conio.h"
class emp
public:
int no;
char na[30],d[20];
float sa;
void getdata();
void display();
};
cin>>no;
cin>>na;
cin>>d;
cin>>sa;
5
}
cout<<"\n\t\t"<<no<<"\t"<<na<<"\t\t"<<d<<"\t "<<sa;
void main()
int ch,l,i;
emp e;
clrscr();
cout<<"\n\t\t\tEMPLOYEE DETAILS";
cout<<"\n\t\t\t~~~~~~~~ ~~~~~~~\n";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>l;
do
cout<<"\n\t\t\tEMPLOYEE DETAILS";
cout<<"\n\t\t\t~~~~~~~~ ~~~~~~~\n";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
6
cout<<"\n\t\t1-GET EMP DETAILS";
cout<<"\n\t\t2-DISPLAY";
cout<<"\n\t\t3-EXIT\n";
cin>>ch;
switch(ch)
case 1:
for(i=1;i<=l;i++)
e.getdata();
break;
case 2:
for(i=1;i<=l;i++)
e.display();
break;
7
}while(ch<3);
getch();
EMPLOYEE DETAILS
~~~~~~~~ ~~~~~~~
INPUT
~~~~~
EMPLOYEE DETAILS
~~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
Emp. Details No =1
8
ENTER YOUR SALARY =12000
EMPLOYEE DETAILS
~~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
EMPLOYEE DETAILS
~~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
9
Ex:No
Date:
Aim:
Algorithm:
10
CODING:
#include"iostream.h"
#include"conio.h"
class stud
public:
int no,m1,m2,m3,m4,t;
float avg;
char na[30];
void getdata();
void cal();
void display();
};
cin>>no;
cin>>na;
cin>>m1;
11
cin>>m2;
cin>>m3;
cin>>m4;
t=m1+m2+m3+m4;
avg=t/4;
void main()
int ch,l,i;
stud e[20];
clrscr();
12
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~\n";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>l;
do
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~\n";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cout<<"\n\t\t2-DISPLAY";
cout<<"\n\t\t3-EXIT\n";
cin>>ch;
switch(ch)
case 1:
for(i=1;i<=l;i++)
13
cout<<"\n\t\tStud. Details No ="<<i<<"\n";
e[i].getdata();
break;
case 2:
for(i=1;i<=l;i++)
e[i].display();
break;
}while(ch<3);
getch();
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
14
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
Stud. Details No =1
Stud. Details No =2
15
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
67 kirubha 78 89 87 89 343 85
66 jegan 45 56 67 78 246 61
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
16
Ex:No:
Date:
Aim:
Algorithm:
Declare the derived class and inherit the properties of the base
class.
Inside the main function, create the object for derived class.
17
Using this object, we call the function of both base class and derived
class.
End.
Coding:
#include"iostream.h"
#include"conio.h"
class base
public:
int no,m1,m2,m3,m4,t;
int avg;
char na[30];
void getdata();
};
public:
char g[7];
void cal();
18
void display();
};
cin>>no;
cin>>na;
cin>>m1;
cin>>m2;
cin>>m3;
cin>>m4;
t=m1+m2+m3+m4;
avg=t/4;
19
void stud :: display()
if(avg>80)
cout<<"\tA Grade";
cout<<"\tB Grade";
cout<<"\tC Grade";
else
cout<<"\tD Grade";
void main()
int ch,l,i;
stud e[20];
clrscr();
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~\n";
cout<<"\n\t\tINPUT";
20
cout<<"\n\t\t~~~~~\n";
cin>>l;
do
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~\n";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cout<<"\n\t\t2-DISPLAY";
cout<<"\n\t\t3-EXIT\n";
cin>>ch;
switch(ch)
case 1:
for(i=1;i<=l;i++)
e[i].getdata();
21
break;
case 2:
for(i=1;i<=l;i++)
e[i].display();
break;
}while(ch<3);
getch();
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
22
ENTER THE LIMIT =1
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
Stud. Details No =1
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
23
1-GET STUD. DETAILS
2-DISPLAY
3-EXIT
67 KIRUBHA 78 89 98 87 352 88 A
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
2-DISPLAY
3-EXIT
24
Ex:No:
Date:
Aim:
Algorithm:
c. Inside the base class declare the variables and the member functions.
d. Declare and define the derived class to inherit the properties of the
base class.
25
f. Using this object call the member functions of the base class and two
derived class.
Coding:
#include"iostream.h"
#include"conio.h"
#include"time.h"
#include"dos.h"
#include"math.h"
class date1
public:
struct date k;
int dd,mm,yy;
clrscr();
date1()
getdate(&k);
dd=k.da_day;
mm=k.da_mon;
yy=k.da_year;
26
};
public:
int d,m,y,td,tm,ty;
void getdata()
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>d;
cin>>m;
cin>>y;
void cal()
if(yy>=y)
td=abs(dd-d);
tm=abs(mm-m);
27
ty=abs(yy-y);
else
getdata();
};
public:
void display()
getdata();
cal();
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
};
void main()
28
{
date1 d1;
age a;
clrscr();
cout<<"\n\t\t\tAGE CALCULATION";
cout<<"\n\t\t\t~~~ ~~~~~~~~~~~";
a.display();
getch();
AGE CALCULATION
29
~~~ ~~~~~~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
30
Ex:No:
Date:
Aim:
Algorithm:
To create a class with name init and initialize all variables which belongs
to details of student.
Calc () function of class cal which is used to calculate the total of marks.
Sports class is used to get the height and weight of the student.
31
Stud class is used to call all the function.
Coding:
#include"iostream.h"
#include"conio.h"
class init
public:
int reg,m1,m2,m3,m4;
char name[20];
};
public:
void getdata()
cin>>reg;
32
cin>>name;
cin>>m1;
cin>>m2;
cin>>m3;
cin>>m4;
};
public:
int tt;
float avg;
void calc()
getdata();
tt=m1+m2+m3+m4;
avg=tt/4;
33
void display()
cout<<"\n\t\t"<<reg<<"\t"<<name<<"\t "<<m1<<"\t"<<m2<<""
"\t"<<m3<<"\t"<<m4<<"\t"<<tt<<"\t"<<avg<<"\n";
};
class sports
public:
int h,w;
void getsports()
cin>>h;
cin>>w;
void dis()
else
34
cout<<"\n\t\tYOU ARE NOT ELIGIBLE TO BE A SPORTS MAN";
};
public:
void call()
calc();
getsports();
void show()
display();
dis();
};
void main()
int ch,x,n;
stud s[10];
clrscr();
35
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~";
cin>>n;
do
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~";
cout<<"\n\t\tOPTION";
cout<<"\n\t\t1-GET DETAILS";
cout<<"\n\t\t2-DISPLAY";
cin>>ch;
switch(ch)
case 1:
cout<<"\n\t\tINPUT";
cout<<"\n\t\t-----\n";
for(int i=1;i<=n;i++)
cout<<"\n\t\t"<<i<<"ITH STUDENT";
s[i].call();
36
}
break;
case 2:
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t------\n";
for(i=1;i<=n;i++)
s[i].show();
break;
cin>>x;
}while(x==1);
getch();
STUDENT DETAILS
37
~~~~~~~ ~~~~~~~
STUDENT DETAILS
~~~~~~~ ~~~~~~~
OPTION
1-GET DETAILS
2-DISPLAY
INPUT
-----
1ITH STUDENT
38
ENTER YOUR HEIGHT (IN cm) =174
STUDENT DETAILS
~~~~~~~ ~~~~~~~
OPTION
1-GET DETAILS
2-DISPLAY
OUTPUT
------
30 KIRUBHA 88 87 89 88 352 88
Ex:No:
Date:
FINDING FACTORIAL
39
Aim:
To write a c++ program, to print the factorial number for the given input.
Algorithm:
Inside the main function create the object for the class.
40
Thus the program to be terminated.
Coding:
#include"iostream.h"
#include"conio.h"
class fact
public:
int i,n;
void get()
fa=1;
cout<<"\n\t\t\tFACTORIAL";
cout<<"\n\t\t\t~~~~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>n;
for(i=1;i<=n;i++)
41
fa=fa*i;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
};
void main()
fact f;
clrscr();
f.get();
getch();
FACTORIAL
~~~~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
42
FACTORIAL VALUE =720
Ex:No:
Date:
Aim:
To write a c++ program , to display the interest and total amount for given
input.
Algorithm:
43
Using the values to display the simple interest and total amount.
Inside the main function create the object for the class.
Coding:
#include"iostream.h"
#include"conio.h"
class si
public:
int y;
float p,r,ns,d;
void simpleinter()
cin>>p;
44
cout<<"\n\t\tENTER THE INTEREST RATE =";
cin>>r;
cin>>y;
void cal()
d=(p*y*r)/10;
ns=p+d;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
};
void main()
si s;
clrscr();
cout<<"\n\t\t\tSIMPLE INTEREST";
cout<<"\n\t\t\t~~~~~~ ~~~~~~~~";
cout<<"\n\t\tINPUT";
45
cout<<"\n\t\t~~~~~\n";
s.simpleinter();
s.cal();
getch();
SIMPLE INTEREST
~~~~~~ ~~~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
46
Ex:No:
Date:
ARMSTRONG NUMBER
Aim:
Algorithm:
To start a program.
To get the value for n,store it in n1 and check the value in while
loop.
To store a value in s.
47
To Check n1 and s values, if it is equal(n1==s) means it's a
ARMSRTONG
(or) not ARMSRTONG number.
Coding:
#include<iostream.h>
#include<conio.h>
#include<math.h>
class arms
public:
int n,t,s,d;
void cal()
s=0;
d=0;
cout<<"\n\t\t\tARMSTRONG NUMBER";
cout<<"\n\t\t\t~~~~~~~~~ ~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
48
cin>>n;
t=n;
while(n>0)
d=n%10;
s=s+pow(d,3);
n=n/10;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
if(s==t)
else
};
void main()
arms a;
clrscr();
a.cal();
getch();
49
}
ARMSTRONG NUMBER
~~~~~~~~~ ~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
50
Ex:No
Date:
PALINDROME CHECKING
Aim:
To write a C++ program for check wheather the given string palindrome or not.
Algorithm:
o Inside the class, declare the variables and member function for get
the string, comparing the string and display the result.
o Inside of the pal( ), get the input string , compare the string and its
reverse using string comparing function.
o Here create the object as ‘p’ and call the functions using dot
operator.
CODING:
#include<iostream.h>
#include<conio.h>
#include<string.h>
class palin
public:
char s[38],a[10],b[10];
void pal()
cout<<"\n\t\t\tPALINDROME CHECKING";
cout<<"\n\t\t\t~~~~~~~~~~ ~~~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
52
cin>>s;
strcpy(a,s);
strrev(a);
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
if(strcmp(a,s)==0)
else
};
void main()
palin p;
clrscr();
p.pal();
getch();
} PALINDROME CHECKING
~~~~~~~~~~ ~~~~~~~~
INPUT
~~~~~
53
OUTPUT
------
Ex:No:
Date:
Aim:
To write a cpp program to convert the given binary number into decimal number
Algorithm:
54
Using object call the function and finally display the result
Coding:
#include<iostream.h>
#include<conio.h>
#include<math.h>
class binary
public:
binary()
f=k=i=0;
void cal()
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
n=b;
while(n>0)
r=n%10;
if(r==0 || r==1)
k++;
n=n/10;
f++;
n=0;
i=0;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
if(f==k)
while(b>0)
r=b%10;
n=n+(r*(pow(2,i)));
56
i=i+1;
b=b/10;
else
};
void main()
binary b1;
clrscr();
b1.cal();
getch();
INPUT
57
OUTPUT
Ex:No:
Date:
ADAM NUMBER
Aim:
Algorithm:
58
If the given number is equal to resultant number, it is considered as
ADAM and display the given number.
Coding:
#include<iostream.h>
#include<conio.h>
#include<math.h>
class adam
public:
int n,n1,s,r,f,ro;
void cal()
cout<<"\n\t\t\tADAM NUMBER";
cout<<"\n\t\t\t~~~~ ~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>n;
cout<<"\n\t\tOUTPUT";
59
cout<<"\n\t\t~~~~~~\n";
n1=n;
s=n*n;
f=0;
while(s>0)
r=s%10;
f=(f*10)+r;
s=s/10;
ro=sqrt(f);
f=0;
while(ro>0)
r=ro%10;
f=(f*10)+r;
ro=ro/10;
60
if(n1==f)
else
};
void main()
adam a;
clrscr();
a.cal();
getch();
ADAM NUMBER
~~~~ ~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
61
THE SQUARE VALUE =144
62
Ex:No:
Date:
OPERATOR OVERLOADING
Aim:
Algorithm:
63
To display the addition values.
Coding:
#include<iostream.h>
#include<conio.h>
class complex
public:
float y;
int x;
complex(){}
x=ima;
y=real;
complex operator+(complex);
void disp(void);
64
};
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
void complex::disp()
void main()
int a;
float b;
clrscr();
cout<<"\n\t\t\tOPERATOR OVERLOADING";
cout<<"\n\t\t\t~~~~~~~~ ~~~~~~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
65
cout<<"\n\t\tENTER THE INTEGER NUMBER =";
cin>>a;
cin>>b;
complex c1(a,b);
cin>>a;
cin>>b;
complex c2(a,b),c3;
c3=c1+c2;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
c1.disp();
c2.disp();
cout<<"\n\t\tADDITION RESULT\n";
c3.disp();
getch();
66
OPERATOR OVERLOADING
~~~~~~~~ ~~~~~~~~~~~
INPUT
~~~~~
OUTPUT
~~~~~~
67
X =12
Y =+j1.2
X =1
Y =+j1.2
ADDITION RESULT
X =13
Y =+j2.4
68
Ex:No:
Date:
Aim:
Algorithm:
Declare the derived class and inherit the properties of the base
class.
Inside the main function, create the object for derived class.
Using this object, we call the function of both base class and derived class.
69
End.
Coding
#include<iostream.h>
#include<conio.h>
class base
public:
int h,w,rn;
char na[30],g[20];
void getdata()
cin>>rn;
cin>>na;
cin>>g;
70
cin>>h;
cin>>w;
};
public:
void display()
cout<<"\n\t\t"<<rn<<"\t"<<na<<"\t"<<g<<"\t"<<h<<"\t"<<w;
};
void main()
int i,ch,n;
clrscr();
derived s[10];
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~";
cin>>n;
71
do
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~";
cout<<"\n\t\tOPTION";
cout<<"\n\t\t1-GET DETAILS";
cout<<"\n\t\t2-DISPLAY";
cout<<"\n\t\t3-EXIT";
cin>>ch;
switch(ch)
case 1:
for(i=1;i<=n;i++)
s[i].getdata();
break;
case 2:
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t------";
72
cout<<"\n\t\tROLL_NO NAMEGENDER HEIGHT WEIGHT\n";
for(i=1;i<=n;i++)
s[i].display();
break;
}while(ch<3);
getch();
STUDENT DETAILS
~~~~~~~ ~~~~~~~
OPTION
1-GET DETAILS
2-DISPLAY
3-EXIT
73
ENTER YOUR NAME =KIRUBHA
STUDENT DETAILS
~~~~~~~ ~~~~~~~
OPTION
1-GET DETAILS
2-DISPLAY
3-EXIT
74
Ex:No
Date:
Aim:
algorithm
3. Create class as single with public access specifier and declared variables
name co,g,as char, rn,s,a as int, height and weight as float data types.
4. Get the input values in the base class using the member function.
void getdata()
6. Inherit all the variables and member functions from the base class into
void display()
75
8. In main function, Declare the object for the derived class financial_assit
Coding:
#include<iostream.h>
#include<conio.h>
class basic_info
public:
int rn;
char na[30],g[6];
};
class academic_fit
public:
char co[10];
int s,r,a;
};
public:
void getdata()
76
cout<<"\n\t\tENTER YOUR ROLL NUMBER =";
cin>>rn;
cin>>na;
cin>>g;
cin>>co;
cin>>s;
cin>>r;
cin>>a;
void display()
""<<r<<"\t"<<a;
};
void main()
int ch,n;
77
clrscr();
financial_assit S[10];
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~";
cin>>n;
clrscr();
do
cout<<"\n\t\t\tSTUDENT DETAILS";
cout<<"\n\t\t\t~~~~~~~ ~~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cout<<"\n\t\tOPTION";
cout<<"\n\t\t1-GET DETAILS";
cout<<"\n\t\t2-DISPLAY";
cout<<"\n\t\t3-EXIT";
cin>>ch;
switch(ch)
case 1:
for(int i=1;i<=n;i++)
78
S[i].getdata();
break;
case 2:
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
" S.AMOUNT";
for(i=1;i<=n;i++)
S[i].display();
break;
}while(ch<3);
getch();
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
OPTION
1-GET DETAILS
2-DISPLAY
79
3-EXIT
STUDENT DETAILS
~~~~~~~ ~~~~~~~
INPUT
~~~~~
OPTION
1-GET DETAILS
2-DISPLAY
3-EXIT
OUTPUT
~~~~~~
80
Ex:No:
Date:
NUMBER DISPLAYING
Aim:
Algorithm:
81
To change the initial value of the loop variable we can change the
displaying format
Coding:
#include"iostream.h"
#include"conio.h"
void main()
int n,i,j;
clrscr();
cout<<"\n\t\t\tNUMBER DISPLAYING";
cout<<"\n\t\t\t~~~~~~ ~~~~~~~~~~";
cout<<"\n\t\tINPUT";
cout<<"\n\t\t~~~~~\n";
cin>>n;
cout<<"\n\t\tOUTPUT";
cout<<"\n\t\t~~~~~~\n";
cout<<"\n\t\tFORMAT - 1\n";
for(i=1;i<=n;i++)
82
for(j=1;j<=i;j++)
cout<<"\t"<<j;
cout<<"\n";
cout<<"\n\t\tFORMAT - 2\n";
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
cout<<"\t"<<i;
cout<<"\n";
cout<<"\n\t\tFORMAT - 3\n";
for(i=0;i<=n-1;i++)
for(j=0;j<=i;j++)
cout<<"\t"<<(n-j);
83
cout<<"\n";
getch();
NUMBER DISPLAYING
~~~~~~ ~~~~~~~~~~
FORMAT - 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
FORMAT - 2
2 2
3 3 3
4 4 4 4
5 5 5 5 5
FORMAT - 3
84
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Ex:No
Date:
Aim :
Algorithm:
85
Create () function is used to create a linked list.
Coding:
#include"iostream.h"
#include"conio.h"
class tree
public:
int num,l,c;
struct node
int info;
node *next;
}*head,*nn,*temp,*p;
tree()
86
{
head=NULL;
c=0;
void allo()
nn=new node;
cin>>num;
nn->info=num;
nn->next=NULL;
void create()
allo();
if(head==NULL)
head=nn;
else
temp=head;
87
while(temp->next!=NULL)
temp=temp->next;
temp->next=nn;
void insend()
create();
void delmid()
int c2=1;
if(head==NULL)
head=nn;
else
88
cin>>l;
temp=head;
while(temp->next!=NULL)
c2++;
if(c2==l)
temp->next=temp->next->next;
else
temp=temp->next;
void dis()
cout<<"\n\t\thai..";
if(head==NULL)
89
cout<<"\n\t\tLIST IS EMPTY..";
else
temp=head;
while(temp->next!=NULL)
cout<<" :"<<temp->info<<":";
temp=temp->next;
cout<<" :"<<temp->info<<":";
void search()
int f=0;
if(head==NULL)
cout<<"\n\t\tLIST IS EMPTY";
else
90
cout<<"\n\t\tENTER THE NUMBER TO SEARCH =";
cin>>num;
temp=head;
do
if(temp->info==num)
f=1;
goto k;
else
temp=temp->next;
}while(temp->next!=NULL);
if(temp->info==num)
f=1;
k:
if(f==1)
91
{
else
};
void main()
clrscr();
int ch;
tree t;
do
cout<<"\n\t\tOPTION";
cout<<"\n\t\t1-CREATING";
cout<<"\n\t\t2-INSERT";
cout<<"\n\t\t3-DELETE";
92
cout<<"\n\t\t4-DISPLAY";
cout<<"\n\t\t5-SEARCH";
cout<<"\n\t\t6-EXIT";
cin>>ch;
switch(ch)
case 1:
t.create();
break;
case 2:
t.insbeg();
break;
case 3:
t.delmid();
break;
case 4:
t.dis();
break;
case 5:
t.search();
break;
93
}
}while(ch<11);
getch();
OPTION
1-CREATING
2-INSERT
3-DELETE
4-DISPLAY
5-SEARCH
6-EXIT
|1||2||3||4||5|
|1||2||4||5|
94
ENTER THE POSITION TO INSERT AND ITEM =3 30
| 1 | | 2 | | 3 0| | 4 | | 5 |
Ex:No
Date:
Aim :
Algorithm:
95
Display1 () function is used to display the content of list in forword.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct node
int data;
};
class slink
public:
int item,x,ch,i,ctr,pos;
public:
void create();
void insert();
96
void delet();
void display1();
void display2();
};
void slink::create()
head=ptr=NULL;
do
cin>>item;
n->data=item;
n->prev=NULL;
n->next=NULL;
if(head==NULL)
head=n;
else
ptr->next=n;
n->prev=ptr;
97
ptr=n;
ctr++;
cin>>i;
}while(i==1);
void slink::insert()
cin>>item;
cin>>pos;
n->data=item;
n->prev=NULL;
n->next=NULL;
if((pos<=0)||(pos>ctr+1))
return;
else if(pos==1)
98
{
n->prev=NULL;
n->next=head;
head=n;
else if(pos==ctr+1)
ptr->next=n;
n->next=NULL;
n->prev=ptr;
ptr=n;
else
p=head;
for(i=1;i<pos-1;i++)
p=p->next;
n->next=p->next;
p->next->prev=n;
n->prev=p;
p->next=n;
99
ctr++;
void slink::delet()
cin>>pos;
if((pos<=0)||(pos>ctr))
if(pos==1)
head=head->next;
else
p=head;
for(i=1;i<pos-1;i++)
p=p->next;
q=p->next;
p->next=q->next;
q->next->prev=p;
100
}
ctr--;
void slink::display1()
traverse=head;
while(traverse!=NULL)
cout<<traverse->data<<"<==>";
traverse=traverse->next;
cout<<"NULL";
void slink::display2()
traverse=ptr;
while(traverse!=NULL)
cout<<traverse->data<<"<==>";
traverse=traverse->prev;
cout<<"NULL";
101
}
void main()
slink s;
clrscr();
int ch,x;
lx:
cout<<"\n\t\tOPTION";
cout<<"\n\t\t1.CREATION";
cout<<"\n\t\t2.INSERTION";
cout<<"\n\t\t3.DELETION";
cout<<"\n\t\t4.FORWARD DISPLAY";
cout<<"\n\t\t5.BACKWARD DISPLAY";
cout<<"\n\t\t6.EXIT";
cin>>ch;
switch(ch)
case 1:
s.create();
102
break;
case 2:
s.insert();
break;
case 3:
s.delet();
break;
case 4:
s.display1();
break;
case 5:
s.display2();
break;
case 6:
exit(0);
break;
cin>>x;
if(x==1)
goto lx;
else
103
getch();
OPTION
1-CREATING
2-INSERT
3-DELETE
4- DISPLAY1
5- DISPLAY2
6-EXIT
|1||2||4||5|
| 1 | | 2 | | 3 0| | 4 | | 5 |
| 5 | | 4 | | 3 0| | 2 | | 1 |
104
Ex:No:
Date:
Algorithm:
3. Declare three variables inside the structure such as info, left and right.
7. The cnt () function is used to count the number of list in a linked list.
10.To know how many nodes are in a list we have to call the cnt ()
function.
105
11.To exit the program.
106
#include"iostream.h"
#include"conio.h"
class count
public:
int num;
struct node
int info;
node *next;
}*head,*nn,*temp;
count()
head=NULL;
void allo()
nn=new node;
cin>>num;
nn->info=num;
nn->next=NULL;
107
}
void create()
allo();
if(head==NULL)
head=nn;
else
temp=head;
while(temp->next!=NULL)
temp=temp->next;
temp->next=nn;
void cnt()
int c=1;
if(head==NULL)
108
{
cout<<"\n\t\tLIST IS EMPTY";
else
temp=head;
while(temp->next!=NULL)
c++;
temp=temp->next;
};
void main()
clrscr();
count C;
int ch;
do
109
cout<<"\n\t\t1-CREATE";
cout<<"\n\t\t2-COUNT";
cout<<"\n\t\t3-EXIT";
cin>>ch;
switch(ch)
case 1:
C.create();
break;
case 2:
C.cnt();
break;
}while(ch<3);
getch();
110
OUTPUT
1-CREATE
2-COUNT
3-EXIT
111
112