Advertisement
Guest User

Untitled

a guest
May 19th, 2017
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5. /*
  6. class Date
  7. {
  8. private:
  9. int year, month, day;
  10. public:
  11. Date(int y, int m, int d) { year = y; month = m; day = d; }
  12. bool operator=(const Date d)
  13. {
  14.  
  15. }
  16.  
  17. };
  18. */
  19.  
  20. class MyObject
  21. {
  22. virtual MyObject* clone()=0;
  23. virtual string toString()=0;
  24.  
  25. };
  26.  
  27.  
  28. class UniMember : public MyObject
  29. {
  30. private:
  31. string name, e_mail, dob;
  32.  
  33. public:
  34. UniMember(string n, string e, string d);
  35. virtual void print();
  36. string toString() final override;
  37. };
  38.  
  39. void UniMember::print(){
  40. cout << "UniMember name: "<<name<<endl;
  41. cout << "UniMember e_mail: "<<e_mail<<endl;
  42. cout << "dob: "<<dob<<endl;
  43. }
  44.  
  45. UniMember::UniMember(string n, string e, string d)
  46. : name(n), e_mail(e), dob(d)
  47. {
  48. cout << "UniMem init" << endl;
  49. }
  50.  
  51.  
  52. class Student : public UniMember
  53. {
  54. private:
  55. int admissionYear;
  56. list<string> courses;
  57.  
  58. public:
  59. Student(string n, string e, string d, int y, list<string> coursesList);
  60. virtual void print();
  61. Student* clone() override;
  62.  
  63. };
  64.  
  65. Student* Student::clone(){
  66. return new Student(*this);
  67. }
  68.  
  69. void Student :: print (){
  70. cout <<"Student Admission Year: "<<admissionYear<<endl;
  71. }
  72. Student :: Student(string n, string e, string d, int y, list<string> coursesList)
  73. : UniMember(n, e, d), admissionYear(y), courses(coursesList)
  74. {
  75. cout << "student init" << endl;
  76. }
  77.  
  78. class Teacher : public UniMember
  79. {
  80. private:
  81. list<string> courses;
  82.  
  83. public:
  84. Teacher(string n, string e, string d, list<string> coursesList);
  85. virtual void print();
  86. Teacher* clone() override;
  87.  
  88. };
  89.  
  90. Teacher* Teacher::clone(){
  91. return new Teacher(*this);
  92. }
  93.  
  94. void Teacher :: print(){
  95. UniMember::print();
  96. //print courses
  97. }
  98. Teacher :: Teacher(string n, string e, string d, list<string> coursesList)
  99. : UniMember(n, e, d), courses(coursesList)
  100. {
  101. cout << "teacher init" << endl;
  102. }
  103.  
  104. void test1()
  105. {
  106. UniMember* pUniMember;
  107. list<string> L = { "maths", "c++", "stuff" };
  108. pUniMember = new Student{"John", "john@stud.com", "1827-05-28", 1997, L};
  109.  
  110. list<string> tL = { "theory of something", "physics" };
  111. pUniMember = new Teacher {"Peter", "boss@uni.ro", "1672-02-12", tL};
  112. pUniMember->print();
  113.  
  114. Teacher* pTeacher;
  115. pTeacher = new Teacher {"Ralph", "ralph@uni.ro", "1972-02-12", tL};
  116. // pTeacher = new UniMember { ""}
  117. }
  118.  
  119. void test_lab10_1(){
  120. list<UniMember*>uList;
  121. list<string> L = { "maths", "c++", "stuff" };
  122. list<string> tL = { "theory of something", "physics" };
  123. uList.push_back(new Teacher{"Peter", "boss@uni.ro", "1672-02-12", tL});
  124. uList.push_back(new Student{"John", "john@stud.com", "1827-05-28", 1997, L});
  125. // uList.push_back(new UniMember{"DASAS","asd@asd.com","123-123-123"});
  126. for (list<UniMember*>::iterator it = uList.begin();it!=uList.end();++it){
  127. (*it)->print();
  128. cout << endl;
  129. }
  130. }
  131.  
  132. //void testNotInst(){
  133. // UniMember{"ASDAWD","asd22@a22sd.com","123-123-123"};
  134. //
  135. //}
  136.  
  137. string UniMember::toString(){
  138. return string("abc");
  139. }
  140.  
  141. int main()
  142. {
  143. // UniMember Andrew{"Andrew", "andrew@uni.com", "2017-04-12"};
  144. //
  145. // list<string> L = { "maths", "c++", "stuff" };
  146. // Student John{"John", "john@stud.com", "1827-05-28", 1997, L};
  147. //
  148. // list<string> tL = { "theory of chibrit", "boring stuff III" };
  149. // Teacher Peter{"Peter", "boss@uni.ro", "1672-02-12", tL};
  150. return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement