Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Transport {
- private:
- char destinacija[30];
- int cena;
- int km;
- public:
- Transport (char *destinacija="",int cena=0,int km=0) {
- strcpy(this->destinacija,destinacija);
- this->cena=cena;
- this->km=km;
- }
- char *getDestinacija() {
- return destinacija;
- }
- int getkM( ) {
- return km;
- }
- virtual int cenaTransport() {
- return cena;
- }
- bool operator<(const Transport &t) {
- return (this->km < t.km);
- }
- ~Transport() {}
- };
- class AvtomobilTransport : public Transport {
- private:
- bool sofer;
- public:
- AvtomobilTransport(char *destinacija="", int cena=0, int km=0,bool sofer=false) : Transport(destinacija,cena,km){
- this->sofer = sofer;
- }
- int cenaTransport(){
- if(sofer == true){
- int cenaZgolemena = Transport::cenaTransport()*20/100;
- return Transport::cenaTransport() + cenaZgolemena;
- }else
- return Transport::cenaTransport();
- }
- ~AvtomobilTransport(){
- }
- };
- class KombeTransport : public Transport{
- private:
- int brojLugje;
- public:
- KombeTransport(char *destinacija="", int cena=0, int km=0, int brojLugje=0) :Transport(destinacija,cena,km){
- this->brojLugje = brojLugje;
- }
- int cenaTransport(){
- return Transport::cenaTransport() - brojLugje*200;
- }
- ~KombeTransport(){
- }
- };
- void pecatiPoloshiPonudi(Transport **niza, int brojLugje, Transport &t){
- Transport *temp;
- for(int i=0; i<brojLugje; i++){
- for(int j=i; j<brojLugje; j++){
- if(!(*niza[i] < *niza[j])){
- temp = niza[j];
- niza[i] = niza[j];
- niza[j] = temp;
- }
- }
- }
- for(int i=0; i<brojLugje; i++){
- if(niza[i]->cenaTransport() > t.cenaTransport()){
- cout << niza[i]->getDestinacija() << " " <<niza[i]->getkM() << " " << niza[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