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 cenata;
- int rastojanie;
- public:
- Transport(){}
- Transport(const char *destinacija,int cenata,int rastojanie){
- strcpy(this->destinacija,destinacija);
- this->cenata=cenata;
- this->rastojanie=rastojanie;
- }
- virtual ~Transport(){}
- bool operator<(Transport &d){
- if(rastojanie<d.rastojanie){
- return true;
- }else
- return false;
- }
- void set_ime(char *a){
- strcpy(destinacija,a);
- }
- void set_cena(int a){
- cenata=a;
- }
- void set_rastojanie(int a){
- rastojanie=a;
- }
- char *getIme(){
- return destinacija;
- }
- int getRastojanie(){
- return rastojanie;
- }
- int getCena(){
- return cenata;
- }
- virtual double cenaTransport()=0;
- };
- class AvtomobilTransport:public Transport{
- private:
- bool shofer;
- public:
- AvtomobilTransport(){}
- AvtomobilTransport(const char *destinacija,int cenata,int rastojanie,bool shofer):Transport(destinacija,cenata,rastojanie){
- this->shofer=shofer;
- }
- ~AvtomobilTransport(){}
- double cenaTransport(){
- if(shofer==true){
- return cenata+(cenata*0.20);
- }else
- return cenata;
- }
- };
- class KombeTransport:public Transport{
- private:
- int lugje;
- public:
- KombeTransport(){}
- KombeTransport(const char *destinacija,int cenata,int rastojanie,int lugje):Transport(destinacija,cenata,rastojanie){
- this->lugje=lugje;
- }
- ~KombeTransport(){}
- double cenaTransport(){
- return cenata-(lugje*200);
- }
- };
- void pecatiPoloshiPonudi(Transport **a,int n,Transport &d){
- for(int i=0;i<n;i++){
- for(int j=i+1;j<n;j++){
- if(*a[j] < *a[i]){
- Transport *temp = a[i];
- a[i]=a[j];
- a[j]= temp;
- }
- }
- }
- for(int i=0;i<n;i++)
- {
- if(a[i]->getCena()> d.getCena())
- {
- cout<<a[i]->getIme()<<" "<<a[i]->getRastojanie()<<" "<<a[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