nrk009

OOPS ASS 4

Oct 2nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Info
  5. {
  6.     protected:
  7.     char *name,*blood_grp,*DoB;
  8.     public:
  9.     Info(char *Name,char *Bld_Grp,char *dob)
  10.     {
  11.         name=new char[strlen(Name)+1];
  12.         strcpy(name,Name);
  13.         blood_grp=new char[strlen(Bld_Grp)+1];
  14.         strcpy(blood_grp,Bld_Grp);
  15.         DoB=new char[strlen(dob)+1];
  16.         strcpy(DoB,dob);
  17.     }
  18. };
  19.  
  20. class Stats
  21. {
  22.     protected:
  23.     int Height,Weight;
  24.     public:
  25.     Stats(int height,int weight)
  26.     {
  27.         Height=height;
  28.         Weight=weight;
  29.     }
  30. };
  31.  
  32. class Insurance
  33. {
  34.     protected:
  35.     char * Addr;
  36.     int Policy_No;
  37.     public:
  38.     Insurance(char *add,int No)
  39.     {
  40.         Policy_No=No;
  41.         Addr=new char[strlen(add)];
  42.         strcpy(Addr,add);
  43.     }
  44. };
  45.  
  46. class Person : public Info,public Stats,public Insurance
  47. {
  48.     int Tel_no,Lic_no;
  49.     public:
  50.     Person(char *Name,char *Bld_Grp,char *dob,int height,int weight,char *add,int No,int Tel,int Lic) :
  51.     Info(Name,Bld_Grp,dob), Stats(height,weight), Insurance(add,No)
  52.     {
  53.         Tel_no=Tel;
  54.         Lic_no=Lic;
  55.     }
  56.     void display()
  57.     {
  58.       cout<<name<<"\t"<<blood_grp<<"\t"<<DoB<<"\t"<<Height<<"\t"<<Weight;
  59.       cout<<"\t"<<Addr<<"\t"<<Policy_No<<"\t"<<Tel_no<<"\t"<<Lic_no<<"\n";
  60.     }
  61.  
  62.     void Edit()
  63.     {
  64.       int t,val;
  65.       char temp[100];
  66.       cout<<"Enter the field to edit\n";
  67.       cout<<"1. Name\n";
  68.       cout<<"2. Blood group\n";
  69.       cout<<"3. Date of birth\n";
  70.       cout<<"4. Height\n";
  71.       cout<<"5. Weight\n";
  72.       cout<<"6. Address\n";
  73.       cout<<"7. Policy number\n";
  74.       cout<<"8. Telephone number\n";
  75.       cout<<"9. LIC number\n";
  76.       cout<<"\nenter your choice: ";
  77.       cin>>t;
  78.       switch(t)
  79.       {
  80.         case 1:cout<<"Enter the updated name: ";
  81.                cin>>temp;
  82.                delete[] name;
  83.                name=new char[strlen(temp)+1];
  84.                strcpy(name,temp);
  85.                break;
  86.         case 2:cout<<"Enter the updated blood group: ";
  87.                cin>>temp;
  88.                delete[] blood_grp;
  89.                blood_grp=new char[strlen(temp)+1];
  90.                strcpy(blood_grp,temp);
  91.                break;
  92.         case 3:cout<<"Enter the updated date of birth: ";
  93.                cin>>temp;
  94.                delete[] DoB;
  95.                DoB=new char[strlen(temp)+1];
  96.                strcpy(DoB,temp);
  97.                break;
  98.         case 4:cout<<"Enter the updated height: ";
  99.                cin>>val;
  100.                Height=val;
  101.                break;
  102.         case 5:cout<<"Enter the updated weighted: ";
  103.                cin>>val;
  104.                Weight=val;
  105.                break;
  106.         case 6:cout<<"Enter the updated address: ";
  107.                cin>>temp;
  108.                delete[] Addr;
  109.                Addr=new char[strlen(temp)+1];
  110.                strcpy(Addr,temp);
  111.                break;
  112.         case 7:cin>>val;
  113.                Policy_No=val;
  114.                break;
  115.         case 8:cin>>val;
  116.                Tel_no=val;
  117.                break;
  118.         case 9:cin>>val;
  119.                Lic_no=val;
  120.                break;
  121.       }
  122.     }
  123.  
  124.     char *getName()
  125.     {
  126.       return name;
  127.     }
  128. };
  129.  
  130. void Insert(Person *P[100],int &n)
  131. {
  132.   int x;
  133.   do
  134.   {
  135.   cout<<"Enter the required info\n";
  136.   char name[100],blood_grp[100],DoB[100];
  137.   char Addr[100];
  138.   long long int Policy_No;
  139.   int Height,Weight;
  140.   int Tel_no,Lic_no;
  141.   cout<<"\nEnter the name: ";
  142.   cin>>name;
  143.   cout<<"\nEnter the Blood: ";
  144.   cin>>blood_grp;
  145.   cout<<"\nEnter the DoB: ";
  146.   cin>>DoB;
  147.   cout<<"\nEnter the Height: ";
  148.   cin>>Height;
  149.   cout<<"\nEnter the Weight: ";
  150.   cin>>Weight;
  151.   cout<<"\nEnter the Address: ";
  152.   cin>>Addr;
  153.   cout<<"\nEnter Policy Number: ";
  154.   cin>>Policy_No;
  155.   cout<<"\nEnter the Tel No: ";
  156.   cin>>Tel_no;
  157.   cout<<"\nEnter the Lic No: ";
  158.   cin>>Lic_no;
  159.   P[n++]=new Person(name,blood_grp,DoB,Height,Weight,Addr,Policy_No,Tel_no,Lic_no);
  160.   cout<<"RECORD INSERTED\n";
  161.   cout<<"To Enter another record press 1 or else 0\n";
  162.   cin>>x;
  163.   }
  164.   while(x!=0);
  165. }
  166.  
  167. void Display(Person *P[100],int n)
  168. {
  169.    for(int i=0;i<n;i++)
  170.     P[i]->display();
  171. }
  172.  
  173. void Update(Person *P[100],int n)
  174. {
  175.   char name[100];
  176.   cout<<"Enter Person Name\n";
  177.   cin>>name;
  178.     for(int i=0;i<n;i++)
  179.     {
  180.       char *Name=P[i]->getName();
  181.       if(!strcmp(Name,name))
  182.       {
  183.         P[i]->Edit();
  184.         return;
  185.       }
  186.     }
  187.   cout<<"Record not found\n";
  188. }
  189.  
  190. void Search(Person *P[100],int n)
  191. {
  192.   char name[100];
  193.   cout<<"Enter Person Name\n";
  194.   cin>>name;
  195.     for(int i=0;i<n;i++)
  196.     {
  197.       char *Name=P[i]->getName();
  198.       if(!strcmp(Name,name))
  199.       {
  200.         P[i]->display();
  201.         return;
  202.       }
  203.     }
  204.   cout<<"Record not found\n";
  205. }
  206.  
  207. void Swap(Person *P1,Person *P2)
  208. {
  209.   Person temp=*P1;
  210.   *P1=*P2;
  211.   *P2=temp;
  212. }
  213.  
  214. void Delete(Person *P[100],int &n)
  215. {
  216.   char name[100];
  217.   cout<<"Enter Person Name\n";
  218.   cin>>name;
  219.     for(int i=0;i<n;i++)
  220.     {
  221.       char *Name=P[i]->getName();
  222.       if(!strcmp(Name,name))
  223.       {
  224.         swap(P[i],P[n-1]);
  225.         delete P[n-1];
  226.         n--;
  227.         return;
  228.       }
  229.     }
  230.   cout<<"Record not found\n";
  231. }
  232.  
  233. int main()
  234. {
  235.   int n=0,x,flag=0;
  236.   Person *P[100];
  237.   while(1)
  238.   {
  239.     cout<<"Enter the  operation you want to perform: \n";
  240.     cout<<"\n1. Insert a record";
  241.     cout<<"\n2. Display a record";
  242.     cout<<"\n3. Update a record";
  243.     cout<<"\n4. Search a record";
  244.     cout<<"\n5. Delete a record";
  245.     cout<<"\n0. Exit";
  246.     cout<<"\n\nEnter your choice: ";
  247.     cin>>x;
  248.     switch(x)
  249.     {
  250.       case 0:flag=1;
  251.              break;
  252.       case 1:Insert(P,n);
  253.              break;
  254.       case 2:Display(P,n);
  255.              break;
  256.       case 3:Update(P,n);
  257.              break;
  258.       case 4:Search(P,n);
  259.              break;
  260.       case 5:Delete(P,n);
  261.              break;
  262.     }
  263.     if(flag)
  264.       break;
  265.   }
  266. }
Add Comment
Please, Sign In to add comment