Advertisement
JStefan

[Vezbi] Transport

May 3rd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. // вашиот код треба да биде тука
  7. class Transport {
  8. protected:
  9.    char destinacija[20];
  10.    int osnovna_cena;
  11.    int rastojanie;
  12. public:
  13.    Transport(const char* destinacija = "", const int osnovna_cena = 0, const int rastojanie = 0) {
  14.       strcpy(this->destinacija, destinacija);
  15.       this->rastojanie = rastojanie;
  16.       this->osnovna_cena = osnovna_cena;
  17.    }
  18.  
  19.    bool operator<(const Transport& obj) {
  20.       return rastojanie < obj.rastojanie;
  21.    }
  22.  
  23.    virtual int cenaTransport() { return osnovna_cena; }
  24.  
  25.    // getters
  26.    const char* getDestinacija() const { return destinacija; }
  27.    const int getOsnovnaCena() const { return osnovna_cena; }
  28.    const int getRastojanie() const { return rastojanie; }
  29.  
  30.    // setters
  31.    void setDestinacija(const char* dest) { strcpy(destinacija, dest); }
  32.    void setOsnovnaCena(const int cena) { osnovna_cena = cena; }
  33.    void setRastojanie(const int rast) { rastojanie = rast; }
  34.  
  35.    virtual ~Transport() {}
  36. };
  37.  
  38. class AvtomobilTransport : public Transport {
  39.    bool platen_shofer;
  40. public:
  41.    AvtomobilTransport(const char* destinacija, const int osnovna_cena, const int rastojanie,const bool platen_shofer = false)
  42.    : Transport(destinacija, osnovna_cena, rastojanie) {
  43.       this->platen_shofer = platen_shofer;
  44.    }
  45.  
  46.    int cenaTransport() {
  47.       if(platen_shofer) {
  48.          return Transport::cenaTransport() * 1.20;
  49.       }
  50.       return Transport::cenaTransport();
  51.    }
  52.  
  53.    const bool getPlatenShofer() const { return platen_shofer; }
  54.    void setPlatenShofer(const bool pl_shof) { platen_shofer = pl_shof; }
  55.  
  56.    ~AvtomobilTransport() {}
  57. };
  58.  
  59. class KombeTransport : public Transport {
  60.    int patnici;
  61. public:
  62.    KombeTransport(const char* destinacija, const int osnovna_cena, const int rastojanie,const int patnici = 0)
  63.    : Transport(destinacija, osnovna_cena, rastojanie) {
  64.       this->patnici = patnici;
  65.    }
  66.  
  67.    int cenaTransport() {
  68.       return Transport::cenaTransport() - (patnici * 200);
  69.    }
  70.  
  71.    const int getPatnici() const { return patnici; }
  72.    void setPatnici(const int patn) { patnici = patn; }
  73.  
  74.    ~KombeTransport() {}
  75. };
  76.  
  77. void sortirajPonudi(Transport** ponudi, int n) {
  78.    for(int i = 0; i < n; ++i) {
  79.       for(int j = 0; j < n - 1 - i; ++j) {
  80.          if(ponudi[i]->getRastojanie() > ponudi[i+1]->getRastojanie()) {
  81.             Transport* t = ponudi[i];
  82.             ponudi[i] = ponudi[i+1];
  83.             ponudi[i+1] = t;
  84.          }
  85.       }
  86.    }
  87. }
  88.  
  89. void pecatiPoloshiPonudi(Transport** ponudi, int n, Transport& t) {
  90.    sortirajPonudi(ponudi, n);
  91.    for(int i = 0; i < n; ++i) {
  92.       if(ponudi[i]->cenaTransport() > t.cenaTransport()) {
  93.          cout << ponudi[i]->getDestinacija() << " " << ponudi[i]->getRastojanie() << " " << ponudi[i]->cenaTransport() << endl;
  94.       }
  95.    }
  96. }
  97.  
  98. int main(){
  99.  
  100. char destinacija[20];
  101. int tip,cena,rastojanie,lugje;
  102. bool shofer;
  103. int n;
  104. cin>>n;
  105. Transport  **ponudi;
  106. ponudi=new Transport *[n];
  107.  
  108. for (int i=0;i<n;i++){
  109.  
  110.     cin>>tip>>destinacija>>cena>>rastojanie;
  111.     if (tip==1) {
  112.         cin>>shofer;
  113.         ponudi[i]=new AvtomobilTransport(destinacija,cena,rastojanie,shofer);
  114.  
  115.     }
  116.     else {
  117.         cin>>lugje;
  118.         ponudi[i]=new KombeTransport(destinacija,cena,rastojanie,lugje);
  119.     }
  120.  
  121.  
  122. }
  123.  
  124. AvtomobilTransport nov("Ohrid",2000,600,false);
  125. pecatiPoloshiPonudi(ponudi,n,nov);
  126.  
  127. for (int i=0;i<n;i++) delete ponudi[i];
  128. delete [] ponudi;
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement