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 destinacija[20];
- int cena;
- int km;
- public:
- Transport(){}
- Transport(char destinacija[],int cena,int km){
- strcpy(this->destinacija,destinacija);
- this->cena=cena;
- this->km=km;
- }
- virtual int cenaTransport(){
- return cena;
- }
- bool operator <(Transport &t){
- return this->km<t.km;
- }
- void pecati(){
- cout<<destinacija<<" "<<km<<" ";
- }
- ~Transport(){}
- };
- class AvtomobilTransport : public Transport {
- private:
- bool shofer;
- public:
- AvtomobilTransport(){}
- AvtomobilTransport(char destinacija[],int cena,int km,bool shofer) : Transport(destinacija,cena,km){
- this->shofer=shofer;
- }
- int cenaTransport(){
- if(shofer){
- return Transport::cenaTransport() + Transport::cenaTransport()*20/100;
- }else
- return Transport::cenaTransport();
- }
- void pecati(){
- Transport::pecati();
- cout<<cenaTransport()<<endl;
- }
- };
- class KombeTransport : public Transport{
- private:
- int patnici;
- public:
- KombeTransport(){}
- KombeTransport(char destinacija[],int cena,int km,int patnici) : Transport(destinacija,cena,km){
- this->patnici=patnici;
- }
- int cenaTransport(){
- return Transport::cenaTransport()-patnici*200;
- }
- void pecati(){
- Transport::pecati();
- cout<<cenaTransport()<<endl;
- }
- };
- void pecatiPoloshiPonudi(Transport **niza,int n,Transport &t){
- Transport *pom;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n-1;j++)
- {
- if(niza[j+1] < niza[j])
- {
- pom=niza[j+1];
- niza[j+1]=niza[j];
- niza[j]=pom;
- }
- }
- }
- for(int i=0;i<n;i++){
- if(niza[i]->cenaTransport()>t.cenaTransport()){
- niza[i]->pecati();
- }
- }
- }
- 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