1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <string>
#include <algorithm>
struct aut {
std::string reg;
double dom {};
int bropu {};
aut() {}
aut(const std::string& reg, double dom, int bropu);
bool distance(double x1, double y1, double x2, double y2) const;
std::string getreg() const;
};
struct parking {
double X {}, Y {};
aut Auti[100] {};
size_t nraut {};
parking() {}
parking(double X, double Y, const aut auti[100], size_t nraut);
double getx() const;
double gety() const;
aut biggestdom() const;
bool insidedom(parking second) const;
bool removeaut(const std::string& reg);
};
aut::aut(const std::string& reg_, double dom_, int bropu_) : reg(reg_), dom(dom_), bropu(bropu_) {};
bool aut::distance(double x1, double y1, double x2, double y2) const {
const auto dx {x1 - x2}, dy {y1 - y2};
const auto distance {std::sqrt(dx * dx + dy * dy)};
return distance <= dom;
};
std::string aut::getreg() const {
return reg;
}
parking::parking(double x, double y, const aut auti[100], size_t nraut_) : X(x), Y(y), nraut(nraut_) {
std::copy_n(auti, 100, Auti);
}
aut parking::biggestdom() const {
size_t big {};
double biggest {Auti[0].dom};
for (size_t i = 1; i < nraut; ++i)
if (Auti[i].dom > biggest) {
biggest = Auti[i].dom;
big = i;
}
return Auti[big];
}
bool parking::insidedom(parking second) const {
const auto dx1 {second.X - X}, dy1 {second.Y - Y};
const auto distanceparking {sqrt(dx1 * dx1 + dy1 * dy1)};
for (size_t i = 0; i < nraut; ++i)
if (Auti[i].dom >= distanceparking)
return true;
return false;
}
double parking::gety() const {
return Y;
}
double parking::getx() const {
return X;
}
bool parking::removeaut(const std::string& reg) {
//TO DO
}
int main()
{
aut a1("fist", 40.0, 3);
aut a2("second", 10.0, 8);
aut auti1[100] {a1, a2};
parking pa1(10.0, 10.0, auti1, 2);
}
|