Design a base class with name, date of birth, blood group and another base class consisting of the data members such as height and weight. Design one more base class consisting of the insurance policy number and contact address. The derived class contains the data members’ telephone numbers and driving license number multiple inheritance.

                   MULTIPLE INHERITANCE


Multiple inheritances is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class.



               Multiple Inheritance is a feature of an object-oriented concept, where a class can inherit properties of more than one parent class. The problem occurs when there exist methods with the same signature in both the superclasses and subclasses. On calling the method, the compiler cannot determine which class method to be called and even on calling which class method gets the priority.


PROGRAM

  • Design a base class with name, date of birth, blood group and another base class consisting of the data members such as height and weight. Design one more base class consisting of the insurance policy number and contact address. The derived class contains the data members’ telephone numbers and driving license number.   Write a menu-driven program to carry out the following things: 
          i. Build a master table 
          ii.  Display       
          iii.  Insert a new entry 
          iv. Delete entry 
          v.  Edit  
          vi.  Search for a record 
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class base1
{
  protected:
     char name[10],bloodgr[2];
     int datofbir[10];

};
class base2
{
  protected:
      float height,weight;

};

class base3
{
  protected:
 int inspolno[10];
 char addr[10];

};
class derive:public base1,public base2,public base3
{
  int telno[10];
  int drivlic[15];
  public:
  void accept();
  void display();
  int search(char na[10]);
};
void derive::accept()
{
      cout<<"Enter name\n";
      cin>>name;
      cout<<"Enter bloodgroup\n";
      cin>>bloodgr;
      cout<<"Enter date of birth\n";
      cin>>datofbir;
      cout<<"Enter height \n";
      cin>>height;
      cout<<"Enter weight\n";
      cin>>weight;
      cout<<"Enter address\n";
      cin>>addr;
      cout<<"Enter insurance no\n";
      cin>>inspolno;
      cout<<"Enter tele no\n";
      cin>>telno[10];
      cout<<"Enter drivinglicno\n";
      cin>>drivlic[15];

}
void derive::display()
{     cout<<" name:"<<name<<"\n";
      cout<<" bloodgroup:"<<bloodgr<<"\n";
      cout<<" date of birth:"<<datofbir<<"\n";
      cout<<" height:"<<height<<"\n";
      cout<<" weight:"<<weight<<"\n";
      cout<<" address:"<<addr<<"\n";
      cout<<" insurance no:"<<inspolno<<"\n";
      cout<<" tele no:"<<telno[10]<<"\n";
      cout<<" drivinglicno:"<<drivlic[15]<<"\n";


}
int derive::search(char na[10])
{


    if(strcmp(na,name)==0)
    return 1;
    else
    return 0;
}


int main()
{
  derive d1[20];
  int no,i,n,pos; char na[10],nam[10];
  //clrscr();
  while(no!=7)
  {
  cout<<"Enter 1 to accept\nEnter 2 for display\nEnter 3 to search\nEnter 4 to insert at location";
  cout<<"\nEnter 5 to delete\nEnter 6 to edit\n";
  cout<<"Enter your choice";
  cin>>no;
  switch(no)
  {
    case 1:cout<<"Enter no data to be accepted\n";
    cin>>n;
    for(i=0;i<n;i++)
    {
       d1[i].accept();
    }
    break;
    case 2:
      for(i=0;i<n;i++)
      {
        d1[i].display();
       }
     break;
    case 3: cout<<"Enter the name\n";
     cin>>na;
     for(i=0;i<n;i++)
     {
       if(d1[i].search(na))
       {
  d1[i].display();
  break;
  }

     }
   if(i==n)
   cout<<"record not found";
     break;
    case 4:
    cout<<"enter the position in u want to insert";
    cin>>pos;
    for(i=0;i<n;i++)
      {
        if(i==pos)
  {
    d1[i+1]=d1[i];
  }
     }
    d1[pos].accept();
    n++;
    break;
    case 5:  cout<<"Enter the record name to be deleated\n";
     cin>>nam;
     for(i=0;i<n;i++)
     {
       if(d1[i].search(nam))
       {
   for(;i<n;i++)
    {
      d1[i]=d1[i+1];

    }
  break;
  }

     }
     --n;
    case 6:  cout<<"Enter the record name to be edited\n";
     cin>>nam;
     for(i=0;i<n;i++)
     {
       if(d1[i].search(nam))
       {
  d1[i].accept();
  break;
       }
    }
     break;
  }
 }

 getch();
 return 0;
}
OUTPUT:  Enter 1 to accept
Enter 2 for display
Enter 3 to search
Enter 4 to insert at location
Enter 5 to delete
Enter 6 to edit
Enter your choice1
Enter no data to be accepted
2
Enter name
rishu
Enter bloodgroup
A
Enter date of birth
01022001
Enter height 
6
Enter weight
55
Enter address
pimpri 
Enter insurance no
345654
Enter tele no
02034564
Enter drivinglicno
34534644
Enter name
tejas
Enter bloodgroup
O
Enter date of birth
15022001
Enter height 
6
Enter weight
55
Enter address
talegaon
Enter insurance no
2345664
Enter tele no
020565433
Enter drivinglicno
457544564
Enter 1 to accept
Enter 2 for display
Enter 3 to search
Enter 4 to insert at location
Enter 5 to delete
Enter 6 to edit
Enter your choice2
 name:rishu
 bloodgroup:A
 date of birth:1022001
 height:6
 weight:55
 address:pimpri
 insurance no:345654
 tele no:2034564
 drivinglicno:1634362740
 name:tejas
 bloodgroup:O
 date of birth:15022001
 height:6
 weight:55
 address:talegaon
 insurance no:2345664
 tele no:20565433
 drivinglicno:457544564
Enter 1 to accept
Enter 2 for display
Enter 3 to search
Enter 4 to insert at location
Enter 5 to delete
Enter 6 to edit
Enter your choice3
Enter the name
rishu
 name:rishu
 bloodgroup:A
 date of birth:1022001
 height:6
 weight:55
 address:pimpri
 insurance no:345654
 tele no:2034564
 drivinglicno:1634362740
Enter 1 to accept
Enter 2 for display
Enter 3 to search
Enter 4 to insert at location
Enter 5 to delete
Enter 6 to edit
Enter your choice5
Enter the record name to be deleated
rishu
Enter the record name to be edited
tejas
Enter name
mohan
Enter bloodgroup
A
Enter date of birth
02032002
Enter height 
5
Enter weight
54
Enter address
pp
Enter insurance no
54553433
Enter tele no
554335534
Enter drivinglicno
5643334
Enter 1 to accept
Enter 2 for display
Enter 3 to search
Enter 4 to insert at location
Enter 5 to delete
Enter 6 to edit
Enter your choice2
 name:mohan
 bloodgroup:A
 date of birth:2032002
 height:5
 weight:54
 address:pp
 insurance no:54553433
 tele no:554335534
 drivinglicno:5643334


No comments:

Post a Comment

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages