Advertisement
StefiIOE

Transport bez sortiranje

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