Skip to content

Commit 39b8613

Browse files
committed
Lab 14 dop started
1 parent d21fa9e commit 39b8613

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

Semester_2/Lab_14/main.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
//* Segment: координаты начала и коодинаты конца
2020

2121
//? исправить: сделать чтобы айдишники задавались по умолчанию автоматически
22-
//? доп: написать функцию сравнения длин контуров двух фигур
23-
// (круг сравнивать с отрезком -> длина окружности сравнивается с длиной отрезка)
22+
//? доп: написать функцию сравнения длин контуров(!) двух фигур
23+
//? (круг сравнивать с отрезком -> длина окружности сравнивается с длиной отрезка)
2424

2525
#include "shape.h"
2626

@@ -64,4 +64,22 @@ int main() {
6464
cout << endl << "----------" << endl;
6565
list.push_front(new Segment(42));
6666
list.print_all();
67+
68+
cout << endl << "---------- dop ----------" << endl;
69+
70+
cout << "id_42 == id_24: "
71+
<< (list.get(42) == list.get(24) ? "True" : "False")
72+
<< endl;
73+
74+
cout << "contour id24: " << list.get(24).get_contour_length() << endl;
75+
cout << "contour id42: " << list.get(42).get_contour_length() << endl;
76+
77+
// для теста нужно создать одинаковые Circle и Segment
78+
79+
list.push_front(new Circle(123, {0, 0}, 0, "нет слов, одни эмоции"));
80+
list.push_front(new Segment(321, {0, 0}, {0, 0}));
81+
82+
cout << "id_123 == id_321: "
83+
<< (list.get(123) == list.get(321) ? "True" : "False")
84+
<< endl;
6785
}

Semester_2/Lab_14/shape.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include "shape.h"
2+
3+
#include "math.h"
4+
#define PI 3.1415926535898
5+
26
using namespace std;
37

48
// class Point
@@ -27,6 +31,14 @@ int Shape::get_id() {
2731
return id;
2832
}
2933

34+
double Shape::get_contour_length() {
35+
return 0;
36+
}
37+
38+
bool Shape::operator==(Shape &s) {
39+
return get_contour_length() == s.get_contour_length();
40+
}
41+
3042
// class Circle
3143

3244
Circle::Circle(int id, Point pos, int r, string text):
@@ -40,6 +52,10 @@ void Circle::print() {
4052
cout << "text: " << text << endl;
4153
}
4254

55+
double Circle::get_contour_length() {
56+
return 2 * PI * r;
57+
}
58+
4359
// class Segment
4460

4561
Segment::Segment(int id, Point start, Point end):
@@ -53,6 +69,10 @@ void Segment::print() {
5369
cout << "end pos: " << end << endl;
5470
}
5571

72+
double Segment::get_contour_length() {
73+
return sqrt(pow(end.x - start.x, 2) + pow(end.y - start.y, 2));
74+
}
75+
5676
// class Node
5777

5878
Node::Node(Shape* s, Node* next):

Semester_2/Lab_14/shape.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Shape {
2222
Shape(int id, Point pos = {0});
2323
virtual void print();
2424
int get_id();
25+
virtual double get_contour_length();
26+
bool operator==(Shape &s);
2527
};
2628

2729
class Circle : public Shape {
@@ -32,6 +34,7 @@ class Circle : public Shape {
3234
public:
3335
Circle(int id, Point pos = {0}, int r = 1, string text = "");
3436
virtual void print();
37+
virtual double get_contour_length();
3538
};
3639

3740
class Segment : public Shape {
@@ -41,6 +44,7 @@ class Segment : public Shape {
4144
public:
4245
Segment(int id, Point start = {0}, Point end = {0});
4346
virtual void print();
47+
virtual double get_contour_length();
4448
};
4549

4650
class Node {
@@ -58,19 +62,9 @@ class FigureList {
5862

5963
public:
6064
FigureList();
61-
62-
// добавить фигуру в начало списка
6365
void push_front(Shape* s);
64-
65-
// добавить фигуру в конец списка
6666
void push_back(Shape* s);
67-
68-
// найти фигуру всписке по идентификатору
6967
Shape &get(int id);
70-
71-
// удалить фигуру из списка
7268
void erase(int id);
73-
74-
// вывести на экран в текстовом режиме информацию о всех фигурах в списке
7569
void print_all();
7670
};

0 commit comments

Comments
 (0)