Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- #include <string>
- #include <cstring>
- using namespace std;
- class NegativeException {
- string exc;
- friend ostream& operator<<(ostream& os, const NegativeException& vi) {
- os << "исключение " << vi.exc;
- }
- public:
- NegativeException() {
- this->exc = "NegativeException";
- }
- };
- class DrawnBox {
- protected:
- double w;
- double h;
- public:
- DrawnBox(double w = 0, double h = 0) {
- if (w < 0 || h < 0)throw NegativeException();
- this->w = w;
- this->h = h;
- }
- DrawnBox(const DrawnBox& a) {
- w = a.w;
- h = a.h;
- }
- friend ostream& operator<<(ostream& os, const DrawnBox& a) {
- os << "DrawnBox: Width=" << a.w << " Hight=" << a.h;
- return os;
- }
- bool equals(const DrawnBox& a) {
- if (a.w == w && a.h == h)return true;
- return false;
- }
- };
- class Box : protected DrawnBox {
- protected:
- double d;
- public:
- Box(double d = 0, double w = 0, double h = 0) : DrawnBox(w, h) {
- if (d < 0)throw NegativeException();
- this->d = d;
- }
- Box(const Box& a) {
- this->w = a.w;
- this->h = a.h;
- this->d = a.d;
- }
- bool equals(const Box& a) {
- if (a.w == w && a.h == h && a.d == d)return true;
- return false;
- }
- friend ostream& operator<<(ostream& os, const Box& a) {
- os << "Box: Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d;
- return os;
- }
- };
- class BoxWeight : protected virtual Box {
- protected:
- double weight;
- public:
- BoxWeight(double weight = 0, double d = 0, double w = 0, double h = 0) : Box(d, w, h) {
- if (weight < 0)throw NegativeException();
- this->weight = weight;
- }
- BoxWeight(const BoxWeight& a) {
- this->weight = a.weight;
- this->w = a.w;
- this->h = a.h;
- this->d = a.d;
- }
- bool equalW(const BoxWeight& a) {
- if (weight == a.weight)return true;
- return false;
- }
- bool equals(const BoxWeight& a) {
- if (a.w == w && a.h == h && a.d == d)return true;
- return false;
- }
- friend ostream& operator<<(ostream& os, const BoxWeight& a) {
- os << "BoxWeight: Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d << " Weight=" << a.weight;
- return os;
- }
- };
- class BoxNamed : protected virtual Box {
- protected:
- string name;
- public:
- BoxNamed(string name = "Box", double d = 0, double w = 0, double h = 0) : Box(d, w, h) {
- this->name = name;
- }
- BoxNamed(const BoxNamed& a) {
- this->name = a.name;
- this->w = a.w;
- this->h = a.h;
- this->d = a.d;
- }
- bool equals(const BoxNamed& a) {
- if (a.w == w && a.h == h && a.d == d)return true;
- return false;
- }
- bool equalN(const BoxNamed& a) {
- if (name == a.name)return true;
- return false;
- }
- friend ostream& operator<<(ostream& os, const BoxNamed& a) {
- os << "BoxNamed: Name=" << a.name << " Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d;
- return os;
- }
- };
- class UberBox : protected BoxWeight, protected BoxNamed {
- public:
- UberBox(string name = "Box", double d = 0, double w = 0, double h = 0, double weight = 0) : BoxWeight(weight, d, w, h) {
- //{
- /*
- this->weight = weight;
- this->w = w;
- this->h = h;
- this->d = d;*/
- this->name = name;
- }
- UberBox(const UberBox& a) {
- this->name = a.name;
- this->w = a.w;
- this->h = a.h;
- this->d = a.d;
- this->weight = a.weight;
- }
- friend ostream& operator<<(ostream& os, const UberBox& a) {
- os << "UberBox: Name=" << a.name << " Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d << " Weight=" << a.weight;
- return os;
- }
- };
- int main() {
- UberBox a = UberBox("Zarabotalo!", 4, 4, 4, 4);
- BoxNamed b = BoxNamed("Zarabotalo?", 3, 3, 3);
- BoxWeight c = BoxWeight(2, 2, 2, 2);
- Box d = Box(1, 1, 1);
- DrawnBox z = DrawnBox(9, 9);
- cout << a << endl << b << endl << c << endl << d << endl << z << endl;
- /*
- BoxWeight copy = BoxWeight(c);
- if (copy.equals(c))cout << "BoxWeight equals +" << endl;
- if (copy.equalW(c))cout << "BoxWeight equalW +" << endl;
- BoxNamed copy1 = BoxNamed(b);
- if (copy1.equals(b))cout << "BoxNamed equals +" << endl;
- if (copy1.equalN(b))cout << "BoxNamed equals +" << endl;
- Box copy2 = Box(d);
- if (copy2.equals(d))cout << "Box equals +" << endl;
- DrawnBox copy3 = DrawnBox(z);
- if (copy3.equals(z))cout << "++++++++++++++++++++++++" << endl;*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement