Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Transport{
- protected:
- char destination[100];
- int price;
- int distance;
- public:
- Transport()
- {
- strcpy(this->destination,"");
- this->price=0;
- this->distance=0;
- }
- Transport(const char *destination,int price,int distance)
- {
- strcpy(this->destination,destination);
- this->price=price;
- this->distance=distance;
- }
- Transport(const Transport &t)
- {
- strcpy(this->destination,t.destination);
- this->price=t.price;
- this->distance=t.distance;
- }
- virtual int cenaTransport()=0;
- int get_price()
- {
- return price;
- }
- int get_distance()
- {
- return distance;
- }
- char * get_destination()
- {
- return destination;
- }
- virtual ~Transport(){}
- };
- class AvtomobilTransport:public Transport{
- private:
- bool platenSofer;
- public:
- AvtomobilTransport(const char *destination="",int price=0,int distance=0
- ,bool platenSofer=false):Transport(destination,price,distance)
- {
- this->platenSofer=platenSofer;
- }
- void setSofer(bool sofer)
- {
- platenSofer=sofer;
- }
- int cenaTransport()
- {
- if(platenSofer==true)
- {
- return this->price*1.2;
- }
- else return this->price;
- }
- };
- class KombeTransport:public Transport{
- private:
- int people;
- public:
- KombeTransport(const char *destination="",int price=0,int distance=0
- ,int people=0):Transport(destination,price,distance)
- {
- this->people=people;
- }
- void setPeople(int peps)
- {
- this->people=peps;
- }
- int cenaTransport()
- {
- if(people>0)
- {
- return this->price - (this->people*200);
- }
- else return this->price;
- }
- };
- bool operator < (Transport *t,Transport &t1)
- {
- if(t->get_distance()<t1.get_distance())
- return true;
- else return false;
- }
- 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]->get_destination()<<" "<<ponudi[i]->get_distance()<<" "<<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;
- }
Advertisement
Add Comment
Please, Sign In to add comment