Advertisement
csetanzil

Untitled

Nov 10th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. /// using inheritance write a program code by Kibria Tanzil
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  class person
  6. {
  7.  public:
  8.    int age;
  9.    char name[30];
  10.    void display1()
  11.    {
  12.        cout<<"Name : "<<name<<endl<<"Age : "<<age<<endl;
  13.    }
  14. };
  15. class teacher: public person
  16. {
  17.  char degree[20];
  18.  public:
  19.  teacher(char *s,int a,char *d)
  20. {
  21.     strcpy(name,s);
  22.     age = a;
  23.     strcpy(degree,d);
  24. }
  25.  
  26. void display()
  27. {
  28.     cout<<"Profession : Teacher"<<endl;
  29.     display1();
  30.     cout<<"Degree : "<<degree<<endl;
  31. }
  32.  
  33. };
  34. class student : public person
  35. {
  36. int id;
  37. public:
  38. student(char *s,int a,int i)
  39. {
  40. strcpy(name,s);
  41. age = a;
  42. id = i;
  43. }
  44. void display()
  45. {
  46.     cout<<endl<<endl<<"Profession : Student"<<endl;
  47.     display1();
  48.     cout<<"Student id : "<<id<<endl;
  49. }
  50. };
  51.  
  52. int main()
  53. {
  54.     teacher ob1("Kibria",100,"BSc Engg");
  55.     student ob2("Ayub",23,164010);
  56.      ob1.display();
  57.      ob2.display();
  58.      return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement