Advertisement
jordanov

[OOP] Транспорт

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