Advertisement
Guest User

Untitled

a guest
May 13th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. class Person
  5. {
  6. string name;
  7. string family;
  8. public:
  9. Person(string _name = "", string _family = "") :name(_name), family(_family) {}
  10. Person(const Person &other) :name(other.name), family(other.family) {}
  11. Person& operator =(const Person &other)
  12. {
  13. name = other.name;
  14. family = other.family;
  15. return *this;
  16. }
  17. /* no dynamic memory here,destructor not needed
  18. ~Person()
  19. {
  20.  
  21. }
  22. */
  23. Person::string Name()
  24. {
  25. return name;
  26. }
  27. Person::string Family()
  28. {
  29. return family;
  30. }
  31. };
  32. class Student :public Person
  33. {
  34. int age;
  35. int SchoolID;
  36. public:
  37. Student(string _name = "", string _family = "", int _age = 0, int _ID = 0) :Person(_name, _family), age(_age), SchoolID(_ID) {}
  38. Student(const Student &other) : Person(other), age(other.age), SchoolID(other.SchoolID) {}
  39.  
  40. Student& operator =(const Student &other)
  41. {
  42. Person::operator=(other);
  43. age = other.age;
  44. SchoolID = other.SchoolID;
  45. return *this;
  46. }
  47. /* no dynamic memory here,destructor not needed
  48. ~Student()
  49. {
  50.  
  51. }
  52. */
  53. int ID()
  54. {
  55. return SchoolID;
  56. }
  57. void Print()
  58. {
  59. cout << Person::Name() << " " << Person::Family() << ": " << age << " years old, ID: " << SchoolID << endl;
  60. }
  61. };
  62. class Teacher :public Person
  63. {
  64. string subject;
  65. public:
  66. Teacher(string _name = "", string _family = "", string _subject = "") :Person(_name, _family), subject(_subject) {}
  67. Teacher(const Teacher &other) :Person(other), subject(other.subject) {}
  68. Teacher& operator =(const Teacher &other)
  69. {
  70. Person::operator=(other);
  71. subject = other.subject;
  72. return *this;
  73. }
  74. /* no dynamic memory here,destructor not needed
  75. ~Student()
  76. {
  77.  
  78. }
  79. */
  80. string Subject()
  81. {
  82. return subject;
  83. }
  84. void Print()
  85. {
  86. cout << Person::Name() << " " << Person::Family() << ": " << subject << endl;
  87. }
  88. };
  89. class School
  90. {
  91. Student *students;
  92. Teacher *teachers;
  93. int studentSize;
  94. int teacherSize;
  95. public:
  96. School(Student *_students = nullptr, int _studentSize = 0, Teacher *_teachers = nullptr, int _teachersize = 0) :students(_students), teachers(_teachers), studentSize(_studentSize), teacherSize(_teachersize) {}
  97. School(School &other) :students(other.students), studentSize(other.studentSize), teachers(other.teachers), teacherSize(other.teacherSize) {}
  98. School& operator =(School &other)
  99. {
  100. School *temp = new School(other);
  101. *this = *temp;
  102. return *this;
  103. }
  104.  
  105. ~School()
  106. {
  107. delete[] students;
  108. delete[] teachers;
  109. }
  110.  
  111. Student StudentByID(int ID)
  112. {
  113. for (int i = 0; i < studentSize; i++)
  114. {
  115. if (students[i].ID() == ID)
  116. {
  117. return students[i];
  118. }
  119. }
  120. }
  121. void PrintStudentInfo(string _name, string _family)
  122. {
  123. for (int i = 0; i < studentSize; i++)
  124. {
  125. if (students[i].Name() == _name && students[i].Family() == _family)
  126. {
  127. students[i].Print();
  128. //break; бих бреакнал, но по условие се иска да намерим всички ученици с тези имена
  129. }
  130. }
  131. }
  132. void PrintTeacherDiscipline(string _discipline)
  133. {
  134. for (int i = 0; i < teacherSize; i++)
  135. {
  136. if (teachers[i].Subject() == _discipline)
  137. teachers[i].Print();
  138. }
  139. }
  140. };
  141. int main()
  142. {
  143. Teacher *teachers = new Teacher[5];
  144. teachers[0] = Teacher("Joeseph", "Goebbels", "History");
  145. teachers[1] = Teacher("Anne", "Frank", "Literature");
  146. teachers[2] = Teacher("Heinrich", "Himmler", "Physical Education");
  147. teachers[3] = Teacher("Hermann", "Fegelein", "Math");
  148. teachers[4] = Teacher("Eva", "Braun", "Music");
  149. Student *students = new Student[5];
  150. students[0] = Student("Good", "Goyim", 12, 0);
  151. students[1] = Student("Kaik", "Shekelstein", 13, 1);
  152. students[2] = Student("Not", "See", 11, 2);
  153. students[3] = Student("Sicks", "Gorrilion", 12, 3);
  154. students[4] = Student("Didnot", "Ingwrong", 13, 4);
  155. School school = School(students, 5, teachers, 5);
  156. school.PrintStudentInfo("Kaik", "Shekelstein");
  157. school.PrintTeacherDiscipline("History");
  158. Student test = school.StudentByID(3);
  159. test.Print();
  160. system("pause");
  161. return 0;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement