lesson 3, exercise 2

This commit is contained in:
Alexander Zhirov 2021-06-25 15:24:13 +03:00
parent 023dfa6c14
commit 6a05ccbf97
3 changed files with 112 additions and 7 deletions

View File

@ -87,8 +87,9 @@ public:
class Square : public Parallelogram class Square : public Parallelogram
{ {
Square(float side_a, float side_b) public:
: Parallelogram(side_a, side_b, side_b) { } Square(float side_a)
: Parallelogram(side_a, side_a, side_a) { }
float area() float area()
{ {
@ -102,6 +103,7 @@ class Square : public Parallelogram
class Rhombus : public Parallelogram class Rhombus : public Parallelogram
{ {
public:
Rhombus(float side_a, float side_b) Rhombus(float side_a, float side_b)
: Parallelogram(side_a, side_b, side_b) { } : Parallelogram(side_a, side_b, side_b) { }

View File

@ -1,8 +1,56 @@
#ifndef EXERCISE_2_HPP_ #ifndef EXERCISE_2_HPP_
#define EXERCISE_2_HPP_ #define EXERCISE_2_HPP_
#include <iostream>
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 #endif

View File

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <functional>
#include <vector> #include <vector>
#include "exercise_1.hpp" #include "exercise_1.hpp"
#include "exercise_2.hpp" #include "exercise_2.hpp"
@ -7,13 +8,67 @@
using namespace std; using namespace std;
void ex_1();
void ex_2();
void ex_3();
void ex_4();
void ex_5();
int main() int main()
{ {
// Exercise 1 // ex_1();
ex_2();
Parallelogram A(15, 9); ex_3();
ex_4();
// Figure* figures[5]; ex_5();
return 0; 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<reference_wrapper<Figure>> f;
f.push_back(Pgrm);
f.push_back(Crcl);
f.push_back(Rctgl);
f.push_back(Sqre);
f.push_back(Rmbs);
for (reference_wrapper<Figure> 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()
{
}