SHARE
TWEET

Untitled

a guest May 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class Vozac
  6. {
  7.    protected:
  8.       char ime[100];
  9.       int vozrast;
  10.       int trki;
  11.       bool vet;
  12.    public:
  13.       // Constructors
  14.       Vozac(){}
  15.       Vozac(const char *ime, int vozrast, int trki, bool vet)
  16.          : vozrast(vozrast), trki(trki), vet(vet) { strcpy(this->ime, ime); }
  17.       virtual ~Vozac(){}
  18.  
  19.       // Overloaded operators
  20.       friend std::ostream &operator <<(std::ostream &output, const Vozac &ob)
  21.       {
  22.          output << ob.ime << std::endl;
  23.          output << ob.vozrast << std::endl;
  24.          output << ob.trki << std::endl;
  25.          if(ob.vet) output << "VETERAN" << std::endl;
  26.          return output;
  27.       }
  28.  
  29.       // Functions
  30.       virtual float zarabotuvacka() const = 0;
  31.       virtual float danok() const = 0;
  32. };
  33.  
  34. class Avtomobilist : public Vozac
  35. {
  36.    private:
  37.       float cena_avto;
  38.    public:
  39.       // Constructors
  40.       Avtomobilist(){}
  41.       Avtomobilist(const char *ime, int vozrast, int trki, bool vet, float cena_avto)
  42.          : Vozac(ime, vozrast, trki, vet), cena_avto(cena_avto){}
  43.      
  44.       // Functions
  45.       float zarabotuvacka() const override { return (float)cena_avto / 5; }
  46.       float danok() const override
  47.       {
  48.          if(trki > 10) { return zarabotuvacka() * 0.15; }
  49.          else { return zarabotuvacka() * 0.10; }
  50.       }
  51. };
  52.  
  53. class Motociklist : public Vozac
  54. {
  55.    private:
  56.       int mokjnost;
  57.    public:
  58.       // Constructors
  59.       Motociklist(){}
  60.       Motociklist(const char *ime, int vozrast, int trki, bool vet, int mokjnost)
  61.          : Vozac(ime, vozrast, trki, vet), mokjnost(mokjnost){}
  62.  
  63.       // Functions
  64.       float zarabotuvacka() const override { return mokjnost * 20; }
  65.       float danok() const override
  66.       {
  67.          if(vet) return zarabotuvacka() * 0.25;
  68.          else return zarabotuvacka() * 0.20;
  69.       }
  70. };
  71.  
  72. bool operator ==(const Vozac &v1, const Vozac &v2) { return v1.zarabotuvacka() == v2.zarabotuvacka(); }
  73. int soIstaZarabotuvachka(Vozac **niza, int n, Vozac *ob)
  74. {
  75.    int count = 0;
  76.    for(int i = 0; i < n; i++)
  77.    {
  78.       if(*niza[i] == *ob) count++;
  79.    }
  80.    return count;
  81. }
  82.  
  83. int main() {
  84.     int n, x;
  85.     cin >> n >> x;
  86.     Vozac **v = new Vozac*[n];
  87.     char ime[100];
  88.     int vozrast;
  89.     int trki;
  90.     bool vet;
  91.     for(int i = 0; i < n; ++i) {
  92.         cin >> ime >> vozrast >> trki >> vet;
  93.         if(i < x) {
  94.             float cena_avto;
  95.             cin >> cena_avto;
  96.             v[i] = new Avtomobilist(ime, vozrast, trki, vet, cena_avto);
  97.         } else {
  98.             int mokjnost;
  99.             cin >> mokjnost;
  100.             v[i] = new Motociklist(ime, vozrast, trki, vet, mokjnost);
  101.         }
  102.     }
  103.     cout << "=== DANOK ===" << endl;
  104.     for(int i = 0; i < n; ++i) {
  105.         cout << *v[i];
  106.         cout << v[i]->danok() << endl;
  107.     }
  108.     cin >> ime >> vozrast >> trki >> vet;
  109.     int mokjnost;
  110.     cin >> mokjnost;
  111.     Vozac *vx = new Motociklist(ime, vozrast, trki, vet, mokjnost);
  112.     cout << "=== VOZAC X ===" << endl;
  113.     cout << *vx;
  114.     cout << "=== SO ISTA ZARABOTUVACKA KAKO VOZAC X ===" << endl;
  115.     cout << soIstaZarabotuvachka(v, n, vx);
  116.     for(int i = 0; i < n; ++i) {
  117.         delete v[i];
  118.     }
  119.     delete [] v;
  120.     delete vx;
  121.     return 0;
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top