Добавил:
vvrstcnho
Рад, если кому-то помог
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные работы С++ (для ИВТ) / Готовые лабы С++ / Лаба5 / Laba 5 (7)
.cpp#include <iostream>
#include <locale>
#include <vector>
using namespace std;
class Point {
protected:
double x, y;
public:
Point(double x_val = 0, double y_val = 0) : x(x_val), y(y_val) {}
virtual void draw() const {
cout << "(" << x << ", " << y << ")";
}
virtual void move(double dx, double dy) {
x += dx;
y += dy;
}
virtual ~Point() {}
};
class Segment : public Point {
protected:
Point endPoint;
public:
Segment(double x1 = 0, double y1 = 0, double x2 = 1, double y2 = 1)
: Point(x1, y1), endPoint(x2, y2) {}
void draw() const override {
cout << "Отрезок "; Point::draw();
cout << " - "; endPoint.draw(); cout << endl;
}
void move(double dx, double dy) override {
Point::move(dx, dy);
endPoint.move(dx, dy);
}
};
class Quadrilateral : public Segment {
protected:
Point point3, point4;
public:
Quadrilateral(double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4)
: Segment(x1, y1, x2, y2), point3(x3, y3), point4(x4, y4) {}
void draw() const override {
cout << "Четырёхугольник: "; Point::draw(); cout << ", ";
endPoint.draw(); cout << ", "; point3.draw(); cout << ", ";
point4.draw(); cout << endl;
}
void move(double dx, double dy) override {
Segment::move(dx, dy);
point3.move(dx, dy);
point4.move(dx, dy);
}
void fill() const {
cout << "Закрашиваем четырёхугольник" << endl;
}
};
class Trapezoid : public Quadrilateral {
public:
Trapezoid(double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4)
: Quadrilateral(x1, y1, x2, y2, x3, y3, x4, y4) {}
void draw() const override {
cout << "Трапеция: "; Point::draw(); cout << ", ";
endPoint.draw(); cout << ", "; point3.draw(); cout << ", ";
point4.draw(); cout << endl;
}
bool isIsosceles() const {
// Проверка на равнобедренность (упрощённо)
return true;
}
};
int main() {
setlocale(LC_ALL, "ru_RU.UTF-8");
Point point(0, 0);
Segment segment(0, 0, 5, 0);
Quadrilateral quad(0, 0, 5, 0, 5, 3, 0, 3);
Trapezoid trap(0, 0, 6, 0, 4, 3, 2, 3);
point.draw();
segment.draw();
quad.draw();
trap.draw();
quad.fill();
cout << "Трапеция равнобедренная: " << trap.isIsosceles() << endl;
return 0;
}
Соседние файлы в папке Лаба5
