You are on page 1of 112

Ex:No

Date:

ADDING TWO NUMBERS USING INCREMENT OPERATOR

Aim:

To write a c++ program to add two numbers without using Arithmetic


operators.(Using Increment operator)

Algorithm:

 Start the program.

 In main function, declare necessary variables.

 Get two numbers a and b from user .

 Using for loop, increment the a value until a<=b.

 Print the a value.

 Stop the program.

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";

cout<<"\n\t\tENTER THE A VAULE =";

cin>>a;

cout<<"\n\t\tENTER THE B VAULE =";

cin>>b;

cout<<"\n\t\tOUTPUT";

cout<<"\n\t\t~~~~~~\n";

cout<<"\n\t\tA Value ="<<a;

cout<<"\n\t\tB Value ="<<b<<"\n";

for(int i=1;i<=b;i++)

2
{

a++;

cout<<"\n\t\tTHE RESULT ="<<a;

getch();

ADDITION OPERATION

~~~~~~~~ ~~~~~~~~~

INPUT

~~~~~

ENTER THE A VAULE =32

ENTER THE B VAULE =12

OUTPUT

~~~~~~

A Value =32

B Value =12

THE RESULT =44

3
Ex:No

Date:

DISPLAYING EMPLOYEE DETAILS

Aim:

To write c++ program to display the Emloyee details using class.

Algorithm:

 Start the program.

 Declare the class name as employee.

 Inside the class, declare the function name as getdata() and

 In getdata(), get the employee details from the user and in

 Putdata show employee details.

 Inside the main function create object as emp for class.

 Using object call the function.

 Stop the program.

4
CODING:

#include"iostream.h"

#include"conio.h"

class emp

public:

int no;

char na[30],d[20];

float sa;

void getdata();

void display();

};

void emp :: getdata()

cout<<"\n\t\tENTER YOUR EMP. NUMBER =";

cin>>no;

cout<<"\n\t\tENTER YOUR NAME =";

cin>>na;

cout<<"\n\t\tENTER YOUR DESIG NATION =";

cin>>d;

cout<<"\n\t\tENTER YOUR SALARY =";

cin>>sa;

5
}

void emp :: display()

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";

cout<<"\n\t\tENTER THE LIMIT =";

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";

cout<<"\n\t\tENTER YOUR CHOICE =";

cin>>ch;

switch(ch)

case 1:

for(i=1;i<=l;i++)

cout<<"\n\t\tEmp. Details No ="<<i<<"\n";

e.getdata();

break;

case 2:

cout<<"\n\t\tNO NAME DESIGNATION SALARY";

for(i=1;i<=l;i++)

e.display();

break;

7
}while(ch<3);

getch();

EMPLOYEE DETAILS

~~~~~~~~ ~~~~~~~

INPUT

~~~~~

ENTER THE LIMIT =1

EMPLOYEE DETAILS

~~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET EMP DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =1

Emp. Details No =1

ENTER YOUR EMP. NUMBER =67

ENTER YOUR NAME =KIRUBHA

ENTER YOUR DESIGNATION =SOFTWARE

8
ENTER YOUR SALARY =12000

EMPLOYEE DETAILS

~~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET EMP DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =2

NO NAME DESIGNATION SALARY

67 KIRUBHA SOFTWARE 12000

EMPLOYEE DETAILS

~~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET EMP DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =3

9
Ex:No

Date:

DISPLAYING STUDENT DETAILS

Aim:

To write a c++ program for to print the student details

Algorithm:

 To create a class first with name stud.

 Initialize a class variables an member functions .

 We have three member functions to display the student details.

 Getdata() function is used to get the student details.

 Function cal() which is used to calculate the total and average.

 Function display() which is used to display the student details.

 To invoke a class member we use the object named as S.

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();

};

void stud :: getdata()

cout<<"\n\t\tENTER YOUR REG. NUMBER =";

cin>>no;

cout<<"\n\t\tENTER YOUR NAME =";

cin>>na;

cout<<"\n\t\tENTER THE CPP MFC MARK =";

cin>>m1;

cout<<"\n\t\tENTER THE DBMS MARK =";

11
cin>>m2;

cout<<"\n\t\tENTER THE CPP MARK =";

cin>>m3;

cout<<"\n\t\tENTER THE CO MARK =";

cin>>m4;

void stud :: cal()

t=m1+m2+m3+m4;

avg=t/4;

void stud :: display()

cal(); // to call the cal function

cout<<"\n\t\t"<<no<<"\t"<<na<<"\t "<<m1<<"\t "<<m2<<"\t "

" "<<m3<<"\t "<<m4<<"\t "<<t<<"\t "<<avg;

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";

cout<<"\n\t\tENTER THE LIMIT =";

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\t1-GET STUD. DETAILS";

cout<<"\n\t\t2-DISPLAY";

cout<<"\n\t\t3-EXIT\n";

cout<<"\n\t\tENTER YOUR CHOICE =";

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:

cout<<"\n\t\tNO NAMEMFC DBMSCPP "

" CO TOTAL AVERAGE";

for(i=1;i<=l;i++)

e[i].display();

break;

}while(ch<3);

getch();

STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

ENTER THE LIMIT =2

14
STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET STUD. DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =1

Stud. Details No =1

ENTER YOUR REG. NUMBER =67

ENTER YOUR NAME =kirubha

ENTER THE CPP MFC MARK =78

ENTER THE DBMS MARK =89

ENTER THE CPP MARK =87

ENTER THE CO MARK =89

Stud. Details No =2

ENTER YOUR REG. NUMBER =66

ENTER YOUR NAME =jegan

ENTER THE CPP MFC MARK =45

ENTER THE DBMS MARK =56

ENTER THE CPP MARK =67

ENTER THE CO MARK =78

15
STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET STUD. DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =2

NO NAME MFC DBMS CPP CO TOTAL AVERAGE

67 kirubha 78 89 87 89 343 85

66 jegan 45 56 67 78 246 61

STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET STUD. DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =3

16
Ex:No:

Date:

IMPLEMENTION OF SINGLE INHERITANCE

Aim:

To write a program to implement the single-Inheritance.

Algorithm:

Start the program.

Include the necessary header files.

Define the base class.

Declare the variables and member function in the base class.

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();

};

class stud : public base

public:

char g[7];

void cal();

18
void display();

};

void base :: getdata()

cout<<"\n\t\tENTER YOUR REG. NUMBER =";

cin>>no;

cout<<"\n\t\tENTER YOUR NAME =";

cin>>na;

cout<<"\n\t\tENTER THE CPP MFC MARK =";

cin>>m1;

cout<<"\n\t\tENTER THE DBMS MARK =";

cin>>m2;

cout<<"\n\t\tENTER THE CPP MARK =";

cin>>m3;

cout<<"\n\t\tENTER THE CO MARK =";

cin>>m4;

void stud :: cal()

t=m1+m2+m3+m4;

avg=t/4;

19
void stud :: display()

cal(); // to call the cal function

cout<<"\n\t"<<no<<"\t"<<na<<"\t "<<m1<<"\t "<<m2<<"\t "

" "<<m3<<"\t "<<m4<<"\t "<<t<<"\t "<<avg;

if(avg>80)

cout<<"\tA Grade";

else if(avg<80 && avg>75)

cout<<"\tB Grade";

else if(avg<75 && avg>60)

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";

cout<<"\n\t\tENTER THE LIMIT =";

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\t1-GET STUD. DETAILS";

cout<<"\n\t\t2-DISPLAY";

cout<<"\n\t\t3-EXIT\n";

cout<<"\n\t\tENTER YOUR CHOICE =";

cin>>ch;

switch(ch)

case 1:

for(i=1;i<=l;i++)

cout<<"\n\t\tStud. Details No ="<<i<<"\n";

e[i].getdata();

21
break;

case 2:

cout<<"\n\tNO NAMEMFC DBMSCPP "

" CO TOTAL AVERAGE GRADE";

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

~~~~~

1-GET STUD. DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =1

Stud. Details No =1

ENTER YOUR REG. NUMBER =67

ENTER YOUR NAME =KIRUBHA

ENTER THE CPP MFC MARK =78

ENTER THE DBMS MARK =89

ENTER THE CPP MARK =98

ENTER THE CO MARK =87

STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

23
1-GET STUD. DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =2

NO NAME MFC DBMS CPP CO TOTAL AVERAGE GRADE

67 KIRUBHA 78 89 98 87 352 88 A

STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

1-GET STUD. DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =3

24
Ex:No:

Date:

IMPLEMENTION OF MULTILEVEL INHERITANCE

Aim:

To write a C++ program to implement the Multi-level inheritance.

Algorithm:

a. Start the program.

b. Define the base class.

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.

e. Declare and define another derived class to inherit the properties of


both base class and derived 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
};

class get : public date1

public:

int d,m,y,td,tm,ty;

void getdata()

cout<<"\n\t\tINPUT";

cout<<"\n\t\t~~~~~\n";

cout<<"\n\t\tENTER THE DAY OF YOUR DOB =";

cin>>d;

cout<<"\n\t\tENTER THE MONTH OF YOUR DOB =";

cin>>m;

cout<<"\n\t\tENTER THE YEAR OF YOUR DOB =";

cin>>y;

void cal()

if(yy>=y)

td=abs(dd-d);

tm=abs(mm-m);

27
ty=abs(yy-y);

else

cout<<"\n\t\tENTER THE CORRECT DATE OF BIRTH..";

getdata();

};

class age : public get

public:

void display()

getdata();

cal();

cout<<"\n\t\tOUTPUT";

cout<<"\n\t\t~~~~~~\n";

cout<<"\n\t\tYour Age ="<<ty<<"\t Month ="<<tm<<"\t Day ="<<ty;

};

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

~~~~~

ENTER THE DAY OF YOUR DOB =22

ENTER THE MONTH OF YOUR DOB =6

ENTER THE YEAR OF YOUR DOB =1990

OUTPUT

~~~~~~

Your Age =20 Month =5 Day =20

30
Ex:No:

Date:

IMPLEMENTATION HYBRID INHERITANCE

Aim:

To write a c++ program for implementing the Hybrid Inheritance.

Algorithm:

 To create a class with name init and initialize all variables which belongs
to details of student.

 Initialize a class get to get the details of student.

 Getdata() function is used to get the student details.

 Display() function is used to display all 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.

 To invoke stud class we declare an object called as s.

Coding:

#include"iostream.h"

#include"conio.h"

class init

public:

int reg,m1,m2,m3,m4;

char name[20];

};

class get : public init

public:

void getdata()

cout<<"\n\t\tENTER YOUR ROLL NUMBER =";

cin>>reg;

cout<<"\n\t\tENTER YOUR NAME =";

32
cin>>name;

cout<<"\n\t\tENTER YOUR MFC MARK =";

cin>>m1;

cout<<"\n\t\tENTER YOUR DBMS MARK =";

cin>>m2;

cout<<"\n\t\tENTER YOUR CO MARK =";

cin>>m3;

cout<<"\n\t\tENTER YOUR CPP MARK =";

cin>>m4;

};

class cal : public get

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()

cout<<"\n\t\tENTER YOUR HEIGHT (IN cm) =";

cin>>h;

cout<<"\n\t\tENTER YOUR WEIGHT =";

cin>>w;

void dis()

if(h>=165 && w>=60)

cout<<"\n\t\tYOU ARE ELIGIBLE TO BE A SPORTS MAN";

else

34
cout<<"\n\t\tYOU ARE NOT ELIGIBLE TO BE A SPORTS MAN";

};

class stud : public cal,sports

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~~~~~~~ ~~~~~~~";

cout<<"\n\t\tENTER THE LIMIT =";

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";

cout<<"\n\t\tENTER YOUR CHOICE =";

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";

cout<<"\n\t\tREG.NO NAMEMFC DBMSCO CPP"

" TOTAL AVG";

for(i=1;i<=n;i++)

s[i].show();

break;

cout<<"\n\t\tDO U WANT TO CONTINUE THIS PROGRAM AGAIN THEN


PRESS->1 =";

cin>>x;

}while(x==1);

getch();

STUDENT DETAILS

37
~~~~~~~ ~~~~~~~

ENTER THE LIMIT =1

STUDENT DETAILS

~~~~~~~ ~~~~~~~

OPTION

1-GET DETAILS

2-DISPLAY

ENTER YOUR CHOICE =1

INPUT

-----

1ITH STUDENT

ENTER YOUR ROLL NUMBER =30

ENTER YOUR NAME =KIRUBHA

ENTER YOUR MFC MARK =88

ENTER YOUR DBMS MARK =87

ENTER YOUR CO MARK =89

ENTER YOUR CPP MARK =88

38
ENTER YOUR HEIGHT (IN cm) =174

ENTER YOUR WEIGHT =65

DO U WANT TO CONTINUE THIS PROGRAM AGAIN THEN PRESS->1 =1

STUDENT DETAILS

~~~~~~~ ~~~~~~~

OPTION

1-GET DETAILS

2-DISPLAY

ENTER YOUR CHOICE =2

OUTPUT

------

