Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. *************************Student.h*****************************
  2. #include<iostream>
  3. #include<string>
  4. using namespace std;
  5.  
  6. class Student {
  7. string ime;
  8. long ind;
  9. int* ocene;
  10. int br_oc, kap;
  11. public:
  12. Student(string iime, long iind, int kapp = 40);
  13. ~Student() { delete[] ocene; }
  14. Student(const Student&) = delete;
  15. Student& operator=(const Student&) = delete;
  16.  
  17. //dohv ind i imena
  18. long dohvInd() const { return ind; }
  19. string dohvIme() const { return ime; }
  20. Student& promeniIme(string iime) { ime = iime; return *this; }
  21. Student& promeniInd(long iind) { ind = iind; return *this; }
  22.  
  23. //dodavanje nove ocene +=
  24. Student& operator+=(int ocena) {
  25. if (br_oc == kap) exit(1);
  26. else
  27. ocene[++br_oc] = ocena;
  28. return *this;
  29. }
  30.  
  31. //dohvatanje broja ocene ocene
  32.  
  33. int dohvBrOcena() const {
  34. return br_oc;
  35. }
  36.  
  37. //dohv ocene sa zadatim rednim brojem
  38.  
  39. int operator[](int i) const {
  40. if (i < 0 || i>br_oc) exit(2);
  41. else
  42. return ocene[i];
  43.  
  44. }
  45.  
  46. //izracunavanje srednje ocene
  47.  
  48. double sr_ocena() {
  49. double suma=0;
  50. if (br_oc > 0) {
  51. for (int i = 0; i < br_oc; suma += ocene[i++]);
  52. return suma / br_oc;
  53.  
  54. }
  55. else return 0;
  56. }
  57.  
  58.  
  59.  
  60. };
  61.  
  62.  
  63.  
  64. ************************************CPP FAJL*****************************************************
  65.  
  66. #include "Student.h"
  67. #include<iostream>
  68.  
  69. using namespace std;
  70.  
  71. int main() {
  72. int n;
  73. cin >> n;
  74. Student** s= new Student*[n];
  75.  
  76. for (int i = 0; i < n; i++) {
  77. string ime;
  78. long ind;
  79. cin >> ime >> ind;
  80. Student *t = new Student(ime, ind);
  81.  
  82. int br_oc;
  83. cin >> br_oc;
  84. for (int j = 0; j < br_oc; j++) {
  85. int ocena; cin >> ocena; *t += ocena;
  86. }
  87.  
  88. //umetanje u uredjeni niz
  89.  
  90. int k = i;
  91. while (k > 0 && s[k - 1]->sr_ocena() < t->sr_ocena()) { s[k] = s[k - 1]; k--; }
  92. s[k] = t;
  93. }
  94.  
  95. //ispisivanje uredjenog niza
  96. //imena i srednje ocene
  97.  
  98. for (int i = 0; i < n; i++) {
  99. cout << s[i]->dohvIme() << " " << s[i]->sr_ocena() << endl;
  100.  
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement