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;
- /*
- *
- * — Существует ли объектно-ориентированный способ стать богатым?
- * — Да, наследование.
- *
- */
- class NegativeException {
- string exc;
- friend ostream& operator<<(ostream& os, const NegativeException& vi) {
- os << "исключение " << vi.exc;
- return os;
- }
- public:
- NegativeException() {
- this->exc = "NegativeException";
- }
- };
- class Rectangle {
- double a, b;
- public:
- Rectangle(double a, double b) {
- if (a <= 0 || b <= 0) throw NegativeException();
- this->a = a;
- this->b = b;
- }
- Rectangle(double a) {
- if (a <= 0)throw NegativeException();
- this->a = a;
- this->b = a;
- }
- Rectangle() {
- this->a = 1;
- this->b = 1;
- }
- double s() {
- return a*b;
- }
- double p() {
- return 2 * a + 2 * b;
- }
- bool equals(Rectangle a) {
- if ((this->a == a.a && this->b == a.b) || (this->a == a.b && this->b == a.a))return true;
- return false;
- }
- bool operator==(Rectangle a) {
- return this->equals(a);
- };
- bool operator!=(Rectangle a) {
- return !(this->equals(a));
- };
- void operator=(Rectangle b) {
- this->a = b.a;
- this->b = b.b;
- };
- friend ostream& operator<<(ostream& os, const Rectangle& at) {
- os << "a=" << at.a << ", b=" << at.b;
- return os;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment