Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- 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 <<endl<< setw(5)<<right << obj->name;
- for (auto obj2 : obj->pointers) {
- cout << endl << setw(9) << right << obj2->name;
- for (auto obj3 : obj2->pointers) {
- cout << endl << setw(13) << right << obj3->name;
- for (auto obj4 : obj3->pointers) {
- cout << endl << setw(17) << right << obj4->name;
- for (auto obj5 : obj4->pointers) {
- cout << endl << setw(21) << right << obj5->name;
- for (auto obj6 : obj5->pointers) {
- cout << endl << setw(25) << right << obj6->name;
- }
- }
- }
- }
- }
- }
- }
- };
- 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);
- }
- };
- class fifth : public Base
- {
- public:
- fifth(string headname, string name, int num, Base* obj) : Base(headname, name, num)
- {
- obj->pointers.push_back(this);
- }
- };
- class sixth : public Base
- {
- public:
- sixth(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;
- fifth* obj5;
- sixth* obj6;
- 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);
- else if (headnum == 5)
- obj5 = new fifth(headname, name, num, obj);
- else if (headnum == 6)
- obj6 = new sixth(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 << "Object tree"<<endl;
- cout << obj.name;
- obj.dataout();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement