Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class Base
- {
- public:
- string name, headname;
- int flag;
- vector <Base*> pointers;
- Base(string name)
- {
- this->headname = "";
- this->name = name;
- this->flag = 1;
- }
- Base(string headname, string name, int num)
- {
- this->headname = headname;
- this->name = name;
- this->flag = num;
- }
- Base* src(string name)
- {
- static Base* sobj;
- for (auto obj : pointers)
- {
- if (obj->name == name)
- {
- sobj = obj;
- break;
- }
- obj->src(name);
- }
- return sobj;
- }
- void create(string headname, string name, int headnum, int num);
- void dataout()
- {
- for (auto obj : pointers)
- {
- cout << "\nThe object " << obj->name;
- if (obj->flag >= 1) cout << " is ready";
- else cout << " is not ready";
- obj->dataout();
- }
- }
- };
- class second : public Base
- {
- public:
- second(string headname, string name, int num, Base* obj) : Base(headname, name, num)
- {
- obj->pointers.push_back(this);
- }
- };
- class third : public Base
- {
- public:
- third(string headname, string name, int num, Base* obj) : Base(headname, name, num)
- {
- obj->pointers.push_back(this);
- }
- };
- class fourth : public Base
- {
- public:
- fourth(string headname, string name, int num, Base* obj) : Base(headname, name, num)
- {
- obj->pointers.push_back(this);
- }
- };
- void Base::create(string headname, string name, int headnum, int num)
- {
- Base* obj;
- second* obj2;
- third* obj3;
- fourth* obj4;
- if (headname == this->name)
- obj = this;
- else
- obj = src(headname);
- if (headnum == 2)
- obj2 = new second(headname, name, num, obj);
- else if (headnum == 3)
- obj3 = new third(headname, name, num, obj);
- else if (headnum == 4)
- obj4 = new fourth(headname, name, num, obj);
- }
- int main()
- {
- int headnum, num;
- string headname, name;
- cin >> name;
- Base obj(name);
- while (true)
- {
- cin >> headname;
- if (headname == "endtree")
- break;
- cin >> name >> headnum >> num;
- obj.create(headname, name, headnum, num);
- }
- cout << "The object " << obj.name << " is ready";
- obj.dataout();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement