Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Transport
- {
- protected:
- char destinacija[50];
- int cena;
- int rastojanie;//vo km
- public:
- Transport(char*destinacija="", int cena = 0 , int rastojanie = 0 )
- {
- strcpy(this->destinacija,destinacija);
- this->cena=cena;
- this->rastojanie=rastojanie;
- }
- Transport(const Transport &t)
- {
- strcpy(this->destinacija,t.destinacija);
- this->cena=t.cena;
- this->rastojanie=t.rastojanie;
- }
- virtual int cenaTransport()=0;
- bool operator < ( Transport &l )
- {
- return this->rastojanie<l.rastojanie;
- }
- char *getDestinacija(){return this->destinacija;}
- int getCena(){return this->cena;}
- int getRastojanie(){return this->rastojanie;}
- };
- class AvtomobilTransport : public Transport
- {
- bool shofer;
- public:
- AvtomobilTransport(char*destinacija="", int cena = 0 , int rastojanie = 0,bool shofer=true)
- :Transport(destinacija,cena,rastojanie)
- {
- this->shofer=shofer;
- }
- AvtomobilTransport (const AvtomobilTransport &a) :Transport(a)
- {
- this->shofer=a.shofer;
- }
- int cenaTransport()
- {
- if(shofer)
- {
- return cena+(cena*0.2);
- }
- else return cena;//moguce da je 0.8
- }
- };
- class KombeTransport : public Transport{
- int n;
- public:
- KombeTransport(char*destinacija="", int cena = 0 , int rastojanie = 0 ,int n = 0)
- :Transport(destinacija,cena,rastojanie)
- {
- this->n=n;
- }
- KombeTransport(const KombeTransport &k): Transport(k)
- {
- this->n=k.n;
- }
- int cenaTransport()
- {
- return cena - (200*n);
- }
- };
- void pecatiPoloshiPonudi(Transport **ponudi , int n , Transport &t)
- {
- Transport *s;
- for(int i = 0 ; i < n ; i ++)
- {
- for(int j = 0 ; j < n ; j++)
- {
- if(ponudi[i]->cenaTransport() < ponudi[j]->cenaTransport())
- {
- s=ponudi[i];
- ponudi[i]=ponudi[j];
- ponudi[j]=s;
- }
- }
- }
- for(int i = 0 ; i < n ; i ++)
- {
- if(ponudi[i]->cenaTransport()>t.cenaTransport())
- {
- cout<<ponudi[i]->getDestinacija()<<" ";
- cout<<ponudi[i]->getRastojanie()<<" ";
- cout<<ponudi[i]->cenaTransport()<<endl;
- }
- }
- }
- int main(){
- char destinacija[20];
- int tip,cena,rastojanie,lugje;
- bool shofer;
- int n;
- cin>>n;
- Transport **ponudi;
- ponudi=new Transport *[n];
- for (int i=0;i<n;i++){
- cin>>tip>>destinacija>>cena>>rastojanie;
- if (tip==1) {
- cin>>shofer;
- ponudi[i]=new AvtomobilTransport(destinacija,cena,rastojanie,shofer);
- }
- else {
- cin>>lugje;
- ponudi[i]=new KombeTransport(destinacija,cena,rastojanie,lugje);
- }
- }
- AvtomobilTransport nov("Ohrid",2000,600,false);
- pecatiPoloshiPonudi(ponudi,n,nov);
- for (int i=0;i<n;i++) delete ponudi[i];
- delete [] ponudi;
- return 0;
- }
Add Comment
Please, Sign In to add comment