Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Wyjatek
- {
- string miejsce;
- int wiersz;
- string blad;
- Wyjatek(string m, int w, string b)
- :miejsce(m), wiersz(w), blad(b)
- {}
- friend ostream &operator<<(ostream &out, const Wyjatek &e)
- {
- out << "Wiersz: " << e.wiersz << " miejsce: " << e.miejsce << " blad: " << e.blad;
- return out;
- }
- };
- class Transport
- {
- private:
- double cena;
- int katalog;
- public:
- void set_cena(double val) { if (val > 0) cena = val; else cout << " Wartosc musi być dodatnia " << endl; }
- void set_katalog(int val) { if (val >= 0) katalog = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
- double get_cena() { return cena; }
- int get_katalog() { return katalog; }
- Transport(double cn, int kt)
- {
- set_cena(cn);
- set_katalog(kt);
- }
- Transport() = default;
- ~Transport()
- {}
- virtual string Opis() = 0;
- friend ostream &operator<<(ostream &out, const Wyjatek &e);
- friend ostream& operator<<(ostream &str, const Transport &src);
- bool operator>(const Transport& src) const
- {
- if (cena > src.cena)
- return true;
- else
- return false;
- }
- bool operator==(const Transport& src) const
- {
- if (cena == src.cena)
- return true;
- else
- return false;
- }
- bool operator<(const Transport& src)const
- {
- if (cena >= src.cena)
- return false;
- else
- return true;
- }
- protected:
- string OpisTransportu()
- {
- return "Cena: " + to_string(get_cena()) + " Numer katalogu: " + to_string(get_katalog());
- }
- };
- class Pojazd :public virtual Transport
- {
- private:
- string marka;
- string material;
- public:
- void set_marka(string val) { marka = val; }
- void set_material(string val) { material = val; }
- string get_marka() { return marka; }
- string get_material() { return material; }
- Pojazd(string mr, string mt)
- {
- set_marka(mr);
- set_material(mt);
- }
- Pojazd() = default;
- ~Pojazd()
- {}
- protected:
- virtual string OpisPojazdu()
- {
- return "Marka: " + marka + " Z matrialu: " + material;
- }
- };
- class Ladowy :public virtual Pojazd
- {
- private:
- int kola;
- public:
- void set_kola(int val) {
- if (val > 0) kola = val;
- else cout << " Wartosc musi być dodatnia " << endl;
- }
- int get_kola() { return kola; }
- Ladowy(string mr, string mt, int kl)
- :Pojazd(mr, mt)
- {
- set_kola(kl);
- }
- Ladowy() = default;
- ~Ladowy()
- {}
- protected:
- string OpisLadowy()
- {
- return "Ilosc kol: " + to_string(get_kola());
- }
- };
- class Wodny :virtual public Pojazd
- {
- private:
- int sruby;
- public:
- void set_sruby(int val) {
- if (val > 0) sruby = val;
- else cout << " Wartosc musi być dodatnia " << endl;
- }
- int get_sruby() { return sruby; }
- Wodny(string mr, string mt, int sr)
- :Pojazd(mr, mt)
- {
- set_sruby(sr);
- }
- Wodny() = default;
- ~Wodny()
- {}
- protected:
- string OpisWodny()
- {
- return "Ilosc srub: " + to_string(get_sruby());
- }
- };
- class LadowoWodny :virtual public Wodny, virtual public Ladowy
- {
- public:
- LadowoWodny(string mr, string mt, int kl, int sr)
- :Ladowy(mr, mt, kl), Wodny(mr, mt, sr)
- {
- }
- LadowoWodny() = default;
- ~LadowoWodny()
- {}
- protected:
- string OpisLadowoWodny()
- {
- return OpisWodny() + OpisLadowy();
- }
- };
- class Naped : public virtual Transport
- {
- private:
- double masa;
- double moc;
- public:
- void set_masa(double val) { if (val > 0) masa = val; else cout << " Wartosc musi być dodatnia " << endl; }
- void set_moc(int val) { if (val > 0) moc = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
- double get_masa() { return masa; }
- int get_moc() { return moc; }
- Naped(double ms, double mc)
- {
- set_masa(ms);
- set_moc(mc);
- }
- Naped() = default;
- ~Naped()
- {}
- protected:
- string OpisNapedu()
- {
- return "Masa: " + to_string(get_masa()) + " Moc: " + to_string(get_moc());
- }
- };
- class Spalinowy :virtual public Naped
- {
- private:
- string paliwo;
- double objetosc;
- public:
- void set_paliwo(string val) { paliwo = val; }
- void set_objetosc(int val) { if (val > 0) objetosc = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
- string get_paliwo() { return paliwo; }
- double get_objetosc() { return objetosc; }
- Spalinowy(double ms, double mc, string pl, double ob)
- :Naped(ms, mc)
- {
- set_paliwo(pl);
- set_objetosc(ob);
- }
- Spalinowy() = default;
- ~Spalinowy()
- {}
- protected:
- string OpisSpalinowego()
- {
- return "Paliwo: " + paliwo + " Objetosc: " + to_string(objetosc);
- }
- };
- class Elektryczny :virtual public Naped
- {
- private:
- string ogniwo;
- double pojemnosc;
- public:
- void set_ogniwo(string val) { ogniwo = val; }
- void set_pojemnosc(int val) { if (val > 0) pojemnosc = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
- string get_ogniwo() { return ogniwo; }
- double get_pojemnosc() { return pojemnosc; }
- Elektryczny(double ms, double mc, string og, double pj)
- :Naped(ms, mc)
- {
- set_ogniwo(og);
- set_pojemnosc(pj);
- }
- Elektryczny() = default;
- ~Elektryczny()
- {}
- protected:
- string OpisElektrycznego()
- {
- return "Ogniwo: " + get_ogniwo() + " Pojemnosc: " + to_string(get_pojemnosc());
- }
- };
- class SpalinowoLandowy :public virtual Spalinowy, public virtual Ladowy
- {
- public:
- SpalinowoLandowy(int kt, double cn, string mr, string mt, int kl, double ms, double mc, string pl, double ob)
- :Spalinowy(ms, mc, pl, ob), Ladowy(mr, mt, kl), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
- {
- }
- string Opis()
- {
- return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisLadowy() + "\n" + OpisNapedu() + "\n" + OpisSpalinowego() + "\n";
- }
- };
- class ElektrycznyLandowy :public virtual Elektryczny, public virtual Ladowy
- {
- public:
- ElektrycznyLandowy(int kt, double cn, string mr, string mt, int kl, double ms, double mc, string og, double pj)
- :Elektryczny(ms, mc, og, pj), Ladowy(mr, mt, kl), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
- {
- }
- string Opis()
- {
- return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisLadowy() + "\n" + OpisNapedu() + "\n" + OpisElektrycznego() + "\n";
- }
- };
- class SpalinowoWodny :public virtual Spalinowy, public virtual Wodny
- {
- public:
- SpalinowoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, string pl, double ob)
- :Spalinowy(ms, mc, pl, ob), Wodny(mr, mt, sr), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
- {
- }
- string Opis()
- {
- return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisSpalinowego() + "\n";
- }
- };
- class ElektrycznoWodny :public virtual Elektryczny, public virtual Wodny
- {
- public:
- ElektrycznoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, string og, double pj)
- :Elektryczny(ms, mc, og, pj), Wodny(mr, mt, sr), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
- {
- }
- string Opis()
- {
- return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisElektrycznego() + "\n";
- }
- };
- class SpalinowyLadowoWodny :public Ladowy, public Spalinowy, public Wodny
- {
- public:
- SpalinowyLadowoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, string pl, double ob, int kl)
- :Spalinowy(ms, mc, pl, ob), Wodny(mr, mt, sr), Transport(cn, kt), Ladowy(mr, mt, kl), Pojazd(mr, mt), Naped(ms, mc)
- {
- }
- string Opis()
- {
- return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisSpalinowego() + "\n" + OpisLadowy() + "\n";
- }
- };
- class ElektrycznyLadowoWodny :public Ladowy, public Elektryczny, public Wodny
- {
- public:
- ElektrycznyLadowoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, double pj, string og, int kl)
- :Elektryczny(ms, mc, og, pj), Wodny(mr, mt, sr), Transport(cn, kt), Ladowy(mr, mt, kl), Pojazd(mr, mt), Naped(ms, mc)
- {
- }
- string Opis()
- {
- return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisElektrycznego() + "\n" + OpisLadowy() + "\n";
- }
- };
- int main()
- {
- SpalinowoLandowy sl(1, 600000.0, "Skoda", "Aluminium", 4, 1200.2, 150.0, "Benzyna", 1200.0);
- cout << sl.Opis() << endl;
- ElektrycznyLandowy el(2, 800000.0, "Honda", "Aluminium", 4, 1000, 101.0, "Litowe", 220);
- cout << el.Opis() << endl;
- SpalinowoWodny sw(3, 1000000.0, "Kawasaki", "Aluminium", 1, 3000, 400.0, "Disel", 5000);
- cout << sw.Opis() << endl;
- ElektrycznoWodny ew(4, 2000000.0, "Hyundai", "Aluminium", 1, 2000, 300.0, "Olowiowe", 100);
- cout << ew.Opis() << endl;
- SpalinowyLadowoWodny slw(5, 3000000.0, "BMW", "Aluminium", 1, 3000, 400.0, "Disel", 5000, 4);
- cout << slw.Opis() << endl;
- ElektrycznyLadowoWodny elw(6, 3500000.0, "BMW", "Aluminium", 1, 3500, 500.0, 400 , "Olowiowe", 4);
- cout << elw.Opis() << endl;
- cout << sl << endl;
- system("pause");
- return 0;
- }
- ostream& operator<<(ostream &str, const Transport &src)
- {
- str << "Cena: " <<src.cena << endl;
- str << "Numer katalogu: " << src.katalog << endl;
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement