Advertisement
Kentoo

S#3

Jun 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class Line {
  7. protected:
  8.     double x1, y1;
  9.     double x2, y2;
  10. public:
  11.     Line() {
  12.         x1 = 0;
  13.         y1 = 0;
  14.         x2 = 0;
  15.         y2 = 0;
  16.     }
  17.     Line(double x1, double y1, double x2, double y2) {
  18.         this->x1 = x1;
  19.         this->y1 = y1;
  20.         this->x2 = x2;
  21.         this->y2 = y2;
  22.     }
  23.     Line(const Line &L) {
  24.         x1 = L.x1;
  25.         y1 = L.y1;
  26.         x2 = L.x2;
  27.         y2 = L.y2;
  28.     }
  29.     ~Line() {}
  30.     void print() {
  31.         cout << "((" << x1 << ";" << y1 << "), (" << x2 << ";" << y2 << "))";
  32.     }
  33.     double getParam() {
  34.         return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
  35.     }
  36.     double getx1() {
  37.         return x1;
  38.     }
  39.     double getx2() {
  40.         return x2;
  41.     }
  42.     double gety1() {
  43.         return y1;
  44.     }
  45.     double gety2() {
  46.         return y2;
  47.     }
  48.     Line operator = (const Line &L) {
  49.         return Line(this->x1 = L.x1, this->y1 = L.y1, this->x2 = L.x2, this->y2 = L.y2);
  50.     }
  51. };
  52.  
  53.  
  54.  
  55. class Rectangle : public Line {
  56. protected:
  57.     Line l1, l2, l3, l4;
  58. public:
  59.     Rectangle() {
  60.         l1 = Line(0, 0, 0, 0);
  61.         l2 = Line(0, 0, 0, 0);
  62.         l3 = Line(0, 0, 0, 0);
  63.         l4 = Line(0, 0, 0, 0);
  64.     }
  65.     Rectangle(Line l1, Line l2, Line l3, Line l4) {
  66.         this->l1 = l1;
  67.         this->l2 = l2;
  68.         this->l3 = l3;
  69.         this->l4 = l4;
  70.     }
  71.     Rectangle(const Rectangle &R) {
  72.         this->l1 = R.l1;
  73.         this->l2 = R.l2;
  74.         this->l3 = R.l3;
  75.         this->l4 = R.l4;
  76.     }
  77.     ~Rectangle() {}
  78.     void print() {
  79.         cout << "(";
  80.         l1.print();
  81.         cout << ", ";
  82.         l2.print();
  83.         cout << ", ";
  84.         l3.print();
  85.         cout << ", ";
  86.         l4.print();
  87.         cout << ")" << endl;
  88.     }
  89.     double getParam() {
  90.         return l1.getParam() * l1.getParam();
  91.     }
  92.     double getxc() {
  93.         return (fmax(fmax(fmax(this->l1.getx1(), this->l1.getx2()), fmax(this->l2.getx1(), this->l2.getx2())), fmax(fmax(this->l3.getx1(), this->l3.getx2()), fmax(this->l4.getx1(), this->l4.getx2()))) +
  94.             fmin(fmin(fmin(this->l1.getx1(), this->l1.getx2()), fmin(this->l2.getx1(), this->l2.getx2())), fmin(fmin(this->l3.getx1(), this->l3.getx2()), fmin(this->l4.getx1(), this->l4.getx2())))) / 2;
  95.     }
  96.     double getyc() {
  97.         return (fmax(fmax(fmax(this->l1.gety1(), this->l1.gety2()), fmax(this->l2.gety1(), this->l2.gety2())), fmax(fmax(this->l3.gety1(), this->l3.gety2()), fmax(this->l4.gety1(), this->l4.gety2()))) +
  98.             fmin(fmin(fmin(this->l1.gety1(), this->l1.gety2()), fmin(this->l2.gety1(), this->l2.gety2())), fmin(fmin(this->l3.gety1(), this->l3.gety2()), fmin(this->l4.gety1(), this->l4.gety2())))) / 2;
  99.     }
  100.     double getSide() {
  101.         return l1.getParam();
  102.     }
  103.     Rectangle operator = (const Rectangle &R) {
  104.         return Rectangle(this->l1 = R.l1, this->l2 = R.l2, this->l3 = R.l3, this->l4 = R.l4);
  105.     }
  106. };
  107.  
  108. class Circle : public Rectangle {
  109. protected:
  110.     double x1, y1, R;
  111. public:
  112.     Circle() {
  113.         x1 = 0;
  114.         y1 = 0;
  115.         R = 0;
  116.     }
  117.     Circle(double x1, double y1, double R) {
  118.         this->x1 = x1;
  119.         this->y1 = y1;
  120.         this->R = R;
  121.     }
  122.     Circle(const Circle &C) {
  123.         this->x1 = C.x1;
  124.         this->y1 = C.y1;
  125.         this->R = C.R;
  126.     }
  127.     Circle(Rectangle &R) {
  128.         this->x1 = R.getxc();
  129.         this->y1 = R.getyc();
  130.         this->R = R.getSide();
  131.     }
  132.     ~Circle() {}
  133.     void print() {
  134.         cout << "((" << x1 << ";" << y1 << "), " << R << ")" << endl;
  135.     }
  136.     double getParam() {
  137.         return 3.14 * R * R;
  138.     }
  139.     Circle operator = (const Circle &R) {
  140.         return Circle(this->x1 = R.x1, this->y1 = R.y1, this->R = R.R);
  141.     }
  142. };
  143.  
  144. void main() {
  145.     Line l;
  146.     l.print();
  147.     cout << endl;
  148.     Line l1(0.1, 0.1, 0.1, 5.1);
  149.     Line l2(0.1, 5.1, 5.1, 5.1);
  150.     Line l3(5.1, 5.1, 5.1, 0.1);
  151.     Line l4(5.1, 0.1, 0.1, 0.1);
  152.     Line l5(0.1, 0.1, 5.1, 5.1);
  153.     l = l1;
  154.     l.print();
  155.     cout << endl;
  156.     cout << l5.getParam() << endl;
  157.     Rectangle R;
  158.     R.print();
  159.     cout << endl;
  160.     Rectangle R1(l1, l2, l3, l4);
  161.     R = R1;
  162.     R.print();
  163.     cout << endl;
  164.     cout << R1.getParam();
  165.     cout << endl;
  166.     Circle C;
  167.     C.print();
  168.     cout << endl;
  169.     Circle C1(R);
  170.     C = C1;
  171.     C.print();
  172.     cout << endl;
  173.     cout << C.getParam();
  174.     system("pause");
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement