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>
#include <string>
using namespace std;
//Base class: College
class College
{
private:
string cname;
string city;
public:
College(){}
//Funciton: get(), display()
virtual void getCollege(){
cout<<"Enter the college name: ";
getline(cin,cname);
cout<<"Enter the college city: ";
getline(cin,city);
}
virtual void displayCollege(){
cout<<"The college name: "<<cname<<"\n";
cout<<"The college city: "<<city<<"\n";
}
};
//Derived class inherited from college: Department
class Department:public College{
//variable: Degree, University
private:
string dname;
public:
Department(){}
//Funciton: get(), display()
virtual void getDepartment(){
cout<<"Enter the department name: ";
getline(cin,dname);
}
virtual void displayDepartment(){
cout<<"The department name: "<<dname<<"\n";
}
};
//Base class: Education
class Education
{
private:
//variable: Degree, University
private:
string degree;
string university;
public:
Education(){}
virtual void getEducation(){
cout<<"Enter the education degree: ";
getline(cin,degree);
cout<<"Enter the education university: ";
getline(cin,university);
}
virtual void displayEducation(){
cout<<"The education degree: "<<degree<<"\n";
cout<<"The education university: "<<university<<"\n";
}
};
//Derived class inherited from college and education: Teacher
class Teacher:public Education, public College
{
private:
string tname;
public:
Teacher(){}
//Funciton: get(), display()
void getTeacher(){
cout<<"Enter the teacher name: ";
getline(cin,tname);
}
void displayTeacher(){
cout<<"The teacher name: "<<tname<<"\n";
}
};
int main(){
Teacher teacher;
teacher.getTeacher();
teacher.getCollege();
teacher.getEducation();
teacher.displayTeacher();
teacher.displayCollege();
teacher.displayEducation();
cout<<"\n";
Department department;
department.getDepartment();
department.getCollege();
department.displayDepartment();
department.displayCollege();
system("pause");
return 0;
}
Comments
Leave a comment