Answer to Question #192940 in C++ for Mani

Question #192940

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.


Input :

TPT

SALEM

CT

B.E

ANNAUNIVERSITY

Rajesh

Output :

TPT

SALEM

CT

B.E

ANNAUNIVERSITY

Rajesh


1
Expert's answer
2021-05-15T07:32:53-0400
#include <iostream>
#include <string>
using namespace std;




class College
{
private:
	string cname;
	string city;
public:
	College(){}
	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();


	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