Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class przedmiot{
- public:
- int kod_przedmiotu;
- int ocena;
- };
- class egzamin
- {
- private:
- string nazwisko;
- int stypendium;
- przedmiot *T;
- int n;
- public:
- egzamin(string nazwisko, int n = 3): nazwisko(nazwisko),n(n)
- {
- T = new przedmiot [this->n];
- this->stypendium=0;
- for (int i = 0; i< this->n;i++)
- {
- this->T[i].ocena = 0;
- this->T[i].kod_przedmiotu = i+1;
- }
- }
- void wpisz(int value,int nr)
- {
- this->T[nr-1].ocena = value;
- }
- void sred (double &s,int &l)
- {
- int ilosc = 0;
- int suma = 0;
- for (int i = 0 ;i < this->n ; i++ )
- if (this->T[i].ocena > 0)
- {
- ilosc++;
- suma+=this->T[i].ocena;
- }
- if (ilosc > 0)
- s =(double) suma /ilosc;
- ilosc = 0;
- for (int i = 0; i < this->n ;i++)
- if (this->T[i].ocena == 0 || this->T[i].ocena == 2)
- ilosc++;
- l = ilosc;
- }
- void wyswietl()
- {
- double sr;
- int il;
- this->sred(sr,il);
- cout<<"Nazwisko: "<<this->nazwisko<<endl;
- if (this->stypendium > 0)
- cout<<"Stypendium: "<<this->stypendium<<endl;
- cout<<"Srednia: "<<sr<<endl
- <<"Ilosc dwojek: "<<il<<endl;
- }
- egzamin* smin(egzamin* w)
- {
- double sr1,sr2;
- int il;
- this->sred(sr1,il);
- w->sred(sr2,il);
- if (sr1 >= sr2)
- return this;
- else return w;
- }
- void styp(int k)
- {
- double sr;
- int il;
- this->sred(sr,il);
- if (sr>4 && il == 0)
- this->stypendium+=k;
- }
- };
- main()
- {
- egzamin T("Walczyna",3);
- T.wpisz(5,1);
- T.wpisz(5,2);
- T.wpisz(4,3);
- T.styp(20);
- T.wyswietl();
- egzamin A("Kowalski",5);
- A.wpisz(4,1);
- A.wpisz(5,2);
- A.wpisz(2,3);
- A.wpisz(3,4);
- A.wpisz(4,5);
- A.styp(20);
- A.wyswietl();
- (A.smin(&T))->wyswietl();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement