C/C++
Задание по c++ много проболел вообще не понимаю
Определите класс line содержащий в качестве полей данных координаты начала и конца линии, а также содержащий методы для чтения и установки координат
#include <iostream>
#include <cmath>
using namespace std;
struct Point {
double x;
double y;
Point()
: x(0), y(0) {}
Point(const double x, const double y)
: x(x), y(y) {}
Point(const pair<double, double>& box)
: x(box.first), y(box.second) {}
void move(const double dx, const double dy) {
x += dx;
y += dy;
}
double length(const Point& p)const {
return sqrt(pow(x - p.x, 2) + pow(y - p.y, 2));
}
Point operator-()const {
return Point(-x, -y);
}
Point& operator+=(const Point& p) {
x += p.x;
y += p.y;
return *this;
}
Point& operator-=(const Point& p) {
x -= p.x;
y -= p.y;
return *this;
}
friend ostream& operator<<(ostream& out, const Point& p) {
return out << "(" << p.x << ", " << p.y << ")";
}
};
class Line {
public:
Line() = default;
Line(const Point& a, const Point& b)
: a(a), b(b) {}
double length()const {
return a.length(b);
}
void set(const Point& a, const Point& b) {
this->a = a;
this->b = b;
}
void move(const Point& a, const Point& b) {
this->a += a;
this->b += b;
}
void move(const Line& line) {
a += line.a;
b += line.b;
}
void show(const char* name)const {
cout << name << ": { " << a << "; " << b << " }\n";
}
private:
Point a;
Point b;
};
int main() {
Line a;
a.show("A");
a.move({ 2, 4 }, { 8, 6 });
a.show("A");
Line b({ 2, 7 }, { 3, 9 });
b.show("B");
Line c;
c.show("C");
c.set({ 4, 1 }, { 7, 5 });
c.show("C");
Point n({ 5, 4 });
Point m({ 1, 3 });
Line d;
d.show("D");
d.set(n, m);
d.show("D");
a.move(d);
a.show("A");
a.move(-m, -n);
a.show("A");
system("pause > nul");
}
P.S. Очень надеюсь на то, что теперь я снял все ваши вопросы и у вас не возникнет проблем с защитой. Удачи вам и будьте здоровы!
#include <cmath>
using namespace std;
struct Point {
double x;
double y;
Point()
: x(0), y(0) {}
Point(const double x, const double y)
: x(x), y(y) {}
Point(const pair<double, double>& box)
: x(box.first), y(box.second) {}
void move(const double dx, const double dy) {
x += dx;
y += dy;
}
double length(const Point& p)const {
return sqrt(pow(x - p.x, 2) + pow(y - p.y, 2));
}
Point operator-()const {
return Point(-x, -y);
}
Point& operator+=(const Point& p) {
x += p.x;
y += p.y;
return *this;
}
Point& operator-=(const Point& p) {
x -= p.x;
y -= p.y;
return *this;
}
friend ostream& operator<<(ostream& out, const Point& p) {
return out << "(" << p.x << ", " << p.y << ")";
}
};
class Line {
public:
Line() = default;
Line(const Point& a, const Point& b)
: a(a), b(b) {}
double length()const {
return a.length(b);
}
void set(const Point& a, const Point& b) {
this->a = a;
this->b = b;
}
void move(const Point& a, const Point& b) {
this->a += a;
this->b += b;
}
void move(const Line& line) {
a += line.a;
b += line.b;
}
void show(const char* name)const {
cout << name << ": { " << a << "; " << b << " }\n";
}
private:
Point a;
Point b;
};
int main() {
Line a;
a.show("A");
a.move({ 2, 4 }, { 8, 6 });
a.show("A");
Line b({ 2, 7 }, { 3, 9 });
b.show("B");
Line c;
c.show("C");
c.set({ 4, 1 }, { 7, 5 });
c.show("C");
Point n({ 5, 4 });
Point m({ 1, 3 });
Line d;
d.show("D");
d.set(n, m);
d.show("D");
a.move(d);
a.show("A");
a.move(-m, -n);
a.show("A");
system("pause > nul");
}
P.S. Очень надеюсь на то, что теперь я снял все ваши вопросы и у вас не возникнет проблем с защитой. Удачи вам и будьте здоровы!
Точно. Писать "вообще не понимаю" может только больной. На голову. Но это не лечится!
Александр Иваненко
Писать о том что ты полосатый жираф может только больной. На голову. но это не лечится!
Какие могут быть болезни в столь юном возрасте?
Воспаление хитрости?
Ковид лени? :))
Воспаление хитрости?
Ковид лени? :))
Александр Иваненко
пневмония
Александр Иваненко
Раз я молод, я не человек что ли? Заболеть может кто угодно, если что)
Похожие вопросы
- Нужна помощь с выполнением заданий в C++
- Задание на C/C++
- Помогите решить задание на c++
- Задание на C++. Помощь с кодом.
- Задание по C++
- 24 задание егэ, C++
- Помощь с заданием на c++
- Помогите решить задание на C++
- Информатика задание по c++
- Помогите понять суть задания на C++, написать программу с такой задачей: