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[100];
- int cena;
- int km;
- public:
- Transport() {
- cena = 0;
- km = 0;
- }
- Transport(char *destinacija, int cena, int km) {
- strcpy(this->destinacija, destinacija);
- this->cena = cena;
- this->km = km;
- }
- /* Transport(const Transport &t) {
- strcpy(this->destinacija, t.destinacija);
- this->cena = t.cena;
- this->km = t.km;
- }
- Transport &operator=(const Transport &t) {
- if (this != &t) {
- strcpy(this->destinacija, t.destinacija);
- this->cena = t.cena;
- this->km = t.km;
- }
- return *this;
- }*/
- bool operator<(Transport &t2) {
- if (this->km < t2.km) {
- return true;
- } else
- return false;
- }
- virtual ~Transport() {}
- virtual double cenaTransport() = 0;
- //=============SETTERS & GETTERS ================
- int getKm() {
- return km;
- }
- char *getDestinacija() {
- return destinacija;
- }
- };
- class AvtomobilTransport : public Transport {
- private:
- bool sofer;
- public:
- AvtomobilTransport() : Transport() {
- sofer = false;
- }
- AvtomobilTransport(char *destinacija, int cena, int km, bool sofer)
- : Transport(destinacija, cena, km) {
- this->sofer = sofer;
- }
- ~AvtomobilTransport() {}
- double cenaTransport() {
- if (sofer) {
- return cena * 1.20;
- } else
- return cena;
- }
- };
- class KombeTransport : public Transport {
- private:
- int brLugje;
- public:
- KombeTransport() : Transport() {
- brLugje = 0;
- }
- KombeTransport(char *destinacija, int cena, int km, int brLugje)
- : Transport(destinacija, cena, km) {
- this->brLugje = brLugje;
- }
- ~KombeTransport() {}
- int getBrLugje() {
- return brLugje;
- }
- double cenaTransport() {
- return cena - (200 * brLugje);
- }
- };
- void sort(Transport **ponudi, int n) {
- for (int i = 0; i < n; ++i) {
- for (int j = i + 1; j < n; ++j) {
- if (!(*ponudi[i] < *ponudi[j])) {
- Transport *temp = ponudi[i];
- ponudi[i] = ponudi[j];
- ponudi[j] = temp;
- }
- }
- }
- }
- void pecatiPoloshiPonudi(Transport **ponudi, int n, Transport &nov) {
- // pomosna niza od poskapite ponudi koi ke gi sortiram
- int j = 0;
- int elementsCounter = 0;
- for (int i = 0; i < n; ++i) {
- // gi dodavam ponudite so se poskapi od &nov vo temp
- if (ponudi[i]->cenaTransport() > nov.cenaTransport()) {
- elementsCounter++;
- }
- }
- Transport **temp = new Transport *[elementsCounter];
- j = 0;
- for (int i = 0; i < n; ++i) {
- // gi dodavam ponudite so se poskapi od &nov vo temp
- if (ponudi[i]->cenaTransport() > nov.cenaTransport()) {
- temp[j++] = ponudi[i];
- }
- }
- sort(temp, elementsCounter);
- for (int i = 0; i < j; ++i) {
- cout << temp[i]->getDestinacija() << " "
- << temp[i]->getKm() << " "
- << temp[i]->cenaTransport() << endl;
- }
- delete[] temp;
- }
- 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