Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Написать простенькую Программу

Пользователь
Пользователь
Статус
Оффлайн
Регистрация
30 Янв 2018
Сообщения
284
Реакции
52
1591396021706.png
 
C++:
Expand Collapse Copy
static constexpr double CS_pid = 3.14159265358979323846;

class Circle
{
public:
    Circle()
    {
        m_cx = m_cy = 0.0f;
        m_r = 0.0;
    }
   
    Circle(float cx, float cy, double r)
    {
        m_cx = cx, m_cy = cy;
        m_r = r;
    }
   
    float area()
    {
        return (float)(CS_pid * m_r * m_r);
    }
   
    float length()
    {
        return (float)(2.0 * CS_pid * m_r);
    }
   
    bool cross(const Circle& other)
    {
        float cent_dist_sqr = ((other.m_cx - m_cx) * (other.m_cx - m_cx)) + ((other.m_cy - m_cy) * (other.m_cy - m_cy));
        return cent_dist_sqr < ((other.m_r + m_r) * (other.m_r + m_r));
    }
   
    void set(const Circle& other)
    {
        m_cx = other.m_cx, m_cy = other.m_cy;
        m_r = other.m_r;
    }
   
    void get(Circle& other)
    {
        other.m_cx = m_cx, other.m_cy = m_cy;
        other.m_r = m_r;
    }
   
protected:
    float m_cx, m_cy;
    double m_r;
};
P.S. условия задачи с Get и Set глупость, C++ сам сгенерирует конструкторы и операторы присваивания по умолчанию.
 
Назад
Сверху Снизу