Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Transport{
- protected:
- char podatoci[100];
- int Cena;
- int rastojanie;
- public:
- /*Transport(char *p, int c, int r)
- {
- strcpy(podatoci,p);
- Cena=c;
- rastojanie=r;
- }*/
- bool operator<(const Transport &k)
- {
- if(rastojanie<k.rastojanie)return 1;
- else return 0;
- }
- virtual double cenaTransport()=0;
- char *getPodatoci(){return podatoci;}
- int getCena(){return Cena;}
- int getRastojanie(){return rastojanie;}
- };
- class AvtomobilTransport:public Transport{
- bool sofer;
- public:
- AvtomobilTransport(){}
- AvtomobilTransport(char *p, int c, int r, int s){
- sofer=s;
- strcpy(podatoci,p);
- Cena=c;
- rastojanie=r;
- }
- bool getSofer(){return sofer;}
- double cenaTransport()
- {
- if(sofer==1)
- return Cena+Cena*0.2;
- else return Cena;
- }
- bool operator<(const AvtomobilTransport &k)
- {
- if(rastojanie<k.rastojanie)return 1;
- else return 0;
- }
- };
- class KombeTransport:public Transport{
- int brojLugje;
- public:
- KombeTransport(){}
- KombeTransport(char *p, int c, int r, int b){
- brojLugje=b;
- strcpy(podatoci,p);
- Cena=c;
- rastojanie=r;
- }
- int getLugje(){return brojLugje;}
- double cenaTransport(){
- return Cena-(brojLugje*200);
- }
- bool operator<(const KombeTransport &k)
- {
- if(rastojanie<k.rastojanie)return 1;
- else return 0;
- }
- };
- void pecatiPoloshiPonudi(Transport **pon,int n, AvtomobilTransport &newA)
- {
- for(int i=0;i<n;i++)
- {
- for(int j=i+1;j<n;j++)
- {
- if(*pon[j]<*pon[i])
- {
- Transport *pom;
- pom=pon[i];
- pon[i]=pon[j];
- pon[j]=pom;
- }
- }
- }
- for(int i=0;i<n;i++)
- {
- if(pon[i]->cenaTransport()>newA.cenaTransport())
- {
- cout<<pon[i]->getPodatoci()<<" "<<pon[i]->getRastojanie()<<" "<<pon[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
Advertisement