Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <assert.h>
- #include <string>
- using namespace std;
- class A1 {
- private:
- string color;
- public:
- A1(string color) { this->color = color; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- };
- class A3 {
- private:
- string name;
- public:
- A3(string name) { this->name = name; }
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- };
- class B1 : private A1{
- private:
- string color;
- public:
- B1(string color, int age) : A1(color) {
- this->color = color;
- }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- };
- class B2 : public A1, public A3 {
- private:
- int age;
- public:
- B2(string color, int age, string name) : A1(color), A3(name) {
- this->age = age;
- }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- };
- class B3 : protected A3 {
- private:
- string name;
- public:
- B3(int age, string name) : A3(name) {
- this->name = name;
- }
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- };
- class C1 : protected B1, public B2 {
- private:
- string color;
- int age;
- public:
- C1(string color, int age, string name) : B1(color, age), B2(color, age, name) {
- this->color = color; this->age = age;
- }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- };
- class C2 : private B1, public B2, protected B3 {
- private:
- string name;
- int age;
- string color;
- public:
- C2(string color, int age, string name) : B1(color, age), B2(color, age, name), B3(age, name) {
- this->name = name; this->age = age; this->color = color;
- }
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- };
- class C3 : protected B2, private B3 {
- string name;
- int age;
- string color;
- public:
- C3(string color, int age, string name) : B2(color, age, name), B3(age, name) {
- this->name = name; this->age = age; this->color = color;
- }
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- };
- class D1 : private C1, public C2 {
- private:
- string name;
- int age;
- string color;
- public:
- D1(string color, int age, string name) : C1(color, age, name), C2(color, age, name) {
- this->name = name; this->age = age; this->color = color;
- }
- D1() : C1("", 0, ""), C2("", 0, "") {}
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- friend ostream& operator<< (ostream& os, D1& d1) {
- os << "D1(" << d1.getName() << ")" << endl;
- return os;
- }
- friend istream& operator>> (istream& is, D1& d1) {
- string in;
- cin >> in; assert(in == "D1(");
- cin >> d1.color;
- cin >> in; assert(",");
- cin >> d1.age;
- cin >> in; assert(",");
- cin >> d1.name;
- cin >> in; assert(")");
- return is;
- }
- };
- class D2 : protected C2, public C3 {
- private:
- string name;
- int age;
- string color;
- public:
- D2(string color, int age, string name) : C2(color, age, name), C3(color, age, name) {
- this->name = name; this->age = age; this->color = color;
- }
- D2() : C2("", 0, ""), C3("", 0, "") {}
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- friend ostream& operator<< (ostream& os, D2& d2) {
- os << "D2(" << d2.getName() << ")" << endl;
- return os;
- }
- friend istream& operator>> (istream& is, D2& d2) {
- string in;
- cin >> in; assert(in == "D2(");
- cin >> d2.color;
- cin >> in; assert(",");
- cin >> d2.age;
- cin >> in; assert(",");
- cin >> d2.name;
- cin >> in; assert(")");
- return is;
- }
- };
- class E1 : public D1, public D2
- {
- private:
- bool isJedi;
- string name;
- int age;
- string color;
- public:
- E1() : D1(), D2() {}
- void SetJediStatus(bool JediStatus) { isJedi = JediStatus; };
- bool GetJediStatus() { return isJedi; };
- string& getName() { return name; }
- void setName(string name) { this->name = name; }
- int getAge() { return age; }
- void setAge(int age) { this->age = age; }
- string& getColor() { return color; }
- void setColor(string color) { this->color = color; }
- E1(string color, int age, string name, bool JediStatus) : D2(color, age, name), D1(color, age, name)
- {
- isJedi = JediStatus;
- this->name = name;
- this->age = age;
- this->color = color;
- }
- friend ostream& operator<< (ostream& os, E1& e1) {
- os << e1.getName() << " " << e1.getAge()<<" year old, with "<<
- e1.getColor() <<" color of hair ";
- e1.GetJediStatus() == true ? os << "is jedi!" : os << "isn't jedi!";
- return os;
- }
- friend istream& operator>> (istream& is, E1& e1) {
- string in;
- cin >> in; assert(in == "jedi(");
- cin >> e1.color;
- cin >> in; assert(",");
- cin >> e1.age;
- cin >> in; assert(",");
- cin >> e1.name;
- cin >> in; assert(",");
- cin >> in;
- bool jediStatus = in == "1" ? true : false;
- e1.SetJediStatus(jediStatus);
- cin >> in; assert(")");
- return is;
- }
- };
- int main() {
- //D1 d1; D2 d2;
- //cin >> d1; cin >> d2;
- //cout << "D1(" << d1.getColor() << ", " << d1.getAge() << ", " << d1.getName() << ")" << endl;
- //cout << "D2(" << d2.getColor() << ", " << d2.getAge() << ", " << d2.getName() << ")" << endl;
- //C1 c1("yellow", 44, "mr"); C2 c2("white", 13, "hello"); C3 c3("black", 33, "mss");
- //cout << "C1(" << c1.getColor() << ", " << c1.getAge() << ", " << c1.getName() << ")" << endl;
- //cout << "C2(" << c2.getColor() << ", " << c2.getAge() << ", " << c2.getName() << ")" << endl;
- //cout << "C3(" << c3.getColor() << ", " << c3.getAge() << ", " << c3.getName() << ")" << endl;
- //B2 b2("pink", 6, "Him");
- //cout << "B2(" << b2.getColor() << ", " << b2.getAge() << ", " << b2.getName() << ")" << endl;
- //A1 a1("COLOR"); A3 a3("NAME");
- //cout << "A1(" << a1.getColor() << ")" << endl;
- //cout << "A3(" << a3.getName() << ")" << endl;
- E1 e1("red", 21, "Darth Vader", true);
- cout << e1 <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement