Relz / OOP

Лабораторные работы по Объектно-ориентированному программированию (IDE - Visual Studio 2015)
0 stars 0 forks source link

Замечания по Shapes #9

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
class CRectangle : public ISolidShape
{
public:
    CRectangle(CPoint const& leftTop, double width, double height, std::string const& outlineColor, std::string const& fillColor);
    ~CRectangle() = default;
    double GetArea() const override;
    double GetPerimeter() const override;
    std::string ToString() const override;
    std::string GetOutlineColor() const override;
    std::string GetFillColor() const override;
    CPoint const& GetLeftTop() const;
    CPoint const& GetRightBottom() const;
    double GetWidth() const;
    double GetHeight() const;
private:
    CPoint m_leftTop;
    CPoint m_rightBottom;
    double m_width;
    double m_height;
    std::string m_outlineColor;
    std::string m_fillColor;
};
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
shared_ptr<IShape> GetMaxAreaShape(vector<shared_ptr<IShape>> &shapes)
{
    return *min_element(shapes.begin(), shapes.end(), [&]
    (shared_ptr<IShape> const& shape1, shared_ptr<IShape> const& shape2)
    {
        return shape1->GetArea() > shape2->GetArea();
    });
}

shared_ptr<IShape> GetMinPerimeterShape(vector<shared_ptr<IShape>> &shapes)
{
    return *min_element(shapes.begin(), shapes.end(), [&]
    (shared_ptr<IShape> const& shape1, shared_ptr<IShape> const& shape2)
    {
        return shape1->GetPerimeter() < shape2->GetPerimeter();
    });
}
alexey-malov commented 7 years ago
void PrintShapes(vector<shared_ptr<IShape>> &shapes)
{
    for (auto shape : shapes)
    {
        cout << shape->ToString() << "\n";
    }
    cout << "Shape with maximum area: \n"
        << GetMaxAreaShape(shapes)->ToString() << "\n";
    cout << "Shape with minimum perimeter: \n"
        << GetMinPerimeterShape(shapes)->ToString() << "\n";
}
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
AniSkyWorker commented 7 years ago
AniSkyWorker commented 7 years ago
AniSkyWorker commented 7 years ago
AniSkyWorker commented 7 years ago
AniSkyWorker commented 7 years ago
AniSkyWorker commented 7 years ago
AniSkyWorker commented 7 years ago

}


- [ ] наследовать интерфейс от конкретного класса - тяжкое преступление, измените архитектуру(избегайте ромбовидного наследования)
```c++
class ISolidShape : public CShape
AniSkyWorker commented 7 years ago

пока что остановлюсь, k = 0.65

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago