Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Line {
- protected:
- double x1, y1;
- double x2, y2;
- public:
- Line() {
- x1 = 0;
- y1 = 0;
- x2 = 0;
- y2 = 0;
- }
- Line(double x1, double y1, double x2, double y2) {
- this->x1 = x1;
- this->y1 = y1;
- this->x2 = x2;
- this->y2 = y2;
- }
- Line(const Line &L) {
- x1 = L.x1;
- y1 = L.y1;
- x2 = L.x2;
- y2 = L.y2;
- }
- ~Line() {}
- void print() {
- cout << "((" << x1 << ";" << y1 << "), (" << x2 << ";" << y2 << "))";
- }
- double getParam() {
- return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
- }
- double getx1() {
- return x1;
- }
- double getx2() {
- return x2;
- }
- double gety1() {
- return y1;
- }
- double gety2() {
- return y2;
- }
- Line operator = (const Line &L) {
- return Line(this->x1 = L.x1, this->y1 = L.y1, this->x2 = L.x2, this->y2 = L.y2);
- }
- };
- class Rectangle : public Line {
- protected:
- Line l1, l2, l3, l4;
- public:
- Rectangle() {
- l1 = Line(0, 0, 0, 0);
- l2 = Line(0, 0, 0, 0);
- l3 = Line(0, 0, 0, 0);
- l4 = Line(0, 0, 0, 0);
- }
- Rectangle(Line l1, Line l2, Line l3, Line l4) {
- this->l1 = l1;
- this->l2 = l2;
- this->l3 = l3;
- this->l4 = l4;
- }
- Rectangle(const Rectangle &R) {
- this->l1 = R.l1;
- this->l2 = R.l2;
- this->l3 = R.l3;
- this->l4 = R.l4;
- }
- ~Rectangle() {}
- void print() {
- cout << "(";
- l1.print();
- cout << ", ";
- l2.print();
- cout << ", ";
- l3.print();
- cout << ", ";
- l4.print();
- cout << ")" << endl;
- }
- double getParam() {
- return l1.getParam() * l1.getParam();
- }
- double getxc() {
- 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()))) +
- 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;
- }
- double getyc() {
- 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()))) +
- 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;
- }
- double getSide() {
- return l1.getParam();
- }
- Rectangle operator = (const Rectangle &R) {
- return Rectangle(this->l1 = R.l1, this->l2 = R.l2, this->l3 = R.l3, this->l4 = R.l4);
- }
- };
- class Circle : public Rectangle {
- protected:
- double x1, y1, R;
- public:
- Circle() {
- x1 = 0;
- y1 = 0;
- R = 0;
- }
- Circle(double x1, double y1, double R) {
- this->x1 = x1;
- this->y1 = y1;
- this->R = R;
- }
- Circle(const Circle &C) {
- this->x1 = C.x1;
- this->y1 = C.y1;
- this->R = C.R;
- }
- Circle(Rectangle &R) {
- this->x1 = R.getxc();
- this->y1 = R.getyc();
- this->R = R.getSide();
- }
- ~Circle() {}
- void print() {
- cout << "((" << x1 << ";" << y1 << "), " << R << ")" << endl;
- }
- double getParam() {
- return 3.14 * R * R;
- }
- Circle operator = (const Circle &R) {
- return Circle(this->x1 = R.x1, this->y1 = R.y1, this->R = R.R);
- }
- };
- void main() {
- Line l;
- l.print();
- cout << endl;
- Line l1(0.1, 0.1, 0.1, 5.1);
- Line l2(0.1, 5.1, 5.1, 5.1);
- Line l3(5.1, 5.1, 5.1, 0.1);
- Line l4(5.1, 0.1, 0.1, 0.1);
- Line l5(0.1, 0.1, 5.1, 5.1);
- l = l1;
- l.print();
- cout << endl;
- cout << l5.getParam() << endl;
- Rectangle R;
- R.print();
- cout << endl;
- Rectangle R1(l1, l2, l3, l4);
- R = R1;
- R.print();
- cout << endl;
- cout << R1.getParam();
- cout << endl;
- Circle C;
- C.print();
- cout << endl;
- Circle C1(R);
- C = C1;
- C.print();
- cout << endl;
- cout << C.getParam();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement