Base class: College
variable: cname, city
Funciton: get(), display()
Derived class inherited from college: Department
variable: dname
function :get(), display()
Base class: Education
variable: Degree, University
function : get(), display()
Derived class inherited from college and education: Teacher
variable: Teacher
tname function : get(), display()
Write a C++ program to display the details of faculty members in an institution.
#include <iostream>
using namespace std;
class College{
protected:
string cname, city;
public:
College(){}
virtual void get(){}
virtual void display(){}
};
class Department: public College{
protected:
string dname;
public:
Department(){}
void get(){}
void display(){}
};
class Education{
protected:
string degree, university;
public:
void get(){}
void display(){}
};
class Teacher: public College, public Education{
string tname;
public:
Teacher(){}
void get(){
cout<<"Enter teacher name: ";
cin>>tname;
cout<<"Enter teacher degree: ";
cin>>degree;
cout<<"Enter university: ";
cin>>university;
cout<<"Enter college: ";
cin>>cname;
cout<<"Enter city: ";
cin>>city;
}
void display(){
cout<<"Teacher name: "<<tname<<endl;
cout<<"Degree: "<<degree<<endl;
cout<<"University: "<<university<<endl;
cout<<"College: "<<cname<<endl;
cout<<"City: "<<city<<endl;
}
};
int main(){
Teacher teacher;
teacher.get();
cout<<"\nTeacher details are; \n";
teacher.display();
return 0;
}
Comments
Leave a comment