REG.NO NAME MFC DBMS CO CPP TOTAL AVG

30 KIRUBHA 88 87 89 88 352 88

YOU ARE ELIGIBLE TO BE A SPORTS MAN

DO U WANT TO CONTINUE THIS PROGRAM AGAIN THEN PRESS->1 =NO

Ex:No:

Date:

FINDING FACTORIAL

39
Aim:

To write a c++ program, to print the factorial number for the given input.

Algorithm:

 Start the program.

 Include the header files.

 Declare the base class as fact.

 Inside the class declare the variables and functions to

calculate the factorial value for the given number.

 Display the factorial value.

 Inside the main function create the object for the class.

 Using this object call the member functions of the class.

40
 Thus the program to be terminated.

Coding:

#include"iostream.h"

#include"conio.h"

class fact

public:

int i,n;

long int fa;

void get()

fa=1;

cout<<"\n\t\t\tFACTORIAL";

cout<<"\n\t\t\t~~~~~~~~~";

cout<<"\n\t\tINPUT";

cout<<"\n\t\t~~~~~\n";

cout<<"\n\t\tENTER THE NUMBER TO FIND FACTORIAL VALUE =";

cin>>n;

for(i=1;i<=n;i++)

41
fa=fa*i;

cout<<"\n\t\tOUTPUT";

cout<<"\n\t\t~~~~~~\n";

cout<<"\n\t\tFACTORIAL VALUE ="<<fa;

};

void main()

fact f;

clrscr();

f.get();

getch();

FACTORIAL

~~~~~~~~~

INPUT

~~~~~

ENTER THE NUMBER TO FIND FACTORIAL VALUE =6

OUTPUT

~~~~~~

42
FACTORIAL VALUE =720

Ex:No:

Date:

SIMPLE INTEREST CALCULATING

Aim:

To write a c++ program , to display the interest and total amount for given
input.

Algorithm:

 Start the program.

 Include the header files.

 Declare the class as interest.

 Inside the class declare the variables and functions .

 Get values for the variable principle, n, number of rate.

43
 Using the values to display the simple interest and total amount.

 Inside the main function create the object for the class.

 Using this object call the member functions of the class.

 Thus the program to be terminated.

Coding:

#include"iostream.h"

#include"conio.h"

class si

public:

int y;

float p,r,ns,d;

void simpleinter()

cout<<"\n\t\tENTER THE PRINCIPLE AMOUNT =";

cin>>p;

44
cout<<"\n\t\tENTER THE INTEREST RATE =";

cin>>r;

cout<<"\n\t\tENTER THE YEAR =";

cin>>y;

void cal()

d=(p*y*r)/10;

ns=p+d;

cout<<"\n\t\tOUTPUT";

cout<<"\n\t\t~~~~~~\n";

cout<<"\n\t\tPRI_AMOUNT INTEREST_RATE YEAR NET SALARI";

cout<<"\n\t\t"<<p<<"\t\t "<<r<<"\t\t"<<y<<"\t "<<ns;

};

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

~~~~~

ENTER THE PRINCIPLE AMOUNT =15000

ENTER THE INTEREST RATE =2.4

ENTER THE YEAR =6

OUTPUT

~~~~~~

PRI_AMOUNT INTEREST_RATE YEAR NET SALARI

15000 2.4 6 36600.00

46
Ex:No:

Date:

ARMSTRONG NUMBER

Aim:

To write a program in C++ for "Armstrong Number".

Algorithm:

 To start a program.

 To declare the variables n,t,s,r.

 To get the value for n,store it in n1 and check the value in while
loop.

 To mod the n value by 10 and store it in r.

 Initialize s=0.Cube the value of r and add the variable of s value


with r.

 To store a value in s.

 To divide a n value by 10.Store it in n.

47
 To Check n1 and s values, if it is equal(n1==s) means it's a
ARMSRTONG
(or) not ARMSRTONG number.

 To compile & run the program and display the result.

 End the program.

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";

cout<<"\n\t\tENTER THE NUMBER :" ;

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)

cout<<"\n\t\tTHE GIVEN NUMBER IS ARMSTRONG";

else

cout<<"\n\t\tTHE GIVEN NUMBER IS NOT ARMSTRONG";

};

void main()

arms a;

clrscr();

a.cal();

getch();

49
}

ARMSTRONG NUMBER

~~~~~~~~~ ~~~~~~

INPUT

~~~~~

ENTER THE NUMBER :153

OUTPUT

