Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Indeks;
- class Ocena
- {
- private:
- string przedmiot;
- float nota;
- public:
- Ocena();
- Ocena(string przedmiot1, float nota1);
- void UstawPrzedmiot(string p);
- string ZwrocPrzedmiot();
- void UstawNota(float n);
- float ZwrocNota();
- void Wypisz();
- bool operator<(Ocena oc2);
- Ocena& operator++(int n); //n jest "kuk³¹" do odró¿nienia dwoch wersji
- friend ostream& operator<<(ostream& c, Ocena oc);
- friend class Indeks;
- };
- class Indeks
- {
- public:
- string osoba;
- private:
- Ocena *oceny;
- int rozmiar;
- public:
- Indeks(int rozmiar1);
- ~Indeks();
- void Ustaw(int poz, string przedmiot, float nota);
- };
- Indeks::Indeks(int rozmiar1)
- {
- rozmiar=rozmiar1;
- oceny=new Ocena[rozmiar];
- }
- Indeks::~Indeks()
- {
- delete[]oceny;
- rozmiar=0;
- }
- void Indeks::Ustaw(int poz, string przedmiot, float nota)
- {
- oceny[poz].przedmiot=przedmiot;
- oceny[poz].nota=nota;
- }
- Ocena::Ocena(string przedmiot1, float nota1)
- {
- przedmiot=przedmiot1;
- nota=nota1;
- }
- Ocena::Ocena()
- {
- przedmiot="";
- nota=0;
- }
- void Ocena::Wypisz()
- {
- cout<<przedmiot<<": "<<endl;
- cout<<nota<<endl;
- }
- void Ocena::UstawPrzedmiot(string p)
- {
- przedmiot=p;
- }
- void Ocena::UstawNota(float n)
- {
- nota=n;
- }
- float Ocena::ZwrocNota()
- {
- return nota;
- }
- bool Ocena::operator<(Ocena oc2)//przeciazenie operatorow w klasie
- {
- if(nota<oc2.nota)
- return true;
- else
- return false;
- }
- bool operator>(Ocena oc1, Ocena oc2)
- {
- if(oc1.ZwrocNota()>oc2.ZwrocNota())
- return true;
- else
- return false;
- }
- string Ocena::ZwrocPrzedmiot()
- {
- return przedmiot;
- }
- Ocena&Ocena::operator++(int n)
- {
- if(nota==2.0)
- {
- nota++;
- }
- else if( (nota>2.0) && (nota<5.0) )
- {
- nota=nota+0.5;
- }
- return *this; //samo this jest wskaznikiem.
- }
- ostream& operator<<(ostream& c, Ocena oc)//musi byc poza klasa
- { //musimy zaprzyjaŸnic w klasie
- c<< oc.przedmiot << ":"<< oc.nota;
- return c;
- }
- int main()
- {
- Ocena oc1("Analiza",3);
- Ocena *oc2= new Ocena("Algebra",4);
- if(oc1>*oc2) //if(oc1.operator>(*oc2))
- cout<<"Przedmiot :"<<oc1.ZwrocPrzedmiot();
- else
- cout<<"Przedmiot :"<<oc2->ZwrocPrzedmiot();
- cout << endl << endl;
- cout << oc1 << endl;
- oc1++;
- cout << oc1;
- cout << endl << endl;
- oc1.Wypisz();
- oc2->Wypisz();
- }
- // funkcja znajdz , ktora zwraca ocene po wpisauniu przedmiotu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement