Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// using inheritance write a program code by Kibria Tanzil
- #include<bits/stdc++.h>
- using namespace std;
- class person
- {
- public:
- int age;
- char name[30];
- void display1()
- {
- cout<<"Name : "<<name<<endl<<"Age : "<<age<<endl;
- }
- };
- class teacher: public person
- {
- char degree[20];
- public:
- teacher(char *s,int a,char *d)
- {
- strcpy(name,s);
- age = a;
- strcpy(degree,d);
- }
- void display()
- {
- cout<<"Profession : Teacher"<<endl;
- display1();
- cout<<"Degree : "<<degree<<endl;
- }
- };
- class student : public person
- {
- int id;
- public:
- student(char *s,int a,int i)
- {
- strcpy(name,s);
- age = a;
- id = i;
- }
- void display()
- {
- cout<<endl<<endl<<"Profession : Student"<<endl;
- display1();
- cout<<"Student id : "<<id<<endl;
- }
- };
- int main()
- {
- teacher ob1("Kibria",100,"BSc Engg");
- student ob2("Ayub",23,164010);
- ob1.display();
- ob2.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement