Write a C++ Program To Implemantation Searching sorting using STL

#include<iostream.h>
#include<list>
using namespace std;

class person
{
     public:
                char name[30];
                char dob[20];
                char phno[11];
                void insert();
                void display();
                void search();
                void sort();
};

person p1;
list<person>s1;
list<person>::iterator P;

bool operator<(person &p,person &q)
{
     if(strcmp(p.name,q.name)<0)
           return true;
     else
           return false;
}

void person:: insert()
{
     cout<<"\nEnter name:";
     cin>>p1.name;
     cout<<"\nEnter Date of birth:";
     cin>>p1.dob;
     cout<<"\nEnter phone number:";
     cin>>p1.phno;
     s1.push_back(p1);
}

void person:: display()
{
     cout<<"\nName\tDate of birth\tPhone no.\n\n";
     for(P=s1.begin();P!=s1.end();P++)
     {
         cout<<(*P).name<<"\t"<<(*P).dob<<"\t"<<(*P).phno<<"\n";
     }
}

void person::search()
{
     char srch[20];
     int flag=0;
     cout<<"\nEnter the name:";
     cin>>srch;
     for(P=s1.begin();P!=s1.end();P++)
     {
           if(strcmp((*P).name,srch)==0)
           {
                cout<<"\nRecord found!!";
                cout<<"\nName\tBirth date\tPhone no.";
                cout<<"\n"<<(*P).name<<"\t"<<(*P).dob<<"\t"<<(*P).phno;
                flag=1;
                break;
           }
     }
     if(flag==0)
     cout<<"\nRecord not found!!";
}

void person::sort()
{
     s1.sort();
     cout<<"Sorted successfully!!";
}

void main()
{
 
     int ch;
     person p;
     do
     {
          cout<<"\n\tMenu\n1.Create\n2.Display\n3.Search\n4.Sort\n5.Exit\nEnter your choice:";
           cin>>ch;
           switch(ch)
           {
                case 1:
                           p.insert();
                           break;
                case 2:
                           p.display();
                           break;
                case 3:
                           p.search();
                           break;
                case 4:
                           p.sort();
                           p.display();
                           break;
                case 5:
                           exit(0);
                           break;
           }
     }while(ch!=5);
}





---------------------------------OUTPUT---------------------------------

       

Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:1

Enter name:Niraj

Enter Date of birth:30/04/1991

Enter phone number:1423465734

        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:1

Enter name:Kalpesh

Enter Date of birth:23/7/1990

Enter phone number:3425637765

        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:1

Enter name:Siddesh

Enter Date of birth:7/3/1991

Enter phone number:2534449875

        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:2

Name    Date of birth   Phone no.

Niraj   30/04/1991      1423465734
Kalpesh 23/7/1990       3425637765
Siddesh 7/3/1991        2534449875

        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:3

Enter the name:niraj

Record not found!!
        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:3

Enter the name:Niraj

Record found!!
Name    Birth date      Phone no.
Niraj   30/04/1991      1423465734
        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit
Enter your choice:4

Sorted successfully!!
Name    Date of birth   Phone no.

Kalpesh 23/7/1990       3425637765
Niraj   30/04/1991      1423465734
Siddesh 7/3/1991        2534449875

        Menu
1.Create
2.Display
3.Search
4.Sort
5.Exit

Enter your choice:5
Previous
Next Post »

Disqus Shortname

Comments system