Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class przedmiot{
  6.     public:
  7.         int kod_przedmiotu;
  8.         int ocena;
  9. };
  10.  
  11. class egzamin
  12. {
  13.     private:
  14.         string nazwisko;
  15.         int stypendium;
  16.         przedmiot *T;
  17.         int n;
  18.     public:
  19.         egzamin(string nazwisko, int n = 3): nazwisko(nazwisko),n(n)
  20.         {
  21.             T = new przedmiot [this->n];
  22.             this->stypendium=0;
  23.             for (int i = 0; i< this->n;i++)
  24.             {
  25.                 this->T[i].ocena = 0;
  26.                 this->T[i].kod_przedmiotu = i+1;
  27.             }
  28.         }
  29.         void wpisz(int value,int nr)
  30.         {
  31.             this->T[nr-1].ocena = value;
  32.         }
  33.         void sred (double &s,int &l)
  34.         {
  35.             int ilosc = 0;
  36.             int suma = 0;
  37.             for (int i = 0 ;i < this->n ; i++ )
  38.                 if (this->T[i].ocena > 0)
  39.                     {
  40.                         ilosc++;
  41.                         suma+=this->T[i].ocena;
  42.                     }
  43.             if (ilosc > 0)
  44.             s =(double) suma /ilosc;
  45.             ilosc = 0;
  46.             for (int i = 0; i < this->n ;i++)
  47.                 if (this->T[i].ocena == 0 || this->T[i].ocena == 2)
  48.                     ilosc++;
  49.             l = ilosc;
  50.         }
  51.         void wyswietl()
  52.         {
  53.             double sr;
  54.             int il;
  55.             this->sred(sr,il);
  56.             cout<<"Nazwisko: "<<this->nazwisko<<endl;
  57.             if (this->stypendium > 0)
  58.                 cout<<"Stypendium: "<<this->stypendium<<endl;
  59.             cout<<"Srednia: "<<sr<<endl
  60.             <<"Ilosc dwojek: "<<il<<endl;
  61.            
  62.         }
  63.         egzamin* smin(egzamin* w)
  64.         {
  65.             double sr1,sr2;
  66.             int il;
  67.             this->sred(sr1,il);
  68.             w->sred(sr2,il);
  69.             if (sr1 >= sr2)
  70.                 return this;
  71.             else return w;
  72.         }
  73.         void styp(int k)
  74.         {
  75.             double sr;
  76.             int il;
  77.             this->sred(sr,il);
  78.             if (sr>4 && il == 0)
  79.             this->stypendium+=k;
  80.         }
  81. };
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. main()
  90. {
  91.     egzamin T("Walczyna",3);
  92.     T.wpisz(5,1);
  93.     T.wpisz(5,2);
  94.     T.wpisz(4,3);
  95.     T.styp(20);
  96.     T.wyswietl();
  97.     egzamin A("Kowalski",5);
  98.     A.wpisz(4,1);
  99.     A.wpisz(5,2);
  100.     A.wpisz(2,3);
  101.     A.wpisz(3,4);
  102.     A.wpisz(4,5);
  103.     A.styp(20);
  104.     A.wyswietl();
  105.     (A.smin(&T))->wyswietl();
  106.    
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement