Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <list>
  5. #include <iterator>
  6. #include <fstream>
  7. using namespace std;
  8. class cstudent
  9. {
  10. private:
  11. vector <double> grades;
  12. protected:
  13. string fnum;
  14. public:
  15. cstudent(string getfnum)
  16. {
  17. fnum = getfnum;
  18. }
  19. cstudent(const cstudent& obj)
  20. {
  21. fnum = obj.fnum;
  22. }
  23. void set_fnum(string getfnum)
  24. {
  25. fnum = getfnum;
  26. }
  27. string getfnum()
  28. {
  29. return fnum;
  30. }
  31. virtual double avgcalc()
  32. {
  33. if (grades.size() > 0)
  34. {
  35. vector<double>::iterator iter;
  36. double avg_grade(0);
  37. for (iter = grades.begin(); iter != grades.end(); iter++)
  38. {
  39. avg_grade += (*iter);
  40. }
  41. avg_grade = avg_grade / grades.size();
  42. return avg_grade;
  43. }
  44. }
  45. friend ostream& operator <<(ostream& out, const cstudent& obj)
  46. {
  47. out << obj.fnum;
  48. return out;
  49. }
  50. friend istream& operator >>(istream& in, cstudent& obj)
  51. {
  52. in >> obj.fnum;
  53. return in;
  54. }
  55. cstudent operator =(cstudent& obj)
  56. {
  57. fnum = obj.fnum;
  58. return *this;
  59. }
  60. };
  61. class examBook
  62. {
  63. string discipline;
  64. int discPoints;
  65. public:
  66. examBook() {}
  67. examBook(string getdiscipline, int getdiscPoints)
  68. {
  69. discipline = getdiscipline; discPoints = getdiscPoints;
  70. }
  71.  
  72. string getdiscipline() {
  73. return discipline;
  74. }
  75.  
  76. int getdiscPoints() {
  77. return discPoints;
  78. }
  79. void show()
  80. {
  81. cout << getdiscipline();
  82. cout << endl << getdiscipline();
  83. }
  84. friend ostream& operator <<(ostream& out, const examBook& obj)
  85. {
  86. return (out << obj.discipline << endl << obj.discPoints << endl);
  87. }
  88.  
  89. friend istream& operator >>(istream& in, examBook& obj) {
  90. in >> obj.discipline;
  91. in >> obj.discPoints;
  92. return in;
  93. }
  94. };
  95. class cstudentbook : public cstudent
  96. {
  97. list<examBook> listOfBooks;
  98. public:
  99. cstudentbook() {};
  100. void setList(examBook& obj)
  101. {
  102. listOfBooks.push_back(obj);
  103. }
  104. void show()
  105. {
  106. list<examBook>::iterator iter;
  107. for (iter = listOfBooks.begin(); iter != listOfBooks.end(); iter++)
  108. {
  109. (*iter).show();
  110. }
  111. }
  112. };
  113. int main()
  114. {
  115. examBook predmet("matematika", 10),predmet2("istoriq",40);
  116. cstudentbook obekt;
  117. obekt.setList(predmet);
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement