Mitrezzz

Мој Термин

May 6th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Lekar {
  7. protected:
  8.     int fax;
  9.     char ime[15];
  10.     char prezime[15];
  11.     double p;
  12. public:
  13.     Lekar() {
  14.     }
  15.     Lekar (const int fax, const char *ime, const char *prezime, const double p) {
  16.         this->fax = fax;
  17.         strcpy(this->ime,ime);
  18.         strcpy(this->prezime,prezime);
  19.         this->p = p;
  20.     }
  21.     Lekar (const Lekar &l) {
  22.         fax = l.fax;
  23.         strcpy(ime,l.ime);
  24.         strcpy(prezime,l.prezime);
  25.         p = l.p;
  26.     }
  27.     Lekar& operator= (const Lekar &l) {
  28.         if (this!=&l) {
  29.             fax = l.fax;
  30.             strcpy(ime,l.ime);
  31.             strcpy(prezime,l.prezime);
  32.             p = l.p;
  33.         }
  34.         return *this;
  35.     }
  36.     void pecati() {
  37.         cout<<fax<<": "<<ime<<" "<<prezime<<endl;
  38.     }
  39.     double plata () {
  40.         return p;
  41.     }
  42. };
  43.  
  44. class MaticenLekar :public Lekar {
  45. private:
  46.     int brPacienti;
  47.     double *kotizacii;
  48. public:
  49.     MaticenLekar () {
  50.         this->kotizacii = new double[0];
  51.     }
  52.     MaticenLekar (const Lekar &l, const int brPacienti, const double *kotizacii) : Lekar (l) {
  53.         this->brPacienti = brPacienti;
  54.         this->kotizacii = new double[brPacienti];
  55.         for (int i=0; i<brPacienti; i++) {
  56.             this->kotizacii[i] = kotizacii[i];
  57.         }
  58.     }
  59.     MaticenLekar (const MaticenLekar &ml) {
  60.         fax = ml.fax;
  61.         strcpy(ime,ml.ime);
  62.         strcpy(prezime,ml.prezime);
  63.         p = ml.p;
  64.         brPacienti = ml.brPacienti;
  65.         kotizacii = new double[brPacienti];
  66.         for (int i=0; i<brPacienti; i++) {
  67.             kotizacii[i] = ml.kotizacii[i];
  68.         }
  69.  
  70.     }
  71.     MaticenLekar& operator=(const MaticenLekar &ml) {
  72.         if (this!=&ml) {
  73.             fax = ml.fax;
  74.             strcpy(ime,ml.ime);
  75.             strcpy(prezime,ml.prezime);
  76.             p = ml.p;
  77.             brPacienti = ml.brPacienti;
  78.             kotizacii = new double[brPacienti];
  79.             for (int i=0; i<brPacienti; i++) {
  80.                 kotizacii[i] = ml.kotizacii[i];
  81.             }
  82.         }
  83.         return *this;
  84.     }
  85.     ~MaticenLekar () {
  86.         delete[] kotizacii;
  87.     }
  88.     double prosek () {
  89.         double zbir=0;
  90.         double prosek;
  91.         for (int i=0; i<brPacienti; i++) {
  92.             zbir+=kotizacii[i];
  93.         }
  94.         prosek = zbir/brPacienti;
  95.         return prosek;
  96.     }
  97.     void pecati() {
  98.         Lekar::pecati();
  99.         cout<<"Prosek na kotizacii: "<<prosek()<<endl;
  100.     }
  101.     double plata() {
  102.         return Lekar::plata() + (prosek()*30)/100;
  103.     }
  104. };
  105.  
  106. int main() {
  107.     int n;
  108.     cin>>n;
  109.     int pacienti;
  110.     double kotizacii[100];
  111.     int faksimil;
  112.     char ime [20];
  113.     char prezime [20];
  114.     double osnovnaPlata;
  115.  
  116.     Lekar * lekari = new Lekar [n];
  117.     MaticenLekar * maticni = new MaticenLekar [n];
  118.  
  119.     for (int i=0; i<n; i++) {
  120.         cin >> faksimil >> ime >> prezime >> osnovnaPlata;
  121.         lekari[i] = Lekar(faksimil,ime,prezime,osnovnaPlata);
  122.     }
  123.  
  124.     for (int i=0; i<n; i++) {
  125.         cin >> pacienti;
  126.         for (int j=0; j<pacienti; j++) {
  127.             cin >> kotizacii[j];
  128.         }
  129.         maticni[i]=MaticenLekar(lekari[i],pacienti,kotizacii);
  130.     }
  131.  
  132.     int testCase;
  133.     cin>>testCase;
  134.  
  135.     if (testCase==1) {
  136.         cout<<"===TESTIRANJE NA KLASATA LEKAR==="<<endl;
  137.         for (int i=0; i<n; i++) {
  138.             lekari[i].pecati();
  139.             cout<<"Osnovnata plata na gorenavedeniot lekar e: "<<lekari[i].plata()<<endl;
  140.         }
  141.     } else {
  142.         cout<<"===TESTIRANJE NA KLASATA MATICENLEKAR==="<<endl;
  143.         for (int i=0; i<n; i++) {
  144.             maticni[i].pecati();
  145.             cout<<"Platata na gorenavedeniot maticen lekar e: "<<maticni[i].plata()<<endl;
  146.         }
  147.     }
  148.  
  149.     delete [] lekari;
  150.     delete [] maticni;
  151.  
  152.     return 0;
  153. }
Add Comment
Please, Sign In to add comment