Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdlib>
- #include <string>
- #include <iostream>
- #include <cmath>
- using namespace std;
- /*
- *
- * “В C++ всего 2 вещи получились не так: начальный замысел и реализация.”
- * — Бертран Мейер
- *
- */
- /** Класс исключений
- */
- class NegativeException {
- string exc;
- friend ostream& operator<<(ostream& os, const NegativeException& vi) {
- os << "исключение " << vi.exc;
- return os;
- }
- public:
- NegativeException() {
- this->exc = "NegativeException";
- }
- };
- class Orb {
- private:
- double r;
- public:
- Orb(double r = 1) {
- if (r <= 0)throw NegativeException();
- this->r = r;
- };
- Orb(const Orb &orig) {
- this->r = orig.r;
- };
- /**
- * Переопределённый оператор вывода iostream
- */
- friend ostream& operator<<(ostream& os, const Orb& at) {
- os << "r=" << at.r;
- return os;
- };
- /**
- * Деструктор. Не нужен пока нет указателей
- */
- ~Orb() {
- };
- /**
- * Площадь
- * @return площадь
- */
- double s() {
- return (4 * M_PI * r * r);
- };
- /**
- * Объём
- * @return объём
- */
- double v() {
- return 4 / 3 * (M_PI * r * r * r);
- };
- double getR() {
- return this->r;
- };
- //переопределённые операторы
- bool operator==(Orb a) {
- return this->equals(a);
- };
- bool operator!=(Orb a) {
- return !(this->equals(a));
- };
- void operator=(Orb b) {
- this->r = b.r;
- };
- protected:
- bool equals(const Orb &a) {
- if (a.r == this->r) return true;
- return false;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment