Create a class Person that contains data members as Person_Name, City, Mob_No. Write a C++ program to perform following functions: i. To accept and display Person information ii. To search the mobile number of a given person iii. To search the Person details of a given mobile number (Use Function Overloading)

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<iostream.h>
#include<conio.h>
#include<string.h>
class person
{
public:
   int no,mob; 
   char name[10],city[10];
   void acc() // function overloading 
   {
    cout<<"\nEnter person no : ";
      cin>>no;
      cout<<"\nEnter person name : ";
      cin>>name;
      cout<<"\nEnter person city : ";
      cin>>city;
      cout<<"\nEnter person mob no : ";
      cin>>mob;

   }
   void acc(char nme[]) // function overloading 
   {
    if(strcmp(nme,name)==0)
      {
      cout<<"\nperson name   : "<<name;
      cout<<"\nperson mob no : "<<mob;
      }
   }
   void acc(int mno)  // function overloading 
   {
    if(mno==mob)
      {
      cout<<"\nperson name   : "<<name;
      cout<<"\nperson mob no : "<<mob;
      }
   }
   void dis()
   {
      cout<<"\nperson details"<<endl;
      cout<<"\nperson no     : "<<no;
      cout<<"\nperson name   : "<<name;
      cout<<"\nperson city   : "<<city;
      cout<<"\nperson mob no : "<<mob;
   }

};
void main()
{
   char nme[10];
   int mno,i,no,ch;// mno=mobile no , no=total person no , ch=choice
   do{
   cout<<"\n1.Accept person details\n2.Display person details\n3.ii. To search the mobile number of a given person\n4.To search the Person details of a given mobile number\n5.Exit\nEnter your choice :- ";
   cin>>ch;
   switch(ch)
   {
   case 1:cout<<"Enter how many Person Details you want to enter: ";
    cin>>no;
          person p[20];
          for(i=0;i<no;i++)
    {
p[i].acc();
    }break;
   case 2:for(i=0;i<no;i++)
    p[i].dis();
          break;
   case 3:cout<<"\nEnter person name search for mob no : ";
    cin>>nme;
          for(i=0;i<no;i++)
  p[i].acc(nme);
          break;
   case 4:cout<<"\nEnter mob no search for person name : ";
  cin>>mno;
  for(i=0;i<no;i++)
  p[i].acc(mno);
          break;
   }
   }while(ch!=5);
}

0 Comments