Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- class Person
- {
- string name;
- string family;
- public:
- Person(string _name = "", string _family = "") :name(_name), family(_family) {}
- Person(const Person &other) :name(other.name), family(other.family) {}
- Person& operator =(const Person &other)
- {
- name = other.name;
- family = other.family;
- return *this;
- }
- /* no dynamic memory here,destructor not needed
- ~Person()
- {
- }
- */
- Person::string Name()
- {
- return name;
- }
- Person::string Family()
- {
- return family;
- }
- };
- class Student :public Person
- {
- int age;
- int SchoolID;
- public:
- Student(string _name = "", string _family = "", int _age = 0, int _ID = 0) :Person(_name, _family), age(_age), SchoolID(_ID) {}
- Student(const Student &other) : Person(other), age(other.age), SchoolID(other.SchoolID) {}
- Student& operator =(const Student &other)
- {
- Person::operator=(other);
- age = other.age;
- SchoolID = other.SchoolID;
- return *this;
- }
- /* no dynamic memory here,destructor not needed
- ~Student()
- {
- }
- */
- int ID()
- {
- return SchoolID;
- }
- void Print()
- {
- cout << Person::Name() << " " << Person::Family() << ": " << age << " years old, ID: " << SchoolID << endl;
- }
- };
- class Teacher :public Person
- {
- string subject;
- public:
- Teacher(string _name = "", string _family = "", string _subject = "") :Person(_name, _family), subject(_subject) {}
- Teacher(const Teacher &other) :Person(other), subject(other.subject) {}
- Teacher& operator =(const Teacher &other)
- {
- Person::operator=(other);
- subject = other.subject;
- return *this;
- }
- /* no dynamic memory here,destructor not needed
- ~Student()
- {
- }
- */
- string Subject()
- {
- return subject;
- }
- void Print()
- {
- cout << Person::Name() << " " << Person::Family() << ": " << subject << endl;
- }
- };
- class School
- {
- Student *students;
- Teacher *teachers;
- int studentSize;
- int teacherSize;
- public:
- School(Student *_students = nullptr, int _studentSize = 0, Teacher *_teachers = nullptr, int _teachersize = 0) :students(_students), teachers(_teachers), studentSize(_studentSize), teacherSize(_teachersize) {}
- School(School &other) :students(other.students), studentSize(other.studentSize), teachers(other.teachers), teacherSize(other.teacherSize) {}
- School& operator =(School &other)
- {
- School *temp = new School(other);
- *this = *temp;
- return *this;
- }
- ~School()
- {
- delete[] students;
- delete[] teachers;
- }
- Student StudentByID(int ID)
- {
- for (int i = 0; i < studentSize; i++)
- {
- if (students[i].ID() == ID)
- {
- return students[i];
- }
- }
- }
- void PrintStudentInfo(string _name, string _family)
- {
- for (int i = 0; i < studentSize; i++)
- {
- if (students[i].Name() == _name && students[i].Family() == _family)
- {
- students[i].Print();
- //break; бих бреакнал, но по условие се иска да намерим всички ученици с тези имена
- }
- }
- }
- void PrintTeacherDiscipline(string _discipline)
- {
- for (int i = 0; i < teacherSize; i++)
- {
- if (teachers[i].Subject() == _discipline)
- teachers[i].Print();
- }
- }
- };
- int main()
- {
- Teacher *teachers = new Teacher[5];
- teachers[0] = Teacher("Joeseph", "Goebbels", "History");
- teachers[1] = Teacher("Anne", "Frank", "Literature");
- teachers[2] = Teacher("Heinrich", "Himmler", "Physical Education");
- teachers[3] = Teacher("Hermann", "Fegelein", "Math");
- teachers[4] = Teacher("Eva", "Braun", "Music");
- Student *students = new Student[5];
- students[0] = Student("Good", "Goyim", 12, 0);
- students[1] = Student("Kaik", "Shekelstein", 13, 1);
- students[2] = Student("Not", "See", 11, 2);
- students[3] = Student("Sicks", "Gorrilion", 12, 3);
- students[4] = Student("Didnot", "Ingwrong", 13, 4);
- School school = School(students, 5, teachers, 5);
- school.PrintStudentInfo("Kaik", "Shekelstein");
- school.PrintTeacherDiscipline("History");
- Student test = school.StudentByID(3);
- test.Print();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement