Advertisement
deko96

Возило

Apr 26th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.17 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Vozilo {
  5. protected:
  6.     float masa;
  7.     int sirina;
  8.     int visina;
  9. public:
  10.     Vozilo(float masa = 0, int sirina = 0, int visina = 0) {
  11.         this->masa = masa;
  12.         this->sirina = sirina;
  13.         this->visina = visina;
  14.     }
  15.     float getMasa() { return masa; }
  16.     int getSirina() { return sirina; }
  17.     virtual int vratiDnevnaCena() = 0;
  18. };
  19. class Avtomobil : public Vozilo {
  20. private:
  21.     int brVrati;
  22. public:
  23.     Avtomobil(float masa = 0, int sirina = 0, int visina = 0, int brVrati = 0) : Vozilo(masa, sirina, visina) {
  24.         this->brVrati = brVrati;
  25.     }
  26.     int vratiDnevnaCena() {
  27.         if(brVrati < 5)
  28.             return 100;
  29.         else
  30.             return 130;
  31.     }
  32. };
  33. class Avtobus : public Vozilo {
  34. private:
  35.     int brPatnici;
  36. public:
  37.     Avtobus(float masa = 0, int sirina = 0, int visina = 0, int brPatnici = 0) : Vozilo(masa, sirina, visina) {
  38.         this->brPatnici = brPatnici;
  39.     }
  40.     int vratiDnevnaCena() {
  41.         return brPatnici * 5;
  42.     }
  43. };
  44. class Kamion : public Vozilo {
  45. private:
  46.     float maxTovar;
  47. public:
  48.     Kamion(float masa = 0, int sirina = 0, int visina = 0, float maxTovar = 0) : Vozilo(masa, sirina, visina) {
  49.         this->maxTovar = maxTovar;
  50.     }
  51.     int vratiDnevnaCena() {
  52.         return (masa+maxTovar)*0.02;
  53.     }
  54. };
  55. class ParkingPlac {
  56. private:
  57.     Vozilo **v;
  58.     int n;
  59. public:
  60.     ParkingPlac() {
  61.         n = 0;
  62.         v = new Vozilo*[50];
  63.     }
  64.     ParkingPlac(Vozilo **v, int n) {
  65.         this->n = n;
  66.         this->v = new Vozilo*[n];
  67.         for(int i = 0; i < n; ++i)
  68.             this->v[i] = v[i];
  69.     }
  70.     ~ParkingPlac() {
  71.         for(int i = 0; i < n; ++i)
  72.             delete v[i];
  73.         delete [] v;
  74.     }
  75.     ParkingPlac &operator +=(Vozilo *x) {
  76.         v[n] = x;
  77.         n++;
  78.         return *this;
  79.     }
  80.     float presmetajVkupnaMasa() {
  81.         float res = 0;
  82.         for(int i = 0; i < n; ++i)
  83.             res += v[i]->getMasa();
  84.         return res;
  85.     }
  86.     int brojVozilaPoshirokiOd(int l) {
  87.         int counter = 0;
  88.         for(int i = 0; i < n; ++i) {
  89.             if(v[i]->getSirina() > l)
  90.                 counter++;
  91.         }
  92.         return counter;
  93.     }
  94.     void pecati() {
  95.         int cars = 0;
  96.         int buses = 0;
  97.         int trucks = 0;
  98.         for(int i = 0; i < n; ++i) {
  99.             Avtomobil *car = dynamic_cast<Avtomobil *>(v[i]);
  100.             if(car != 0)
  101.                 cars++;
  102.  
  103.             Avtobus *bus = dynamic_cast<Avtobus *>(v[i]);
  104.             if(bus != 0)
  105.                 buses++;
  106.  
  107.             Kamion *truck = dynamic_cast<Kamion *>(v[i]);
  108.             if(truck != 0)
  109.                 trucks++;
  110.         }
  111.         cout << "Brojot na avtomobili e " << cars << ", brojot na avtobusi e " << buses << " i brojot na kamioni e " << trucks << endl;
  112.     }
  113.     int pogolemaNosivostOd(Vozilo &x) {
  114.         int counter = 0;
  115.         for(int i = 0; i < n; ++i) {
  116.             Kamion *truck = dynamic_cast<Kamion *>(v[i]);
  117.             if(truck != 0) {
  118.                 if(v[i]->getMasa() > x.getMasa())
  119.                     counter++;
  120.             }
  121.         }
  122.         return counter;
  123.     }
  124.     int vratiDnevnaZarabotka() {
  125.         float total = 0;
  126.         for(int i = 0; i < n; ++i) {
  127.             total += v[i]->vratiDnevnaCena();
  128.         }
  129.         return total;
  130.     }
  131.  
  132. };
  133. int main(){
  134. ParkingPlac p;
  135. int n;
  136. cin>>n;
  137. int shirina,visina, broj;
  138. float masa,nosivost;
  139. for (int i=0;i<n;i++){
  140.     int type;
  141.     cin>>type;
  142.     if(type==1){
  143.         cin>>masa>>shirina>>visina>>broj;
  144.         Avtomobil *a=new Avtomobil(masa,shirina,visina,broj);
  145.         p+=a;
  146.     }
  147.     if(type==2){
  148.         cin>>masa>>shirina>>visina>>broj;
  149.         p+=new Avtobus(masa,shirina,visina,broj);
  150.     }
  151.     if(type==3){
  152.         cin>>masa>>shirina>>visina>>nosivost;
  153.         p+=new Kamion(masa,shirina,visina,nosivost);
  154.     }
  155. }
  156. p.pecati();
  157.  
  158. cout<<"\nZarabotkata e "<<p.vratiDnevnaZarabotka()<<endl;
  159. cout<<"Vkupnata masa e "<<p.presmetajVkupnaMasa()<<endl;
  160. cout<<"Brojot poshiroki od 5 e "<<p.brojVozilaPoshirokiOd(5)<<endl;
  161. Avtomobil a(1200,4,3,5);
  162. cout<<"Brojot na kamioni so nosivost pogolema od avtomobilot e "<<p.pogolemaNosivostOd(a)<<endl;
  163.  
  164. return 0;
  165.  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement