Агент527
29.12.2021 13:10

Массив. напишите программу, которая при введении «0» будет выводить «конец программы».

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
Marysilly
26.02.2021 14:53

С++20

#include <iostream>#include <vector>class Point {public:    int x, y;    Point() = default;    Point(const Point &) = default;    Point(int _x, int _y) : x(_x), y(_y) {}    Point operator + (const Point& p) const {        return Point {x + p.x, y + p.y};    }    Point operator - (const Point& p) const {        return Point {x - p.x, y - p.y};    }    std::vector<Point> operator & (const Point& p) const {        return std::vector<Point> {                Point {x + p.x, y + p.y},                Point {x - p.x, y + p.y},                Point {x + p.x, y - p.y},                Point {x - p.x, y - p.y},                Point {x + p.y, y + p.x},                Point {x - p.y, y + p.x},                Point {x + p.y, y - p.x},                Point {x - p.y, y - p.x},        };    }    static Point max (const Point& p1, const Point& p2) {        return Point {std::max(p1.x, p2.x), std::max(p1.y, p2.y)};    }    static Point min (const Point& p1, const Point& p2) {        return Point {std::min(p1.x, p2.x), std::min(p1.y, p2.y)};    }    [[nodiscard]] int distance_to_by_ch (const Point & p) const {        return std::max(std::abs(p.x - x), std::abs(p.y - y));    }    [[nodiscard]] int distance_to_by_m (const Point & p) const {        return std::abs(p.x - x) + std::abs(p.y - y);    }    friend std::ostream &operator << (std::ostream &os, Point const &p) {        return os << "(" << p.x << ";" << p.y << ")";    }    Point & operator = (const Point &) = default;    bool operator == (const Point & p) const {        return x == p.x && y == p.y;    }};class Horse {public:    const Point p;    explicit Horse (const Point position) : p(position) { }    [[nodiscard]] bool can_I_kill_this_guy (const Point & m) const {        auto field = p & Point{2, 3};        return std::find(field.begin(), field.end(), m) != field.end();    }};std::istream &to_number(std::istream &stream) {    char ch;    do {        ch = stream.get();    }    while (!isalpha(ch));    if (isupper(ch)) ch -= 16; else ch -= 48;    stream.putback(ch);    return stream;}int main () {    Point horse_p{}, stranger_p{};    std::cin >> horse_p.x >> to_number >> horse_p.y;    std::cin >> stranger_p.x >> to_number >> stranger_p.y;    Horse jack(horse_p);    std::cout << "I am a Horse placed on " << jack.p << ". "              << "Can I kill those guy on " << stranger_p << "? "              << "-> " << std::boolalpha << jack.can_I_kill_this_guy(stranger_p); }
Поле шахматной доски определяется парой – буква и цифра. Буква (a … h) означает горизонталь при счет
Поле шахматной доски определяется парой – буква и цифра. Буква (a … h) означает горизонталь при счет
Поле шахматной доски определяется парой – буква и цифра. Буква (a … h) означает горизонталь при счет
0,0(0 оценок)
Ответ:
QueenBee2403
02.02.2021 14:04

/*Решение с обобщения формула Брахмагупты для произвольного четырехугольника. Функция perimeter(double x[], double y[]) возвращает значение периметра, функция area(double x[], double y[]) возвращает значение площади, пример использования и реализация приведены ниже. */

#include <iostream>

#include <math.h>

double perimeter(double x[], double y[]);

double area(double x[], double y[]);

int main()

{

   double x[4], y[4];

   std::cout << "Quadrangle ABCD\n";

   for (auto i = 0; i < 4; i++)

   {

       std::cout << "Input coordinates of point " << char(i + 'A') << ": ";

       std::cin >> x[i] >> y[i];

   }

   std::cout << perimeter(x, y) << " " << area(x, y);

   

   return 0;

}

double perimeter(double x[], double y[])

{

   double a[4], p = 0;

   for (auto i = 0; i < 4; i++)

   {

       a[i] = sqrt((x[i]-x[(i + 1) % 4]) * (x[i]-x[(i + 1) % 4]) + (y[i]-y[(i + 1) % 4]) * (y[i]-y[(i + 1) % 4]));

       p += a[i];

   }

   return p;

}

double area(double x[], double y[])

{

   double a[4], p = 0, s = 1, d[2];

   for (auto i = 0; i < 4; i++)

   {

       a[i] = sqrt((x[i]-x[(i + 1) % 4]) * (x[i]-x[(i + 1) % 4]) + (y[i]-y[(i + 1) % 4]) * (y[i]-y[(i + 1) % 4]));

       p += a[i];

   }

   for (auto i = 0; i < 4; i++)

   {

       s *= (p / 2- a[i]);

   }

   for (auto i = 0; i < 2; i++)

   {

       d[i] = sqrt((x[i]-x[i + 2]) * (x[i]-x[i + 2]) + (y[i]-y[i + 2]) * (y[i]-y[i + 2]));

   }

   s -= (a[0] * a[2] + a[1] * a[3] + d[0] * d[1]) * (a[0] * a[2] + a[1] * a[3] - d[0] * d[1]) / 4;

   s = sqrt(s);

   return s;

}

0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота