Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class VehiculAcvatic
- {
- private:
- int greutate;
- protected:
- string nume;
- public:
- int getGreutate()
- {
- return greutate;
- }
- VehiculAcvatic()
- {
- greutate = 0;
- }
- VehiculAcvatic(int greutate)
- {
- if (greutate >= 0)
- {
- this->greutate = greutate;
- }
- else
- {
- throw 505;
- }
- }
- };
- class Bicicleta
- {
- private:
- string producator;
- protected:
- string nume;
- public:
- Bicicleta()
- {
- producator = "Necunoscut";
- }
- Bicicleta(string producator)
- {
- this->producator = producator;
- }
- string getProducator()
- {
- if (producator.length() > 0)
- {
- return producator;
- }
- throw exception("producator este invalid!");
- }
- virtual void Start()
- {
- cout << "Bicicleta s-a pus in miscare" << endl;
- }
- };
- class Hidrobicicleta : public VehiculAcvatic, public Bicicleta
- {
- public:
- Hidrobicicleta()
- {
- }
- Hidrobicicleta(string producator, int greutate) : Bicicleta(producator), VehiculAcvatic(greutate)
- {
- VehiculAcvatic::nume = "hidrobicicleta";
- }
- void Start() // nu trb sa mai pun virtual deoarece in baza ei este virtual (in bicicleta)
- {
- cout << "Hidrobicicleta s-a pus in miscare" << endl;
- }
- };
- int main()
- {
- Hidrobicicleta h1;
- cout << h1.getProducator() << endl;
- Hidrobicicleta h2("Explorer", 50);
- cout << h2.getGreutate() << endl;
- Bicicleta b1;
- b1.Start();
- h1.Start();
- b1 = h1;
- b1.Start();
- Bicicleta *pb = &h1;
- pb->Start();
- Bicicleta b2("");
- try
- {
- VehiculAcvatic v(-2);
- b2.getProducator();
- }
- catch (exception e)
- {
- cout << e.what();
- }
- catch (int x)
- {
- cout << x;
- }
- catch (...)
- {
- }
- }
- /* THE DIAMOND OF DEATH
- vehicul
- /\
- / \
- / \
- / \
- / \
- / \
- / \
- / \
- / \
- / \
- / \
- / \
- vehicul acvatic bicicleta
- \ /
- \ /
- \ /
- \ /
- \ /
- \ /
- \ /
- \ /
- \ /
- \ /
- \ /
- \/
- hidrobicicleta
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement