Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.58 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <assert.h>
  4. #include <string>
  5. using namespace std;
  6. class A1 {
  7. private:
  8.     string color;
  9. public:
  10.     A1(string color) { this->color = color; }
  11.     string& getColor() { return color; }
  12.     void setColor(string color) { this->color = color; }
  13. };
  14.  
  15. class A3 {
  16. private:
  17.     string name;
  18. public:
  19.     A3(string name) { this->name = name; }
  20.     string& getName() { return name; }
  21.     void setName(string name) { this->name = name; }
  22. };
  23. class B1 : private A1{
  24. private:
  25.     string color;
  26. public:
  27.     B1(string color, int age) : A1(color) {
  28.         this->color = color;
  29.     }
  30.     string& getColor() { return color; }
  31.     void setColor(string color) { this->color = color; }
  32. };
  33. class B2 : public A1, public A3 {
  34. private:
  35.     int age;
  36. public:
  37.     B2(string color, int age, string name) : A1(color), A3(name) {
  38.         this->age = age;
  39.     }
  40.     int getAge() { return age; }
  41.     void setAge(int age) { this->age = age; }
  42. };
  43. class B3 : protected A3 {
  44. private:
  45.     string name;
  46. public:
  47.     B3(int age, string name) : A3(name) {
  48.         this->name = name;
  49.     }
  50.     string& getName() { return name; }
  51.     void setName(string name) { this->name = name; }
  52. };
  53. class C1 : protected B1, public B2 {
  54. private:
  55.     string color;
  56.     int age;
  57. public:
  58.     C1(string color, int age, string name) : B1(color, age), B2(color, age, name) {
  59.         this->color = color; this->age = age;
  60.     }
  61.     int getAge() { return age; }
  62.     void setAge(int age) { this->age = age; }
  63.     string& getColor() { return color; }
  64.     void setColor(string color) { this->color = color; }
  65. };
  66. class C2 : private B1, public B2, protected B3 {
  67. private:
  68.     string name;
  69.     int age;
  70.     string color;
  71. public:
  72.     C2(string color, int age, string name) : B1(color, age), B2(color, age, name), B3(age, name) {
  73.         this->name = name; this->age = age; this->color = color;
  74.     }
  75.     string& getName() { return name; }
  76.     void setName(string name) { this->name = name; }
  77.     int getAge() { return age; }
  78.     void setAge(int age) { this->age = age; }
  79.     string& getColor() { return color; }
  80.     void setColor(string color) { this->color = color; }
  81. };
  82. class C3 : protected B2, private B3 {
  83.     string name;
  84.     int age;
  85.     string color;
  86. public:
  87.     C3(string color, int age, string name) : B2(color, age, name), B3(age, name) {
  88.         this->name = name; this->age = age; this->color = color;
  89.     }
  90.     string& getName() { return name; }
  91.     void setName(string name) { this->name = name; }
  92.     int getAge() { return age; }
  93.     void setAge(int age) { this->age = age; }
  94.     string& getColor() { return color; }
  95.     void setColor(string color) { this->color = color; }
  96. };
  97. class D1 : private C1, public C2 {
  98. private:
  99.     string name;
  100.     int age;
  101.     string color;
  102. public:
  103.     D1(string color, int age, string name) : C1(color, age, name), C2(color, age, name) {
  104.         this->name = name; this->age = age; this->color = color;
  105.     }
  106.     D1() : C1("", 0, ""), C2("", 0, "") {}
  107.     string& getName() { return name; }
  108.     void setName(string name) { this->name = name; }
  109.     int getAge() { return age; }
  110.     void setAge(int age) { this->age = age; }
  111.     string& getColor() { return color; }
  112.     void setColor(string color) { this->color = color; }
  113.     friend ostream& operator<< (ostream& os, D1& d1) {
  114.         os << "D1(" << d1.getName() << ")" << endl;
  115.         return os;
  116.     }
  117.     friend istream& operator>> (istream& is, D1& d1) {
  118.         string in;
  119.         cin >> in; assert(in == "D1(");
  120.         cin >> d1.color;
  121.         cin >> in; assert(",");
  122.         cin >> d1.age;
  123.         cin >> in; assert(",");
  124.         cin >> d1.name;
  125.         cin >> in; assert(")");
  126.         return is;
  127.     }
  128. };
  129.  
  130. class D2 : protected C2, public C3 {
  131. private:
  132.     string name;
  133.     int age;
  134.     string color;
  135. public:
  136.     D2(string color, int age, string name) : C2(color, age, name), C3(color, age, name) {
  137.         this->name = name; this->age = age; this->color = color;
  138.     }
  139.     D2() : C2("", 0, ""), C3("", 0, "") {}
  140.     string& getName() { return name; }
  141.     void setName(string name) { this->name = name; }
  142.     int getAge() { return age; }
  143.     void setAge(int age) { this->age = age; }
  144.     string& getColor() { return color; }
  145.     void setColor(string color) { this->color = color; }
  146.     friend ostream& operator<< (ostream& os, D2& d2) {
  147.         os << "D2(" << d2.getName() << ")" << endl;
  148.         return os;
  149.     }
  150.     friend istream& operator>> (istream& is, D2& d2) {
  151.         string in;
  152.         cin >> in; assert(in == "D2(");
  153.         cin >> d2.color;
  154.         cin >> in; assert(",");
  155.         cin >> d2.age;
  156.         cin >> in; assert(",");
  157.         cin >> d2.name;
  158.         cin >> in; assert(")");
  159.         return is;
  160.     }
  161. };
  162. class E1 : public D1, public D2
  163. {
  164. private:
  165.     bool isJedi;
  166.     string name;
  167.     int age;
  168.     string color;
  169. public:
  170.     E1() : D1(), D2() {}
  171.     void SetJediStatus(bool JediStatus) { isJedi = JediStatus; };
  172.     bool GetJediStatus() { return isJedi; };
  173.     string& getName() { return name; }
  174.     void setName(string name) { this->name = name; }
  175.     int getAge() { return age; }
  176.     void setAge(int age) { this->age = age; }
  177.     string& getColor() { return color; }
  178.     void setColor(string color) { this->color = color; }
  179.     E1(string color, int age, string name, bool JediStatus) : D2(color, age, name), D1(color, age, name)
  180.     {
  181.         isJedi = JediStatus;
  182.         this->name = name;
  183.         this->age = age;
  184.         this->color = color;
  185.     }
  186.     friend ostream& operator<< (ostream& os, E1& e1) {
  187.         os << e1.getName() << " " << e1.getAge()<<" year old, with "<<
  188.             e1.getColor() <<" color of hair ";
  189.         e1.GetJediStatus() == true ? os << "is jedi!" : os << "isn't jedi!";
  190.         return os;
  191.     }
  192.     friend istream& operator>> (istream& is, E1& e1) {
  193.         string in;
  194.         cin >> in; assert(in == "jedi(");
  195.         cin >> e1.color;
  196.         cin >> in; assert(",");
  197.         cin >> e1.age;
  198.         cin >> in; assert(",");
  199.         cin >> e1.name;
  200.         cin >> in; assert(",");
  201.         cin >> in;
  202.         bool jediStatus = in == "1" ? true : false;
  203.         e1.SetJediStatus(jediStatus);
  204.         cin >> in; assert(")");
  205.         return is;
  206.     }
  207.  
  208. };
  209.  
  210. int main() {
  211.     //D1 d1; D2 d2;
  212.     //cin >> d1; cin >> d2;
  213.     //cout << "D1(" << d1.getColor() << ", " << d1.getAge() << ", " << d1.getName() << ")" << endl;
  214.     //cout << "D2(" << d2.getColor() << ", " << d2.getAge() << ", " << d2.getName() << ")" << endl;
  215.     //C1 c1("yellow", 44, "mr"); C2 c2("white", 13, "hello"); C3 c3("black", 33, "mss");
  216.     //cout << "C1(" << c1.getColor() << ", " << c1.getAge() << ", " << c1.getName() << ")" << endl;
  217.     //cout << "C2(" << c2.getColor() << ", " << c2.getAge() << ", " << c2.getName() << ")" << endl;
  218.     //cout << "C3(" << c3.getColor() << ", " << c3.getAge() << ", " << c3.getName() << ")" << endl;
  219.     //B2 b2("pink", 6, "Him");
  220.     //cout << "B2(" << b2.getColor() << ", " << b2.getAge() << ", " << b2.getName() << ")" << endl;
  221.     //A1 a1("COLOR"); A3 a3("NAME");
  222.     //cout << "A1(" << a1.getColor() << ")" << endl;
  223.     //cout << "A3(" << a3.getName() << ")" << endl;
  224.     E1 e1("red", 21, "Darth Vader", true);
  225.     cout << e1 <<endl;
  226.     return 0;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement