Untitled
unknown
plain_text
2 years ago
2.1 kB
9
Indexable
#include <iostream>
#include <string>
using namespace std;
class Person {
protected:
string name;
int age;
public:
Person(const string& name, int age) {
this->name = name;
this->age = age;
}
string getName() {
return name;
}
int getAge() {
return age;
}
};
class Student : public Person {
private:
string major;
public:
Student(const string& name, int age, const string& major)
: Person(name, age) {
this->major = major;
}
string getMajor() {
return major;
}
};
class Teacher : public Person {
private:
string course;
public:
Teacher(const string& name, int age, const string& course)
: Person(name, age) {
this->course = course;
}
string getCourse() {
return course;
}
};
class TA : public Student, public Teacher {
public:
TA(const string& name, int age, const string& major, const string& course)
: Student(name, age, major), Teacher(name, age, course) {}
string getName() {
return Student::getName();
}
int getAge() {
return Student::getAge();
}
void show() {
cout << "Name: " << getName() << endl;
cout << "Age: " << getAge() << endl;
cout << "Major: " << getMajor() << endl;
cout << "Course: " << getCourse() << endl;
}
};
int main() {
Student student("Mehrab", 20, "Computer Science");
Teacher teacher("Meher Afroj", 35, "Mathematics");
TA ta("Bob", 25, "Physics", "Chemistry");
cout << "Student Information:" << endl;
cout << "Name: " << student.getName() << endl;
cout << "Age: " << student.getAge() << endl;
cout << "Major: " << student.getMajor() << endl;
cout << endl;
cout << "Teacher Information:" << endl;
cout << "Name: " << teacher.getName() << endl;
cout << "Age: " << teacher.getAge() << endl;
cout << "Course: " << teacher.getCourse() << endl;
cout << endl;
cout << "TA Information:" << endl;
ta.show();
return 0;
}
Editor is loading...