~~~~~~

THE GIVEN NUMBER IS ARMSTRONG

50
Ex:No

Date:

PALINDROME CHECKING

Aim:

To write a C++ program for check wheather the given string palindrome or not.

Algorithm:

o Start the program with header files.

o Create the class in the name of palin.

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 Inside of the pal ( ), display the result of the comparison whether


given string is palindrome or not.
51
o Create main ( ) function and invoke the member functions using the
object of the class.

o Here create the object as ‘p’ and call the functions using dot
operator.

o End the program using getch ( ) function.

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";

cout<<"ENTER THE STRING =:";

52
cin>>s;

strcpy(a,s);

strrev(a);

cout<<"\n\t\tOUTPUT";

cout<<"\n\t\t~~~~~~\n";

if(strcmp(a,s)==0)

cout<<"THE GIVEN STRING IS PALINDROME";

else

cout<<"THE GIVEN STRING IS NOT PALINDROME";

};

void main()

palin p;

clrscr();

p.pal();

getch();

} PALINDROME CHECKING

~~~~~~~~~~ ~~~~~~~~

INPUT

~~~~~

ENTER THE NAME =AMMA

53
OUTPUT

------

THE GIVEN STRING IS PALINDROME

Ex:No:

Date:

BINARY TO DECIMAL CONVERSION

Aim:

To write a cpp program to convert the given binary number into decimal number

Algorithm:

 Start the program.

 Declare a class name as Binary.


Check whether the condition is true.then separate

 binary digit and multiply with two to the power of i value.

 Increment the i value.

 Loop will executed until the condition is satisfied.

 Inside the main function create object for class binary.

54
 Using object call the function and finally display the result

 Stop the program.

Coding:

#include<iostream.h>

#include<conio.h>

#include<math.h>

class binary

public:

long int b,r,f,k,i,n;

binary()

f=k=i=0;

void cal()

cout<<"\n\t\t\tBINARY TO DICIMAL CONVERSION";

cout<<"\n\t\t\t~~~~~~ ~~ ~~~~~~~ ~~~~~~~~~~";

cout<<"\n\t\tINPUT";

cout<<"\n\t\t~~~~~\n";

cout<<"\n\t\tENTER THE BINARY NUMBER =";


55
cin>>b;

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;

cout<<"\n\t\tTHE CORRESPONDING DECIMAL VALUE ="<<n;

else

cout<<"\n\t\tBINARY CONVERSION IS NOT POSIBLE..";

};

void main()

binary b1;

clrscr();

b1.cal();

getch();

BINARY TO DICIMAL CONVERSION

~~~~~~ ~~ ~~~~~~~ ~~~~~~~~~~

INPUT

ENTER THE BINARY NUMBER =1111

57
OUTPUT

THE CORRESPONDING DECIMAL VALUE =15

Ex:No:

Date:

ADAM NUMBER

Aim:

To write a c++ program to implement ADAM number.

Algorithm:

 Start the process.

 Declare the variable n,n1,r,ro,f as integer.

 Create the following functions void cal()

 Get the value for ‘n’ variable using cal() function.

 Square that number using mathematical operations, reverse it and root it


finally reverse it.

58
 If the given number is equal to resultant number, it is considered as
ADAM and display the given number.

 End the process.

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";

cout<<"\n\t\tENTER THE NUMBER =";

cin>>n;

cout<<"\n\t\tOUTPUT";
59
cout<<"\n\t\t~~~~~~\n";

n1=n;

s=n*n;

cout<<"\n\n\t\tTHE SQUARE VALUE ="<<s;

f=0;

while(s>0)

r=s%10;

f=(f*10)+r;

s=s/10;

cout<<"\n\n\t\tTHE REVERSE VALUE ="<<f;

ro=sqrt(f);

cout<<"\n\n\t\tTHE SQUARE ROOT VALUE ="<<ro;

f=0;

while(ro>0)

r=ro%10;

f=(f*10)+r;

ro=ro/10;

cout<<"\n\n\t\tTHE REVERSE VALUE ="<<f;

60
if(n1==f)

cout<<"\n\n\t\tTHE GIVEN NUMBER IS ADAM";

else

cout<<"\n\n\t\tTHE GIVEN NUMBER IS NOT ADAM";

};

void main()

adam a;

clrscr();

a.cal();

getch();

ADAM NUMBER

~~~~ ~~~~~~

INPUT

~~~~~

ENTER THE NUMBER =12

OUTPUT

~~~~~~

