Advertisement
Arkanium77

Untitled

May 9th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. class NegativeException {
  10.     string exc;
  11.  
  12.     friend ostream& operator<<(ostream& os, const NegativeException& vi) {
  13.         os << "исключение " << vi.exc;
  14.     }
  15. public:
  16.  
  17.     NegativeException() {
  18.         this->exc = "NegativeException";
  19.     }
  20. };
  21.  
  22. class DrawnBox {
  23. protected:
  24.     double w;
  25.     double h;
  26.  
  27. public:
  28.  
  29.     DrawnBox(double w = 0, double h = 0) {
  30.         if (w < 0 || h < 0)throw NegativeException();
  31.         this->w = w;
  32.         this->h = h;
  33.     }
  34.  
  35.     DrawnBox(const DrawnBox& a) {
  36.         w = a.w;
  37.         h = a.h;
  38.     }
  39.  
  40.     friend ostream& operator<<(ostream& os, const DrawnBox& a) {
  41.         os << "DrawnBox: Width=" << a.w << " Hight=" << a.h;
  42.         return os;
  43.     }
  44.  
  45.     bool equals(const DrawnBox& a) {
  46.         if (a.w == w && a.h == h)return true;
  47.         return false;
  48.     }
  49.  
  50. };
  51.  
  52. class Box : protected DrawnBox {
  53. protected:
  54.     double d;
  55. public:
  56.  
  57.     Box(double d = 0, double w = 0, double h = 0) : DrawnBox(w, h) {
  58.         if (d < 0)throw NegativeException();
  59.         this->d = d;
  60.     }
  61.  
  62.     Box(const Box& a) {
  63.         this->w = a.w;
  64.         this->h = a.h;
  65.         this->d = a.d;
  66.     }
  67.  
  68.     bool equals(const Box& a) {
  69.         if (a.w == w && a.h == h && a.d == d)return true;
  70.         return false;
  71.     }
  72.  
  73.     friend ostream& operator<<(ostream& os, const Box& a) {
  74.         os << "Box: Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d;
  75.         return os;
  76.     }
  77. };
  78.  
  79. class BoxWeight : protected virtual Box {
  80. protected:
  81.     double weight;
  82. public:
  83.  
  84.     BoxWeight(double weight = 0, double d = 0, double w = 0, double h = 0) : Box(d, w, h) {
  85.         if (weight < 0)throw NegativeException();
  86.         this->weight = weight;
  87.     }
  88.  
  89.     BoxWeight(const BoxWeight& a) {
  90.         this->weight = a.weight;
  91.         this->w = a.w;
  92.         this->h = a.h;
  93.         this->d = a.d;
  94.     }
  95.  
  96.     bool equalW(const BoxWeight& a) {
  97.         if (weight == a.weight)return true;
  98.         return false;
  99.     }
  100.  
  101.     bool equals(const BoxWeight& a) {
  102.         if (a.w == w && a.h == h && a.d == d)return true;
  103.         return false;
  104.     }
  105.  
  106.     friend ostream& operator<<(ostream& os, const BoxWeight& a) {
  107.         os << "BoxWeight: Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d << " Weight=" << a.weight;
  108.         return os;
  109.     }
  110. };
  111.  
  112. class BoxNamed : protected virtual Box {
  113. protected:
  114.     string name;
  115. public:
  116.  
  117.     BoxNamed(string name = "Box", double d = 0, double w = 0, double h = 0) : Box(d, w, h) {
  118.         this->name = name;
  119.     }
  120.  
  121.     BoxNamed(const BoxNamed& a) {
  122.         this->name = a.name;
  123.         this->w = a.w;
  124.         this->h = a.h;
  125.         this->d = a.d;
  126.     }
  127.  
  128.     bool equals(const BoxNamed& a) {
  129.         if (a.w == w && a.h == h && a.d == d)return true;
  130.         return false;
  131.     }
  132.  
  133.     bool equalN(const BoxNamed& a) {
  134.         if (name == a.name)return true;
  135.         return false;
  136.     }
  137.  
  138.     friend ostream& operator<<(ostream& os, const BoxNamed& a) {
  139.         os << "BoxNamed: Name=" << a.name << " Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d;
  140.         return os;
  141.     }
  142. };
  143.  
  144. class UberBox : protected  BoxWeight, protected  BoxNamed {
  145. public:
  146.  
  147.     UberBox(string name = "Box", double d = 0, double w = 0, double h = 0, double weight = 0) : BoxWeight(weight, d, w, h) {
  148.     //{  
  149.         /*
  150.         this->weight = weight;
  151.         this->w = w;
  152.         this->h = h;
  153.         this->d = d;*/
  154.         this->name = name;
  155.     }
  156.  
  157.     UberBox(const UberBox& a) {
  158.         this->name = a.name;
  159.         this->w = a.w;
  160.         this->h = a.h;
  161.         this->d = a.d;
  162.  
  163.         this->weight = a.weight;
  164.     }
  165.  
  166.     friend ostream& operator<<(ostream& os, const UberBox& a) {
  167.         os << "UberBox: Name=" << a.name << " Width=" << a.w << " Hight=" << a.h << " Depth=" << a.d << " Weight=" << a.weight;
  168.         return os;
  169.     }
  170. };
  171.  
  172. int main() {
  173.  
  174.     UberBox a = UberBox("Zarabotalo!", 4, 4, 4, 4);
  175.     BoxNamed b = BoxNamed("Zarabotalo?", 3, 3, 3);
  176.     BoxWeight c = BoxWeight(2, 2, 2, 2);
  177.     Box d = Box(1, 1, 1);
  178.     DrawnBox z = DrawnBox(9, 9);
  179.     cout << a << endl << b << endl << c << endl << d << endl << z << endl;
  180.     /*
  181.     BoxWeight copy = BoxWeight(c);
  182.     if (copy.equals(c))cout << "BoxWeight equals +" << endl;
  183.     if (copy.equalW(c))cout << "BoxWeight equalW +" << endl;
  184.     BoxNamed copy1 = BoxNamed(b);
  185.     if (copy1.equals(b))cout << "BoxNamed equals +" << endl;
  186.     if (copy1.equalN(b))cout << "BoxNamed equals +" << endl;
  187.     Box copy2 = Box(d);
  188.     if (copy2.equals(d))cout << "Box equals +" << endl;
  189.     DrawnBox copy3 = DrawnBox(z);
  190.     if (copy3.equals(z))cout << "++++++++++++++++++++++++" << endl;*/
  191.     return 0;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement