StefiIOE

Transport vezbi

May 11th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Transport
  7. {
  8.     protected:
  9.     char destinacija[50];
  10.     int cena;
  11.     int rastojanie;//vo km
  12.     public:
  13.     Transport(char*destinacija="", int cena = 0 , int rastojanie = 0 )
  14.     {
  15.         strcpy(this->destinacija,destinacija);
  16.         this->cena=cena;
  17.         this->rastojanie=rastojanie;
  18.     }
  19.     Transport(const Transport &t)
  20.     {
  21.         strcpy(this->destinacija,t.destinacija);
  22.         this->cena=t.cena;
  23.         this->rastojanie=t.rastojanie;
  24.     }
  25.     virtual int cenaTransport()=0;
  26.     bool operator < ( Transport &l )
  27.     {
  28.     return this->rastojanie<l.rastojanie;
  29.     }
  30.     char *getDestinacija(){return this->destinacija;}
  31.     int getCena(){return this->cena;}
  32.     int getRastojanie(){return this->rastojanie;}
  33.    
  34.    
  35. };
  36.  
  37. class AvtomobilTransport : public Transport
  38. {
  39. bool shofer;
  40.     public:
  41.     AvtomobilTransport(char*destinacija="", int cena = 0 , int rastojanie = 0,bool shofer=true)
  42.     :Transport(destinacija,cena,rastojanie)
  43.     {
  44.     this->shofer=shofer;
  45.     }
  46.     AvtomobilTransport (const AvtomobilTransport &a) :Transport(a)
  47.     {
  48.     this->shofer=a.shofer;
  49.     }
  50.     int cenaTransport()
  51.     {
  52.         if(shofer)
  53.         {
  54.         return cena+(cena*0.2);
  55.         }
  56.         else return cena;//moguce da je 0.8    
  57.     }
  58. };
  59. class KombeTransport : public Transport{
  60. int n;
  61.     public:
  62.     KombeTransport(char*destinacija="", int cena = 0 , int rastojanie = 0 ,int n = 0)
  63.         :Transport(destinacija,cena,rastojanie)
  64.         {
  65.         this->n=n;
  66.         }
  67.     KombeTransport(const KombeTransport &k): Transport(k)
  68.     {
  69.         this->n=k.n;
  70.     }
  71.     int cenaTransport()
  72.     {
  73.  
  74.         return cena -  (200*n);
  75.    
  76.     }
  77.        
  78. };
  79. void pecatiPoloshiPonudi(Transport **ponudi , int n , Transport &t)
  80. {
  81. Transport *s;
  82.     for(int i = 0 ; i < n ; i ++)
  83.     {
  84.         for(int j = 0 ; j < n ; j++)
  85.         {
  86.         if(ponudi[i]->cenaTransport() < ponudi[j]->cenaTransport())
  87.             {
  88.             s=ponudi[i];
  89.             ponudi[i]=ponudi[j];
  90.             ponudi[j]=s;
  91.             }
  92.         }
  93.     }
  94.     for(int i = 0 ; i < n ; i ++)
  95.     {
  96.         if(ponudi[i]->cenaTransport()>t.cenaTransport())
  97.         {
  98.             cout<<ponudi[i]->getDestinacija()<<" ";
  99.             cout<<ponudi[i]->getRastojanie()<<" ";
  100.             cout<<ponudi[i]->cenaTransport()<<endl;
  101.         }
  102.     }
  103.    
  104.  
  105. }
  106. int main(){
  107.  
  108. char destinacija[20];
  109. int tip,cena,rastojanie,lugje;
  110. bool shofer;
  111. int n;
  112. cin>>n;
  113. Transport  **ponudi;
  114. ponudi=new Transport *[n];
  115.  
  116. for (int i=0;i<n;i++){
  117.  
  118.     cin>>tip>>destinacija>>cena>>rastojanie;
  119.     if (tip==1) {
  120.         cin>>shofer;
  121.         ponudi[i]=new AvtomobilTransport(destinacija,cena,rastojanie,shofer);
  122.  
  123.     }
  124.     else {
  125.         cin>>lugje;
  126.         ponudi[i]=new KombeTransport(destinacija,cena,rastojanie,lugje);
  127.     }
  128.  
  129.  
  130. }
  131.  
  132. AvtomobilTransport nov("Ohrid",2000,600,false);
  133. pecatiPoloshiPonudi(ponudi,n,nov);
  134.  
  135. for (int i=0;i<n;i++) delete ponudi[i];
  136. delete [] ponudi;
  137. return 0;
  138. }
Add Comment
Please, Sign In to add comment