61
THE SQUARE VALUE =144

THE REVERSE VALUE =441

THE SQUARE ROOT VALUE =21

THE REVERSE VALUE =12

THE GIVEN NUMBER IS ADAM

62
Ex:No:

Date:

OPERATOR OVERLOADING

Aim:

To write a program in c++ for adding complex numbers using operator


overloading.

Algorithm:

 Start the program.

 To include the header files.

 To declare the class and declare the operator overloading member


functions.

 To overload the “+” operator to add the complex numbers.

 To create an object in main function .

 Pass the complex numbers to the operator overloading function.

63
 To display the addition values.

 End the program.

Coding:

#include<iostream.h>

#include<conio.h>

class complex

public:

float y;

int x;

complex(){}

complex(int ima,float real)

x=ima;

y=real;

complex operator+(complex);

void disp(void);
64
};

complex complex::operator + (complex c)

complex temp;

temp.x=x+c.x;

temp.y=y+c.y;

return(temp);

void complex::disp()

cout<<"\n\t\tX ="<<x<<"\n\t\tY =+j"<<y<<"\n";

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";

cout<<"\n\t\tINPUT FOR FIRST OBJECT\n";

65
cout<<"\n\t\tENTER THE INTEGER NUMBER =";

cin>>a;

cout<<"\n\t\tENTER THE REAL NUMBER =";

cin>>b;

complex c1(a,b);

cout<<"\n\t\tINPUT FOR SECOND OBJECT\n";

cout<<"\n\t\tENTER THE INTEGER NUMBER =";

cin>>a;

cout<<"\n\t\tENTER THE REAL NUMBER =";

cin>>b;

complex c2(a,b),c3;

c3=c1+c2;

cout<<"\n\t\tOUTPUT";

cout<<"\n\t\t~~~~~~\n";

cout<<"\n\t\tINPUT OF FIRST OBJECT\n";

c1.disp();

cout<<"\n\t\tINPUT OF SECOND OBJECT\n";

c2.disp();

cout<<"\n\t\tADDITION RESULT\n";

c3.disp();

getch();

66
OPERATOR OVERLOADING

~~~~~~~~ ~~~~~~~~~~~

INPUT

~~~~~

INPUT FOR FIRST OBJECT

ENTER THE INTEGER NUMBER =12

ENTER THE REAL NUMBER =1.2

INPUT FOR SECOND OBJECT

ENTER THE INTEGER NUMBER =1

ENTER THE REAL NUMBER =1.2

OUTPUT

~~~~~~

INPUT OF FIRST OBJECT

67
X =12

Y =+j1.2

INPUT OF SECOND OBJECT

X =1

Y =+j1.2

ADDITION RESULT

X =13

Y =+j2.4

68
Ex:No:

Date:

IMPLEMENTION OF SINGLE INHERITANCE

Aim:

To write a program to implement the single-Inheritance.

Algorithm:

 Start the program.

 Include the necessary header files.

 Define the base class.

 Declare the variables and member function in the base class.

 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()

cout<<"\n\t\tENTER YOUR ROLL NUMBER =";

cin>>rn;

cout<<"\n\t\tENTER YOUR NAME =";

cin>>na;

cout<<"\n\t\tENTER YOUR GENDER =";

cin>>g;

cout<<"\n\t\tENTER YOUR HEIGHT (IN c.m) =";

70
cin>>h;

cout<<"\n\t\tENTER YOUR WEIGHT (IN k.g) =";

cin>>w;

};

class derived : public base

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~~~~~~~ ~~~~~~~";

cout<<"\n\t\tENTER THE LIMIT =";

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";

cout<<"\n\t\tENTER YOUR CHOICE =";

cin>>ch;

switch(ch)

case 1:

for(i=1;i<=n;i++)

cout<<"\n\t\t"<<i<<" =ITH NUMBER OF STUDENT";

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();

ENTER THE LIMIT =1

STUDENT DETAILS

~~~~~~~ ~~~~~~~

OPTION

1-GET DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =1

1 =ITH NUMBER OF STUDENT

ENTER YOUR ROLL NUMBER =30

73
ENTER YOUR NAME =KIRUBHA

ENTER YOUR GENDER =MALE

ENTER YOUR HEIGHT (IN c.m) =173

ENTER YOUR WEIGHT (IN k.g) =65

STUDENT DETAILS

~~~~~~~ ~~~~~~~

OPTION

1-GET DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =2

