nrk009

inheritance oops assi 9

Oct 2nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class base1
  4. {
  5.     protected:
  6.     char name[20];
  7.     char dob[20];
  8.     char bg[5];
  9.  
  10.     public:
  11.     base1()
  12.     {
  13.     }
  14.     base1(char *x1,char *x2,char *x3)
  15.     {
  16.        strcpy(name,x1);
  17.        strcpy(dob,x2);
  18.        strcpy(bg,x3);
  19.     }
  20.     void BASE1()
  21.     {
  22.        cout<<"\nname: "<<name;
  23.        cout<<"\ndate of birth: "<<dob;
  24.        cout<<"\nblood group: "<<bg;
  25.     }
  26. };
  27.  
  28. class base2
  29. {
  30.     protected:
  31.     float height;
  32.     float weight;
  33.  
  34.     public:
  35.     base2()
  36.     {
  37.     }
  38.     base2(float x4,float x5)
  39.     {
  40.         height=x4;
  41.         weight=x5;
  42.     }
  43.     void BASE2()
  44.     {
  45.         cout<<"\nheight: "<<height;
  46.         cout<<"\nweight: "<<weight;
  47.     }
  48. };
  49. class base3
  50. {
  51.     protected:
  52.     int pno;
  53.     char *add;
  54.  
  55.     public:
  56.     base3()
  57.     {
  58.     }
  59.     base3(int x6,char *x7)
  60.     {
  61.         pno=x6;
  62.         strcpy(add,x7);
  63.     }
  64.     void BASE3()
  65.     {
  66.         cout<<"\npolicy number: "<<pno;
  67.         cout<<"\naddress details: "<<add;
  68.     }
  69. };
  70.  
  71. class derived:public base1,public base2,public base3
  72. {
  73.     int phoneno;
  74.     int drivingno;
  75.  
  76.     public:
  77.     derived()
  78.     {
  79.     }
  80.     derived(char *x1,char *x2,char *x3,float x4,float x5,int x6,char *x7,int x8,int x9):base1(x1,x2,x3),base2(x4,x5),base3(x6,x7)
  81.     {
  82.         phoneno=x8;
  83.         drivingno=x9;
  84.     }
  85.     void display()
  86.     {
  87.         BASE1();
  88.         BASE2();
  89.         BASE3();
  90.         cout<<"\nphone number:"<<phoneno;
  91.         cout<<"\ndriving number:"<<drivingno;
  92.     }
  93. };
  94. int main()
  95. {
  96.     derived *d;
  97.     int i,n,y=1,x,phoneno,drivingno,pno;
  98.     float height,weight;
  99.     char name[100],bg[100],dob[100],add[100];
  100.     while(y)
  101.     {
  102.         cout<<"Enter your choice: ";
  103.         cout<<"\n1.Enter details\n2.show details\n3.exit\n";
  104.         cin>>x;
  105.         switch(x)
  106.         {
  107.         case 1:
  108.         cout<<"\n---------EMPLOYEE---------\n";
  109.         cout<<"\nEnter the name of the employee: ";
  110.         cin>>name;
  111.         cout<<"\nEnter the date of birth: ";
  112.         cin>>dob;
  113.         cout<<"\nEnter the blood group: ";
  114.         cin>>bg;
  115.         cout<<"\nEnter the height of the employee: ";
  116.         cin>>height;
  117.         cout<<"\nEnter the weight of the employee: ";
  118.         cin>>weight;
  119.         cout<<"\nEnter the policy number: ";
  120.         cin>>pno;
  121.         cout<<"\nEnter the address details: ";
  122.         cin>>add;
  123.         cout<<"\nEnter phone number: ";
  124.         cin>>phoneno;
  125.         cout<<"\nEnter driving license number: ";
  126.         cin>>drivingno;
  127.         d=new derived(name,dob,bg,height,weight,pno,add,phoneno,drivingno);
  128.         break;
  129.  
  130.         case 2:
  131.         cout<<"\nEmployee details:\n";
  132.         d->display();
  133.         break;
  134.  
  135.         case 3:exit(0);
  136.         break;
  137.      }
  138.     cout<<"for continue.....press<1> or press<0>\n";
  139.     cin>>y;
  140.    }
  141. }
Add Comment
Please, Sign In to add comment