#include <iostream>
#include <fstream>
using namespace std;
int counter = 1; // счетчик. Для форматированного вывода экземпляров

class Pyramid {
    friend double Perimetr(const Pyramid& pyramid);
public:
    double x, h, a; // x - сторона основания, h - высота, a - апофема
    Pyramid() {
        cout << endl << "--------------------------------------------------" << endl;
        cout << "Этот обьект был создан в конструкторе по умолчанию. Область: " << this << endl;
        x = h = a = 3;
    }
    Pyramid(double p, double k, double q) {
        cout << endl << "--------------------------------------------------" << endl;
        cout << "Этот обьект был создан в конструкторе с параметрами. Область: " << this << endl;
        x = p;
        h = k;
        a = q;
    }
    Pyramid(const Pyramid& obj) {
        cout << endl << "--------------------------------------------------" << endl;
        cout << "Этот обьект был создан в конструкторе копирования. Область: " << this << endl;
        this->x = obj.x;
        this->h = obj.h;
        this->a = obj.a;
    }
    Pyramid& operator=(const Pyramid& obj) {
        if (this != &obj) {
            this->x = obj.x;
            this->h = obj.h;
            this->a = obj.a;
        }
        return *this;
    }
    Pyramid operator+(const Pyramid& b) {
        Pyramid temp;
        temp.x = this->x + b.x;
        temp.h = this->h + b.h;
        temp.a = this->a + b.a;
        return temp;
    }
    void SHOW() {
        cout << endl << "--------------------------------------------------" << endl;
        cout << "  p" << counter << "\tx --> " << x << ";\th --> " << h << ";\ta --> " << a << endl;
    }
    ~Pyramid() {
        cout << endl << "--------------------------------------------------" << endl;
        cout << "Удаление объекта в области " << this << " деструктором.\n";
    }
private:
    double Sb = 10;
};

double Perimetr(const Pyramid& pyramid);

int main() {
    setlocale(0, "");
    Pyramid p1, p2(2, 4, 6);
    p1.SHOW(); counter++;
    p2.SHOW();
    counter = 1;

    p1 = p2;
    cout << "\nПриравнял p1 к p2 -->>\n";
    p1.SHOW(); counter++;
    p2.SHOW();

    Pyramid p3 = p1 + p2;
    cout << "\nСложил p1 и p2 -->>\n";
    counter = 1;
    p1.SHOW(); counter++;
    p2.SHOW();

    return 0;
}

double Perimetr(const Pyramid& pyramid)
{
    return (2 * pyramid.Sb) / pyramid.a; // формула из файла "Ф?ГУРИ"
}
