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++ это сделать сложнее, но, когда вы это делаете,
- * вы отстреливаете себе ногу целиком.”
- * - Бьерн Страуструп
- *
- */
- class NegativeException {
- string exc;
- friend ostream& operator<<(ostream& os, const NegativeException& vi) {
- os << "исключение " << vi.exc;
- return os;
- }
- public:
- NegativeException() {
- this->exc = "NegativeException";
- }
- };
- class SidesException {
- string exc;
- friend ostream& operator<<(ostream& os, const SidesException& vi) {
- os << "исключение " << vi.exc;
- return os;
- }
- public:
- SidesException() {
- this->exc = "SidesException";
- }
- };
- class Triangle {
- private:
- double a, b, c;
- public:
- Triangle(double a, double b, double c) {
- if (a <= 0 || b <= 0 || c <= 0) {
- throw NegativeException();
- }
- if (test(a, b, c)) {
- throw SidesException();
- }
- this->a = a;
- this->b = b;
- this->c = c;
- };
- Triangle(double ab, double c) {
- if (ab <= 0 || c <= 0) {
- throw NegativeException();
- }
- if (test(ab, ab, c)) {
- throw SidesException();
- }
- this->a = ab;
- this->b = ab;
- this->c = c;
- };
- Triangle(double a) {
- if (a <= 0) {
- throw NegativeException();
- }
- if (test(a, a, a)) {
- throw SidesException();
- }
- this->a = a;
- this->b = a;
- this->c = a;
- };
- Triangle() {
- this->a = 1;
- this->b = 1;
- this->c = 1;
- };
- Triangle(const Triangle &orig) {
- this->a = orig.a;
- this->b = orig.b;
- this->c = orig.c;
- };
- //Переопределённый вывод
- friend ostream& operator<<(ostream& os, const Triangle& at) {
- os << "a=" << at.a << ", b=" << at.b << ", c=" << at.c;
- return os;
- };
- ~Triangle() {
- };
- double s() {
- double P = p() / 2;
- return sqrt(P * (P - a) * (P - b) * (P - c));
- };
- double p() {
- return a + b + c;
- };
- /**
- * <u>Радиус <b>вписанной</b> окружности</u><br>
- *
- * @return Радиус вписанной окружности
- */
- double r() {
- return ((2 * s()) / (a + b + c));
- };
- /**
- * <u>Радиус <b>описанной</b> окружности</u><br>
- *
- * @return Радиус описанной окружности
- */
- double R() {
- return (a * b * c) / (4 * s());
- };
- bool operator==(Triangle a) {
- return this->equals(a);
- };
- bool operator!=(Triangle a) {
- return !(this->equals(a));
- };
- void operator=(Triangle b) {
- this->a = b.a;
- this->b = b.b;
- this->c = b.c;
- };
- protected:
- //Проверка неравенства треугольника
- static bool test(double a, double b, double c) {
- if (a + b > c && a + c > b && c + b > a) {
- return false;
- }
- return true;
- };
- bool equals(const Triangle &two) {
- if (this->a == two.a) {
- if (this->b == two.b) {
- if (this->c == two.c) {
- return true;
- }
- }
- if (this->b == two.c) {
- if (this->c == two.b) {
- return true;
- }
- }
- }
- if (this->b == two.a) {
- if (this->c == two.b) {
- if (this->a == two.c) {
- return true;
- }
- }
- if (this->c == two.c) {
- if (this->a == two.b) {
- return true;
- }
- }
- }
- if (this->c == two.a) {
- if (this->a == two.b) {
- if (this->b == two.c) {
- return true;
- }
- }
- if (this->a == two.c) {
- if (this->b == two.b) {
- return true;
- }
- }
- }
- return false;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment