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 * destination;
- int price;
- int km;
- const void copy(const Transport &orig){
- this->destination = new char[strlen(orig.destination)+1];
- strcpy(this->destination, orig.destination);
- this->price = orig.price;
- this->km = orig.km;
- }
- public:
- Transport(){
- this->destination = new char[0];
- this->price = 0;
- this->km = 0;
- }
- Transport(const char * destination, const int price, const int km){
- this->destination = new char[strlen(destination)+1];
- strcpy(this->destination, destination);
- this->price = price;
- this->km = km;
- }
- Transport(const Transport &orig){
- this->copy(orig);
- }
- Transport &operator=(const Transport &orig){
- if(this != &orig){
- delete [] this->destination;
- this->copy(orig);
- }
- return *this;
- }
- ~Transport(){
- delete [] this->destination;
- }
- virtual double cenaTransport(){
- return this->price;
- }
- bool operator<(const Transport &orig){
- if(this->km < orig.km)
- return true;
- else
- return false;
- }
- const int getKm(){
- return this->km;
- }
- const char * getDest(){
- return this->destination;
- }
- };
- class AvtomobilTransport : public Transport{
- private:
- bool platen;
- public:
- AvtomobilTransport(){
- this->platen = false;
- }
- AvtomobilTransport(const char * destination, const int price, const int km, const bool platen) : Transport(destination, price, km){
- this->platen = platen;
- }
- ~AvtomobilTransport(){}
- double cenaTransport(){
- if(this->platen)
- return this->price + (this->price * 0.2);
- else
- return this->price;
- }
- };
- class KombeTransport : public Transport{
- private:
- int lugje;
- public:
- KombeTransport(){
- this->lugje = 0;
- }
- KombeTransport(const char * destination, const int price, const int km, const int lugje) : Transport(destination, price, km){
- this->lugje = lugje;
- }
- ~KombeTransport(){}
- double cenaTransport(){
- return this->price - (200 * this->lugje);
- }
- };
- const void pecatiPoloshiPonudi(Transport **ponudi, int n, Transport ponuda){
- //sort
- for(int i=0; i<n; i++){
- for(int j=i+1; j<n; j++){
- if(ponudi[i]->getKm() > ponudi[j]->getKm()){
- Transport *tmp = ponudi[i];
- ponudi[i] = ponudi[j];
- ponudi[j] = tmp;
- }
- }
- }
- for(int i=0; i<n; i++){
- if(ponudi[i]->cenaTransport() > ponuda.cenaTransport())
- cout << ponudi[i]->getDest() << " " << ponudi[i]->getKm() << " " << ponudi[i]->cenaTransport() << endl;
- }
- }
- //main
- 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