Answer to Question #273641 in C++ for Elena

Question #273641

A HighSchool application has two classes: the Person base class and the Student child

class. Using inheritance, create two new classes, Teacher and CollegeStudent. A

Teacher will be like Person but will have additional properties such as salary (the

amount the teacher earns) and subject (e.g. “Computer Science”, “Chemistry”,

“English”, “Other”) .Teacher class having a method displayDetails() to display all the

information about a teacher. The CollegeStudent class will derive from the Student

class by adding a year (current level in college) and major (e.g. “Electrical

Engineering”, “Communications”, “Undeclared”). CollegeStudent class having a

method printDetails() to display details about collegestudents.Create object of

Teacher and CollegeStudent class and call the method.


1
Expert's answer
2021-11-30T18:18:39-0500
#include <iostream>
#include <string>
using namespace std;






class Person{
private:
	string name;
	int age;
public:


	Person(){}


	Person(string name,int age){
		this->name=name;
		this->age=age;
	}


	string getName(){
		return this->name;
	}
	int getAge(){
		return this->age;
	}


};


class Student:public Person{


};
class Teacher:public Person{
private:
	float salary;
	string subject;
public:


	Teacher(){}


	Teacher(float salary,string subject){
		this->salary=salary;
		this->subject=subject;
	}


	float getSalary(){
		return this->salary;
	}
	string getSubject(){
		return this->subject;
	}
	
	void displayDetails(){
		cout<<"Salary: "<<salary<<"\n";
		cout<<"Subject: "<<subject<<"\n";
	}


}; 


class CollegeStudent:public Student{
private:
	int year;
	string major ;
public:


	CollegeStudent(){}


	CollegeStudent(int year,string major){
		this->year=year;
		this->major=major;
	}


	
	void printDetails(){
		cout<<"Year: "<<year<<"\n";
		cout<<"Major: "<<major <<"\n";
	}




}; 




int main()
{
	Teacher teacher(5522,"Computer Science");
	CollegeStudent collegeStudent(2,"Communications");
	teacher.displayDetails();
	collegeStudent.printDetails();
	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