Advertisement
ilevishinov

Транспорт

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