Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Indeks;
  5. class Ocena
  6. {
  7. private:
  8.     string przedmiot;
  9.     float nota;
  10.  
  11. public:
  12.     Ocena();
  13.     Ocena(string przedmiot1, float nota1);
  14.     void UstawPrzedmiot(string p);
  15.     string ZwrocPrzedmiot();
  16.     void UstawNota(float n);
  17.     float ZwrocNota();
  18.     void Wypisz();
  19.     bool operator<(Ocena oc2);
  20.     Ocena& operator++(int n); //n jest "kuk³¹" do odró¿nienia dwoch wersji
  21.  
  22.     friend ostream& operator<<(ostream& c, Ocena oc);
  23.     friend class Indeks;
  24.  
  25. };
  26. class Indeks
  27. {
  28. public:
  29.     string osoba;
  30. private:
  31.     Ocena *oceny;
  32.     int rozmiar;
  33.     public:
  34.     Indeks(int rozmiar1);
  35.     ~Indeks();
  36.     void Ustaw(int poz, string przedmiot, float nota);
  37.  
  38.  
  39. };
  40. Indeks::Indeks(int rozmiar1)
  41. {
  42.     rozmiar=rozmiar1;
  43.     oceny=new Ocena[rozmiar];
  44. }
  45. Indeks::~Indeks()
  46. {
  47.     delete[]oceny;
  48.     rozmiar=0;
  49. }
  50. void Indeks::Ustaw(int poz, string przedmiot, float nota)
  51. {
  52.     oceny[poz].przedmiot=przedmiot;
  53.     oceny[poz].nota=nota;
  54. }
  55.  
  56. Ocena::Ocena(string przedmiot1, float nota1)
  57. {
  58.     przedmiot=przedmiot1;
  59.     nota=nota1;
  60. }
  61. Ocena::Ocena()
  62. {
  63.     przedmiot="";
  64.     nota=0;
  65. }
  66. void Ocena::Wypisz()
  67. {
  68.     cout<<przedmiot<<": "<<endl;
  69.     cout<<nota<<endl;
  70. }
  71. void Ocena::UstawPrzedmiot(string p)
  72. {
  73.     przedmiot=p;
  74. }
  75.  
  76. void Ocena::UstawNota(float n)
  77. {
  78.     nota=n;
  79. }
  80.  
  81. float Ocena::ZwrocNota()
  82. {
  83.     return nota;
  84. }
  85. bool Ocena::operator<(Ocena oc2)//przeciazenie operatorow w klasie
  86. {
  87.     if(nota<oc2.nota)
  88.         return true;
  89.     else
  90.         return false;
  91. }
  92.  
  93. bool operator>(Ocena oc1, Ocena oc2)
  94. {
  95.     if(oc1.ZwrocNota()>oc2.ZwrocNota())
  96.         return true;
  97.         else
  98.         return false;
  99. }
  100. string Ocena::ZwrocPrzedmiot()
  101. {
  102.     return przedmiot;
  103. }
  104.  
  105.  
  106.  
  107. Ocena&Ocena::operator++(int n)
  108. {
  109.   if(nota==2.0)
  110.         {
  111.             nota++;
  112.         }
  113.         else if( (nota>2.0) && (nota<5.0) )
  114.         {
  115.             nota=nota+0.5;
  116.         }
  117.      return *this; //samo this jest wskaznikiem.
  118. }
  119.  
  120. ostream& operator<<(ostream& c, Ocena oc)//musi byc poza klasa
  121. { //musimy zaprzyjaŸnic w klasie
  122.     c<< oc.przedmiot << ":"<< oc.nota;
  123.     return c;
  124. }
  125.  
  126.  
  127. int main()
  128. {
  129. Ocena oc1("Analiza",3);
  130. Ocena *oc2= new Ocena("Algebra",4);
  131.  
  132.     if(oc1>*oc2) //if(oc1.operator>(*oc2))
  133.     cout<<"Przedmiot :"<<oc1.ZwrocPrzedmiot();
  134.     else
  135.     cout<<"Przedmiot :"<<oc2->ZwrocPrzedmiot();
  136.  
  137. cout << endl << endl;
  138. cout << oc1 << endl;
  139. oc1++;
  140. cout << oc1;
  141. cout << endl << endl;
  142.  
  143. oc1.Wypisz();
  144. oc2->Wypisz();
  145.  
  146. }
  147. // funkcja znajdz , ktora zwraca ocene po wpisauniu przedmiotu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement