Advertisement
Guest User

Untitled

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