ROLL_NO NAME GENDER HEIGHT WEIGHT

30 KIRUBHA MALE 173 65

74
Ex:No

Date:

DISPLAYING STUDENT DETAILS

Aim:

To write a cpp program for displaying the student details

algorithm

1. Start the process.

2. Include required header file.

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()

5. Derive a new class as derived from single base class.

6. Inherit all the variables and member functions from the base class into

the derived class.

7. Create a new member function and display the values.

void display()

75
8. In main function, Declare the object for the derived class financial_assit

as S, using the object call the member functions.

9. Stop the process.

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;

};

class financial_assit:public basic_info,public academic_fit

public:

void getdata()

76
cout<<"\n\t\tENTER YOUR ROLL NUMBER =";

cin>>rn;

cout<<"\n\t\tENTER YOUR NAME =";

cin>>na;

cout<<"\n\t\tENTER YOUR GENDER =";

cin>>g;

cout<<"\n\t\tENTER YOUR COURSE NAME =";

cin>>co;

cout<<"\n\t\tENTER YOUR SEMESTER =";

cin>>s;

cout<<"\n\t\tENTER YOUR RANK =";

cin>>r;

cout<<"\n\t\tENTER YOUR SEMESTER AMOUNT =";

cin>>a;

void display()

cout<<"\n\t\t"<<rn<<"\t"<<na<<"\t"<<g<<"\t "<<co<<"\t "<<s<<"\t\t"

""<<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~~~~~~~ ~~~~~~~";

cout<<"\n\t\tENTER THE LIMIT =";

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";

cout<<"\n\t\tENTER YOUR CHOICE =";

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";

cout<<"\n\t\tR.NO NAME GENDER COURSE SEMESTER RANK"

" 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

ENTER YOUR CHOICE =1

ENTER YOUR ROLL NUMBER =30

ENTER YOUR NAME =KIRUBHA

ENTER YOUR GENDER =MALE

ENTER YOUR COURSE NAME =MCA

ENTER YOUR SEMESTER =1

ENTER YOUR RANK =1

ENTER YOUR SEMESTER AMOUNT =13000

STUDENT DETAILS

~~~~~~~ ~~~~~~~

INPUT

~~~~~

OPTION

1-GET DETAILS

2-DISPLAY

3-EXIT

ENTER YOUR CHOICE =2

OUTPUT

~~~~~~

R.NO NAME GENDER COURSE SEMESTER RANK S.AMOUNT

30 KIRUBHA MALE MCA 1 1 13000

80
Ex:No:

Date:

NUMBER DISPLAYING

Aim:

To write a c++ program for produce the following output.

Algorithm:

 Start the program

 Declare the variables such as n,I,j as integer

 Get the limit for displaying number format

 There are two for loops are used to displaying a format 1

81
 To change the initial value of the loop variable we can change the
displaying format

 Exit the program

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";

cout<<"\n\t\tENTER THE LIMIT =";

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

~~~~~~ ~~~~~~~~~~

ENTER THE LIMIT =5

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:

IMPLEMENTATION OF SINGLY LINKED LIST

Aim :

To write a cpp program for implementing singly linked list.

Algorithm:

 Initially declare a class list and it has a structure named as node

 To declare the structure variable such as head ,temp and p.

 Function insend () is used to insert an item at end of the list.

 Delmid () function is used to delete a node at a specified location.

85
 Create () function is used to create a linked list.

 Display () function is used to display the content of list.

 Function search () is used to find an item which is present or no.

 Exit function is used to end the program

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;

cout<<"\n\t\tENTER THE NUMBER TO INSERT =";

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

cout<<"\n\t\tEnter The Position To Delete=";

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
{

cout<<"\n\t\tTHE GIVEN ITEM IS FOUND";

else

cout<<"\n\t\tTHE GIVEN ITEM IS NOT FOUND";

};

void main()

clrscr();

int ch;

tree t;

do

cout<<"\n\t\t\tSINGLE LISTED OPERATION";

cout<<"\n\t\t\t~~~~~~ ~~~~~~ ~~~~~~~~~";

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";

cout<<"\n\t\tENTER YOUR CHOICE =";

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();

SINGLE LISTED OPERATION

~~~~~~ ~~~~~~ ~~~~~~~~~

OPTION

1-CREATING

2-INSERT

3-DELETE

4-DISPLAY

5-SEARCH

6-EXIT

ENTER YOUR CHOICE =1

ENTER THE NUMBER TO INSERT =1

ENTER YOUR CHOICE =4

|1||2||3||4||5|

ENTER YOUR CHOICE =3

ENTER THE POSITION TO DELETE =3

|1||2||4||5|

ENTER YOUR CHOICE =2

94
ENTER THE POSITION TO INSERT AND ITEM =3 30

| 1 | | 2 | | 3 0| | 4 | | 5 |

Ex:No

Date:

IMPLEMENTATION OF DOUBLY LINKED LIST

Aim :

To write a cpp program for implementing doubly linked list.

Algorithm:

 Initially declare a class list and it has a structure named as node

 To declare the structure variable such as head ,temp and p.

 Function insend () is used to insert an item at end of the list.

 Delmid () function is used to delete a node at a specified location.

95
 Display1 () function is used to display the content of list in forword.

 Display2 () function is used to display the content of list in backword.

 Exit function is used to end the program

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

struct node

int data;

struct node *next,*prev;

};

class slink

public:

int item,x,ch,i,ctr,pos;

struct node *n,*ptr,*head,*traverse,*p,*q;

public:

void create();

void insert();

96
void delet();

void display1();

void display2();

};

void slink::create()

head=ptr=NULL;

do

cout<<"Enter the element to be created:";

cin>>item;

n=(struct node *)malloc(sizeof(struct node));

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++;

cout<<"Want to create another node ?(1-yes,0-no):";

cin>>i;

}while(i==1);

void slink::insert()

cout<<"Enter the element to be inserted:";

cin>>item;

cout<<"Enter the position:";

cin>>pos;

n=(struct node *)malloc(sizeof(struct node));

n->data=item;

n->prev=NULL;

n->next=NULL;

if((pos<=0)||(pos>ctr+1))

cout<<"Atempt to insert in the wrong position:";

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()

cout<<"Enter the position:";

cin>>pos;

if((pos<=0)||(pos>ctr))

cout<<"Attempt to delete at wrong position";

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\t\tDOUBLY LINKED LIST OPERATION";

cout<<"\n\t\t\t~~~~~~ ~~~~~~ ~~~~ ~~~~~~~~~";

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";

cout<<"\n\t\tEnter your choice:";

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;

cout<<"\nDo you want to continue?(1-yes,0-no):";

cin>>x;

if(x==1)

goto lx;

else

103
getch();

DOUBLY LISTED OPERATION

~~~~~~ ~~~~~~ ~~~~~~~~~

OPTION

1-CREATING

2-INSERT

3-DELETE

4- DISPLAY1

5- DISPLAY2

6-EXIT

ENTER YOUR CHOICE =1

ENTER THE NUMBER TO INSERT =1

ENTER YOUR CHOICE =3

ENTER THE POSITION TO DELETE =3

|1||2||4||5|

ENTER YOUR CHOICE =4

| 1 | | 2 | | 3 0| | 4 | | 5 |

ENTER YOUR CHOICE =4

| 5 | | 4 | | 3 0| | 2 | | 1 |

104
Ex:No:

Date:

COUNT THE NUMBER OF NODES

Algorithm:

1. Start the program.

2. Initially create a structure with a name node.

3. Declare three variables inside the structure such as info, left and right.

4. We have to use three functions to count the number of nodes in a


linked list.

5. An allo () function is used to create a new Node.

6. And create () function is used to create a linked list.

7. The cnt () function is used to count the number of list in a linked list.

8. We have to create a object for class count named as C.

9. To call the create () function for create 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;

cout<<"\n\t\tNUMBER NODES IN THE LIST IS ="<<c;

};

void main()

clrscr();

count C;

int ch;

do

109
cout<<"\n\t\t1-CREATE";

cout<<"\n\t\t2-COUNT";

cout<<"\n\t\t3-EXIT";

cout<<"\n\t\tENTER YOUR CHOICE =";

cin>>ch;

switch(ch)

case 1:

cout<<"\n\t\tENTER THE ITEM TO INSERT =";

C.create();

break;

case 2:

C.cnt();

break;

}while(ch<3);

getch();

110
OUTPUT

1-CREATE

2-COUNT

3-EXIT

ENTER YOUR CHOICE =1

ENTER THE ITEM TO INSERT =1

ENTER YOUR CHOICE =1

ENTER THE ITEM TO INSERT =2

ENTER YOUR CHOICE =1

ENTER THE ITEM TO INSERT =3

ENTER YOUR CHOICE =2

NUMBER NODES IN THE LIST IS =3

111
112

You might also like