Answer to Question #174155 in C++ for Rahul

Question #174155

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.


1
Expert's answer
2021-03-28T03:35:32-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS