Mitrezzz

Транспорт

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