Answer to Question #272339 in C++ for Imran

Question #272339

Create a class Person having name, age and gender as its data members. Create


another class Employee which has employername and dailywages as it data member.


From these two classes derive another class teacher which contains teacher grade as


data member.


i. Write set and get functions to enter and display the data members.


ii. Write main function to implement these classes. Enter the teacher data to show


multiple inheritance.

1
Expert's answer
2021-11-27T11:37:08-0500
#include<iostream>
#include<string>
using namespace std;

class Person
{
	string name;
	int age;
	string gender;
public:
	//Setters
	void SetName()
	{
		cout << "Please, enter a name of person: ";
		cin >> name;
	}
	void SetAge() 
	{
		cout << "Please, enter an age of person: ";
		cin >> age;
	}
	void setGender() 
	{
		cout << "Please, enter a gender of person: ";
		cin >> gender;
	}
	//Getters
	string GetName() { return name; }
	int GetAge() { return age; }
	string GetGender() { return gender; }
};

class Employee
{
	string emplName;
	double dailyWages;
public:
	//Setters
	void SetEmplName() 
	{
		cout << "Please, enter an emoloyername of employee: ";
		cin >> emplName;
	}
	void SetDailyWages() 
	{
		cout << "Please, enter a dailywages of employee: ";
		cin >> dailyWages;
	}
	//Getters
	string GetEmplName() { return emplName; }
	double GetDailyWages() { return dailyWages; }
};

class Teacher: public Person, public Employee
{
	double teachGrade;
public:
	//Setter
	void SetTeachGrade()
	{
		cout << "Please, enter a teacher grade of teacher: ";
		cin >> teachGrade;
	}
	//Getter
	double GetTeachGrade() { return teachGrade; }
};


int main()
{
	Teacher t;
	t.SetName();
	t.SetAge();
	t.setGender();
	t.SetEmplName();
	t.SetDailyWages();
	t.SetTeachGrade();
	cout << "The name of person is " << t.GetName()
		<< "\nThe age of person is " << t.GetAge()
		<< "\nThe gender of person is " << t.GetGender()
		<< "\nThe emoloyername of emoloyee is " << t.GetEmplName()
		<< "\nThe dailywages of emoloyee is " << t.GetDailyWages()
		<< "\nThe teacher grade of teacher is " << t.GetTeachGrade();
}

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