Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 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. unsigned int discPoints;
  65. public:
  66. examBook(string getdiscipline, int getdiscPoints)
  67. { discipline = getdiscipline; discPoints = getdiscPoints; }
  68.  
  69. string getdiscipline() {
  70. return discipline;
  71. }
  72.  
  73. int getdiscPoints() {
  74. return discPoints;
  75. }
  76.  
  77. friend ostream& operator <<(ostream& out, const examBook& obj) {
  78. return (out << obj.discipline << endl << obj.discPoints << endl);
  79. }
  80.  
  81. friend istream& operator >>(istream& in, examBook& obj){
  82. in >> obj.discipline;
  83. in >> obj.discPoints;
  84. return in;
  85. }// i/o stream
  86.  
  87. // friend ofstream& operator >>(ofstream& out, const examBook& obj) {
  88. // return (out << obj.discipline << endl << obj.discPoints << endl);
  89. //}
  90.  
  91. friend ifstream& operator <<(ifstream& in, examBook& obj) {
  92. in >> obj.discipline;
  93. in >> obj.discPoints;
  94. return in;
  95. }// i/o fstream
  96.  
  97.  
  98.  
  99. /* examBook operator +(examBook ob) {
  100. examBook temp;
  101. temp.discPoints = discPoints + ob.discPoints;
  102. return temp;
  103. }*/
  104. /* friend int iCardSum(examBook& obj, int addedPoints) {
  105. obj.discPoints += addedPoints;
  106. return obj.discPoints;
  107. }*/
  108.  
  109. friend unsigned operator +(examBook& ob,const unsigned int & iCardSum) {
  110. return ob.discPoints = ob.discPoints + iCardSum;
  111. }
  112. };
  113. class CStudentBook:public cstudent
  114. {
  115. private:
  116. list<examBook>exmB_points;
  117. public:
  118. CStudentBook();
  119.  
  120. void showAll() {
  121.  
  122. list<examBook>::iterator it;
  123. for (it = exmB_points.begin(); it != exmB_points.end(); it++)
  124. {
  125. cout << (*it).getdiscipline() << (*it).getdiscPoints() << endl;
  126. }
  127. }
  128.  
  129. void setList(examBook& ob) {
  130. exmB_points.push_back(ob);
  131. }
  132.  
  133. };
  134.  
  135. int main()
  136. {
  137. examBook predmet("matematika", 10), predmet1("da",3);
  138. // cout << predmet << endl;
  139. // cin >> predmet;
  140. //// iCardSum(predmet, 10);
  141. // predmet + (predmet,10);
  142. // cout << predmet << endl;
  143.  
  144.  
  145. /*ofstream myfile("test.txt");
  146. cin >> predmet;
  147. if (myfile.is_open())
  148. {
  149. myfile << predmet;
  150. myfile.close();
  151. }
  152. else cout << "Unable to open file";
  153.  
  154. string line;
  155. ifstream da("test.txt");
  156. if (da.is_open())
  157. {
  158. cout << line << '\n';
  159.  
  160. da.close();
  161. }
  162. else cout << "Unable to open file";*/
  163. CStudentBook obe;
  164. obe.set_fnum("123");
  165. obe.setList(predmet);
  166. obe.setList(predmet1);
  167. obe.showAll();
  168. system("pause");
  169. return 0;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement