Advertisement
Josif_tepe

Untitled

Nov 18th, 2023
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class Ucenik{
  8. private:
  9.     string ime;
  10.     double prosek;
  11.     int skolska_godina;
  12. public:
  13.     Ucenik(){
  14.     }
  15.     Ucenik(string _ime, double _prosek, int _skolska_godina){
  16.         ime = _ime;
  17.         prosek = _prosek;
  18.         skolska_godina = _skolska_godina;
  19.     }
  20.     Ucenik & operator ++ (int i){
  21.         skolska_godina++;
  22.         return *this;
  23.     }
  24.     friend ostream & operator << (ostream & stream, Ucenik u);
  25.     bool operator > (Ucenik tmp) {
  26.         if(prosek > tmp.prosek){
  27.             return true;
  28.         }
  29.         return false;
  30.     }
  31.     double get_prosek() {
  32.         return prosek;
  33.     }
  34. };
  35. ostream & operator << (ostream & stream, Ucenik u) {
  36.     stream << u.ime << " " << u.prosek << " " << u.skolska_godina << endl;
  37.     return stream;
  38. }
  39. class Paralelka {
  40. private:
  41.     int n;
  42.     Ucenik * niza;
  43. public:
  44.     Paralelka () {}
  45.     Paralelka(int _n) {
  46.         n = _n;
  47.         niza = new Ucenik[n];
  48.     }
  49.     Paralelka & operator += (Ucenik u) {
  50.         Ucenik tmp[n + 1];
  51.         for(int i = 0; i < n; i++) {
  52.             tmp[i] = niza[i];
  53.         }
  54.         tmp[n] = u;
  55.         n++;
  56.         niza = new Ucenik[n];
  57.        
  58.         for(int i = 0; i < n; i++) {
  59.             niza[i] = tmp[i];
  60.         }
  61.         return *this;
  62.     }
  63.     Paralelka & operator ++ (int i) {
  64.         for(int i = 0; i < n; i++) {
  65.             niza[i]++;
  66.         }
  67.         return *this;
  68.     }
  69.     void nagrada() {
  70.         for(int i = 0; i < n; i++) {
  71.             if(niza[i].get_prosek() == 10.0) {
  72.                 cout << niza[i];
  73.             }
  74.         }
  75.     }
  76.     void najvisokProsek() {
  77.         double najgolem_prosek = 0.0;
  78.         int idx = 0;
  79.         for(int i = 0; i < n; i++) {
  80.             if(niza[i].get_prosek() > najgolem_prosek) {
  81.                 najgolem_prosek = niza[i].get_prosek();
  82.                 idx = i;
  83.             }
  84.         }
  85.         cout << niza[idx];
  86.     }
  87.     friend ostream & operator << (ostream & stream, Paralelka tmp);
  88. };
  89. ostream & operator << (ostream & stream, Paralelka tmp) {
  90.     for(int i = 0; i < tmp.n; i++) {
  91.         stream << tmp.niza[i];
  92.     }
  93.     return stream;
  94. }
  95.    
  96. int main()
  97. {
  98.     Ucenik u1("Martina Martinovska", 9.5, 3);
  99.     Ucenik u2("Darko Darkoski", 7.3, 2);
  100.     Ucenik u3("Angela Angelovska", 10, 3);
  101.     Paralelka p(0);
  102.     p += u1;
  103.     p += u2;
  104.     p += u3;
  105.     cout << p;
  106.     cout << "Nagradeni:" << endl;
  107.     p.nagrada();
  108.     cout << endl;
  109.     p.najvisokProsek();
  110.     cout << endl;
  111.     u2++;
  112.     cout << p;
  113.     cout << endl;
  114.     p++;
  115.     cout << p;
  116.     return 0;
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement