Monday, 25 March 2019

CPP-EX62

Create a class Telephone containing name,telephone no. & city as data members & write necessary member functions for  the following- - Search the telephone number with given name - Search name with given telephone number - Search all customers in a given city. (Use given city)

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

void searchname();
void seacrhphno();
void searchcity();
char n[20],c[20];
 long phno;

 class telephone
     {
     char name[20],city[20];
     long phoneno;

     public:
        void getdata()
        {
        cout<<"\n Enter the name: ";
         cin>>name;
        cout<<"\n Enter the city name: ";
         cin>>city;
        cout<<"\n Enter the phone number: ";
         cin>>phoneno;
        }
        void display()
           {
           cout<<"\n Name: "<<name<<"\n City name: "<<city<<"\n Telephone no."<<phoneno;
           }

        void searchname()
           {
           if(strcmp(name,n)==0)
         {
         cout<<name<<"\n"<<phoneno;
         }
          }
       void searchcity()
          {
           if(strcmp(city,c)==0)
         {
         display();
         }
          }
      void searchphno()
          {
          if((phoneno=phno)==1)
        {
        cout<<name<<"\n"<<phoneno;
        }
          }
    };
   void main()
      {
      clrscr();
      telephone t[20];
      int ch,num;
      char cont;
      cout<<"\n 1. Accept the information: ";
      cout<<"\n 2. Search by name: ";
      cout<<"\n 3. Search by telephone no.";
      cout<<"\n 4. Search by city.";

      do
    {
    cout<<"\n Enter your choice. ";
     cin>>ch;
    switch(ch)
         {
         case 1:
        cout<<"\n Enter the number of information you want to enter.";
          cin>>num;
        for(int i=0;i<num;i++)
           {
           t[i].getdata();
           }
        for(i=0;i<num;i++)
           {
           t[i].display();
           }
           break;
         case 2:
           cout<<"\n Enter the name to be searched: ";
             cin>>n;
            for(i=0;i<num;i++)
               {
               t[i].searchname();
               }
           break;
         case 3:
           cout<<"\n Enter the phone number to be searched: ";
             cin>>phno;
            for(i=0;i<num;i++)
               {
               t[i].searchphno();
               }
           break;
        case 4:
          cout<<"\n Enter the city name to be searched: ";
            cin>>c;
           for(i=0;i<num;i++)
             {
             t[i].searchcity();
             }
          break;
        }
        cout<<"\n Do u want to continue.";
        cin>>cont;
    }
        while(cont=='Y' ||cont=='y');
     getch();
       }