diff --git a/lesson_3/exercise_1.hpp b/lesson_3/exercise_1.hpp index a3b6dac..11bbc18 100644 --- a/lesson_3/exercise_1.hpp +++ b/lesson_3/exercise_1.hpp @@ -87,8 +87,9 @@ public: class Square : public Parallelogram { - Square(float side_a, float side_b) - : Parallelogram(side_a, side_b, side_b) { } +public: + Square(float side_a) + : Parallelogram(side_a, side_a, side_a) { } float area() { @@ -102,6 +103,7 @@ class Square : public Parallelogram class Rhombus : public Parallelogram { +public: Rhombus(float side_a, float side_b) : Parallelogram(side_a, side_b, side_b) { } diff --git a/lesson_3/exercise_2.hpp b/lesson_3/exercise_2.hpp index 5c99457..9965410 100644 --- a/lesson_3/exercise_2.hpp +++ b/lesson_3/exercise_2.hpp @@ -1,8 +1,56 @@ #ifndef EXERCISE_2_HPP_ #define EXERCISE_2_HPP_ +#include +class Car +{ +private: + std::string m_company; + std::string m_model; +protected: + std::string getCompany() const + { + return m_company; + } + std::string getModel() const + { + return m_model; + } +public: + Car(std::string company, std::string model) : m_company(company), m_model(model) + { + std::cout << "Транспортное средство компании " + getCompany() + ", модель " + getModel() << std::endl; + } +}; +class PassengerCar : virtual public Car +{ +public: + PassengerCar(std::string company, std::string model) : Car(company, model) + { + std::cout << "Легковой автомобиль компании " + getCompany() + ", модель " + getModel() << std::endl; + } +}; + +class Bus : virtual public Car +{ +public: + Bus(std::string company, std::string model) : Car(company, model) + { + std::cout << "Автобус компании " + getCompany() + ", модель " + getModel() << std::endl; + } +}; + +class Minivan : public PassengerCar, public Bus +{ +public: + Minivan(std::string company, std::string model) : + PassengerCar(company, model), Bus(company, model), Car(company, model) + { + std::cout << "Минивэн компании " + getCompany() + ", модель " + getModel() << std::endl; + } +}; #endif diff --git a/lesson_3/main.cpp b/lesson_3/main.cpp index 40a5fd6..a7bc753 100644 --- a/lesson_3/main.cpp +++ b/lesson_3/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "exercise_1.hpp" #include "exercise_2.hpp" @@ -7,13 +8,67 @@ using namespace std; +void ex_1(); +void ex_2(); +void ex_3(); +void ex_4(); +void ex_5(); + int main() { - // Exercise 1 - - Parallelogram A(15, 9); - -// Figure* figures[5]; +// ex_1(); + ex_2(); + ex_3(); + ex_4(); + ex_5(); return 0; } + +void ex_1() +{ + Parallelogram Pgrm(15.2, 9.5); + Circle Crcl(14.5); + Rectangle Rctgl(14.0, 7.1); + Square Sqre(23.3); + Rhombus Rmbs(17.4, 13.2); + + vector> f; + + f.push_back(Pgrm); + f.push_back(Crcl); + f.push_back(Rctgl); + f.push_back(Sqre); + f.push_back(Rmbs); + + for (reference_wrapper
c : f) + c.get().area(); + + /* + * Площадь параллелограмма равна 144.4 + * Площадь круга равна 660.52 + * Площадь прямоугольника равна 99.4 + * Площадь квадрата равна 542.89 + * Площадь ромба равна 229.68 + */ +} + +void ex_2() +{ + Minivan m("Макдоналдс", "ABC"); +} + +void ex_3() +{ + +} + +void ex_4() +{ + +} + +void ex_5() +{ + +}