Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ude<iostream>
- #include<cstring>
- using namespace std;
- class Transport
- {
- protected:
- char *destinacija;
- int cena;
- int km;
- public:
- virtual float CenaTransport()=0;
- Transport(char *destinacija="",int cena=0,int km=0)
- {
- this->cena=cena;
- this->km=km;
- this->destinacija=new char [strlen(destinacija)+1];
- strcpy(this->destinacija,destinacija);
- }
- void copy(const Transport &t)
- {
- km=t.km;
- destinacija=new char [strlen(t.destinacija)+1];
- cena=t.cena;
- }
- float CenaTransport()const
- {
- return cena;
- }
- int getCena(){
- return cena;
- }
- int getKM()const{
- return km;
- }
- char *getDestinacija()
- {
- return destinacija;
- }
- ~Transport (){ delete [] destinacija;}
- };
- class AvtomobilTransport : public Transport
- {
- protected:
- bool shofer;
- public:
- AvtomobilTransport(char *destinacija="",int cena=0,int km=0,bool shofer=false): Transport(destinacija,cena,km)
- {
- this->shofer=shofer;
- }
- AvtomobilTransport(const AvtomobilTransport &a)
- {
- Transport :: copy(a);
- shofer=a.shofer;
- }
- float CenaTransport (){
- if(shofer)
- {
- return getCena() *1.20;
- }
- else
- {
- return getCena();
- }
- }
- bool operator < (const Transport &t){
- if (getKM()<t.getKM ()){
- return true;
- }
- else{
- return false;
- }
- }
- ~AvtomobilTransport () {}
- };
- class KombeTransport : public Transport
- {
- protected:
- int patnici;
- public:
- KombeTransport(char *destinacija="",int cena=0,int km=0,int patnici=0) :Transport(destinacija,cena,km)
- {
- this->patnici=patnici;
- }
- KombeTransport(const KombeTransport &k)
- {
- Transport :: copy(k);
- patnici=k.patnici;
- }
- float CenaTransport()
- {
- return getCena()-200 * patnici;
- }
- bool operator < (const Transport &t){
- if (getKM()<t.getKM()){
- return true;
- }
- else{
- return false;
- }
- }
- ~KombeTransport () {}
- };
- void pecatiPoloshiPonudi(Transport **t,int brojponudi, Transport &T)
- {
- for(int i = 0 ; i < brojponudi ; i++)
- {
- if(t[i]->CenaTransport ()>T.CenaTransport())
- {
- cout<<t[i]->getDestinacija() <<" "<<t[i]->getKM()<<" "<<t[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