Write a C++ program to implement inheritance shown in following figure:
Accept and display data of one teacher and one student using object of class ‘Info’
#include<iostream.h>
#include<conio.h>
class Teacher
{
protected:
char Name[20];
int empid;
};
class Student
{
protected:
char sname[20];
int rollno;
};
class Info:public Teacher,public Student
{
public:
void acceptT()
{
cout<<"\nEnter data for teacher:";
cout<<"\nName:";
cin>>Name;
cout<<"\nEmployee id:";
cin>>empid;
}
void displayT()
{
cout<<"\nTeacher's data is:";
cout<<"\nName:"<<Name;
cout<<"\nEmployee id:"<<empid;
}
void acceptS()
{
cout<<"\nEnter student's data:";
cout<<"\nName:";
cin>>sname;
cout<<"\nRoll no:";
cin>>rollno;
}
void displayS()
{
cout<<"\nStudent's data is:";
cout<<"\nName:"<<sname;
cout<<"\nRoll no:"<<rollno;
}
};
void main()
{
Info I;
clrscr();
I.acceptT();
I.displayT();
I.acceptS();
I.displayS();
getch();
}