1212// Связаный список должен быть реализован с помощью двух классов
1313// Node (элемент списка) и List (сам список)
1414
15- #include < cstdlib>
16- #include < string>
15+ // TODO:
16+ // * связный список (List) элементов (Node)
17+ // * вывод параметров фигуры через метод print()
18+ // * Circle: радиус, надпись произвольной длины
19+ // * Segment: координаты начала и коодинаты конца
1720
18- using namespace std ;
21+ // ? исправить: сделать чтобы айдишники задавались по умолчанию автоматически
22+ // ? доп: написать функцию сравнения длин контуров двух фигур
23+ // (круг сравнивать с отрезком -> длина окружности сравнивается с длиной отрезка)
1924
20- class Shape {
21- protected:
22- int id;
23- int x, y;
25+ #include " shape.h"
2426
25- public:
26- Shape (int id, int x, int y);
27- void print ();
28- };
27+ int main () {
28+ FigureList list;
2929
30- class Circle : public Shape {
31- protected:
32- int r;
33- string text;
30+ Circle *c_1 = new Circle (42 , {0 , 0 }, 1 , " lol kek" );
31+ Circle *c_2 = new Circle (24 , {4 , 2 }, 7 , " cheburek" );
32+ Segment *s_1 = new Segment (1 , {0 , 0 }, {42 , 42 });
3433
35- public:
36- Circle (int id, int x, int y, int r, string text);
37- void print ();
38- };
34+ list.push_front (c_1);
35+ list.push_front (c_2);
36+ list.push_front (s_1);
3937
40- class Segment : public Shape {
41- protected:
42- int x_start, y_start, x_end, y_end;
43-
44- public:
45- Segment (int id, int x_start, int y_start, int x_end, int y_end);
46- void print ();
47- };
38+ list.print_all ();
4839
49- class FigureList {
50- private:
51- Shape* arr[100 ];
52- int size = 0 ;
40+ cout << endl << " ----------" << endl;
5341
54- public:
55- void add (Shape* s);
42+ list.push_back (new Segment (2 , {6 , 18 }, {4 , 2 }));
43+ list.push_front (new Circle (618 , {7 , 7 }, 7 , " kek" ));
44+ list.print_all ();
5645
57- Shape & get ( int id) ;
46+ cout << endl << " ---------- " << endl ;
5847
59- // найти фигуру всписке по идентификатору
60- Shape& findFigure (int id);
48+ list.get (2 ).print ();
49+ cout << " ---------\n " ;
50+ list.get (42 ).print ();
6151
62- // удалить фигуру из списка
63- void erase (int id);
52+ cout << endl << " ----------del 42----------" << endl;
53+ list.erase (42 );
54+ list.print_all ();
6455
65- // вывести на экран в текстовом режиме информацию о всех фигурах в списке
66- void printAll ( );
67- } ;
56+ cout << endl << " ----------del 2-------- " << endl;
57+ list. erase ( 2 );
58+ list. print_all () ;
6859
60+ cout << endl << " ----------del 618--------" << endl;
61+ list.erase (618 );
62+ list.print_all ();
6963
70- int main () {
71- FigureList list;
64+ cout << endl << " ----------" << endl;
65+ list.push_front (new Segment (42 ));
66+ list.print_all ();
7267}
0 commit comments