Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Info
- {
- protected:
- char *name,*blood_grp,*DoB;
- public:
- Info(char *Name,char *Bld_Grp,char *dob)
- {
- name=new char[strlen(Name)+1];
- strcpy(name,Name);
- blood_grp=new char[strlen(Bld_Grp)+1];
- strcpy(blood_grp,Bld_Grp);
- DoB=new char[strlen(dob)+1];
- strcpy(DoB,dob);
- }
- };
- class Stats
- {
- protected:
- int Height,Weight;
- public:
- Stats(int height,int weight)
- {
- Height=height;
- Weight=weight;
- }
- };
- class Insurance
- {
- protected:
- char * Addr;
- int Policy_No;
- public:
- Insurance(char *add,int No)
- {
- Policy_No=No;
- Addr=new char[strlen(add)];
- strcpy(Addr,add);
- }
- };
- class Person : public Info,public Stats,public Insurance
- {
- int Tel_no,Lic_no;
- public:
- Person(char *Name,char *Bld_Grp,char *dob,int height,int weight,char *add,int No,int Tel,int Lic) :
- Info(Name,Bld_Grp,dob), Stats(height,weight), Insurance(add,No)
- {
- Tel_no=Tel;
- Lic_no=Lic;
- }
- void display()
- {
- cout<<name<<"\t"<<blood_grp<<"\t"<<DoB<<"\t"<<Height<<"\t"<<Weight;
- cout<<"\t"<<Addr<<"\t"<<Policy_No<<"\t"<<Tel_no<<"\t"<<Lic_no<<"\n";
- }
- void Edit()
- {
- int t,val;
- char temp[100];
- cout<<"Enter the field to edit\n";
- cout<<"1. Name\n";
- cout<<"2. Blood group\n";
- cout<<"3. Date of birth\n";
- cout<<"4. Height\n";
- cout<<"5. Weight\n";
- cout<<"6. Address\n";
- cout<<"7. Policy number\n";
- cout<<"8. Telephone number\n";
- cout<<"9. LIC number\n";
- cout<<"\nenter your choice: ";
- cin>>t;
- switch(t)
- {
- case 1:cout<<"Enter the updated name: ";
- cin>>temp;
- delete[] name;
- name=new char[strlen(temp)+1];
- strcpy(name,temp);
- break;
- case 2:cout<<"Enter the updated blood group: ";
- cin>>temp;
- delete[] blood_grp;
- blood_grp=new char[strlen(temp)+1];
- strcpy(blood_grp,temp);
- break;
- case 3:cout<<"Enter the updated date of birth: ";
- cin>>temp;
- delete[] DoB;
- DoB=new char[strlen(temp)+1];
- strcpy(DoB,temp);
- break;
- case 4:cout<<"Enter the updated height: ";
- cin>>val;
- Height=val;
- break;
- case 5:cout<<"Enter the updated weighted: ";
- cin>>val;
- Weight=val;
- break;
- case 6:cout<<"Enter the updated address: ";
- cin>>temp;
- delete[] Addr;
- Addr=new char[strlen(temp)+1];
- strcpy(Addr,temp);
- break;
- case 7:cin>>val;
- Policy_No=val;
- break;
- case 8:cin>>val;
- Tel_no=val;
- break;
- case 9:cin>>val;
- Lic_no=val;
- break;
- }
- }
- char *getName()
- {
- return name;
- }
- };
- void Insert(Person *P[100],int &n)
- {
- int x;
- do
- {
- cout<<"Enter the required info\n";
- char name[100],blood_grp[100],DoB[100];
- char Addr[100];
- long long int Policy_No;
- int Height,Weight;
- int Tel_no,Lic_no;
- cout<<"\nEnter the name: ";
- cin>>name;
- cout<<"\nEnter the Blood: ";
- cin>>blood_grp;
- cout<<"\nEnter the DoB: ";
- cin>>DoB;
- cout<<"\nEnter the Height: ";
- cin>>Height;
- cout<<"\nEnter the Weight: ";
- cin>>Weight;
- cout<<"\nEnter the Address: ";
- cin>>Addr;
- cout<<"\nEnter Policy Number: ";
- cin>>Policy_No;
- cout<<"\nEnter the Tel No: ";
- cin>>Tel_no;
- cout<<"\nEnter the Lic No: ";
- cin>>Lic_no;
- P[n++]=new Person(name,blood_grp,DoB,Height,Weight,Addr,Policy_No,Tel_no,Lic_no);
- cout<<"RECORD INSERTED\n";
- cout<<"To Enter another record press 1 or else 0\n";
- cin>>x;
- }
- while(x!=0);
- }
- void Display(Person *P[100],int n)
- {
- for(int i=0;i<n;i++)
- P[i]->display();
- }
- void Update(Person *P[100],int n)
- {
- char name[100];
- cout<<"Enter Person Name\n";
- cin>>name;
- for(int i=0;i<n;i++)
- {
- char *Name=P[i]->getName();
- if(!strcmp(Name,name))
- {
- P[i]->Edit();
- return;
- }
- }
- cout<<"Record not found\n";
- }
- void Search(Person *P[100],int n)
- {
- char name[100];
- cout<<"Enter Person Name\n";
- cin>>name;
- for(int i=0;i<n;i++)
- {
- char *Name=P[i]->getName();
- if(!strcmp(Name,name))
- {
- P[i]->display();
- return;
- }
- }
- cout<<"Record not found\n";
- }
- void Swap(Person *P1,Person *P2)
- {
- Person temp=*P1;
- *P1=*P2;
- *P2=temp;
- }
- void Delete(Person *P[100],int &n)
- {
- char name[100];
- cout<<"Enter Person Name\n";
- cin>>name;
- for(int i=0;i<n;i++)
- {
- char *Name=P[i]->getName();
- if(!strcmp(Name,name))
- {
- swap(P[i],P[n-1]);
- delete P[n-1];
- n--;
- return;
- }
- }
- cout<<"Record not found\n";
- }
- int main()
- {
- int n=0,x,flag=0;
- Person *P[100];
- while(1)
- {
- cout<<"Enter the operation you want to perform: \n";
- cout<<"\n1. Insert a record";
- cout<<"\n2. Display a record";
- cout<<"\n3. Update a record";
- cout<<"\n4. Search a record";
- cout<<"\n5. Delete a record";
- cout<<"\n0. Exit";
- cout<<"\n\nEnter your choice: ";
- cin>>x;
- switch(x)
- {
- case 0:flag=1;
- break;
- case 1:Insert(P,n);
- break;
- case 2:Display(P,n);
- break;
- case 3:Update(P,n);
- break;
- case 4:Search(P,n);
- break;
- case 5:Delete(P,n);
- break;
- }
- if(flag)
- break;
- }
- }
Add Comment
Please, Sign In to add comment